-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.ebnf
50 lines (40 loc) · 1.67 KB
/
grammar.ebnf
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
(* GLYPH - language specification *)
imp = 'import', '"', file, '"' ; (* preproccessor directive *)
def = 'define', ident, replacement ; (* preproccessor directive *)
statement = assign | dec | if ;
(* need to finish filling in the if statement *)
if = "if", "(", ")", { statement }, "end if" ;
assign = dec, "=", { letter | digit | "_" | ident }
| ident, "=" { letter | digit | "_" | ident };
(* need to decide how to handle constants *)
(* type alias doesn't require an alias type *)
dec = "dec", ident, ":", type, [ "int" | "float" | "char" | "bool" | ident ] ;
type = "alias" | "var" | "const" ;
(* Mathematic Operators *)
expression = expression, [ "*" | "/" ], expression
| expression, [ "+" | "-" ], expression
| int
| float
| bool
| char
| ident
| "(", expression, ")" ;
(* specify the data types *)
int = number;
float = number, ".", { digit } ;
char = "'", ? Any ASCII Character ? "'" ;
char_too = '"', ? Any ASCII Character ?, '"' ;
bool = "0" | "1" ;
ident = letter, [ letter | digit | "_" ] ;
(* Lower Case and Upper Case characters *)
letter = "A" | "B" | "C" | "D" | "E" | "F" | "G"
| "H" | "I" | "J" | "K" | "L" | "M" | "N"
| "O" | "P" | "Q" | "R" | "S" | "T" | "U"
| "V" | "W" | "X" | "Y" | "Z" | "a" | "b"
| "c" | "d" | "e" | "f" | "g" | "h" | "i"
| "j" | "k" | "l" | "m" | "n" | "o" | "p"
| "q" | "r" | "s" | "t" | "u" | "v" | "w"
| "x" | "y" | "z" ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; (* 0 - 9 *)
number = [ "-" ], { digit } ; (* a proper number, still need digit to help with floats *)
WS = "\n" | "\t" | "\r" | " " | ? Any White Space Characters ? ; (* White Space *)