diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2018-09-10 07:02:34 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2018-09-10 07:02:34 +0200 |
commit | ff303401e2abbe4b3edb9161efdc231c14097489 (patch) | |
tree | 2e605fe08bd2ffe6b2ac92fb757b61ece6396133 /old | |
parent | 87da5f12b7c055471bce6eb5e9b19607f09500ec (diff) | |
download | compilertests-ff303401e2abbe4b3edb9161efdc231c14097489.tar.gz compilertests-ff303401e2abbe4b3edb9161efdc231c14097489.tar.bz2 |
some work on bootstrapping the compiler
Diffstat (limited to 'old')
-rw-r--r-- | old/minie.ebnf | 7 | ||||
-rw-r--r-- | old/minipascal.ebnf | 133 |
2 files changed, 137 insertions, 3 deletions
diff --git a/old/minie.ebnf b/old/minie.ebnf index 04beb5a..5d15a41 100644 --- a/old/minie.ebnf +++ b/old/minie.ebnf @@ -4,9 +4,9 @@ Letter = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" Identifier = Letter { Letter | Digit } . Number = Digit { Digit } . Constant = Number . -Factor = Constant | VariableName | "(" Expression ")" . +Factor = [ "+" | "-" ] Constant | VariableName | "(" Expression ")" . Term = Factor { ( "*" | "/" ) Factor } . -Expression = [ "+" | "-" ] Term { ( "+" | "-" ) Term } . +Expression = Term { ( "+" | "-" ) Term } . VariableName = Identifier . Assignment = VariableName ":=" Expression . StatementList = Statement { ";" Statement } @@ -14,5 +14,6 @@ IfStatement = "if" Condition "do" StatementList "else" StatementList "end" . Statement = Assignment | IfStatement . StatementBlock = "begin" StatementList "end" . VariableDeclaration = Identifier ":" Type . +ImportBlock = "IMPORT" Identifier { "," Identifier } . DeclarationBlock = "VAR" VariableDeclaration { ";" VariableDeclaration } . -Module = "module" Identifier ";" DeclarationBlock StatementBlock . +Module = "module" Identifier ";" ImportBlock DeclarationBlock StatementBlock . diff --git a/old/minipascal.ebnf b/old/minipascal.ebnf new file mode 100644 index 0000000..e0acf4a --- /dev/null +++ b/old/minipascal.ebnf @@ -0,0 +1,133 @@ + __________________________________________________________________ + + Syntax of Mini-Pascal (Welsh & McKeag, 1980) + __________________________________________________________________ + + Syntax in recursive descent order + __________________________________________________________________ + + <program> ::= program <identifier> ; <block> . + + <block> ::= <variable declaration part> + <procedure declaration part> + <statement part> + __________________________________________________________________ + + <variable declaration part> ::= <empty> | + var <variable declaration> ; + { <variable declaration> ; } + + <variable declaration> ::= <identifier > { , <identifier> } : <type> + + <type> ::= <simple type> | <array type> + + <array type> ::= array [ <index range> ] of <simple type> + + <index range> ::= <integer constant> .. <integer constant> + + <simple type> ::= <type identifier> + + <type identifier> ::= <identifier> + __________________________________________________________________ + + <procedure declaration part> ::= { <procedure declaration> ; } + + <procedure declaration> ::= procedure <identifier> ; <block> + __________________________________________________________________ + + <statement part> ::= <compound statement> + + <compound statement> ::= begin <statement>{ ; <statement> } end + + <statement> ::= <simple statement> | <structured statement> + __________________________________________________________________ + + <simple statement> ::= <assignment statement> | <procedure statement> | + <read statement> | <write statement> + + <assignment statement> ::= <variable> := <expression> + + <procedure statement> ::= <procedure identifier> + + <procedure identifier> ::= <identifier> + + <read statement> ::= read ( <input variable> { , <input variable> } ) + + <input variable> ::= <variable> + + <write statement> ::= write ( <output value> { , <output value> } ) + + <output value> ::= <expression> + __________________________________________________________________ + + <structured statement> ::= <compound statement> | <if statement> | + <while statement> + + <if statement> ::= if <expression> then <statement> | + if <expression> then <statement> else <statement> + + <while statement> ::= while <expression> do <statement> + __________________________________________________________________ + + <expression> ::= <simple expression> | + <simple expression> <relational operator> <simple expression> + + <simple expression> ::= <sign> <term> { <adding operator> <term> } + + <term> ::= <factor> { <multiplying operator> <factor> } + + <factor> ::= <variable> | <constant> | ( <expression> ) | not <factor> + __________________________________________________________________ + + <relational operator> ::= = | <> | < | <= | >= | > + + <sign> ::= + | - | <empty> + + <adding operator> ::= + | - | or + + <multiplying operator> ::= * | div | and + __________________________________________________________________ + + <variable> ::= <entire variable> | <indexed variable> + + <indexed variable> ::= <array variable> [ <expression> ] + + <array variable> ::= <entire variable> + + <entire variable> ::= <variable identifier> + + <variable identifier> ::= <identifier> + __________________________________________________________________ + + Lexical grammar + __________________________________________________________________ + + <constant> ::= <integer constant> | <character constant> | <constant + identifier> + + <constant identifier> ::= <identifier> + + <identifier> ::= <letter> { <letter or digit> } + + <letter or digit> ::= <letter> | <digit> + + <integer constant> ::= <digit> { <digit> } + + <character constant> ::= '< any character other than ' >' | '''' + + <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 + + <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 + + <special symbol> ::= + | - | * | = | <> | < | > | <= | >= | + ( | ) | [ | ] | := | . | , | ; | : | .. | div | or | + and | not | if | then | else | of | while | do | + begin | end | read | write | var | array | + procedure | program + + <predefined identifier> ::= integer | Boolean | true | false + __________________________________________________________________ |