Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %token EOF
- %token <string> ID
- %token <int> INT
- %token <string> STRING
- %token COMMA COLON SEMICOLON LPAREN RPAREN LBRACKET RBRACKET LBRACE RBRACE DOT PLUS MINUS EQ NEQ LT LE GT GE OR ARRAY IF THEN ELSE WHILE FOR TO DO LET IN END OF BREAK NIL FUNCTION VAR TYPE AND COLON_EQ
- %token UMINUS
- %token TIMES DIVIDE
- %right OF
- %nonassoc COLON_EQ
- %nonassoc THEN
- %nonassoc ELSE
- %left AND OR
- %nonassoc EQ NEQ LT LE GT GE
- %left PLUS MINUS
- %left TIMES DIVIDE
- %nonassoc UMINUS
- %type<unit>program
- %start program
- %%
- decs:
- | {}
- | decs dec {}
- ;
- type_id:
- | ID {}
- ;
- dec:
- | tydec {}
- | vardec {}
- | fundec {}
- ;
- tydec:
- | TYPE type_id EQ ty {}
- ;
- ty:
- | type_id {}
- | LBRACE tyfields RBRACE {}
- | ARRAY OF type_id {}
- ;
- tyfields:
- | {}
- | ID COLON type_id {}
- | tyfields COMMA ID COLON type_id {}
- ;
- vardec:
- | VAR ID COLON EQ exp {}
- | VAR ID COLON type_id COLON EQ exp {}
- ;
- procedure_declaration:
- | FUNCTION ID LPAREN tyfields RPAREN EQ exp {}
- ;
- fundec:
- | procedure_declaration {}
- | FUNCTION ID LPAREN tyfields RPAREN COLON type_id EQ exp {}
- ;
- program:
- | exp EOF {}
- ;
- exp:
- (*lvalue*)
- | ID {}
- | lvalue_not_ID {}
- | valueless_exp {}
- | NIL {}
- | sequencing {}
- | no_value {}
- | integer_literal {}
- | string_literal {}
- | negation {}
- (*arithmetic*)
- | exp PLUS exp {}
- | exp MINUS exp {}
- | exp TIMES exp {}
- | exp DIVIDE exp {}
- (*comparison*)
- | exp EQ exp {}
- | exp NEQ exp {}
- | exp GE exp {}
- | exp LE exp {}
- | exp GT exp {}
- | exp LT exp {}
- | boolean_operators {}
- | IF exp THEN exp {}
- | IF exp THEN exp ELSE exp {}
- | record_creation {}
- | array_creation {}
- | let_exp {}
- | parentheses {}
- (*assignment*)
- | lvalue COLON_EQ exp {}
- ;
- valueless_exp:
- | function_call {(*que si la fonction est une procédure*)}
- | while_exp {}
- | for_exp {}
- | break {}
- ;
- string_literal:
- | STRING {}
- ;
- integer_literal:
- | INT {print_int $1}
- ;
- negation:
- | MINUS exp %prec UMINUS {}
- ;
- indirect:
- | ID LBRACKET exp RBRACKET {}
- ;
- lvalue:
- | ID {}
- | lvalue_not_ID {}
- ;
- lvalue_not_ID:
- | lvalue DOT ID {}
- | ID LBRACKET exp RBRACKET {}
- | lvalue_not_ID LBRACKET exp RBRACKET {}
- ;
- sequencing:
- | LPAREN exp_seq RPAREN {}
- ;
- exp_seq:
- | exp SEMICOLON exp {}
- | exp_seq SEMICOLON exp {}
- ;
- no_value:
- | LPAREN RPAREN {}
- ;
- function_call:
- | ID LPAREN RPAREN {}
- | ID LPAREN function_params RPAREN {}
- ;
- function_params:
- | exp {}
- | function_params COMMA exp {}
- ;
- boolean_operators:
- | exp AND exp {}
- | exp OR exp {}
- ;
- record_creation:
- type_id LBRACE record_fields RBRACE {}
- ;
- record_fields:
- | {}
- | ID EQ exp {}
- | record_fields COMMA ID EQ exp {}
- ;
- array_creation:
- | indirect OF exp {}
- ;
- while_exp:
- | WHILE exp DO valueless_exp {}
- ;
- for_exp:
- | FOR ID COLON_EQ exp TO exp DO valueless_exp {}
- ;
- break:
- | BREAK {}
- ;
- let_exp:
- | LET decs IN expseq END {}
- ;
- parentheses:
- | LPAREN exp RPAREN {}
- ;
- expseq:
- | {}
- | exp {}
- | expseq SEMICOLON exp {}
- ;
- (*Sub expressions*)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement