diff --git a/doc/concrete_syntax.txt b/doc/concrete_syntax.txt new file mode 100755 index 0000000..e7e0ad4 --- /dev/null +++ b/doc/concrete_syntax.txt @@ -0,0 +1,117 @@ +################################################################################ + 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 = { ClassDecl } Expression + +ClassDecl = "class" ident [ "extends" ident ] "{" { Member } "}" + +Member = FieldDecl + | MethodDef + +FieldDecl = Formal ";" + +MethodDef = Formal "(" [ Formal { "," Formal} ] ")" Block + +Formal = Type ident + +Block = "{" { Statement } [ "return" Expression ] "}" + +Type = "Int" + | "Null" + | ident + +Statement = "while" "(" Expression ")" "{" { Statement } "}" + | Formal "=" Expression ";" + | ident "=" Expression ";" + | Expression ";" + | "printInt" "(" Expression ")" ";" + | "printChar" "(" Expression ")" ";" + +Expression = "if" "(" Expression ")" Expression [ "else" Expression ] + | 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" + | "this" + | "null" + | "readInt" + | "readChar" + | "(" Expression ")" + | Block + | "new" ident Params + | Factor "." ident + | Factor "." ident Params + +Params = "(" Expressions ")" + +Expressions = [ Expression { "," Expression } ] + +################################################################################ +$Id$