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

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

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

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

reference		-> name

literal			-> number | true | false

type			-> name

Part 1 Notes:

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

Sample Programs

Hello World (even though we don't have strings yet)

class Entry
{
	# Simple  program that prints 5 and returns 0
	public int main()
	{
		print(5);
	}
}