######################################################################## LEXICAL GRAMMAR ######################################################################## input = { inputelement } inputelement = whitespace | comment | token token = ident | number | string | '(' | ')' | ... /* to complete */ comment = '/' '/' { cchar } ident = letter { letter | digit | '_' } number = "0" | digit1 { digit } string = '"' { schar } '"' whitespace = ' ' | '\t' | '\f' | '\n' letter = 'a' | ... | 'z' | 'A' | ... | 'Z' digit = '0' | digit1 digit1 = '1' | ... | '9' cchar = all characters except for '\n' schar = all characters except for '\n' and '"' ######################################################################## SYNTACTICAL GRAMMAR ######################################################################## Program = { Declaration } Expression Declaration = FunDecl | ClassDecl FunDecl = "def" ident "(" Formals ")" ":" Type "=" Expression ";" Formal = ident ":" Type Formals = [ Formal { "," Formal } ] ClassDecl = "class" ident "{" { Field } "}" Field = "val" Formal ";" Type = "Int" | ident | "(" Types ")" "=>" Type Types = [ Type { "," Type } ] Statement = "while" "(" Expression ")" "{" { Statement } "}" | "var" Formal "=" Expression ";" | "let" ident "=" Expression ";" | "do" Expression ";" Expression = "if" "(" Expression ")" Expression [ "else" Expression ] | OrExpression OrExpression = AndExpression | OrExpression "|" AndExpression AndExpression = CmpExpression | AndExpression "&" CmpExpression CmpExpression = [ SumExpression CompOp ] SumExpression CompOp = "==" | "!=" | "<" | ">" | "<=" | ">=" SumExpression = Term | SumExpression SumOp Term SumOp = "+" | "-" Term = [ Term ProdOp ] [ NegateOp ] Factor NegateOp = "-" | "!" ProdOp = "*" | "/" | "%" Factor = ident | number | string | "true" | "false" | "null" | "(" Expression ")" | "{" { Statement } [ Expression ] "}" | Factor Params | "new" ident Params | Factor "." ident Params = "(" Expressions ")" Expressions = [ Expression { "," Expression } ] ###################################################################### $Id: concrete_syntax.txt,v 1.2 2004/10/27 08:25:43 cremet Exp $