Skip to content

Instantly share code, notes, and snippets.

@thauansrx
Created November 8, 2019 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thauansrx/d7af28232551d066d30f019f014d498e to your computer and use it in GitHub Desktop.
Save thauansrx/d7af28232551d066d30f019f014d498e to your computer and use it in GitHub Desktop.
grammar aps_compiladores_c_rec;
/*
Executar
antlr4 Aps.g4
javac Aps*.java
grun Aps prog -gui input.txt
*/
/*
Funciona a regra de precedentes mas contem recursão a esquerda
*/
prog: (atribuicao EOF)*;
atribuicao: IDENTIFICADOR OP_ATRIB expr1 PV;
expr1 : expr1 expr2 | expr1 OP_ARIT1 expr1| expr2;
expr2 : expr2 OP_ARIT2 expr2 | valor;
valor : IDENTIFICADOR | NUMERO;
IDENTIFICADOR : [a-z] ( [a-z] | [0-9] | [_] )*;
OP_ATRIB: [=];
NUMERO: [0-9]+ | [0-9]+ '.' [0-9]+;
OP_ARIT1: [*/];
OP_ARIT2: [+-];
PV: [;];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment