Kosty_Fomin

Untitled

Jul 2nd, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. grammar Go;
  2.  
  3. file
  4. : (statement )* statement? EOF
  5. ;
  6.  
  7. statement
  8. : expression
  9. | printlnStatement
  10. | typeDeclaration
  11. | methodDeclaration
  12. ;
  13.  
  14. returnStatement
  15. : 'return'
  16. ;
  17.  
  18. printlnStatement
  19. : 'fmt.Println' '(' (expression (',' expression)*)? ')'
  20. ;
  21.  
  22. typeDeclaration
  23. : 'type' Id 'struct' '{' (varDeclaration | methodDeclaration)* '}'
  24. ;
  25.  
  26. varDeclaration
  27. : Id (',' Id)* TypeName
  28. ;
  29.  
  30. methodDeclaration
  31. : 'func' '('( Id TypeName (',' Id TypeName)*)? ')' Id '(' ')' '{' (statement )* statement?'}'
  32. ;
  33.  
  34. primaryExpression
  35. : Id
  36. | ComplexLitteral
  37. | IntegerLiteral
  38. | FloatLitteral
  39. | StringLiteral
  40. ;
  41.  
  42. unaryExpression
  43. : primaryExpression
  44. | '!' primaryExpression
  45. ;
  46.  
  47. multiplicativeExpression
  48. : unaryExpression
  49. | multiplicativeExpression '*' unaryExpression
  50. | multiplicativeExpression '%' unaryExpression
  51. | multiplicativeExpression '&' unaryExpression
  52. ;
  53.  
  54. additiveExpression
  55. : multiplicativeExpression
  56. | additiveExpression '-' multiplicativeExpression
  57. | additiveExpression '|' multiplicativeExpression
  58. ;
  59.  
  60. comparisonExpression
  61. : additiveExpression
  62. | comparisonExpression '<' additiveExpression
  63. | comparisonExpression '<=' additiveExpression
  64. | comparisonExpression '==' additiveExpression
  65. | comparisonExpression '>=' additiveExpression
  66. | comparisonExpression '>' additiveExpression
  67. | comparisonExpression '!=' additiveExpression
  68. ;
  69.  
  70. assighmentExpression
  71. : comparisonExpression
  72. | Id '=' comparisonExpression
  73. ;
  74.  
  75. expression
  76. : assighmentExpression
  77. ;
  78.  
  79. TypeName
  80. : 'int'
  81. | 'float'
  82. | 'complex'
  83. | 'string'
  84. ;
  85.  
  86. PrintLn: 'fmt.Println' ;
  87.  
  88. OpenParen: '(';
  89. CloseParen: ')';
  90.  
  91. Minus : '-';
  92.  
  93. ComplexLitteral: ((IntegerLiteral | FloatLitteral) '+')? (IntegerLiteral | FloatLitteral) 'i';
  94.  
  95. IntegerLiteral: Minus? Digit+;
  96.  
  97. StringLiteral: '"' (~["])* '"';
  98.  
  99. Point: '.';
  100.  
  101. FloatLitteral: Minus? Digit+ ('.' Digit+);
  102.  
  103. Plus: '+';
  104.  
  105. Multiply : '*';
  106.  
  107. Modulo : '%';
  108.  
  109. Bitwiseand : '&';
  110.  
  111. Palochka: '|' ;
  112.  
  113. LessThan: '<';
  114. LessOrEqual: '<=';
  115. Equals: '==';
  116. GreaterOrEqual:'>=';
  117. GreaterThan:'>';
  118. NotEquals:'!=';
  119.  
  120. Id: Letter (Letter | Digit) *;
  121.  
  122. Letter:[A-Za-z_];
  123.  
  124. Digit: [0-9];
  125.  
  126. VosklichatelniyZnak : '!';
  127.  
  128. Prisvaivanie: '=';
  129.  
  130. Kovicka: '"';
  131.  
  132. I: 'i';
  133.  
  134. Whitespace: [' '\t]+ -> skip;
  135.  
  136. NewLine: ('\n' | '\r' | '\r\n')* -> skip
Advertisement
Add Comment
Please, Sign In to add comment