Computer Science Department
Programming Methods Laboratory

Compilation     winter 99/00
Ecole Polytechnique Federale de Lausanne
J0 Syntax

ModuleDeclaration = "module" ident "{" { Declaration } "}".

Declaration = VarDeclaration | FunDeclaration.

VarDeclaration = Type ident ";".

Type = "int" | "string" | Type "[" "]".

FunDeclaration = ( Type | "void" ) ident "(" [ Formals ] ")" Block.

Formals = Formal { "," Formal }.

Formal = Type ident.

Block = "{" { BlockStatement } "}".

BlockStatement = Statement | VarDeclaration.

Statement = FunCall | Assignment | Block |
            IfStatement | WhileStatement | ReturnStatement.

FunCall = ident "(" [ Expressions ] ")" ";".

Assignment = ident { "[" Expression "]" } "=" Expression ";".

IfStatement = "if" "(" Expression ")" Statement [ "else" Statement ].

WhileStatement = "while" "(" Expression ")" Statement.

ReturnStatement = "return" Expression ";".

Expression = AndExpression | Expression "|" AndExpression. 

AndExpression = CmpExpression | AndExpression "&" CmpExpression.

CmpExpression = SumExpression [ CompOp SumExpression ]. 

CompOp = "==" | "!=" | "<" | ">" | "<=" | ">=".

SumExpression = Term | SumExpression SumOp Term.

SumOp = "+" | "-".

Term = [ "-" ] Factor | Term ProdOp [ "-" ] Factor.

ProdOp = "*" | "/" | "%".

Factor = ident [ "(" [ Expressions ] ") ] { "[" Expression "]" } | number | string |
         "(" Expression ")" | "!" Factor | "newarray" Type "(" Expression ")".

Expressions = Expression { "," Expression }.