Advertisement
Guest User

sinziii

a guest
Nov 13th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1.  
  2. %%
  3.  
  4. %{
  5.  
  6. private void write(String descricao, String lexema) {
  7. System.out.println(lexema + " - " + descricao);
  8. }
  9. %}
  10.  
  11. %class LexicalAnalyzer
  12.  
  13. %type void
  14.  
  15. Whitespace = [\n| |\t|\r]
  16. Identifier = [_|a-z|A-Z][a-z|A-Z|0-9|_]*
  17. Plus = "+"
  18. Minus = "-"
  19. MUL = "*"
  20. DIV = "/"
  21. INTEGER = 0|[1-9][0-9]*
  22. FLOAT = (([0-9]+[.][0-9]*)|([0-9]*[.][0-9]+))
  23. NEWLINE = [\n]
  24. TEXT = ((['].[^\x]+[']) | ([\"].[^\x]+[\"]))
  25.  
  26.  
  27.  
  28. %%
  29.  
  30. "public" {write("Reserved word public", yytext()); }
  31. "include" {write("Reserved word include ", yytext());}
  32. "print" {write("Write", yytext());}
  33. "read" {write("Read ", yytext());}
  34. "class" {write("Class", yytext());}
  35. "enum" {write("Enum",yytext());}
  36. "int" {write("Integer type", yytext());}
  37. "float" {write("Float", yytext() );}
  38.  
  39. "{" {write("left bracket", yytext());}
  40. "}" {write("right bracket", yytext());}
  41. ";" {write("Instruction end", yytext());}
  42. "(" {write("left parenthesis", yytext());}
  43. ")" {write("right parenthesis", yytext());}
  44. "[" {write("left listpar", yytext());}
  45. "]" {write("right listpar", yytext());}
  46.  
  47. {Whitespace} {write("Whitespace", yytext()); }
  48. {Identifier} {write("Identifier", yytext()); }
  49. {Plus} {write("Plus operator", yytext());}
  50. {Minus} {write("Minus operator", yytext());}
  51. {MUL} {write("Multiplying operator", yytext());}
  52. {DIV} {write("Division operator", yytext());}
  53. {INTEGER} {write("Integer", yytext()); }
  54. {FLOAT} {write("Float ",yytext());}
  55. {NEWLINE} {write("\\n \t - \tnew line escape");}
  56. {TEXT} {write("Text ", yytext());}
  57.  
  58.  
  59. ">" {write("Greater than operator", yytext());}
  60. "<" {write("Less than operator", yytext());}
  61.  
  62. ">=" {write("Greater or equal", yytext());}
  63. "<=" {write("Less or equal", yytext());}
  64.  
  65. "==" {write("Equality operator", yytext());}
  66. "=" {write("Attribution operator", yytext());}
  67.  
  68. "++" {write("Incremental operator", yytext());}
  69. "--" {write("Decrement operator", yytext());}
  70.  
  71. . { throw new RuntimeException("Invalid character " + yytext()); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement