-
Notifications
You must be signed in to change notification settings - Fork 39
/
grammar.txt
70 lines (49 loc) · 1.42 KB
/
grammar.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
63
64
65
66
67
68
69
70
statements: basic | simple | compound
basic: assign
simple: print, condition, for, plot
compound: function, class
(basic)
assign:
numbers: var x = 1
strings: var y = string this is a string
words: var z = berry
var_refs: var a = @ b
booleans: var c = bool true/false/1/0
arrays: var num_arr = [1,2,3,4,5]
(simple)
print:
words: print word
var_refs: print @ x/@ num_arr/@ num_arr[1]
strings: print string now printing a string
and evaluate: print eval (1+2+3)
condition:
equality: if word = word print yes
greater: if @ x > 1 print string x is greater than 1
less: if 2 < @ y print num_arr[1]
for:
words: for 1 times : print greenBerry
strings: for 2 times : print string greenBerry is great
var_refs: for 3 times : print @ x/@ num_arr/@ num_arr[1]
plot:
linear graph: plot 1,2,3,4,5 x-time 4,8,15,16,23,42 y-numbers
(compound)
function:
declaration: func name : print string functions are easy
with parameters: func p x : print @ x
call: call name
class:
declaration: class Dinosaur : strength = 100 action roar : print roarrrrr
method call: make Dinosaur roar
check attribute: see strength of Dinosaur
add attribute: add to Dinosaur attribute age = string very ancient
add method: add to Dinosaur action chomp : print string om nom nom
>statement:
(var_ref | number)
>identifier:
('bool' ('true' | 'false')
| 'string' (word*0+)
| '@' var_ref)
>var_ref:
('@' id
| '@' id '[' number ']'
| '@' id '[' number ',' number ]')