-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstage3.grm
90 lines (72 loc) · 3.62 KB
/
stage3.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
"Name" = 'Sharp Grammar'
"Version" = '1.0'
"Author" = 'Michael Bebenita'
"Case Sensitive" = 'True'
"Start Symbol" = <Variable_Declarations>
! Scanner Rules
{ALPHA_NUMERIC} = {DIGIT} + {LETTER}
{HEX_DIGIT} = {DIGIT} + [abcdef] + [ABCDEF]
{String Char} = {Printable} - ["]
! Identifiers must start with a letter followed any amount of letters, digits or underscores.
identifier = {LETTER}({ALPHA_NUMERIC} | _)*
! Literals may be either true or false, integers, real numbers, or characters.
boolean_literal = (true)|(false)
integer_literal = ({DIGIT}+) | (0x{HEX_DIGIT}+)
real_literal = {DIGIT}*'.'{DIGIT}+f
character_literal = ''{LETTER}''
string_literal = '"'{String Char}*'"'
<Literal> ::= boolean_literal
| integer_literal
| real_literal
| character_literal
| string_literal
!! Types
<Type> ::= <Structure_Type>
| <Primitive_Type>
| <Array_Type>
<Structure_Type> ::= identifier
<Primitive_Type> ::= bool
| int
| real
| char
| void
<Array_Type> ::= <Structure_Type> '[' ']'
| <Primitive_Type> '[' ']'
!!
!! Variable stuff.
!!
<Variable_Declarations> ::= <Variable_Declaration>
| <Variable_Declarations> <Variable_Declaration>
<Variable_Declaration> ::= <Type> identifier ';'
| <Type> identifier '=' <Expression> ';'
| <Type> identifier '=' new '[' <Expression> ']' ';'
| <Type> identifier '=' '{' <Elements> '}' ';'
<Elements> ::= <Element>
| <Elements> ',' <Element>
<Element> ::= <Expression>
| '{' <Elements> '}'
!! expressions
<Expression> ::= <Expression_Term>
| <Expression> '+' <Expression_Term>
| <Expression> '-' <Expression_Term>
<Expression_Term> ::= <Expression_Factor>
| <Expression_Term> '*' <Expression_Factor>
| <Expression_Term> '/' <Expression_Factor>
<Expression_Factor> ::= <Expression_Binary>
| <Expression_Factor> '%' <Expression_Binary>
| <Expression_Factor> '>' <Expression_Binary>
| <Expression_Factor> '<' <Expression_Binary>
| <Expression_Factor> '>=' <Expression_Binary>
| <Expression_Factor> '<=' <Expression_Binary>
| <Expression_Factor> '==' <Expression_Binary>
| <Expression_Factor> '!=' <Expression_Binary>
<Expression_Binary> ::= <Expression_Unary>
| <Expression_Binary> '&&' <Expression_Unary>
| <Expression_Binary> '||' <Expression_Unary>
<Expression_Unary> ::= '+' <Expression_Primary>
| '-' <Expression_Primary>
| '!' <Expression_Primary>
| <Expression_Primary>
| <Expression_Primary> '[' <Expression> ']'
<Expression_Primary> ::= <Literal>
| '(' <Expression> ')'