欢迎光临
我们一直在努力

Mini Java编译器(二)-JSP教程,Java技巧及代码

建站超值云服务器,限时71元/月

二、mini java的文法

bnf

goal

::=

mainclass ( typedeclaration )* <eof>

mainclass

::=

"class" identifier "{" "public" "static" "void" "main" "(" "string" "[" "]" identifier ")" "{" printstatement "}" "}"

typedeclaration

::=

classdeclaration

|

classextendsdeclaration

classdeclaration

::=

"class" identifier "{" ( vardeclaration )* ( methoddeclaration )* "}"

classextendsdeclaration

::=

"class" identifier "extends" identifier "{" ( vardeclaration )* ( methoddeclaration )* "}"

vardeclaration

::=

type identifier ";"

methoddeclaration

::=

"public" type identifier "(" ( formalparameterlist )? ")" "{" ( vardeclaration )* ( statement )* "return" expression ";" "}"

formalparameterlist

::=

formalparameter ( formalparameterrest )*

formalparameter

::=

type identifier

formalparameterrest

::=

"," formalparameter

type

::=

arraytype

|

booleantype

|

integertype

|

identifier

arraytype

::=

"int" "[" "]"

booleantype

::=

"boolean"

integertype

::=

"int"

statement

::=

block

|

assignmentstatement

|

arrayassignmentstatement

|

ifstatement

|

whilestatement

|

printstatement

block

::=

"{" ( statement )* "}"

assignmentstatement

::=

identifier "=" expression ";"

arrayassignmentstatement

::=

identifier "[" expression "]" "=" expression ";"

ifstatement

::=

"if" "(" expression ")" statement "else" statement

whilestatement

::=

"while" "(" expression ")" statement

printstatement

::=

"system.out.println" "(" expression ")" ";"

expression

::=

andexpression

|

compareexpression

|

plusexpression

|

minusexpression

|

timesexpression

|

arraylookup

|

arraylength

|

messagesend

|

primaryexpression

andexpression

::=

primaryexpression "&&" primaryexpression

compareexpression

::=

primaryexpression "<" primaryexpression

plusexpression

::=

primaryexpression "+" primaryexpression

minusexpression

::=

primaryexpression "-" primaryexpression

timesexpression

::=

primaryexpression "*" primaryexpression

arraylookup

::=

primaryexpression "[" primaryexpression "]"

arraylength

::=

primaryexpression "." "length"

messagesend

::=

primaryexpression "." identifier "(" ( expressionlist )? ")"

expressionlist

::=

expression ( expressionrest )*

expressionrest

::=

"," expression

primaryexpression

::=

integerliteral

|

trueliteral

|

falseliteral

|

identifier

|

thisexpression

|

arrayallocationexpression

|

allocationexpression

|

notexpression

|

bracketexpression

integerliteral

::=

<integer_literal>

trueliteral

::=

"true"

falseliteral

::=

"false"

identifier

::=

<identifier>

thisexpression

::=

"this"

arrayallocationexpression

::=

"new" "int" "[" expression "]"

allocationexpression

::=

"new" identifier "(" ")"

notexpression

::=

"!" expression

bracketexpression

::=

"(" expression ")"

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » Mini Java编译器(二)-JSP教程,Java技巧及代码
分享到: 更多 (0)