1
0

ivprog.g4 2.8 KB

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