%{ #include "bisonUtils.h" #include extern int yylex(); extern void yyerror(char *s); %} %error-verbose %token '=' %token '.' %token '{' %token '}' %token '(' %token ')' %token ':' %token ';' %token ',' %token KEYWORD %token NUM %token COMPOP %token SYMBOL %token THIS %token PRIVATE %token VAR %token NUMBER %token IF %token ELSE %left '+' '-' %left '*' '/' %type NomCompose %type Arg ArgList FuncCall %type Operand Expr %type TypedName VarDef %type SimpleInst AssignInst %type ExpLog IfInst %type Inst ListInst InstBlock ListInstBlock %union { char * stringVal; } %% Programme: | Programme Element {fprintf(stderr, "");} Element: KEYWORD {fprintf(stderr, "", $1); } | ListInstBlock | error ; ListInstBlock: InstBlock {fprintf(stderr, "", $1); } | ListInstBlock InstBlock {fprintf(stderr, "", $1); } InstBlock: '{' ListInst '}'{ $$ = c3($1, $2, $3);} ListInst: Inst {fprintf(stderr, "", $1); $$ = copy($1);} | ListInst Inst {fprintf(stderr, "", $2); $$ = c2($1, $2);} Inst: SimpleInst {fprintf(stderr, "", $1); $$ = copy($1);} | IfInst {fprintf(stderr, "", $1); $$ = copy($1);} IfInst: IF '(' ExpLog ')' SimpleInst {$$ = c5($1, $2, $3, $4, $5);} | IF '(' ExpLog ')' SimpleInst ELSE SimpleInst {$$ = c7($1, $2, $3, $4, $5, $6, $7);} | IF '(' ExpLog ')' SimpleInst ELSE IfInst {$$ = c7($1, $2, $3, $4, $5, $6, $7);} ExpLog: Expr COMPOP Expr {$$ = c3($1, $2, $3);} SimpleInst: Expr ';' {fprintf(stderr, "", $1); $$ = copy($1);} | VarDef ';' {fprintf(stderr, "", $1); $$ = copy($1);} | AssignInst ';' {fprintf(stderr, "", $1); $$ = copy($1);} ; AssignInst: NomCompose '=' Expr {$$ = c3($1, $2, $3);} ; VarDef: PRIVATE VAR TypedName { fprintf(stderr, "", $3); $$ = c3($1, $2, $3); } | VAR TypedName { fprintf(stderr, "", $2); $$ = c2($1, $2); } ; TypedName: NomCompose ':' NUMBER { $$ = c3($1, $2, $3);} | NomCompose ':' NomCompose { $$ = c3($1, $2, $3);} ; Expr: Operand { fprintf(stderr, "", $1); $$ = copy($1);} | Expr '+' Operand { $$ = c3($1, $2, $3); } | Expr '-' Operand { $$ = c3($1, $2, $3); } | Expr '*' Operand { $$ = c3($1, $2, $3); } | Expr '/' Operand { $$ = c3($1,$2, $3); } ; Operand: Arg { fprintf(stderr, "", $1); $$ = copy($1); } | FuncCall { fprintf(stderr, "", $1); $$ = copy($1); } ; FuncCall: NomCompose '(' ')' {$$ = c3($1, $2, $3); } | NomCompose '(' ArgList ')' {$$ = c4($1, $2, $3, $4); fprintf(stderr, " = %s", $3);} ArgList: Arg {fprintf(stderr, "", $1); $$ = copy($1); } | ArgList ',' Arg { fprintf(stderr, "", $3); $$ = c3($1, $2, $3); } Arg: NUM {$$ = copy($1); } | NomCompose {fprintf(stderr, "", $1); $$ = copy($1);} NomCompose: SYMBOL {fprintf(stderr, "", $1); $$ = copy($1); } | THIS {fprintf(stderr, "", $1); $$ = copy($1); } | NomCompose '.' SYMBOL {fprintf(stderr, "", $3); $$ = c3($1,$2,$3); } %%