-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgrammarGoldP.txt
62 lines (59 loc) · 1.99 KB
/
grammarGoldP.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"Start Symbol" = <PROGRAM>
!var_type = 'void'|'int'|'float'|'char'
!semi_colon = ';'
!comma = ','
{Id Head} = {Letter} + [_]
{Id Tail} = {Id Head} + {Digit}
var_name = {Id Head}{Id Tail}*
!main = 'main'
!left_parenthesis = '('
!right_parenthesis = ')'
!left_curly_bracket = '{'
!right_curly_bracket = '}'
!if = 'if'
!else = 'else'
!while = 'while'
!return = 'return'
!equal = '='
boolean_op = '&&' | '||'
rel_op = '==' | '!=' | '<' | '>' | '<=' | '>='
arith_op = '+' | '-' | '*' | '/' | '%'
! Definicion de constantes
int_literal = [0123456789]{digit}*
float_literal = {Digit}*'.'{Digit}+
!{Char Ch} = {Printable} - ['']
!CharLiteral = '' ( {Char Ch} | '\'{Printable} )''
<PROGRAM> ::= <MAIN_DEF>
<DECLARATION> ::= <VAR_TYPE> <VAR_LIST> ';'
<VAR_TYPE> ::= 'int'|'float'
<VAR_LIST> ::= <VAR_LIST> ',' <VAR_ITEM>
<VAR_LIST> ::= <VAR_ITEM>
<VAR_ITEM> ::= var_name
<MAIN_DEF> ::= 'int' 'main' '(' ')' '{' <FUNCTION_BODY> '}'
<FUNCTION_BODY> ::= <INTERNAL_DECLARATIONS> <STATEMENT_LIST>
<INTERNAL_DECLARATIONS> ::= <DECLARATION> <INTERNAL_DECLARATIONS>
<INTERNAL_DECLARATIONS> ::= <>
<STATEMENT_LIST> ::= <STATEMENT> <STATEMENT_LIST>
<STATEMENT_LIST> ::= <>
<STATEMENT> ::= <IF_STATEMENT>
<STATEMENT> ::= <EXPRESSION> ';'
<STATEMENT> ::= <WHILE_STATEMENT>
<STATEMENT> ::= <RETURN_STATEMENT>
<STATEMENT> ::= ';'
<WHILE_STATEMENT> ::= 'while' '(' <EXPRESSION> ')' '{' <STATEMENT> '}'
<IF_STATEMENT> ::= 'if' '(' <EXPRESSION> ')' '{' <STATEMENT> '}'
<IF_STATEMENT> ::= 'if' '(' <EXPRESSION> ')' '{' <STATEMENT> '}' else '{' <STATEMENT> '}'
<RETURN_STATEMENT> ::= return <EXPRESSION> ';'
<RETURN_STATEMENT> ::= return ';'
<EXPRESSION> ::= <ASSIGN_EXP>
<ASSIGN_EXP> ::= var_name '=' <BINARY_EXP>
<ASSIGN_EXP> ::= <BINARY_EXP>
<BINARY_EXP> ::= <BINARY_EXP> <BINARY_OP> <PRIMARY_EXPR>
<BINARY_EXP> ::= <PRIMARY_EXPR>
<BINARY_OP> ::= boolean_op
<BINARY_OP> ::= rel_op
<BINARY_OP> ::= arith_op
<PRIMARY_EXPR> ::= var_name
<PRIMARY_EXPR> ::= <CONSTANT>
<PRIMARY_EXPR> ::= '(' <EXPRESSION> ')'
<CONSTANT> ::= int_literal | float_literal