You are on page 1of 3

%{ #include <stdio.h> #include "parseTree.

h" %} %union { /* Lexical */ int ival; float rval; char *sval; int opval; /* Parse Tree */ struct parseTree *tval; } %token %token %token %token %token %token %token %token %token %token %token %token %token %token VAR INTEGER REAL ARRAY OF DOTDOT IF ELSE THEN WHILE DO PROGRAM FUNCTION PROCEDURE BEGIN END ASSIGNOP <OPVAL> RELOP LT LE GT GE EQ NE <OPVAL> ADDOP PLUS MINUS OR <OPVAL> MULOP STAR SLASH DIV MOD AND NOT

%token <sval> ID %token <ival> INUM %token <rval> RNUM %type %type %type %type %type %type %type %type %type %type %type %% program : PROGRAM ID '(' identifier_list ')' ';' declarations subprogram_declarations compound_statement '.' ; <tval> <tval> <tval> <tval> <tval> <tval> <tval> <tval> <tval> <tval> <tval> optional_statements statement_list statement compound_statement procedure_statement variable expression_list expression simple_expression term factor

identifier_list : ID | identifier_list ',' ID ; declarations : declarations VAR identifier_list ':' type ';' | ; type : standard_type | ARRAY '[' INUM DOTDOT INUM ']' OF standard_type ; standard_type : INTEGER | REAL ; subprogram_declarations : subprogram_declarations subprogram_declaration ';' | ; subprogram_declaration : subprogram_head declarations subprogram_declaration compound_statement ; subprogram_head : FUNCTION ID arguments ':' standard_type ';' | PROCEDURE ID arguments ';' ; arguments : '(' parameter_list ')' | ; parameter_list : identifier_list ':' type | parameter_list ';' identifier_list ':' type ; compound_statement : BEGIN optional_statements END ; optional_statements : statement_list | ; statement_list : statement | statement_list ';' statement ;

statement : | | | | ;

variable ASSIGNOP expression procedure_statement compound_statement IF expression THEN statement ELSE statement WHILE expression DO statement

variable : ID | ID '[' expression ']' ; procedure_statement : ID | ID '(' expression_list ')' ; expression_list : expression | expression_list ',' expression ; expression : simple_expression | simple_expression RELOP simple_expression ; simple_expression : term | ADDOP term | simple_expression ADDOP term ; term : factor | term MULOP factor ; factor : | | | | | | ; %% ID ID '(' expression_list ')' ID '[' expression_list ']' INUM RNUM '(' expression ')' NOT factor

You might also like