Last active
February 18, 2017 20:23
-
-
Save pedroduartecosta/d63fb50bbe80db257f7c223bf6da3785 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PARSER_BEGIN(Exemplo) | |
// código Java que invoca o parser | |
public class Exemplo { | |
public static void main(String args[]) throws ParseException { | |
// criação do objecto utilizando o constructor com argumento para | |
// ler do standard input (teclado) | |
Exemplo parser = new Exemplo(System.in); | |
parser.Aritm(); | |
} | |
} | |
PARSER_END(Exemplo) | |
// símbolos que não devem ser considerados na análise | |
SKIP : | |
{ | |
" " | "\t" | "\r" | |
} | |
// definição dos tokens (símbolos terminais) | |
TOKEN : | |
{ | |
<INTEGER: (["0"-"9"])+> | <LF: "\n"> | |
} | |
// definição da produção | |
void Aritm() : {} | |
{ | |
<INTEGER> ( ("+" | "-") <INTEGER> )? <LF> // “(...)?” é equivalente a “[...]” | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment