1
0

ivprog.g4 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. lexer grammar ivprog;
  2. // BEGIN i18n Lexical rules
  3. RK_PROGRAM
  4. : 'program'
  5. ;
  6. RK_REAL
  7. : 'real'
  8. ;
  9. RK_VOID
  10. : 'void'
  11. ;
  12. RK_BOOLEAN
  13. : 'boolean'
  14. ;
  15. RK_STRING
  16. : 'string'
  17. ;
  18. RK_INTEGER
  19. : 'integer'
  20. ;
  21. RK_CHARACTER
  22. : 'character'
  23. ;
  24. RK_SWITCH
  25. : 'switch'
  26. ;
  27. RK_CASE
  28. : 'case'
  29. ;
  30. RK_DEFAULT
  31. : 'otherwise'
  32. ;
  33. RK_CONST
  34. : 'const'
  35. ;
  36. RK_FUNCTION
  37. : 'function'
  38. ;
  39. RK_RETURN
  40. : 'return'
  41. ;
  42. RK_FOR
  43. : 'for'
  44. ;
  45. RK_BREAK
  46. : 'break'
  47. ;
  48. RK_DO
  49. : 'do'
  50. ;
  51. RK_WHILE
  52. : 'while'
  53. ;
  54. RK_IF
  55. : 'if'
  56. ;
  57. RK_ELSE
  58. : 'else'
  59. ;
  60. RK_FALSE
  61. : 'false'
  62. ;
  63. RK_TRUE
  64. : 'true'
  65. ;
  66. fragment RK_LOGICAL_NOT
  67. : 'not'
  68. ;
  69. fragment RK_LOGICAL_AND
  70. : 'AND'
  71. ;
  72. fragment RK_LOGICAL_OR
  73. : 'OR'
  74. ;
  75. RK_REFERENCE
  76. : '&'
  77. ;
  78. // END i18n Lexical rules
  79. // GAMBIARRA : '.' |'á'| 'à'| 'ã'|'â'|'é'|'ê'|'í'|'ó'|'ô'|'õ'|'ú'|'ü'|'ç'|'Ä'|'À'|'Ã'|'Â'|'É'|'Ê'|'Ë'|'Ó'|'Ô'|'Õ'|'Ú'|'Ü'|'Ç'|'#'|'$'|'"'|'§'|'?'|'¹'|'²'|'³'|'£'|'¢'|'¬'|'ª'|'º'|'~'|'\''|'`'|'\\'|'@';
  80. OPEN_PARENTHESIS
  81. : '('
  82. ;
  83. CLOSE_PARENTHESIS
  84. : ')'
  85. ;
  86. OPEN_BRACE
  87. : '['
  88. ;
  89. CLOSE_BRACE
  90. : ']'
  91. ;
  92. OPEN_CURLY
  93. : '{'
  94. ;
  95. CLOSE_CURLY
  96. : '}'
  97. ;
  98. COMMA
  99. : ','
  100. ;
  101. EQUAL
  102. : '<-'
  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. LIB_ID
  130. : ID '.' ID
  131. ;
  132. INTEGER
  133. : [0-9]+
  134. | ('0x'|'0X')(HEX_DIGIT)+
  135. | ('0b'|'0B')[0-1]+
  136. ;
  137. REAL
  138. : [0-9]+ '.' [0-9]+
  139. | [0-9]+ '.' [0-9]* ExponentPart
  140. ;
  141. fragment ExponentPart
  142. : [eE] [+-]? [0-9]+
  143. ;
  144. STRING
  145. : '"' STRING_CHARACTER* '"'
  146. ;
  147. fragment STRING_CHARACTER //String as defined at https://github.com/antlr/grammars-v4/blob/master/java8/Java8.g4
  148. : ~["\\\r\n]
  149. | ESC_SEQ
  150. ;
  151. CHARACTER //Character as defined at https://github.com/antlr/grammars-v4/blob/master/java8/Java8.g4
  152. : '\'' ( ESC_SEQ | ~['\\\r\n]) '\''
  153. ;
  154. WHITESPACE
  155. : ( ' ' | '\t') -> skip
  156. ;
  157. fragment SEMICOLON
  158. : ';'
  159. ;
  160. EOS
  161. : [\r\n]+
  162. | SEMICOLON
  163. ;
  164. fragment HEX_DIGIT
  165. : [0-9a-fA-F]
  166. ;
  167. fragment OCTAL_DIGIT
  168. : [0-7]
  169. ;
  170. fragment ESC_SEQ
  171. : '\\' ('b'|'t'|'n'|'f'|'r'|'"'|'\''|'\\')
  172. | ESC_UNICODE
  173. | ESC_OCTAL
  174. ;
  175. fragment ESC_OCTAL
  176. : '\\' [0-3] OCTAL_DIGIT OCTAL_DIGIT
  177. | '\\' OCTAL_DIGIT OCTAL_DIGIT
  178. | '\\' OCTAL_DIGIT
  179. ;
  180. fragment ESC_UNICODE
  181. : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
  182. ;
  183. COMMENTS
  184. : ('//' ~('\n'|'\r')* '\r'? '\n'
  185. | '/*' .*? '*/') -> channel(HIDDEN)
  186. ;