-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinal_grammar.grm
147 lines (81 loc) · 6.12 KB
/
final_grammar.grm
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
"Name" = 'RICHARD'
"Author" = 'João Victor, Eduardo Marques, Gustavo Henrique, Marcos Aldrey, Marcos Vinicius, Alyson, Alisson, André, Gilvaney, Nielson, Lucas Cardoso'
"Version" = 'The version of the grammar and/or language'
"About" = 'A short description of the grammar'
"Case Sensitive" = 'True'
"Start Symbol" = <Program>
! -------------------------------------------------
! Character Sets
! -------------------------------------------------
{String Chars} = {Printable} + {HT} - ["\]
! -------------------------------------------------
! Terminals
! -------------------------------------------------
StringLiteral = '"' ( {String Chars} | '\' {Printable} )* '"'
Identifier = {Letter}({AlphaNumeric} | '_')*
NumberTerminal = {Number}+('.'{Number}+)?
! -------------------------------------------------
! Rules
! -------------------------------------------------
! The grammar starts below
<Program> ::= <Class> <Program> | <Constants> <Program> |
<Arithmetic> ::= '+' <Expression> | '-' <Expression> |
<Expr Arit> ::= <Mult Exp> <Arithmetic>
<Multiple> ::= '*' <Expression> | '/' <Expression> |
<Mult Exp> ::= <Negate Exp> <Multiple>
<Expression> ::= '(' <Expr Arit> ')' | <Expr Arit>
<Negate Exp> ::= '-' <Initial Value> | <Initial Value>
<Relational Operator> ::= '!=' | '==' | '<' | '<=' | '>' | '>='
<Logic Operator> ::= '&&' | '||'
<Negate> ::= '!' <Negate> |
<Relational Logic> ::= <Relational Operator> <Condition> | <Logic Operator> <Condition> |
<Condition> ::= '(' <Condition> ')' <Relational Logic> | <Negate> <Expression> <Relational Logic>
!Add more values to the rule below - as needed
<Value> ::= 'true' | 'false' | StringLiteral | NumberTerminal
<Array Position> ::= <Expression> |
<Array> ::= '[' <Array Position> ']' <Array> |
<Init Array> ::= '{' <Init Array_2> '}'
<Init Array_2> ::= '(' <Init Array_3> ')' | '(' <Init Array_3> ')' <Init Array_2>
<Init Array_3> ::= <Initial Value> | <Initial Value> ',' <Init Array_3>
<Declaration> ::= <Type> <Valid Identifier>
<Valid Identifier> ::= Identifier <Array>
<Type> ::= 'string' | 'int' | 'float' | 'bool' | 'void' | Identifier
<Identifier With Attributes> ::= <Valid Identifier> <Attribute Access>
<Attribute Access> ::= '.' <Identifier With Attributes> |
<Call Arguments> ::= '(' <Arguments> ')' |
<Valid Values> ::= <Value> | <Identifier With Attributes> <Call Arguments>
<Method Call> ::= <Identifier With Attributes> '(' <Arguments> ')'
<Initial Value> ::= <Init Array> | <Valid Values> <Increment-Decrement>
<Increment-Decrement> ::= '++' <Increment-Decrement> | '--' <Increment-Decrement> |
<Multiple Identifier> ::= ',' <Valid Identifier> <Multiple Identifier> |
<Initialize Constant> ::= <Multiple Identifier> '=' <Expression> <Initialize Constant> |
<Constant Assignment> ::= <Declaration> '=' <Expression> <Initialize Constant> ';' <Constant Assignment> |
<Initialize> ::= '=' <Expression> |
<Initialize Variable> ::= <Multiple Identifier> <Initialize>
<Variable Assignment> ::= <Declaration> <Initialize> <Initialize Variable> ';' <Variable Assignment> |
<Constants> ::= 'const' '{' <Constant Assignment> '}'
<Variables> ::= 'variables' '{' <Variable Assignment> '}'
<Extends> ::= 'extends' Identifier |
<Class Code> ::= <Variables> <Class Code> | <Methods> <Class Code> |
<Class> ::= 'class' Identifier <Extends> '{' <Class Code> '}'
<Parameters> ::= <Declaration> <Parameter> |
<Parameter> ::= ',' <Parameters> |
<Methods> ::= 'method' <Declaration> '(' <Parameters> ')' <Code Block>
<Code Block> ::= '{' <Code Statements> '}'
<Code Statements> ::= <If-Block> <Code Statements> | <Looping-Block> <Code Statements>
| <Line Code> ';' <Code Statements> | <Variables> <Code Statements> |
<Argument> ::= ',' <Initial Value> <Argument> |
<Arguments> ::= <Initial Value> <Argument> |
<Return Statement> ::= <Condition> | '(' <Return Statement> ')' |
<Attributition> ::= '=' <Expression> | <Increment-Decrement>
<Execute Line> ::= <Call Arguments> | <Attributition>
<Line Code> ::= 'return' <Return Statement> | <Read> | <Write> | <Identifier With Attributes> <Execute Line>
<If-Block> ::= 'if' '(' <Condition> ')' 'then' <Code Block> <Else-Block>
<Else-Block> ::= 'else' <Post-Else-Block> |
<Post-Else-Block> ::= <If-Block> | <Code Block> |
<Looping-Block> ::= 'while' '(' <Condition> ')' <Code Block>
<Read> ::= 'read' '(' <Valid Values> <Read Parameters> ')'
<Read Parameters> ::= ',' <Valid Values> <Read Parameters> |
<Write> ::= 'write' '(' <Write Parameters> ')'
<To-Write> ::= ',' <Valid Values> <To-Write> | ',' <Method Call> <To-Write> |
<Write Parameters> ::= <Valid Values> <To-Write> | <Method Call> <To-Write>