lex/ast-lex-yacc/src/parser.y

62 lines
1.6 KiB
Plaintext

%{
#define COLORS
#include <stdio.h>
#include "extio.h"
extern int yylineno;
int yyerror(char*);
int yylex();
%}
%union {
char *str;
int num;
}
%token Variable
%token Integer
%token <str> Ident
%token <num> Number
%token Operator
%%
program: decllist exprlist;
decllist: decl ';'
| decllist decl ';'
| /* empty */ |
error ';' { notify(ERROR, "in declaration"); };
decl: Variable idlist ':' type { notify(DEBUG, "declaration found"); };
idlist: Ident { notify(DEBUG, "identifier found"); };
| idlist ',' Ident;
type: Integer { notify(DEBUG, "type found"); };
exprlist: expr ';' { notify(DEBUG, "expression discovered"); }
| exprlist expr ';';
expr: '(' expr Operator expr ')'
| error expr Operator expr ')' { notify(ERROR, "missing open parenthesis"); }
| '(' error Operator expr ')' { notify(ERROR, "error in left hand expression"); }
| '(' expr error expr ')' { notify(ERROR, "expected operator in expression"); }
| '(' expr Operator error ')' { notify(ERROR, "error in right hand expression"); }
| '(' expr Operator expr error { notify(ERROR, "missing closing parenthesis"); }
| Ident { notify(DEBUG, "identifier: %s", $1); }
| Number { notify(DEBUG, "number: %08x", yyval.num); }
| error ';' { notify(ERROR, "in expression"); };
%%
int main() {
printf("Bitte geben Sie ein Program ein: \n");
yyparse();
return 0;
}
int yyerror(char *s) {
return 0;
}