// **************** // grammar rules // this is the grammar for the simple language. it has standard C/Java semantics for its // statements and function calls. // this grammar does not implement any precedence or associativity for its arithmetic // operators, this needs to be implemented with the appropriate parser generator prog : stmtlist stmtList : stmt | stmtList stmt stmt : returnType VAR '(' ')' stmt | returnType VAR '(' formalParamList ')' stmt | dataType VAR ('=' exp)? ';' | VAR '=' exp ';' | VAR '(' ')' ';' | VAR '(' actualParamList ')' ';' | 'return' ';' | 'return' exp ';' | 'while' '(' exp ')' stmt | 'if' '(' exp ')' stmt | 'if' '(' exp ')' stmt 'else' stmt | '{' stmt+ '}' dataType : 'int' | 'float' returnType : 'void' | dataType formalParamList : dataType VAR | formalParamList ',' dataType VAR actualParamList : exp | actualParamList ',' exp exp : exp '==' exp | exp '<=' exp | exp '+' exp | exp '-' exp | exp '*' exp | exp '/' exp | atom atom : '(' exp ')' | VAR '(' ')' | VAR '(' actualParamList ')' | VAR | INT | FLOAT //************************************************************************* // lexical analyzer stuff - this will need to be processed by lex/flex VAR : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* INT : '-'?'0'..'9'+; FLOAT : '-'?('0'..'9')+ '.' ('0'..'9')* EXPONENT? | '-'?'.' ('0'..'9')+ EXPONENT? | '-'?('0'..'9')+ EXPONENT EXPONENT : ('e'|'E') ('+'|'-')? ('0'..'9')+