Compiler Project (Bali#) Grammar Spring 2008 - Part 3

File			-> (ClassDefinition)*
ClassDefinition		-> class name { (classMember)* }

classMember		-> public (Method)
	Method		-> type name ([type name (, type name)*]) statementBlock

statement		-> (ifStatement | whileLoop | expressionStatement | statementBlock | returnStatement )
statementBlock		-> {(statement | localVariableDeclaration)*}
ifStatement		-> if(expression) statement [else statement]
whileLoop		-> while(expression) statement
returnStatement		-> return expression ;
expressionStatement	-> [expression] ;
localVariableDeclaration	-> my type name [= expression];

expression		-> e1
e1			-> e2 (= e2)*
e2			-> e3 ((||) e3)*
e3			-> e4 ((&&) e4)*
e4			-> e5 ((< | > | <= | =< | >= | => | == | !=) e5)*
e5			-> e6 ((+ | -) e6)*
e6			-> e7 ((* | / | %) e7)*
e7			-> e8 (functionCall)*
e8			-> (! | - | * | cast<type>)* e9
e9			-> literal | reference | (expression) | builtInFunction

builtInFunction		-> sizeof(Type) | ((malloc|print)(expression))
reference			-> name
functionCall		-> ([e1 (, e1)*] )
literal			-> number | string | character | true | false | null

type			-> name (*)*

Part 3 Notes:

The rules defined here supersede semantic rules defined in the full project Grammar.

Differences from Part 2