diff options
Diffstat (limited to 'ecomp-c/minie.ebnf')
-rw-r--r-- | ecomp-c/minie.ebnf | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/ecomp-c/minie.ebnf b/ecomp-c/minie.ebnf index ed55e14..484572d 100644 --- a/ecomp-c/minie.ebnf +++ b/ecomp-c/minie.ebnf @@ -1,33 +1,36 @@ -Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" . -Letter = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" | - "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" . -Special = "_" | " " . -Identifier = Letter { Letter | Digit | "_" } . -Number = Digit { Digit } . -Character = "'" Digit | Letter | Special | "'" . -String = """" { Character } """" . +# scanner/lexer +Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" . +Letter = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" | + "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" . +Special = "_" | " " . +Identifier = Letter { Letter | Digit | "_" } . +Number = Digit { Digit } . +Character = "'" Digit | Letter | Special | "'" . +String = """" { Character } """" . -Factor = Number | Character | String | Identifier [ "[" Expression "]" ] | "(" Expression ")" | "not" Factor . -Term = Factor { ( "*" | "/" | "mod" | "and" ) Factor } . -SimpleExpression = Term { ( "+" | "-" | "or" ) Term } . -RelationalOperator = "=" | "<>" | "<" | ">" | "<=" | ">=" . -Expression = SimpleExpression [ RelationalOperator SimpleExpression ] . -Assignment = Identifier [ "[" Expression "]" ] ":=" Expression . -IfStatement = "if" Expression "do" StatementSequence "else" StatementSequence "end" . -WhileStatement = "while" Expression "do" StatementSequence "end" . -ProcedureCall = Identifier . -Statement = Assignment | IfStatement | WhileStatement | ProcedureCall . -StatementSequence = Statement { ";" Statement } . -StatementBlock = "begin" StatementSequence "end" . -SimpleType = Identifier . -ArrayType = "array" [ ConstExpression ] "of" Type . -Type = SimpleType | ArrayType . -ConstExpression = ( Number | Identifier ) . -ConstDeclaration = Identifier { "," Identifier } ":" Type "=" ConstExpression . -ConstBlock = "const" { ConstDeclaration ";" } . -VariableDeclaration = Identifier { "," Identifier } ":" Type [ ":=" ConstExpression ] . -VariableBlock = "var" { VariableDeclaration ";" } . -ProcedureDeclaration = "procedure" Identifier ";" StatementBlock . -ProcedureBlock = { ProcedureDeclaration } . -DeclarationBlock = [ ConstBlock ] [ VariableBlock ] [ ProcedureBlock ] . -Module = "module" Identifier ";" DeclarationBlock StatementBlock . +# parser +Factor = Number | Character | String | Identifier [ "[" Expression "]" ] | "(" Expression ")" | "not" Factor . +Term = Factor { ( "*" | "/" | "mod" | "and" ) Factor } . +SimpleExpression = Term { ( "+" | "-" | "or" ) Term } . +RelationalOperator = "=" | "<>" | "<" | ">" | "<=" | ">=" . +Expression = SimpleExpression [ RelationalOperator SimpleExpression ] . +Assignment = Identifier [ "[" Expression "]" ] ":=" Expression . +IfStatement = "if" Expression "do" StatementSequence "else" StatementSequence "end" . +WhileStatement = "while" Expression "do" StatementSequence "end" . +ProcedureCall = Identifier . +Statement = Assignment | IfStatement | WhileStatement | ProcedureCall . +StatementSequence = Statement { ";" Statement } . +StatementBlock = "begin" StatementSequence "end" . +SimpleType = Identifier . +ArrayType = "array" [ ConstExpression ] "of" Type . +Type = SimpleType | ArrayType . +ConstExpression = ( Number | Identifier ) . +ConstDeclaration = Identifier { "," Identifier } ":" Type "=" ConstExpression . +ConstBlock = "const" { ConstDeclaration ";" } . +VariableDeclaration = Identifier { "," Identifier } ":" Type [ ":=" ConstExpression ] . +VariableBlock = "var" { VariableDeclaration ";" } . +ProcedureDeclaration = "procedure" Identifier ";" ProcedureDeclarationBlock StatementBlock . +ProcedureBlock = { ProcedureDeclaration } . +ProcedureDeclarationBlock = [ ConstBlock ] [ VariableBlock ] . +DeclarationBlock = [ ConstBlock ] [ VariableBlock ] [ ProcedureBlock ] . +Module = "module" Identifier ";" DeclarationBlock StatementBlock . |