-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammer.txt
44 lines (36 loc) · 2.88 KB
/
grammer.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
program => ( procedure_declaration | function_declaration )* variable_declaration_part ? begin_block_end '.'
procedure_declaration => 'procedure' func_proc_header ';' func_proc_implementation
function_declaration => 'function' func_proc_header ':' type ';' func_proc_implementation
func_proc_header => identifier '(' ( variable_declaration ';' )* ')'
func_proc_implementation => variable_declaration_part ? begin_block_end ';'
variable_declaration_part => 'var' ( variable declaration ';' )*
variable_declaration => identifier ( ',' identifier )* ':' ( type | array_type )
begin_block_end => 'begin' block 'end'
block => ( if_statement | while_statement | for_statement | repeat_statement | 'break'' | 'continue' | 'exit' | expression | func_proc_call )*
func_proc_call => identifier '(' arguments ')'
arguments => ( expression )? ( ',' expression )*
exit => 'exit' + ( '(' expressions ')' )?
for_statement => 'for' expression 'to' expression 'do' begin_block_end ';'
if_statement => 'if' logic_expression 'then' begin_block_end ( ';' | ( 'else' begin_block_end ';') )
while_statement => 'while' logic_expression 'do' begin_block_end ';'
repeat_statement => 'repeat' block 'until' logic_expression ';'
logic_expression => logic_term ( ( 'or' ) logic_term )*
logic_term => compare ( ( 'and' | 'xor' ) compare ) *
compare => expression ( '==' | '!=' | '<' | '>' | '<=' | '>=' | '<>' ) expression
expression => term ( ( '+' | '-' ) term )*
term => fact ( ( '*' | 'div' | 'mod' ) fact )*
fact => ( '-' | 'not')? ( constant | identifier | array_element | func_proc_call | '(' expression ')' )
assign => identifier '=' ( expressions | login_expression ) ';'
type => simple_type | string
simple_type => 'integer' | 'char' | 'real' | 'boolean'
string_type => 'string' ( '[' integer_constant ']' )?
array_type => 'array' '[' integer_constant '.' '.' integer_constant ']' 'of' simple_type array_element_declaration ?
array_element_declaration => '=' '(' constant ( ',' constant )* ')
array_element => identifier ( '[' expression ']' )+
identifier => letter ( letter | digit )*
constant => integer_constant | char_constant | real_constant | boolean_constant | string_constant
integer_constant => digit digit *
char_constant => letter
real_constant => integer_constant . integer_constant
boolean_constant => 'true' | 'false'
string_constant => ''' ( letter | digit )* '''