Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %%
- %{
- private void write(String descricao, String lexema) {
- System.out.println(lexema + " - " + descricao);
- }
- %}
- %class LexicalAnalyzer
- %type void
- Whitespace = [\n| |\t|\r]
- Identifier = [_|a-z|A-Z][a-z|A-Z|0-9|_]*
- Plus = "+"
- Minus = "-"
- MUL = "*"
- DIV = "/"
- INTEGER = 0|[1-9][0-9]*
- FLOAT = (([0-9]+[.][0-9]*)|([0-9]*[.][0-9]+))
- NEWLINE = [\n]
- TEXT = ((['].[^\x]+[']) | ([\"].[^\x]+[\"]))
- %%
- "public" {write("Reserved word public", yytext()); }
- "include" {write("Reserved word include ", yytext());}
- "print" {write("Write", yytext());}
- "read" {write("Read ", yytext());}
- "class" {write("Class", yytext());}
- "enum" {write("Enum",yytext());}
- "int" {write("Integer type", yytext());}
- "float" {write("Float", yytext() );}
- "{" {write("left bracket", yytext());}
- "}" {write("right bracket", yytext());}
- ";" {write("Instruction end", yytext());}
- "(" {write("left parenthesis", yytext());}
- ")" {write("right parenthesis", yytext());}
- "[" {write("left listpar", yytext());}
- "]" {write("right listpar", yytext());}
- {Whitespace} {write("Whitespace", yytext()); }
- {Identifier} {write("Identifier", yytext()); }
- {Plus} {write("Plus operator", yytext());}
- {Minus} {write("Minus operator", yytext());}
- {MUL} {write("Multiplying operator", yytext());}
- {DIV} {write("Division operator", yytext());}
- {INTEGER} {write("Integer", yytext()); }
- {FLOAT} {write("Float ",yytext());}
- {NEWLINE} {write("\\n \t - \tnew line escape");}
- {TEXT} {write("Text ", yytext());}
- ">" {write("Greater than operator", yytext());}
- "<" {write("Less than operator", yytext());}
- ">=" {write("Greater or equal", yytext());}
- "<=" {write("Less or equal", yytext());}
- "==" {write("Equality operator", yytext());}
- "=" {write("Attribution operator", yytext());}
- "++" {write("Incremental operator", yytext());}
- "--" {write("Decrement operator", yytext());}
- . { throw new RuntimeException("Invalid character " + yytext()); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement