BNF for Virgil.jj
NON-TERMINALS
Module
::=
(
ProgramDecl
)? (
TypeDecl
)* <EOF>
ProgramDecl
::=
"program" <IDENTIFIER> "{" (
ProgramMember
)* "}"
ProgramMember
::=
EntryPoint
|
ComponentList
EntryPoint
::=
"entrypoint"
EntryPointName
"=" <IDENTIFIER> "." <IDENTIFIER> ";"
EntryPointName
::=
<IDENTIFIER>
ComponentList
::=
"components" "{"
ComponentRef
( ","
ComponentRef
)* "}"
ComponentRef
::=
<IDENTIFIER>
TypeDecl
::=
(
ClassDecl
|
ComponentDecl
) "{" (
Member
)* "}"
ClassDecl
::=
"class" <IDENTIFIER> (
TypeParamDecl
)? ( "extends"
TypeRef
)?
ComponentDecl
::=
"component" <IDENTIFIER>
Member
::=
MethodDecl
|
FieldDecl
|
ConstructorDecl
MethodDecl
::=
MethodModifiers
"method" <IDENTIFIER> (
TypeParamDecl
)?
FormalParams
( ":"
TypeRef
)?
MethodBody
MethodModifiers
::=
( ( "private" ) )*
FieldModifiers
::=
( ( "private" ) )*
FieldDecl
::=
FieldModifiers
"field"
oneFieldDecl
( ","
oneFieldDecl
)* ";"
ConstructorDecl
::=
"constructor"
FormalParams
SuperClause
MethodBody
SuperClause
::=
( ":" "super"
Arguments
)?
oneFieldDecl
::=
<IDENTIFIER> ":"
TypeRef
( "="
Initializer
)?
Initializer
::=
(
ArrayInitializer
|
Expr
)
ArrayInitializer
::=
"{" (
InitializerList
)? "}"
InitializerList
::=
Initializer
( ","
Initializer
)*
FormalParams
::=
"(" (
ParamDecl
( ","
ParamDecl
)* )? ")"
ParamDecl
::=
<IDENTIFIER> ":"
TypeRef
MethodBody
::=
( ";" |
Block
)
Block
::=
"{" (
BlockStmt
)* "}"
BlockStmt
::=
LocalVarDecl
";"
|
Stmt
LocalVarDecl
::=
"local"
oneLocalVarDecl
( ","
oneLocalVarDecl
)*
oneLocalVarDecl
::=
<IDENTIFIER> ( ":"
TypeRef
)? ( "="
Initializer
)?
Expr
::=
ConditionalExpr
( ( <TK_ASSIGN>
Expr
) | ( <TK_CASSIGN>
Expr
) )?
ConditionalExpr
::=
ConditionalOrExpr
( "?"
Expr
":"
ConditionalExpr
)?
ConditionalOrExpr
::=
ConditionalAndExpr
( "or"
ConditionalAndExpr
)*
ConditionalAndExpr
::=
InclusiveOrExpr
( "and"
InclusiveOrExpr
)*
InclusiveOrExpr
::=
ExclusiveOrExpr
( <TK_OR>
ExclusiveOrExpr
)*
ExclusiveOrExpr
::=
AndExpr
( <TK_XOR>
AndExpr
)*
AndExpr
::=
EqualityExpr
( <TK_AND>
EqualityExpr
)*
EqualityExpr
::=
TypeQueryExpr
( <TK_EQ>
TypeQueryExpr
)*
TypeQueryExpr
::=
RelationalExpr
( ( "instanceof" | "<:" )
TypeInExpr
)?
RelationalExpr
::=
ConcatExpr
(
RelationalOp
ConcatExpr
)*
RelationalOp
::=
( "<" | ">" | ">=" | "<=" )
ConcatExpr
::=
ShiftExpr
( <TK_HASH>
ShiftExpr
)*
ShiftExpr
::=
AdditiveExpr
( <TK_SHIFT>
AdditiveExpr
)*
AdditiveExpr
::=
MultiplicativeExpr
( ( <TK_PLUS> | <TK_MINUS> )
MultiplicativeExpr
)*
MultiplicativeExpr
::=
TypeCastExpr
( <TK_MUL>
TypeCastExpr
)*
TypeCastExpr
::=
PostIncDecExpr
( "::"
TypeInExpr
)*
PostIncDecExpr
::=
UnaryExpr
( <TK_INCDEC> )?
UnaryExpr
::=
(
NegativeLiteral
|
UnaryOp
UnaryExpr
|
PreIncDecExpr
|
Term
)
NegativeLiteral
::=
<TK_MINUS> <DECIMAL_LITERAL>
PreIncDecExpr
::=
<TK_INCDEC>
UnaryExpr
UnaryOp
::=
( <TK_COMPL> | <TK_NOT> | <TK_PLUS> | <TK_MINUS> )
Term
::=
( (
TermPrefix
(
Suffix
)* ) | (
NewExpr
(
NewSuffix
)* ) )
Suffix
::=
(
NewSuffix
|
IndexSuffix
)
NewSuffix
::=
(
MemberSuffix
|
AppSuffix
)
TermPrefix
::=
( (
VarUse
) | (
Literal
) | ( "("
Expr
")" ) )
VarUse
::=
<IDENTIFIER>
Literal
::=
( <ZERO_LITERAL> | <BIN_LITERAL> | <OCTAL_LITERAL> | <DECIMAL_LITERAL> | <HEX_LITERAL> | <STRING_LITERAL> | <CHARACTER_LITERAL> | "null" | "this" | "true" | "false" )
NewExpr
::=
( "new"
TypeRef
) (
NewArraySuffix
|
NewObjectSuffix
)
NewArraySuffix
::=
ArrayDims
NewObjectSuffix
::=
Arguments
ArrayDims
::=
( "["
Expr
"]" )+
MemberSuffix
::=
"." <IDENTIFIER>
AppSuffix
::=
Arguments
IndexSuffix
::=
"["
Expr
"]"
Arguments
::=
"(" (
ListExpr
)? ")"
ListExpr
::=
Expr
( ","
Expr
)*
Stmt
::=
(
Block
|
EmptyStmt
|
BreakStmt
|
ContinueStmt
|
ReturnStmt
|
WhileStmt
|
ForStmt
|
IfStmt
|
DoWhileStmt
|
SwitchStmt
|
ExprStmt
)
IfStmt
::=
"if" "("
Expr
")"
Stmt
( "else"
Stmt
)?
SwitchStmt
::=
"switch" "("
Expr
")" "{" (
SwitchCase
)* "}"
SwitchCase
::=
ValueCase
|
DefaultCase
ValueCase
::=
"case" "("
ListExpr
")"
Stmt
DefaultCase
::=
"default"
Stmt
ForStmt
::=
"for" "(" (
ListExpr
)? ";" (
Expr
)? ";" (
ListExpr
)? ")"
Stmt
ExprStmtList
::=
ExprStmt
( ","
ExprStmt
)*
ExprStmt
::=
Expr
";"
EmptyStmt
::=
";"
BreakStmt
::=
"break" ";"
ContinueStmt
::=
"continue" ";"
ReturnStmt
::=
"return" (
Expr
)? ";"
WhileStmt
::=
"while" "("
Expr
")"
Stmt
DoWhileStmt
::=
"do"
Stmt
"while" "("
Expr
")" ";"
TypeRef
::=
(
NestedType
|
ParameterizedType
|
SimpleType
|
FuncType
) ( "[" "]" )*
NestedType
::=
"("
TypeRef
")"
FuncType
::=
( "function" "(" (
TypeList
)? ")" ( ":"
TypeRef
)? )
TypeParamDecl
::=
"<"
TypeParam
( ","
TypeParam
)* ">"
TypeParam
::=
<IDENTIFIER>
ParameterizedType
::=
<IDENTIFIER> "<"
TypeList
">"
TypeList
::=
TypeRef
( ","
TypeRef
)*
TypeInExpr
::=
(
SimpleType
|
NestedType
)
SimpleType
::=
(
SingularType
|
RawType
)
SingularType
::=
<IDENTIFIER>
RawType
::=
<DECIMAL_LITERAL>