Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. grammar DeadMG;
  2.  
  3. options {
  4. language = C;
  5. }
  6.  
  7. ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
  8. ;
  9.  
  10. INT : '0'..'9'+
  11. ;
  12.  
  13. FLOAT
  14. : ('0'..'9')+ '.' ('0'..'9')* EXPONENT?
  15. | '.' ('0'..'9')+ EXPONENT?
  16. | ('0'..'9')+ EXPONENT
  17. ;
  18.  
  19. COMMENT
  20. : '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}
  21. | '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;}
  22. ;
  23.  
  24. WS : ( ' '
  25. | '\t'
  26. | '\r'
  27. | '\n'
  28. ) {$channel=HIDDEN;}
  29. ;
  30.  
  31. STRING
  32. : '"' ( ESC_SEQ | ~('\\'|'"') )* '"'
  33. ;
  34.  
  35. CHAR: '\'' ( ESC_SEQ | ~('\''|'\\') ) '\''
  36. ;
  37.  
  38. fragment
  39. EXPONENT : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;
  40.  
  41. fragment
  42. HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;
  43.  
  44. fragment
  45. ESC_SEQ
  46. : '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
  47. | UNICODE_ESC
  48. | OCTAL_ESC
  49. ;
  50.  
  51. fragment
  52. OCTAL_ESC
  53. : '\\' ('0'..'3') ('0'..'7') ('0'..'7')
  54. | '\\' ('0'..'7') ('0'..'7')
  55. | '\\' ('0'..'7')
  56. ;
  57.  
  58. fragment
  59. UNICODE_ESC
  60. : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
  61. ;
  62.  
  63. program
  64. : namespace_scope_definitions;
  65.  
  66. namespace_scope_definitions
  67. : (namespace_definition | type_definition | function_definition | variable_definition)+;
  68.  
  69. type_scope_definitions
  70. : (type_definition | function_definition | variable_definition)*;
  71.  
  72. namespace_definition
  73. : 'namespace' ID '{' namespace_scope_definitions '}';
  74.  
  75. type_definition
  76. : 'type' ID? (':' expression (',' expression)+ )? '{' type_scope_definitions '}';
  77.  
  78. function_definition
  79. : ID '(' function_argument_list ')' ('(' function_argument_list ')')? ('->' expression)? compound_statement;
  80.  
  81. function_argument_list
  82. : expression? ID (':=' expression)? (',' function_argument_list)?;
  83.  
  84. const_volatile_qualifiers
  85. : 'const'? 'volatile'?;
  86.  
  87. variable_definition
  88. : 'static'? const_volatile_qualifiers expression? ID ':=' expression
  89. | 'static'? const_volatile_qualifiers expression ID ('(' expression ')')?;
  90.  
  91. literal_expression
  92. : CHAR
  93. | FLOAT
  94. | INT
  95. | STRING
  96. | 'auto'
  97. | 'type'
  98. | type_definition;
  99.  
  100. primary_expression
  101. : literal_expression
  102. | ID
  103. | '(' expression ')';
  104.  
  105. expression
  106. : assignment_expression;
  107.  
  108. assignment_expression
  109. : logical_or_expression (('=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<='| '>>=' | '&=' | '^=' | '|=') assignment_expression)*;
  110.  
  111. logical_or_expression
  112. : logical_and_expression ('||' logical_and_expression)*
  113. ;
  114.  
  115. logical_and_expression
  116. : inclusive_or_expression ('&&' inclusive_or_expression)*
  117. ;
  118.  
  119. inclusive_or_expression
  120. : exclusive_or_expression ('|' exclusive_or_expression)*
  121. ;
  122.  
  123. exclusive_or_expression
  124. : and_expression ('^' and_expression)*
  125. ;
  126.  
  127. and_expression
  128. : equality_expression ('&' equality_expression)*
  129. ;
  130. equality_expression
  131. : relational_expression (('=='|'!=') relational_expression)*
  132. ;
  133.  
  134. relational_expression
  135. : shift_expression (('<'|'>'|'<='|'>=') shift_expression)*
  136. ;
  137.  
  138. shift_expression
  139. : additive_expression (('<<'|'>>') additive_expression)*;
  140.  
  141. additive_expression
  142. : (multiplicative_expression) ('+' multiplicative_expression | '-' multiplicative_expression)*
  143. ;
  144.  
  145. multiplicative_expression
  146. : (unary_expression) (('*' | '/' | '%') unary_expression)*
  147. ;
  148.  
  149. unary_expression
  150. : postfix_expression
  151. | '++' unary_expression
  152. | '--' unary_expression
  153. | ('&' | '*' | '+' | '-' | '~' | '!') multiplicative_expression
  154. | 'sizeof' unary_expression
  155. ;
  156.  
  157. postfix_expression
  158. : primary_expression
  159. | ('[' expression ']' | '(' (expression)* ')' | '.' ID | '->' ID | '++' | '--')*;
  160.  
  161. initializer_statement
  162. : expression ';'
  163. | variable_definition ';';
  164.  
  165. return_statement
  166. : 'return' expression ';';
  167.  
  168. try_statement
  169. : 'try' compound_statement catch_statement;
  170.  
  171. catch_statement
  172. : 'catch' '(' ID ')' compound_statement catch_statement?
  173. | 'catch' '(' '...' ')' compound_statement;
  174.  
  175. for_statement
  176. : 'for' '(' initializer_statement expression? ';' expression? ')' compound_statement;
  177.  
  178. while_statement
  179. : 'while' '(' initializer_statement ')' compound_statement;
  180.  
  181. do_while_statement
  182. : 'do' compound_statement 'while' '(' expression ')';
  183.  
  184. switch_statement
  185. : 'switch' '(' expression ')' '{' case_statement '}';
  186.  
  187. case_statement
  188. : 'case:' (statement)* case_statement?
  189. | 'default:' (statement)*;
  190.  
  191. if_statement
  192. : 'if' '(' initializer_statement ')' compound_statement;
  193.  
  194. statement
  195. : compound_statement
  196. | return_statement
  197. | try_statement
  198. | initializer_statement
  199. | for_statement
  200. | while_statement
  201. | do_while_statement
  202. | switch_statement
  203. | if_statement;
  204.  
  205. compound_statement
  206. : '{' (statement)* '}';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement