ivprog.g4 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. lexer grammar ivprog;
  2. // BEGIN i18n Lexical rules
  3. RK_PROGRAM
  4. : 'programa'
  5. ;
  6. RK_REAL
  7. : 'real'
  8. ;
  9. RK_VOID
  10. : 'vazio'
  11. ;
  12. RK_BOOLEAN
  13. : 'logico'
  14. ;
  15. RK_STRING
  16. : 'cadeia'
  17. ;
  18. RK_INTEGER
  19. : 'inteiro'
  20. ;
  21. RK_CHARACTER
  22. : 'caractere'
  23. ;
  24. RK_SWITCH
  25. : 'escolha'
  26. ;
  27. RK_CASE
  28. : 'caso'
  29. ;
  30. RK_DEFAULT
  31. : 'contrario'
  32. ;
  33. RK_CONST
  34. : 'const'
  35. ;
  36. RK_FUNCTION
  37. : 'funcao'
  38. ;
  39. RK_RETURN
  40. : 'retorne'
  41. ;
  42. RK_FOR
  43. : 'para'
  44. ;
  45. RK_BREAK
  46. : 'pare'
  47. ;
  48. RK_DO
  49. : 'faca'
  50. ;
  51. RK_WHILE
  52. : 'enquanto'
  53. ;
  54. RK_IF
  55. : 'se'
  56. ;
  57. RK_ELSE
  58. : 'senao'
  59. ;
  60. RK_FALSE
  61. : 'falso'
  62. ;
  63. RK_TRUE
  64. : 'verdadeiro'
  65. ;
  66. fragment RK_LOGICAL_NOT
  67. : 'nao'
  68. ;
  69. fragment RK_LOGICAL_AND
  70. : 'E'
  71. ;
  72. fragment RK_LOGICAL_OR
  73. : 'OU'
  74. ;
  75. // END i18n Lexical rules
  76. // GAMBIARRA : '.' |'á'| 'à'| 'ã'|'â'|'é'|'ê'|'í'|'ó'|'ô'|'õ'|'ú'|'ü'|'ç'|'Ä'|'À'|'Ã'|'Â'|'É'|'Ê'|'Ë'|'Ó'|'Ô'|'Õ'|'Ú'|'Ü'|'Ç'|'#'|'$'|'"'|'§'|'?'|'¹'|'²'|'³'|'£'|'¢'|'¬'|'ª'|'º'|'~'|'\''|'`'|'\\'|'@';
  77. OPEN_PARENTHESIS
  78. : '('
  79. ;
  80. CLOSE_PARENTHESIS
  81. : ')'
  82. ;
  83. OPEN_BRACE
  84. : '['
  85. ;
  86. CLOSE_BRACE
  87. : ']'
  88. ;
  89. OPEN_CURLY
  90. : '{'
  91. ;
  92. CLOSE_CURLY
  93. : '}'
  94. ;
  95. COMMA
  96. : ','
  97. ;
  98. EQUAL
  99. : '='
  100. ;
  101. SUM_OP
  102. : ('+'|'-')
  103. ;
  104. MULTI_OP
  105. : ('*'|'/'|'%')
  106. ;
  107. AND_OPERATOR
  108. : RK_LOGICAL_AND
  109. ;
  110. OR_OPERATOR
  111. : RK_LOGICAL_OR
  112. ;
  113. RELATIONAL_OPERATOR
  114. : ('>='|'=='|'<='|'>'|'<'|'!=')
  115. ;
  116. COLON
  117. : ':'
  118. ;
  119. NOT_OPERATOR
  120. : RK_LOGICAL_NOT
  121. ;
  122. ID
  123. : [a-zA-Z_] [a-zA-Z0-9_]*
  124. ;
  125. // ID_BIBLIOTECA : ID '.' ID;
  126. INTEGER
  127. : [0-9]+
  128. | ('0x'|'0X')(HEX_DIGIT)+
  129. | ('0b'|'0B')[0-1]+
  130. ;
  131. REAL
  132. : [0-9]+ '.' [0-9]+
  133. | [0-9]+ '.' [0-9]* ExponentPart
  134. ;
  135. fragment ExponentPart
  136. : [eE] [+-]? [0-9]+
  137. ;
  138. STRING
  139. : '"' STRING_CHARACTER* '"'
  140. ;
  141. fragment STRING_CHARACTER //String as defined at https://github.com/antlr/grammars-v4/blob/master/java8/Java8.g4
  142. : ~["\\\r\n]
  143. | ESC_SEQ
  144. ;
  145. CHARACTER //Character as defined at https://github.com/antlr/grammars-v4/blob/master/java8/Java8.g4
  146. : '\'' ( ESC_SEQ | ~['\\\r\n]) '\''
  147. ;
  148. WHITESPACE
  149. : ( ' ' | '\t') -> skip
  150. ;
  151. fragment SEMICOLON
  152. : ';'
  153. ;
  154. EOS
  155. : [\r\n]+
  156. | SEMICOLON
  157. ;
  158. fragment HEX_DIGIT
  159. : [0-9a-fA-F]
  160. ;
  161. fragment OCTAL_DIGIT
  162. : [0-7]
  163. ;
  164. fragment ESC_SEQ
  165. : '\\' ('b'|'t'|'n'|'f'|'r'|'"'|'\''|'\\')
  166. | ESC_UNICODE
  167. | ESC_OCTAL
  168. ;
  169. fragment ESC_OCTAL
  170. : '\\' [0-3] OCTAL_DIGIT OCTAL_DIGIT
  171. | '\\' OCTAL_DIGIT OCTAL_DIGIT
  172. | '\\' OCTAL_DIGIT
  173. ;
  174. fragment ESC_UNICODE
  175. : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
  176. ;
  177. COMMENTS
  178. : ('//' ~('\n'|'\r')* '\r'? '\n'
  179. | '/*' .*? '*/') -> channel(HIDDEN)
  180. ;