-
Notifications
You must be signed in to change notification settings - Fork 0
/
spl.bnf
55 lines (29 loc) · 2.25 KB
/
spl.bnf
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<program> ::= <identifier> ":" <block> ENDP <identifier> "."
<block> ::= DECLARATIONS <declaration_block> | DECLARATIONS <declaration_block> CODE <statement_list>
<declaration_block> ::= <identifier_list> OF TYPE <type> ";" | <identifier_list> OF TYPE <type> ";" <declaration_block>
<identifier_list> ::= <identifier> | <identifier_list> "," <identifier>
<type> ::= CHARACTER | INTEGER | REAL
<statement_list> ::= <statement> | <statement_list> ";" <statement>
<statement> ::= <assignment_statement> | <if_statement> | <do_statement> | <while_statement> | <for_statement> | <write_statement> | <read_statement>
<assignment_statement> ::= <expression> "->" <identifier>
<if_statement> ::= IF <conditional> THEN <statement_list> ENDIF
| IF <conditional> THEN <statement_list> ELSE <statement_list> ENDIF
<do_statement> ::= DO <statement_list> WHILE <conditional> ENDDO
<while_statement> ::= WHILE <conditional> DO <statement_list> ENDWHILE
<for_statement> ::= FOR <identifier> IS <expression> BY <expression> TO <expression> DO <statement_list> ENDFOR
<write_statement> ::= WRITE "(" <output_list> ")" | NEWLINE
<read_statement> ::= READ "(" <identifier> ")"
<output_list> ::= <value> | <output_list> "," <value>
<conditional> ::= NOT <conditional> | <conditional> AND <conditional> | <conditional> OR <conditional> | <expression> <comparator> <expression>
<comparator> ::= "=" | "<>" | "<" | ">" | "<=" | ">="
<expression> ::= <term> | <expression> "+" <term> | <expression> "-" <term>
<term> ::= <value> | <term> "*" <value> | <term> "/" <value>
<value> ::= <identifier> | <constant> | "(" <expression ")"
<constant> ::= <character_constant> | <number_constant>
<character_constant> ::= "'" <character> "'"
<number_constant> ::= "-" <integer> | "-" <integer> "." <integer> | <integer> "." <integer> | <integer>
<integer> ::= <integer> <digit> | <digit>
<identifier> ::= <identifier> <character> | <character> | <identifier> <digit>
<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