Advertisement
k0mZ

Untitled

Nov 29th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. // import sekcija
  2.  
  3. %%
  4.  
  5. // sekcija opcija i deklaracija
  6. %class MPLexer
  7. %function next_token
  8. %line
  9. %column
  10. %debug
  11. %type Yytoken
  12.  
  13. %eofval{
  14. return new Yytoken( sym.EOF, null, yyline, yycolumn);
  15. %eofval}
  16.  
  17. %{
  18. //dodatni clanovi generisane klase
  19. KWTable kwTable = new KWTable();
  20. Yytoken getKW()
  21. {
  22. return new Yytoken( kwTable.find( yytext() ),
  23. yytext(), yyline, yycolumn );
  24. }
  25. %}
  26.  
  27. //stanja
  28. %xstate KOMENTAR
  29. //makroi
  30. slovo = [a-zA-Z]
  31. cifra = [0-9]
  32. oc16 = [0-9A-F]
  33. %%
  34.  
  35. // pravila
  36. "//" { yybegin( KOMENTAR ); }
  37. <KOMENTAR>~[\n\r] { yybegin( YYINITIAL ); }
  38.  
  39. [\t\n\r ] { ; }
  40. \( { return new Yytoken( sym.LEFTPAR, yytext(), yyline, yycolumn ); }
  41. \) { return new Yytoken( sym.RIGHTPAR, yytext(), yyline, yycolumn ); }
  42.  
  43. \{ { return new Yytoken( sym.LCURLY, yytext(), yyline, yycolumn ); }
  44. \} { return new Yytoken( sym.RCURLY, yytext(), yyline, yycolumn ); }
  45.  
  46. // operatori
  47. && { return new Yytoken( sym.AND,yytext(), yyline, yycolumn ); }
  48. \|\| { return new Yytoken( sym.OR,yytext(), yyline, yycolumn ); }
  49. \+ { return new Yytoken( sym.PLUS,yytext(), yyline, yycolumn ); }
  50. \* { return new Yytoken( sym.MUL,yytext(), yyline, yycolumn ); }
  51. \- { return new Yytoken( sym.MIN,yytext(), yyline, yycolumn ); }
  52. \/ { return new Yytoken( sym.DIV,yytext(), yyline, yycolumn ); }
  53. \< { return new Yytoken( sym.LESS,yytext(), yyline, yycolumn ); }
  54. \<= { return new Yytoken( sym.LESSE,yytext(), yyline, yycolumn ); }
  55. \> { return new Yytoken( sym.GREAT,yytext(), yyline, yycolumn ); }
  56. \>= { return new Yytoken( sym.GREATE,yytext(), yyline, yycolumn ); }
  57. == { return new Yytoken( sym.EQ,yytext(), yyline, yycolumn ); }
  58. \!= { return new Yytoken( sym.NEQ,yytext(), yyline, yycolumn ); }
  59. // separatori
  60. ; { return new Yytoken( sym.DOTCOMMA, yytext(), yyline, yycolumn ); }
  61. , { return new Yytoken( sym.COMMA, yytext(), yyline, yycolumn ); }
  62. = { return new Yytoken( sym.ASSIGN, yytext(), yyline, yycolumn ); }
  63.  
  64.  
  65. //kljucne reci
  66. {slovo}+ { return getKW(); }
  67.  
  68. //"main" { return new Yytoken( sym.MAIN, yytext(), yyline, yycolumn );}
  69. //"char" { return new Yytoken( sym.CHAR, yytext(), yyline, yycolumn );}
  70. // "int" { return new Yytoken( sym.INT, yytext(), yyline, yycolumn ); }
  71. // "real" { return new Yytoken( sym.REAL, yytext(), yyline, yycolumn );}
  72. // "bool" { return new Yytoken( sym.BOOL, yytext(), yyline, yycolumn );}
  73. // "read" { return new Yytoken( sym.READ, yytext(), yyline, yycolumn );}
  74. // "write" { return new Yytoken( sym.WRITE, yytext(), yyline, yycolumn );}
  75. // "while" { return new Yytoken( sym.WHILE, yytext(), yyline, yycolumn );}
  76.  
  77. //konstante
  78. {cifra}+ { return new Yytoken( sym.CONST, yytext(), yyline, yycolumn ); }
  79. //real
  80. 0+\.{cifra}+(E[+-]{cifra}*)? { return new Yytoken( sym.CONST,yytext(), yyline, yycolumn ); }
  81. //int
  82. \${oc16}+ { return new Yytoken( sym.CONST, yytext(), yyline, yycolumn); }
  83. {cifra}+ { return new Yytoken( sym.CONST, yytext(), yyline, yycolumn); }
  84. //bool
  85. "true"|"false" { return new Yytoken(sym.CONST, yytext(), yyline, yycolumn); }
  86.  
  87. //ID (prvo slovo ili _ a zatim proizvoljan broj slova i cifara)
  88. ({slovo} | "_")+ ({slovo}|{cifra}|"_")* { return new Yytoken(sym.ID, yytext(),yyline, yycolumn ); }
  89. //char
  90. '[^]' { return new Yytoken( sym.CONST,yytext(), yyline, yycolumn ); }
  91. //obrada gresaka
  92. . { if (yytext() != null && yytext().length() > 0) System.out.println( "ERROR: " + yytext() ); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement