ivprog.g4 2.6 KB

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