-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgrammar
More file actions
251 lines (199 loc) · 5.83 KB
/
grammar
File metadata and controls
251 lines (199 loc) · 5.83 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
===== Token Type =====
' | " : STRING
1234567890 | 1234567890. : INT | FLOAT
() : STRUCTURE
[] : ARRAY
{} : CLUSTER
+ : PLUS
- : MINUS
* : MUL
/ : DIV
// : INTEGER_DIV
** : POW
% : MOD
< : LESS
> : GREATER
= : EQUAL
== : EQEQUAL
<= : LESSEQUAL
>= : GREATEREQUAL
!= : NOTEQUAL
! : NOT
&& : AND
|| : OR
^ : XOR
& : AND_MOVEMENT
| : OR_MOVEMENT
<< : LEFT_MOVEMENT
>> : RIGHT_MOVEMENT
. : DOT
, : COMMA
: : COLON
? : WEATHER
; : NEWLINE
) : RIGHT_PAR
] : RIGHT_SQB
} : RIGHT_BRACE
-> : AS
# : MACRO
\ : ESCAPE
$ : GETTER
/* : LEFT_COMMENT
*/ : RIGHT_COMMENT
===== TYPE INTRODUCTION =====
Language Type ALL : [Number[INT, FLOAT], STRING[Any], [Array[Any, ...]], Null[Null],
Cluster[Statements, ...], Structure[Any, ...]]
Number Type: Any float or integer without quotation marks.
String Type: Any character within quotation marks.
Array Type: Any Expression within Square Brackets.
Null Type: Any 'null' keyword or function defined default return value
Cluster Type: Any Expression within Braces.
Structure Type: Any Expression within Parentheses.
AttributeCall Type: Underline + IDENTIFIER + Underline, like this structure
_example_ , _hello_, _toy_, _lang_ both AttributeCall
Call this variable: last Underline add GETTER (Eq: $) and first too
$_example_$, $_hello_$, $_toy_$, $_lang_$ both Call This Variable
===== BITWISE INTRODUCTION =====
Bitwise Operator : [
AND : &
OR : |
XOR : ^
NOT : ~
LEFT MOVEMENT : <<
RIGHT MOVEMENT : >>
]
===== COMPUTING ORDER INTRODUCTION =====
(MINUS | PLUS) : Lowest Role -> arith
(MUL | DIV | INTEGER DIV | MOD) : Middle Role -> term
(POW | Caller) : Second Highest Role -> power
(Compare Pos) : Highest Role -> compare_expr
===== KEYWORDS INTRODUCTION =====
Table : [
"global",
"private",
"var",
"delete",
"if",
"elseif",
"else",
"foriter",
"by",
"for",
"from",
"to",
"step",
"repeat",
"until",
"meet",
"break",
"continue",
"function",
"return",
"include"
]
# KEYWORDS [
// redefine variable globally
global <Variable>
// define private for definable objects
private <Keywords> <Expression*>
// define the variable by 'var'
var <IDENTIFIER> = <Expression*>
// delete a variable by 'delete'
delete <IDENTIFIER>
# Condition Controller
and -> True and True: True | False and True: False
or -> True or False: True | False or False: False
not -> False: True | True: False
if ( <Condition*> | <Expression*> ) {
<Statements>;
<Expression*>;
}
elseif ( <Condition*> | <Expression*> ) {
<Statements>;
<Expression*>;
}
else {
<Statements>;
<Expression*>;
}
# Repeat Controller
// Iterate iterable object (Common Array or other iterable object) and copy to IDENTIFIER
// Then you can use it by IDENTIFIER quickly
foriter <IDENTIFIER> by ( <Array> | <Iterable>) {
<Statements>;
<Expression*>;
}
// Iterate a number from value to value, optional argument 'step' is the step to the value
for <IDENTIFIER> from <Expression*> to <Expression*> (step <Expression*> = 1) {
<Statements>;
<Expression*>;
}
// repeat a condition when the condition is true
repeat meet (<Expression*> | <Condition*>) {
<Statements>;
<Expression*>;
}
// repeat a condition until the condition is false
repeat until (<Expression*> | <Condition*>) {
<Statements>;
<Expression
}
// break from the repeat
break
// jump this repeat
continue
# function defined
// define a function by 'function'
function <IDENTIFIER>(<Arguments1>, <Arguments2>, ...) {
<Statements>;
<Expression*>;
}
// return a value from function
return <Expression*>
# FIle I/O
// import headers by 'include'
include <File Headers>
]
===== BUILTIN-FUNCTION INTRODUCTION =====
println -> Output to the standard screen
readline -> Get the user input
int -> Convert a value to the integer type
float -> Convert a value to the float type
string -> Convert a value to the string type
array -> Convert a value to the array type
boolean -> Convert a value to the boolean type
timestamp -> Get the current timestamp
calllist -> Get the callable object's callable list
length -> Get the length
run -> Run the ToyLang source file
idle -> Open official IDLE
===== BUILTIN-VARIABLE INTRODUCTION =====
true -> 1
false -> 0
null -> 0
===== SELF-OPTION INTRODUCTION =====
Subscripts : <Subscriptable>[<Expression*>] -> `[]` after <Subscriptable> means subscripts
Terminator : <IDENTIFIER> ? true : false -> if <IDENTIFIER> is true then choose left value
Nick-Variable : <IDENTIFIER1> -> <IDENTIFIER2> -> This way can copy attribute to the IDENTIFIER2
if IDENTIFIER1's value changed, IDENTIFIER2 will change, too
Hiden-Variable : $__<Variable>__ -> Cannot access this variable by normal way like type
variable directly.
If need call variable below,
need use GETTER type (Eq: $) before it
e.g. $__moder__
===== EXAMPLE CODES =====
```
/* fibonacci with Repeat */
function fibonacci(n=20) {
var result = [];
for i from 0 to n {
if i <= 1 {
var result = result + [1];
} else {
var result = result + (result[i-2] + result[i-1]);
}
}
return result;
}
println(fibonacci(int(readline('Type a number: '))))
```