Program :: ClassDeclaration *
ClassDeclaration :: _Symbol_ (ClassMember *)
ClassMember :: _Symbol_ ClassMemberKind
ClassMemberKind = Field | Method | MainMethod
Field :: Type
Method :: Type (Parameter *) Block
MainMethod :: _Symbol_ Block
Type :: BasicType `u64`
BasicType = _Int_ | _Bool_ | _Void_ | Custom
Custom :: _Symbol_
Parameter :: Type _Symbol_
Block :: Stmt *
Stmt = Block | _Empty_ | If | Expr | While | Return | LocalVariableDeclaration
If :: Expr Stmt (Stmt ?)
While :: Expr Stmt
Return :: Expr ?
LocalVariableDeclaration :: Type _Symbol_ (Expr ?)
Expr = Assignment | Binary | Unary | Postfix | _Null_ | Boolean | Int | Var | MethodPrimary | _This_ | NewObject | NewArray
Assignment :: Expr (Expr *)
Binary :: BinaryOp Expr Expr
Unary :: (UnaryOp *) Expr
Postfix :: Expr (PostfixOp *)
Boolean :: `bool`
Int :: _Symbol_
Var :: _Symbol_
MethodPrimary :: _Symbol_ (Expr *)
NewObject :: _Symbol_
NewArray :: BasicType Expr `u64`
BinaryOp = _Equals_ | _NotEquals_ | _LessThan_ | _GreaterThan_ | _LessEquals_ | _GreaterEquals_ | _LogicalOr_ | _LogicalAnd_ | _Add_ | _Sub_ | _Mul_ | _Div_ | _Mod_
UnaryOp = _Not_ | _Neg_
PostfixOp = MethodInvocation | FieldAccess | ArrayAccess
MethodInvocation :: _Symbol_ (Expr *)
FieldAccess :: _Symbol_
ArrayAccess :: Expr
This is the top-level AST node. It stores all class declarations of the MiniJava program.
This AST node stores the Class declaration, which consists of a name and the members of the class.
This AST node describes a class member. Variants of class members are defined in ClassMemberKind. Every class member has a name.
A class member is either one of
Field
: a declaration of a field of a classMethod
: a method of a classMainMethod
: a main method, which is a special method that is only allowed once in a MiniJava Program
Holds a Type
.
Holds a Type
, a ParameterList
and a Block
.
Holds a Symbol
(The parameter name) and a Block
.
A Type
is basically a BasicType
. Optional it can be an (n-dimensional)
array type.
A BasicType
is either one of
Int
: a 32-bit integerBoolean
: a booleanVoid
: a void typeCustom
: a custom defined type
Holds a Symbol
, which is the name of the type.
This AST node represents a method parameter. A parameter consists of a
Type
and a name.
A Block
in the AST is basically just a vector of statements.
A statement can have one of the kinds:
Block
: A block defined inBlock
Empty
: An empty statement:;
If
: a if expression consisting of the condition, its body and optionally an else statementWhile
: a while loop consisting of the condition and its bodyExpression
: an expression defined inExpr
Return
: a return which can optionally return an expressionLocalVariableDeclaration
: a declaration and optional initialization of a local variable
Holds an Expr
(condition), a Stmt
(body) and a optional Stmt
(else body)
Holds an Expr
(condition) and a Stmt
(body)
Holds an optional Expr
Holds a Type
, a Symbol
and an optional Expr
An expression is either one of
Assignment
: an assignment expressionBinary
: one of the binary operations defined inBinaryOp
Unary
: one of the unary operations defined inUnaryOp
Postfix
: a primary expression with arbitrary many postfix operations defined inPostfixOp
The primary expression from the original grammar are also part of this, since the distinction is only required for correct postfix-op parsing. These are:
Null
: thenull
keywordBoolean
: a boolean literalInt
: an integer literalVar
: use of a variableMethodInvocation
: a method invocationThis
: thethis
keywordNewObject
: generating a new object, e.g.new Foo()
NewArray
: generating a new array, e.g.new int[]
Holds an Expr
and a list of Expr
s
Holds a BinaryOp
and two Expr
s
Holds an UnaryOp
and two Expr
s
Holds an Expr
and a list of PostfixOp
s
Holds a bool
Holds a Symbol
/String
Holds a Symbol
Holds a Symbol
and a list of Expr
s
Holds a Symbol
Holds a BasicType
, an Expr
(Array size) and a u64
(number of following []
)
Binary operations like comparisons (==
, !=
, <=
, ...), logical
operations (||
, &&
) or algebraic operation (+
, -
, *
, /
, %
).
One of the unary operations !
and -
A postfix operation is either one of
MethodInvocation
: a method invocation on a primary expression:foo.method()
FieldAccess
: a field access on a primary expression:foo.bar
ArrayAccess
: an array access on a primary expression:foo[42]
Holds a Symbol
and a list of Expr
s
Holds a Symbol
Holds an Expr
(Index)