################################################################################ SYNTACTICAL GRAMMAR ################################################################################ Program = { ClassDecl } Statement ClassDecl = "class" ident [ "extends" ident ] "{" { Member } "}" Member = FieldDecl | MethodDef FieldDecl = "val" Formal ";" MethodDef = MethodHeader ":" Type "=" Expression ";" | MethodHeader "{" Statements "}" MethodHeader = "def" ident "(" [ Formal { "," Formal} ] ")" Formal = ident ":" Type Type = "Int" | ident VarDecl = "var" Formal "=" Expression ";" Statements = { VarDecl | Statement } Statement = "while" "(" Expression ")" Statement | "if" "(" Expression ")" Statement [ "else" Statement ] | "set" ident "=" Expression ";" | "do" Expression ";" | "printInt" "(" Expression ")" ";" | "printChar" "(" Expression ")" ";" | "{" Statements "}" Expression = [ SumExpression CompOp ] SumExpression CompOp = "==" | "!=" | "<" | ">" | "<=" | ">=" SumExpression = Term | SumExpression SumOp Term SumOp = "+" | "-" | "||" Term = [ Term ProdOp ] [ NegateOp ] Factor NegateOp = "-" | "!" ProdOp = "*" | "/" | "%" | "&&" Factor = ident | number | string | "true" | "false" | "this" | "readInt" | "readChar" | "(" Expression ")" | "{" Statements "return" Expression "}" | "new" ident Arguments | Factor "." ident | Factor "." ident Arguments Arguments = "(" Expressions ")" Expressions = [ Expression { "," Expression } ] ################################################################################