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

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

classMember		-> public (Method)
	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) | builtInFunction

builtInFunction		-> print(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 returns 5
	public int main()
	{
		return (5);
	}
}