Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- grammar tinyc;
- start : program EOF ;
- program : statement | statement program ;
- statement : decl ';' | assign ';' | branch | loop | out ';' |in ';' ;
- decl : 'int' ID ;
- assign : ID '=' expr | ID '=' in;
- out : 'write' '(' expr ')' ;
- in : 'read' '(' ')' ;
- branch : 'if' '(' relation ')' '{' program '}' | 'if' '(' relation ')' '{' program '}' 'else' '{' program '}' ;
- loop : 'while' '(' relation ')' '{' program '}' ;
- relation : exprBool;
- exprBool : exprBool LT exprBool | exprBool LEQ exprBool | exprBool EQ exprBool | exprBool NEQ exprBool | exprBool GEQ exprBool | exprBool GT exprBool | exprBool OR orExprBool | NOT exprBool | orExprBool ;
- orExprBool : orExprBool AND andExprBool | andExprBool ;
- andExprBool : '(' exprBool ')' | expr ;
- expr : expr ADD term | expr SUB term | term;
- term : term MULT oper | term DIV oper | term MOD oper | oper ;
- oper : '(' expr ')' | NUMBER | ID | in ;
- ADD : '+' ;
- SUB : '-' ;
- DIV : '/' ;
- MOD : '%' ;
- MULT : '*' ;
- AND : '&&' ;
- OR : '||' ;
- NOT : '!' ;
- EQ : '==' ;
- LT : '<' ;
- LEQ : '<=' ;
- GT : '>' ;
- GEQ : '>=' ;
- NEQ : '!=' ;
- ID : [a-z]+ ;
- NUMBER : [0-9]+ ;
- COMMENT : '/*' .*? '*/' -> skip ; // .*? matches anything until the first */
- LINE_COMMENT : '//' ~[\r\n]* -> skip ; // ~[\r\n]* matches anything but \r and \n
- WS : [ \n\t\r]+ -> skip;
- ErrorChar : . ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement