-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.txt
26 lines (24 loc) · 1.17 KB
/
grammar.txt
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
PROGRAM ::= program var TYPE_DEFINITION_N begin OPERATOR_N end.
TYPE_DEFINITION_N ::= TYPE_DEFINITION | TYPE_DEFINITION TYPE_DEFINITION_N
TYPE_DEFINITION ::= ID_N : TYPE;
ID_N ::= ID | ID , ID_N
TYPE ::= integer | real | boolean
OPERATOR_N ::= OPERATOR | OPERATOR ; OPERATOR_N
OPERATOR ::= COMPLEX_OPERATOR | ASSIGNMENT_OPERATOR | SWITCH_OPERATOR | FOR_OPERATOR | WHILE_OPERATOR | INPUT_OPERATOR | OUTPUT_OPERATOR
COMPLEX_OPERATOR ::= { OPERATOR_N }
ASSIGNMENT_OPERATOR ::= ID = EXPRESSION | let ID = EXPRESSION
SWITCH_OPERATOR ::= switch EXPRESSION { CASE_N }
CASE_N ::= CASE | CASE CASE_N
CASE ::= case CONSTANT : OPERATOR
FOR_OPERATOR ::= for ASSIGNMENT_OPERATOR to EXPRESSION do OPERATOR
WHILE_OPERATOR ::= do while EXPRESSION OPERATOR loop
INPUT_OPERATOR ::= readln ID_N
OUTPUT_OPERATOR ::= writeln EXPRESSION_N
EXPRESSION_N ::= EXPRESSION | EXPRESSION , EXPRESSION_N
! EXPRESSION ::= E
E ::= A < A | A <= A | A > A | A >= A | A == A | A != A | A
A ::= A + T | A - T | T
T ::= T * P | T / P | P
P ::= ( E ) | ID | CONSTANT
! ID, CONSTANT
program var begin end . : ; ID , integer real boolean { } = let switch case for to do while loop readln writeln + - * / ( ) CONSTANT < <= > >= == !=