lex/ast-lex-yacc/main.y

29 lines
584 B
Plaintext

%{
#include <stdio.h>
extern int yylineno;
%}
%token Variable
%token Integer
%token Ident
%token Number
%%
program: decllist exprlist;
decllist: decl ';' | decllist decl ';' | /* empty */ | error ';' { yyerror(" im Deklarationsteil\n"); };
decl: Variable idlist ':' type;
idlist: Ident | idlist ',' Ident;
type: Integer;
exprlist: /* empty */ ;
%%
int main() {
printf("Bitte geben Sie ein Program ein: \n");
yyparse();
return 0;
}
int yyerror(char *s) {
printf("YACC/[ERR] >>> Failed parsing grammar (%d): ```%s```", yylineno, s);
}