blob: 2bf97088d65ffeb77441276b0266d8a2757313e7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# 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 } """" .
# parser
Factor = Number | Character | String | Identifier [ "[" Expression "]" | ParameterList ] | "(" 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" .
ParameterList = "(" Expression { "," Expression } ")" .
ProcedureCall = Identifier [ ParameterList ] .
Statement = Assignment | IfStatement | WhileStatement | ProcedureCall .
StatementSequence = Statement { ";" Statement } .
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 ";" } .
ParameterDeclaration = Identifier ":" Type .
ParamaterDeclarationList = "(" ParameterDeclaration { "," ParameterDeclaration } ")" [ ":" Type ] .
ProcedureDeclaration = [ "procedure" | "function" ] Identifier [ ParamaterDeclarationList ] ";" ProcedureDeclarationBlock "begin" StatementSequence [ "return" Type ] "end" .
ProcedureDeclarationBlock = [ ConstBlock ] [ VariableBlock ] .
ProcedureBlock = { ProcedureDeclaration } .
DeclarationBlock = [ ConstBlock ] [ VariableBlock ] [ ProcedureBlock ] .
Module = "module" Identifier ";" DeclarationBlock "begin" StatementSequence "end" .
|