ivprog.g4 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. : 'devolva'
  41. ;
  42. RK_FOR
  43. : 'repita_para'
  44. ;
  45. RK_FOR_FROM
  46. : 'de'
  47. ;
  48. RK_FOR_TO
  49. : 'ate'
  50. ;
  51. RK_FOR_PASS
  52. : 'passo'
  53. ;
  54. RK_BREAK
  55. : 'pare'
  56. ;
  57. RK_DO
  58. : 'faca'
  59. ;
  60. RK_WHILE
  61. : 'enquanto'
  62. ;
  63. RK_IF
  64. : 'se'
  65. ;
  66. RK_ELSE
  67. : 'senao'
  68. ;
  69. RK_FALSE
  70. : 'falso'
  71. ;
  72. RK_TRUE
  73. : 'verdadeiro'
  74. ;
  75. fragment RK_LOGICAL_NOT
  76. : 'nao'
  77. ;
  78. fragment RK_LOGICAL_AND
  79. : 'E'
  80. ;
  81. fragment RK_LOGICAL_OR
  82. : 'OU'
  83. ;
  84. RK_REFERENCE
  85. : '&'
  86. ;
  87. // END i18n Lexical rules
  88. // GAMBIARRA : '.' |'á'| 'à'| 'ã'|'â'|'é'|'ê'|'í'|'ó'|'ô'|'õ'|'ú'|'ü'|'ç'|'Ä'|'À'|'Ã'|'Â'|'É'|'Ê'|'Ë'|'Ó'|'Ô'|'Õ'|'Ú'|'Ü'|'Ç'|'#'|'$'|'"'|'§'|'?'|'¹'|'²'|'³'|'£'|'¢'|'¬'|'ª'|'º'|'~'|'\''|'`'|'\\'|'@';
  89. OPEN_PARENTHESIS
  90. : '('
  91. ;
  92. CLOSE_PARENTHESIS
  93. : ')'
  94. ;
  95. OPEN_BRACE
  96. : '['
  97. ;
  98. CLOSE_BRACE
  99. : ']'
  100. ;
  101. OPEN_CURLY
  102. : '{'
  103. ;
  104. CLOSE_CURLY
  105. : '}'
  106. ;
  107. COMMA
  108. : ','
  109. ;
  110. EQUAL
  111. : '<-'
  112. | '←'
  113. ;
  114. SUM_OP
  115. : ('+'|'-')
  116. ;
  117. MULTI_OP
  118. : ('*'|'/'|'%')
  119. ;
  120. AND_OPERATOR
  121. : RK_LOGICAL_AND
  122. ;
  123. OR_OPERATOR
  124. : RK_LOGICAL_OR
  125. ;
  126. RELATIONAL_OPERATOR
  127. : ('>='|'=='|'<='|'>'|'<'|'!=')
  128. ;
  129. COLON
  130. : ':'
  131. ;
  132. NOT_OPERATOR
  133. : RK_LOGICAL_NOT
  134. ;
  135. ID
  136. : [a-zA-Z_] [a-zA-Z0-9_]*
  137. ;
  138. LIB_ID
  139. : ID '.' ID
  140. ;
  141. INTEGER
  142. : [0-9]+
  143. | ('0x'|'0X')(HEX_DIGIT)+
  144. | ('0b'|'0B')[0-1]+
  145. ;
  146. REAL
  147. : [0-9]+ '.' [0-9]+
  148. | [0-9]+ '.' [0-9]* ExponentPart
  149. ;
  150. fragment ExponentPart
  151. : [eE] [+-]? [0-9]+
  152. ;
  153. STRING
  154. : '"' STRING_CHARACTER* '"'
  155. ;
  156. fragment STRING_CHARACTER //String as defined at https://github.com/antlr/grammars-v4/blob/master/java8/Java8.g4
  157. : ~["\\\r\n]
  158. | ESC_SEQ
  159. ;
  160. CHARACTER //Character as defined at https://github.com/antlr/grammars-v4/blob/master/java8/Java8.g4
  161. : '\'' ( ESC_SEQ | ~['\\\r\n]) '\''
  162. ;
  163. WHITESPACE
  164. : ( ' ' | '\t') -> skip
  165. ;
  166. fragment SEMICOLON
  167. : ';'
  168. ;
  169. EOS
  170. : [\r\n]+
  171. | SEMICOLON
  172. ;
  173. fragment HEX_DIGIT
  174. : [0-9a-fA-F]
  175. ;
  176. fragment OCTAL_DIGIT
  177. : [0-7]
  178. ;
  179. fragment ESC_SEQ
  180. : '\\' ('b'|'t'|'n'|'f'|'r'|'"'|'\''|'\\')
  181. | ESC_UNICODE
  182. | ESC_OCTAL
  183. ;
  184. fragment ESC_OCTAL
  185. : '\\' [0-3] OCTAL_DIGIT OCTAL_DIGIT
  186. | '\\' OCTAL_DIGIT OCTAL_DIGIT
  187. | '\\' OCTAL_DIGIT
  188. ;
  189. fragment ESC_UNICODE
  190. : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
  191. ;
  192. COMMENTS
  193. : ('//' ~('\n'|'\r')* '\r'? '\n'
  194. | '/*' .*? '*/') -> channel(HIDDEN)
  195. ;