EulisAires

comp

Mar 19th, 2019
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.57 KB | None | 0 0
  1. package atividade1;
  2.  
  3. %%
  4.  
  5. /* Não altere as configurações a seguir */
  6.  
  7. %line
  8. %column
  9. %unicode
  10. //%debug
  11. %public
  12. %standalone
  13. %class Minijava
  14. %eofclose
  15.  
  16. /* Insira as regras léxicas abaixo */
  17. endLine                 = \r
  18.                         | \n
  19.                         | \r\n
  20. whiteSpace              = {endLine} | [ \t\f]
  21. inputCharacter          = [^\r\n]
  22. oneLineComment          = "/" {inputCharacter}* {endLine}?
  23. multipleLineComment     = "/*" [^*] ~"*/" | "/*" "*"+ "/"
  24. commentText             = ([^*] | \*+[^/*])*
  25. documentationComment    = "/**" {commentText} "*"+ "/"
  26. comment                 = {multipleLineComment}
  27.                         | {oneLineComment}
  28.                         | {documentationComment}
  29. reserved            = "boolean"
  30.                         | "class"
  31.                         | "else"
  32.                         | "extends"
  33.                         | "false"
  34.                         | "if"
  35.                         | "int"
  36.                         | "length"
  37.                         | "main"
  38.                         | "new"
  39.                         | "public"
  40.                         | "return"
  41.                         | "static"
  42.                         | "String"
  43.                         | "System.out.println"
  44.                         | "this"
  45.                         | "true"
  46.                         | "void"
  47.                         | "while"
  48. operators               = &&
  49.                         | "=="
  50.                         | "<"
  51.                         | "!="
  52.                         | "+"
  53.                         | "-"
  54.                         | "*"
  55.                         | "!"
  56. delimiters              = ";"
  57.                         | "."
  58.                         | ","
  59.                         | "="
  60.                         | "("
  61.                         | ")"
  62.                         | "{"
  63.                         | "}"
  64.                         | "["
  65.                         | "]"
  66. letter                  = [A-Za-z]
  67. digit                   = [0-9]
  68. underline               = [_]
  69. integer                 = [1-9]{digit}* | 0
  70. expression              = {underline} | {digit} | {letter}
  71. identifier              = ({letter} | {underline})({expression})*
  72.  
  73. %%
  74.  
  75. {reserved}              { System.out.println("token gerado foi um reservado: '" + yytext() + "' na linha: "
  76.                             + yyline + ", coluna: " + yycolumn); }
  77. {operators}             { System.out.println("token gerado foi um operador: '" + yytext() + "' na linha: "
  78.                             + yyline + ", coluna: " + yycolumn); }
  79. {delimiters}            { System.out.println("token gerado foi um delimitador: '" + yytext() + "' na linha: "
  80.                             + yyline + ", coluna: " + yycolumn); }
  81. {identifier}            { System.out.println("token gerado foi um id: '" + yytext() + "' na linha: "
  82.                             + yyline + ", coluna: " + yycolumn); }
  83. {integer}               { System.out.println("token gerado foi um integer: '" + yytext() + "' na linha: "
  84.                             + yyline + ", coluna: " + yycolumn); }
  85. {comment}               { /* Comentários. */ }
  86. {whiteSpace}            { /* Whitespace. */ }
  87.    
  88. /* Insira as regras léxicas no espaço acima */    
  89.      
  90. . { throw new RuntimeException("Caractere ilegal! '" + yytext() + "' na linha: " + yyline + ", coluna: " + yycolumn); }
Add Comment
Please, Sign In to add comment