Computer Science Department
Programming Methods Laboratory

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

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

Declaration = VarDeclaration
            | FunDeclaration.

VarDeclaration = PrimitiveType ident { "[" number "]" } ";".

PrimitiveType = "boolean"
              | "int"

Type = PrimitiveType
     | Type "[" "]".

FunDeclaration = ( PrimitiveType | "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 = "true"
       | "false"
       | number
       | "!" Factor
       | ident "(" [ Expressions ] ")"
       | ident { "[" Expression "]" }
       | "(" Expression ")"

Expressions = Expression { "," Expression }.