ivprog.g4 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. lexer grammar ivprog;
  2. @lexer::members{
  3. //Translate to fit your language
  4. ivprog.MAIN_FUNCTION_NAME = "start";
  5. ivprog.READ_FUNCTION_NAME = "read";
  6. ivprog.WRITE_FUNCTION_NAME = "write";
  7. }
  8. // BEGIN i18n Lexical rules
  9. RK_PROGRAM
  10. : 'program'
  11. ;
  12. RK_REAL
  13. : 'real'
  14. ;
  15. RK_VOID
  16. : 'void'
  17. ;
  18. RK_BOOLEAN
  19. : 'boolean'
  20. ;
  21. RK_STRING
  22. : 'string'
  23. ;
  24. RK_INTEGER
  25. : 'integer'
  26. ;
  27. RK_CHARACTER
  28. : 'character'
  29. ;
  30. RK_SWITCH
  31. : 'switch'
  32. ;
  33. RK_CASE
  34. : 'case'
  35. ;
  36. RK_DEFAULT
  37. : 'otherwise'
  38. ;
  39. RK_CONST
  40. : 'const'
  41. ;
  42. RK_FUNCTION
  43. : 'function'
  44. ;
  45. RK_RETURN
  46. : 'return'
  47. ;
  48. RK_FOR
  49. : 'for'
  50. ;
  51. RK_BREAK
  52. : 'break'
  53. ;
  54. RK_DO
  55. : 'do'
  56. ;
  57. RK_WHILE
  58. : 'while'
  59. ;
  60. RK_IF
  61. : 'if'
  62. ;
  63. RK_ELSE
  64. : 'else'
  65. ;
  66. RK_FALSE
  67. : 'false'
  68. ;
  69. RK_TRUE
  70. : 'true'
  71. ;
  72. fragment RK_LOGICAL_NOT
  73. : 'not'
  74. ;
  75. fragment RK_LOGICAL_AND
  76. : 'AND'
  77. ;
  78. fragment RK_LOGICAL_OR
  79. : 'OR'
  80. ;
  81. // END i18n Lexical rules
  82. // GAMBIARRA : '.' |'á'| 'à'| 'ã'|'â'|'é'|'ê'|'í'|'ó'|'ô'|'õ'|'ú'|'ü'|'ç'|'Ä'|'À'|'Ã'|'Â'|'É'|'Ê'|'Ë'|'Ó'|'Ô'|'Õ'|'Ú'|'Ü'|'Ç'|'#'|'$'|'"'|'§'|'?'|'¹'|'²'|'³'|'£'|'¢'|'¬'|'ª'|'º'|'~'|'\''|'`'|'\\'|'@';
  83. OPEN_PARENTHESIS
  84. : '('
  85. ;
  86. CLOSE_PARENTHESIS
  87. : ')'
  88. ;
  89. OPEN_BRACE
  90. : '['
  91. ;
  92. CLOSE_BRACE
  93. : ']'
  94. ;
  95. OPEN_CURLY
  96. : '{'
  97. ;
  98. CLOSE_CURLY
  99. : '}'
  100. ;
  101. COMMA
  102. : ','
  103. ;
  104. EQUAL
  105. : '='
  106. ;
  107. SUM_OP
  108. : ('+'|'-')
  109. ;
  110. MULTI_OP
  111. : ('*'|'/'|'%')
  112. ;
  113. AND_OPERATOR
  114. : RK_LOGICAL_AND
  115. ;
  116. OR_OPERATOR
  117. : RK_LOGICAL_OR
  118. ;
  119. RELATIONAL_OPERATOR
  120. : ('>='|'=='|'<='|'>'|'<'|'!=')
  121. ;
  122. COLON
  123. : ':'
  124. ;
  125. NOT_OPERATOR
  126. : RK_LOGICAL_NOT
  127. ;
  128. ID
  129. : [a-zA-Z_] [a-zA-Z0-9_]*
  130. ;
  131. // ID_BIBLIOTECA : ID '.' ID;
  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. ;