|
|
@@ -0,0 +1,160 @@
|
|
|
+COMPILER Oberon
|
|
|
+IGNORE CASE
|
|
|
+
|
|
|
+ (* Oberon grammar extracted from Ulm's Oberon compiler (ulmo)
|
|
|
+ Source: src/compiler/OberonParser.om and src/compiler/OberonLex.om
|
|
|
+ Coco/R grammar for the Oberon language as implemented by ulmo 0.11.0 *)
|
|
|
+
|
|
|
+ (* ------------------------------------------------------------------ *)
|
|
|
+ (* Character classes *)
|
|
|
+ (* ------------------------------------------------------------------ *)
|
|
|
+
|
|
|
+ CHARACTERS
|
|
|
+ letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" .
|
|
|
+ digit = "0123456789" .
|
|
|
+ hexdigit = digit + "ABCDEF" .
|
|
|
+ noQuote = ANY - '"' - "'" .
|
|
|
+ eol = CHR(10) .
|
|
|
+IGNORE CHR(9) .. CHR(13)
|
|
|
+COMMENTS FROM "(*" TO "*)" NESTED
|
|
|
+
|
|
|
+ (* ------------------------------------------------------------------ *)
|
|
|
+ (* Scanner tokens *)
|
|
|
+ (* ------------------------------------------------------------------ *)
|
|
|
+
|
|
|
+ TOKENS
|
|
|
+ ident = letter { letter | digit } .
|
|
|
+ integer = digit { digit } | digit { hexdigit } "H" .
|
|
|
+ real = digit { digit } "." { digit }
|
|
|
+ [ ("E" | "D") [ "+" | "-" ] digit { digit } ] .
|
|
|
+ charconst = digit { hexdigit } "X" .
|
|
|
+ string = '"' { noQuote } '"' .
|
|
|
+
|
|
|
+ (* ------------------------------------------------------------------ *)
|
|
|
+ (* Grammar productions *)
|
|
|
+ (* ------------------------------------------------------------------ *)
|
|
|
+
|
|
|
+ PRODUCTIONS
|
|
|
+
|
|
|
+ Oberon = CompilationUnit .
|
|
|
+
|
|
|
+ CompilationUnit = DefinitionModule | Module .
|
|
|
+
|
|
|
+ DefinitionModule = "DEFINITION" ident ";"
|
|
|
+ [ ImportList ]
|
|
|
+ [ DefinitionSequence ]
|
|
|
+ "END" ident "."
|
|
|
+ .
|
|
|
+
|
|
|
+ DefinitionSequence = { ConstSection | TypeSection | VarSection | DefProcDecl } .
|
|
|
+
|
|
|
+ DefProcDecl = ProcedureHeading ";" .
|
|
|
+
|
|
|
+ Module = "MODULE" ident ";"
|
|
|
+ [ ImportList ]
|
|
|
+ [ DeclarationSequence ]
|
|
|
+ [ "BEGIN" StatementSequence ]
|
|
|
+ "END" ident "."
|
|
|
+ .
|
|
|
+
|
|
|
+ ImportList = "IMPORT"
|
|
|
+ ( ident [ ":=" ident ]
|
|
|
+ { "," ident [ ":=" ident ] } )
|
|
|
+ ";"
|
|
|
+ .
|
|
|
+
|
|
|
+ DeclarationSequence = { ConstSection | TypeSection | VarSection | ProcedureDeclaration ";" }
|
|
|
+ { ForwardDeclaration ";" } .
|
|
|
+
|
|
|
+ ConstSection = "CONST" { ConstantDeclaration ";" } .
|
|
|
+ TypeSection = "TYPE" { TypeDeclaration ";" } .
|
|
|
+ VarSection = "VAR" { VariableDeclaration ";" } .
|
|
|
+
|
|
|
+ ConstantDeclaration = identdef "=" ConstExpression .
|
|
|
+ TypeDeclaration = identdef "=" type .
|
|
|
+ VariableDeclaration = IdentList ":" type .
|
|
|
+
|
|
|
+ identdef = ident [ "*" ] .
|
|
|
+ IdentList = identdef { "," identdef } .
|
|
|
+
|
|
|
+ qualident = ident { "." ident } .
|
|
|
+
|
|
|
+ ConstExpression = expression .
|
|
|
+
|
|
|
+ type = qualident | ArrayType | RecordType
|
|
|
+ | PointerType | ProcedureType .
|
|
|
+
|
|
|
+ ArrayType = "ARRAY" length { "," length } "OF" type .
|
|
|
+ length = ConstExpression .
|
|
|
+
|
|
|
+ RecordType = "RECORD" [ "(" BaseType ")" ]
|
|
|
+ FieldListSequence "END" .
|
|
|
+ BaseType = qualident .
|
|
|
+ FieldListSequence = FieldList { ";" FieldList } .
|
|
|
+ FieldList = [ IdentList ":" type ] .
|
|
|
+
|
|
|
+ PointerType = "POINTER" "TO" type .
|
|
|
+ ProcedureType = "PROCEDURE" [ FormalParameters ] .
|
|
|
+
|
|
|
+ FormalParameters = "(" [ FPSection { ";" FPSection } ] ")"
|
|
|
+ [ ":" qualident ] .
|
|
|
+ FPSection = [ "VAR" ] ident { "," ident } ":" FormalType .
|
|
|
+ FormalType = { "ARRAY" "OF" } ( qualident | ProcedureType ) .
|
|
|
+
|
|
|
+ designator = qualident
|
|
|
+ { "." ident | "[" ExpList "]"
|
|
|
+ | "(" [ ExpList ] ")" | "^" } .
|
|
|
+ ExpList = expression { "," expression } .
|
|
|
+
|
|
|
+ expression = SimpleExpression [ relation SimpleExpression ] .
|
|
|
+ relation = "=" | "#" | "<" | "<=" | ">" | ">=" | "IN" | "IS" .
|
|
|
+
|
|
|
+ SimpleExpression = [ "+" | "-" ] term { AddOperator term } .
|
|
|
+ AddOperator = "+" | "-" | "OR" .
|
|
|
+
|
|
|
+ term = factor { MulOperator factor } .
|
|
|
+ MulOperator = "*" | "/" | "DIV" | "MOD" | "&" .
|
|
|
+
|
|
|
+ factor = number | charconst | string | "NIL" | set
|
|
|
+ | designator [ ActualParameters ]
|
|
|
+ | "(" expression ")" | "~" factor .
|
|
|
+
|
|
|
+ number = integer | real .
|
|
|
+
|
|
|
+ set = "{" [ element { "," element } ] "}" .
|
|
|
+ element = expression [ ".." expression ] .
|
|
|
+
|
|
|
+ ActualParameters = "(" [ ExpList ] ")" .
|
|
|
+
|
|
|
+ statement = [ ident IdentTail | IfStatement
|
|
|
+ | CaseStatement | WhileStatement | RepeatStatement
|
|
|
+ | LoopStatement | WithStatement | "EXIT"
|
|
|
+ | "RETURN" [ expression ] ] .
|
|
|
+ IdentTail = { "." ident | "[" ExpList "]" | "(" [ ExpList ] ")" | "^" }
|
|
|
+ [ ":=" expression | "(" [ ExpList ] ")" ] .
|
|
|
+
|
|
|
+
|
|
|
+ StatementSequence = statement { ";" statement } .
|
|
|
+
|
|
|
+ IfStatement = "IF" expression "THEN" StatementSequence
|
|
|
+ { "ELSIF" expression "THEN" StatementSequence }
|
|
|
+ [ "ELSE" StatementSequence ] "END" .
|
|
|
+
|
|
|
+ CaseStatement = "CASE" expression "OF" case { "|" case }
|
|
|
+ [ "ELSE" StatementSequence ] "END" .
|
|
|
+ case = [ CaseLabelList ":" StatementSequence ] .
|
|
|
+ CaseLabelList = CaseLabels { "," CaseLabels } .
|
|
|
+ CaseLabels = ConstExpression [ ".." ConstExpression ] .
|
|
|
+
|
|
|
+ WhileStatement = "WHILE" expression "DO" StatementSequence "END" .
|
|
|
+ RepeatStatement = "REPEAT" StatementSequence "UNTIL" expression .
|
|
|
+ LoopStatement = "LOOP" StatementSequence "END" .
|
|
|
+ WithStatement = "WITH" qualident ":" qualident "DO" StatementSequence "END" .
|
|
|
+
|
|
|
+ ProcedureDeclaration = ProcedureHeading ";" ProcedureBody ident .
|
|
|
+ ProcedureHeading = "PROCEDURE" [ "*" ] identdef [ FormalParameters ] .
|
|
|
+ ProcedureBody = DeclarationSequence [ "BEGIN" StatementSequence ] "END" .
|
|
|
+
|
|
|
+ ForwardDeclaration = "PROCEDURE" "^" ident [ "*" ] [ FormalParameters ] .
|
|
|
+
|
|
|
+END Oberon.
|