Coco/R - Compiler-Compiler V1.53 Released by Pat Terry 17 September 2002 Source file: cocor/Oberon.atg Grammar Tests: Deletable symbols: case statement FieldList FieldListSequence StatementSequence DeclarationSequence Undefined nonterminals: -- none -- Unreachable nonterminals: -- none -- Circular derivations: -- none -- Underivable nonterminals: -- none -- LL(1) conditions: LL(1) error in statement: ident is the start of several alternatives. LL(1) error in designator: "(" is the start & successor of a deletable structure LL(1) error in qualident: ident is the start & successor of a deletable structure LL(1) error in DeclarationSequence: "PROCEDURE" is the start & successor of a deletable structure LL(1) error in CompilationUnit: "BEGIN" is the start & successor of a deletable structure LL(1) error in CompilationUnit: "END" is the start & successor of a deletable structure Listing: 1 COMPILER Oberon 2 3 /* Oberon grammar extracted from Ulm's Oberon compiler (ulmo) 4 Source: src/compiler/OberonParser.om and src/compiler/OberonLex.om 5 Coco/R grammar for the Oberon language as implemented by ulmo 0.11.0 */ 6 7 /* ------------------------------------------------------------------ */ 8 /* Character classes */ 9 /* ------------------------------------------------------------------ */ 10 11 CHARACTERS 12 letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" . 13 digit = "0123456789" . 14 hexdigit = digit + "ABCDEF" . 15 noQuote = ANY - '"' - "'" . 16 17 /* ------------------------------------------------------------------ */ 18 /* Scanner tokens */ 19 /* ------------------------------------------------------------------ */ 20 21 TOKENS 22 ident = letter { letter | digit } . 23 integer = digit { digit } | digit { hexdigit } "H" . 24 real = digit { digit } "." { digit } 25 [ ("E" | "D") [ "+" | "-" ] digit { digit } ] . 26 charconst = digit { hexdigit } "X" . 27 string = '"' { noQuote } '"' . 28 29 /* ------------------------------------------------------------------ */ 30 /* Grammar productions */ 31 /* ------------------------------------------------------------------ */ 32 33 PRODUCTIONS 34 35 Oberon = CompilationUnit . 36 37 CompilationUnit = [ "DEFINITION" | "MODULE" ] 38 ident 39 [ ImportList ] 40 [ DeclarationSequence ] 41 [ "BEGIN" StatementSequence ] 42 "END" ident "." 43 . 44 45 ImportList = "IMPORT" 46 ( ident [ ":=" ident ] 47 { "," ident [ ":=" ident ] } ) 48 ";" 49 . 50 51 DeclarationSequence = { "CONST" { ConstantDeclaration ";" } 52 | "TYPE" { TypeDeclaration ";" } 53 | "VAR" { VariableDeclaration ";" } 54 | ProcedureDeclaration ";" } 55 { ForwardDeclaration ";" } . 56 57 ConstantDeclaration = identdef "=" ConstExpression . 58 TypeDeclaration = identdef "=" type . 59 VariableDeclaration = IdentList ":" type . 60 61 identdef = ident [ "*" ] . 62 IdentList = identdef { "," identdef } . 63 64 qualident = [ ident "." ] ident . 65 66 ConstExpression = expression . 67 68 type = qualident | ArrayType | RecordType 69 | PointerType | ProcedureType . 70 71 ArrayType = "ARRAY" length { "," length } "OF" type . 72 length = ConstExpression . 73 74 RecordType = "RECORD" [ "(" BaseType ")" ] 75 FieldListSequence "END" . 76 BaseType = qualident . 77 FieldListSequence = FieldList { ";" FieldList } . 78 FieldList = [ IdentList ":" type ] . 79 80 PointerType = "POINTER" "TO" type . 81 ProcedureType = "PROCEDURE" [ FormalParameters ] . 82 83 FormalParameters = "(" [ FPSection { ";" FPSection } ] ")" 84 [ ":" qualident ] . 85 FPSection = [ "VAR" ] ident { "," ident } ":" FormalType . 86 FormalType = { "ARRAY" "OF" } ( qualident | ProcedureType ) . 87 88 designator = qualident 89 { "." ident | "[" ExpList "]" 90 | "(" qualident ")" | "^" } . 91 ExpList = expression { "," expression } . 92 93 expression = SimpleExpression [ relation SimpleExpression ] . 94 relation = "=" | "#" | "<" | "<=" | ">" | ">=" | "IN" | "IS" . 95 96 SimpleExpression = [ "+" | "-" ] term { AddOperator term } . 97 AddOperator = "+" | "-" | "OR" . 98 99 term = factor { MulOperator factor } . 100 MulOperator = "*" | "/" | "DIV" | "MOD" | "&" . 101 102 factor = number | charconst | string | "NIL" | set 103 | designator [ ActualParameters ] 104 | "(" expression ")" | "~" factor . 105 106 number = integer | real . 107 108 set = "{" [ element { "," element } ] "}" . 109 element = expression [ ".." expression ] . 110 111 ActualParameters = "(" [ ExpList ] ")" . 112 113 statement = [ assignment | ProcedureCall | IfStatement 114 | CaseStatement | WhileStatement | RepeatStatement 115 | LoopStatement | WithStatement | "EXIT" 116 | "RETURN" [ expression ] ] . 117 118 assignment = designator ":=" expression . 119 ProcedureCall = designator [ ActualParameters ] . 120 121 StatementSequence = statement { ";" statement } . 122 123 IfStatement = "IF" expression "THEN" StatementSequence 124 { "ELSIF" expression "THEN" StatementSequence } 125 [ "ELSE" StatementSequence ] "END" . 126 127 CaseStatement = "CASE" expression "OF" case { "|" case } 128 [ "ELSE" StatementSequence ] "END" . 129 case = [ CaseLabelList ":" StatementSequence ] . 130 CaseLabelList = CaseLabels { "," CaseLabels } . 131 CaseLabels = ConstExpression [ ".." ConstExpression ] . 132 133 WhileStatement = "WHILE" expression "DO" StatementSequence "END" . 134 RepeatStatement = "REPEAT" StatementSequence "UNTIL" expression . 135 LoopStatement = "LOOP" StatementSequence "END" . 136 WithStatement = "WITH" qualident ":" qualident "DO" StatementSequence "END" . 137 138 ProcedureDeclaration = ProcedureHeading ";" ProcedureBody ident . 139 ProcedureHeading = "PROCEDURE" [ "*" ] identdef [ FormalParameters ] . 140 ProcedureBody = DeclarationSequence [ "BEGIN" StatementSequence ] "END" . 141 142 ForwardDeclaration = "PROCEDURE" "^" ident [ "*" ] [ FormalParameters ] . 143 144 END Oberon. 0 errors Statistics: nr of terminals: 66 (limit 400) nr of non-terminals: 53 (limit 210) nr of pragmas: 0 (limit 434) nr of symbolnodes: 119 (limit 500) nr of graphnodes: 357 (limit 1500) nr of conditionsets: 5 (limit 100) nr of charactersets: 8 (limit 250)