一个简单的语言的语法(三):做些小调整,并将生成目标换到CSharp2 - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-14
5. ) 56. ) 57. ( COMMA id2=Identifier 58. ( ( -> $variableDeclaration ^( SIMPLE_VAR_DECL[$id2, "VarDecl"] ^( typeSpecifier) $id2 ) ) 59. | ( EQ exp=expression 60. -> $variableDeclaration ^( SIMPLE_VAR_DECL_INIT [$id2, "VarDeclInit"] ^( typeSpecifier ) $id2 $exp ) ) 61. | ( ( LBRACK dim1+=Integer RBRACK )+ 62. -> $variableDeclaration ^( ARRAY_VAR_DECL[$id2, "VarDecl"] ^( typeSpecifier $dim1+ ) $id2 ) ) 63. | ( ( LBRACK dim2+=Integer RBRACK )+ EQ al=arrayLiteral 64. - > $variableDeclaration ^( ARRAY_VAR_DECL_INIT[$id2, "VarDeclInit"] ^( typeSpecifier $dim2+ ) $id2 $al ) ) 65. ) 66. { if (null != $dim1) $dim1.Clear(); if (null != $dim2) $dim2.Clear(); } 67. )* 68. SEMICOLON 69. ; 70. 71.typeSpecifier 72. : INT | REAL 73. ; 74. 75.arrayLiteral 76. : LBRACE 77. arrayLiteralElement ( COMMA arrayLiteralElement )* 78. RBRACE 79. -> ^( ARRAY_LITERAL [$LBRACE, "Array"] arrayLiteralElement+ ) 80. ; 81. 82.arrayLiteralElement 83. : expression 84. | arrayLiteral 85. ; 86. 87.blockStatement 88. : LBRACE statement+ RBRACE 89. -> ^( BLOCK[$LBRACE, "Block"] statement+ ) 90. | LBRACE RBRACE // empty block 91. -> EMPTY_BLOCK[$LBRACE, "EmptyBlock"] 92. ; 93. 94.ifStatement 95. : IF^ LPAREN! expression RPAREN! statement ( ELSE! statement )? 96. ; 97. 98.whileStatement 99. : WHILE^ LPAREN! expression RPAREN! statement 100. ; 101. 102.breakStatement 103. : BREAK SEMICOLON! 104. ; 105. 106.readStatement 107. : READ^ variableAccess SEMICOLON! 108. ; 109. 110.writeStatement 111. : WRITE^ expression SEMICOLON! 112. ; 113. 114.variableAccess 115. : Identifier 116. ( -> ^( SIMPLE_VAR_ACCESS[$Identifier, "VarAccess"] Identifier ) 117. | ( LBRACK Integer RBRACK )+ 118. -> ^( ARRAY_VAR_ACCESS[$Identifier, "VarAccess"] Identifier Integer+ ) 119. ) 120. ; 121. 122.expression 123. : assignmentExpression 124. | logicalOrExpression 125. ; 126. 127.assignmentExpression 128. : variableAccess EQ^ expression 129. ; 130. 131.logicalOrExpression 132. : logicalAndExpression ( OROR^ logicalAndExpression )* 133. ; 134. 135.logicalAndExpression 136. : relationalExpression ( ANDAND^ relationalExpression )* 137. ; 138. 139.relationalExpression 140. : additiveExpression ( relationalOperator^ additiveExpression )? 141. | BANG^ relationalExpression 142. ; 143. 144.additiveExpression 145. : multiplicativeExpression ( additiveOperator^ multiplicativeExpression )* 146. ; 147. 148.multiplicativeExpression 149. : primaryExpression ( multiplicativeOperator^ primaryExpression )* 150. ; 151. 152.primaryExpression 153. : variableAccess 154. | Integer 155. | RealNumber 156. | LPAREN! expression RPAREN! 157. | MINUS primaryExpression 158. -> ^( UNARY_MINUS[$MINUS] primaryExpression ) 159. ; 160. 161.relationalOperator 162. : LT | GT | EQEQ | LE | GE | NE 163. ; 164. 165.additiveOperator 166. : PLUS | MINUS 167. ; 168. 169.multiplicativeOperator 170. : MUL | DIV 171. ; 172. 173.// lexer rul |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于一个简单的语言的语法(三):做些小调整,并将生成目标换到CSharp2 - 编程入门网的所有评论