ivprog.g4 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. // 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. LIB_ID
  126. : ID '.' ID
  127. ;
  128. INTEGER
  129. : [0-9]+
  130. | ('0x'|'0X')(HEX_DIGIT)+
  131. | ('0b'|'0B')[0-1]+
  132. ;
  133. REAL
  134. : [0-9]+ '.' [0-9]+
  135. | [0-9]+ '.' [0-9]* ExponentPart
  136. ;
  137. fragment ExponentPart
  138. : [eE] [+-]? [0-9]+
  139. ;
  140. STRING
  141. : '"' STRING_CHARACTER* '"'
  142. ;
  143. fragment STRING_CHARACTER //String as defined at https://github.com/antlr/grammars-v4/blob/master/java8/Java8.g4
  144. : ~["\\\r\n]
  145. | ESC_SEQ
  146. ;
  147. CHARACTER //Character as defined at https://github.com/antlr/grammars-v4/blob/master/java8/Java8.g4
  148. : '\'' ( ESC_SEQ | ~['\\\r\n]) '\''
  149. ;
  150. WHITESPACE
  151. : ( ' ' | '\t') -> skip
  152. ;
  153. fragment SEMICOLON
  154. : ';'
  155. ;
  156. EOS
  157. : [\r\n]+
  158. | SEMICOLON
  159. ;
  160. fragment HEX_DIGIT
  161. : [0-9a-fA-F]
  162. ;
  163. fragment OCTAL_DIGIT
  164. : [0-7]
  165. ;
  166. fragment ESC_SEQ
  167. : '\\' ('b'|'t'|'n'|'f'|'r'|'"'|'\''|'\\')
  168. | ESC_UNICODE
  169. | ESC_OCTAL
  170. ;
  171. fragment ESC_OCTAL
  172. : '\\' [0-3] OCTAL_DIGIT OCTAL_DIGIT
  173. | '\\' OCTAL_DIGIT OCTAL_DIGIT
  174. | '\\' OCTAL_DIGIT
  175. ;
  176. fragment ESC_UNICODE
  177. : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
  178. ;
  179. COMMENTS
  180. : ('//' ~('\n'|'\r')* '\r'? '\n'
  181. | '/*' .*? '*/') -> channel(HIDDEN)
  182. ;