root/trunk/minid2.txt

Revision 179, 9.2 kB (checked in by JarrettBillingsley, 1 year ago)

--

Line 
1 // Lexical
2
3 WhiteSpace:
4     Space {Space}
5
6 Space:
7     ' '
8     '\t'
9     '\v'
10     '\u000C'
11     EndOfLine
12     Comment
13    
14 EndOfLine:
15     '\r'
16     '\n'
17     '\r\n'
18     '\n\r'
19     EndOfFile
20
21 EndOfFile:
22     physical end of file
23     '\0'
24
25 Comment:
26     '/*' {Character} '*/'
27     '//' {Character} EndOfLine
28     NestedComment
29    
30 NestedComment:
31     '/+' {Character | NestedComment} '+/'
32
33 Token:
34     Identifier
35     Keyword
36     CharLiteral
37     StringLiteral
38     IntLiteral
39     FloatLiteral
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     EOF
92
93 Identifier:
94     IdentifierStart {IdentifierChar}
95
96 IdentifierStart:
97     '_'
98     Letter
99
100 IdentifierChar:
101     IdentifierStart
102     DecimalDigit
103
104 Keyword:
105     'as'
106     'break'
107     'case'
108     'class'
109     'catch'
110     'continue'
111     'coroutine'
112     'default'
113     'do'
114     'else'
115     'false'
116     'finally'
117     'for'
118     'foreach'
119     'function'
120     'global'
121     'if'
122     'import'
123     'in'
124     'is'
125     'local'
126     'module'
127     'namespace'
128     'null'
129     'return'
130     'super'
131     'switch'
132     'this'
133     'throw'
134     'true'
135     'try'
136     'vararg'
137     'while'
138     'with'
139     'yield'
140
141 CharLiteral:
142     "'" (Character | EscapeSequence) "'"
143
144 StringLiteral:
145     RegularString
146     WysiwygString
147     AltWysiwygString
148
149 RegularString:
150     '"' {Character | EscapeSequence | EndOfLine} '"'
151
152 EscapeSequence:
153     '\''
154     '\"'
155     '\\'
156     '\a'
157     '\b'
158     '\f'
159     '\n'
160     '\r'
161     '\t'
162     '\v'
163     '\x' HexDigit HexDigit
164     '\u' HexDigit HexDigit HexDigit HexDigit
165     '\U' HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit
166     '\ ' DecimalDigit [DecimalDigit [DecimalDigit]]
167
168 WysiwygString:
169     '@"' {Character | EndOfLine} '"'
170
171 AltWysiwygString:
172     '`' {Character | EndOfLine} '`'
173
174 IntLiteral:
175     Decimal
176     Binary
177     Octal
178     Hexadecimal
179
180 Decimal:
181     DecimalDigit {DecimalDigit | '_'}
182
183 DecimalDigit:
184     '0'
185     '1'
186     '2'
187     '3'
188     '4'
189     '5'
190     '6'
191     '7'
192     '8'
193     '9'
194
195 Binary:
196     '0' ('b' | 'B') (BinaryDigit | '_') {BinaryDigit | '_'}
197
198 BinaryDigit:
199     '0'
200     '1'
201
202 Octal:
203     '0' ('c' | 'C') (OctalDigit | '_') {OctalDigit | '_'}
204
205 OctalDigit:
206     '0'
207     '1'
208     '2'
209     '3'
210     '4'
211     '5'
212     '6'
213     '7'
214
215 Hexadecimal:
216     '0' ('x' | 'X') (HexDigit | '_') {HexDigit | '_'}
217
218 HexDigit:
219     '0'
220     '1'
221     '2'
222     '3'
223     '4'
224     '5'
225     '6'
226     '7'
227     '8'
228     '9'
229     'A'
230     'a'
231     'B'
232     'b'
233     'C'
234     'c'
235     'D'
236     'd'
237     'E'
238     'e'
239     'F'
240     'f'
241
242 FloatLiteral:
243     [DecimalDigit {DecimalDigit | '_'}] '.' (DecimalDigit | '_') {DecimalDigit | '_'} [Exponent]
244     DecimalDigit {DecimalDigit | '_'} [Exponent]
245
246 Exponent:
247     ('e' | 'E')['+' | '-'] (DecimalDigit | '_') {DecimalDigit | '_'}
248
249 // -----------------------------------------------------------------------------------------------------------------
250 // -----------------------------------------------------------------------------------------------------------------
251 // -----------------------------------------------------------------------------------------------------------------
252
253 // Syntax
254
255 Module:
256     ModuleDeclaration {Statement} EOF
257
258 ModuleDeclaration:
259     'module' Identifier {'.' Identifier} ';'
260
261 Statement:
262     ImportStatement
263     BlockStatement
264     ExpressionStatement
265     DeclarationStatement
266     IfStatement
267     WhileStatement
268     DoWhileStatement
269     ForStatement
270     ForeachStatement
271     SwitchStatement
272     ContinueStatement
273     BreakStatement
274     ReturnStatement
275     TryCatchStatement
276     ThrowStatement
277
278 ImportStatement:
279     'import' Identifier {'.' Identifier} [':' Identifier {',' Identifier}] ';'
280     'import' '(' Expression ')' [':' Identifier {',' Identifier}] ';'
281
282 BlockStatement:
283     '{' {Statement} '}'
284    
285 ExpressionStatement:
286     BaseExpression ';'
287
288 DeclarationStatement:
289     VariableDeclaration ';'
290     FunctionDeclaration
291     ClassDeclaration
292     NamespaceDeclaration
293
294 VariableDeclaration:
295     LocalVarDeclaration
296     GlobalVarDeclaration
297    
298 LocalVarDeclaration:
299     'local' Identifier {',' Identifier} ['=' Expression]
300
301 GlobalVarDeclaration:
302     'global' Identifier {',' Identifier} ['=' Expression]
303
304 FunctionDeclaration:
305     ['local' | 'global'] SimpleFunctionDeclaration
306
307 SimpleFunctionDeclaration:
308     'function' Identifier Parameters BlockStatement
309    
310 Parameters:
311     '(' [Identifier ['=' Expression] {',' Identifier ['=' Expression]} [',' 'vararg']] ')'
312     '(' 'vararg' ')'
313
314 ClassDeclaration:
315     ['local' | 'global'] 'class' Identifier [':' Expression] '{' {ClassMember} '}'
316
317 ClassMember:
318     SimpleFunctionDeclaration
319     Identifier ['=' Expression] ';'
320     'this' Parameters BlockStatement
321    
322 NamespaceDeclaration:
323     ['local' | 'global'] 'namespace' Identifier [':' Expression] '{' {NamespaceMember} '}'
324    
325 NamespaceMember:
326     SimpleFunctionDeclaration
327     Identifier ['=' Expression] ';'
328
329 IfStatement:
330     'if' '(' Expression ')' Statement ['else' Statement]
331
332 WhileStatement:
333     'while' '(' Expression ')' Statement
334
335 DoWhileStatement:
336     'do' Statement 'while' '(' Expression ')'
337
338 ForStatement:
339     'for' '(' [ForInitializer {',' ForInitializer}] ';' [Expression] ';' [BaseExpression {',' BaseExpression}] ')' Statement
340     'for' '(' Identifier ':' Expression '..' Expression [',' Expression] ')' Statement
341
342 ForInitializer:
343     BaseExpression
344     LocalVarDeclaration
345
346 ForeachStatement:
347     'foreach' '(' Identifier {',' Identifier} ';' Expression [',' Expression [',' Expression]] ')' Statement
348    
349 SwitchStatement:
350     'switch' '(' Expression ')' '{' CaseStatement {CaseStatement} [DefaultStatement] '}'
351
352 CaseStatement:
353     'case' Expression {',' Expression} ':' {Statement}
354    
355 DefaultStatement:
356     'default' ':' {Statement}
357    
358 ContinueStatement:
359     'continue' ';'
360
361 BreakStatement:
362     'break' ';'
363    
364 ReturnStatement:
365     'return' [Expression {',' Expression}] ';'
366    
367 TryCatchStatement:
368     'try' Statement (('catch' '(' Identifier ')' Statement) || ('finally' Statement))
369    
370 ThrowStatement:
371     'throw' Expression ';'
372
373 BaseExpression:
374     Assignment
375     Expression
376
377 Assignment:
378     AssignmentLHS {',' AssignmentLHS} '=' Expression
379     AssignmentLHS '+=' Expression
380     AssignmentLHS '-=' Expression
381     AssignmentLHS '~=' Expression
382     AssignmentLHS '*=' Expression
383     AssignmentLHS '/=' Expression
384     AssignmentLHS '%=' Expression
385     AssignmentLHS '<<=' Expression
386     AssignmentLHS '>>=' Expression
387     AssignmentLHS '>>>=' Expression
388     AssignmentLHS '|=' Expression
389     AssignmentLHS '^=' Expression
390     AssignmentLHS '&=' Expression
391     AssignmentLHS '?=' Expression
392     '++' PrimaryExpression
393     '--' PrimaryExpression
394     PrimaryExpression '++'
395     PrimaryExpression '--'
396
397 AssignmentLHS:
398     Identifier
399     // Note - for these, the PostfixExpression must start with Identifier or with 'this'.
400     PostfixExpression '[' Expression ']'
401     PostfixExpression '[' [Expression] '..' [Expression] ']'
402     PostfixExpression '.' Identifier
403
404 Expression:
405     ConditionalExpression
406    
407 ConditionalExpression:
408     OrOrExpression
409     OrOrExpression '?' Expression ':' ConditionalExpression
410
411 OrOrExpression:
412     AndAndExpression
413     OrOrExpression '||' AndAndExpression
414
415 AndAndExpression:
416     OrExpression
417     AndAndExpression '&&' OrExpression
418
419 OrExpression:
420     XorExpression
421     OrExpression '|' XorExpression
422
423 XorExpression:
424     AndExpression
425     XorExpression '^' AndExpression
426
427 AndExpression:
428     EqualExpression
429     AndExpression '&' EqualExpression
430
431 EqualExpression:
432     RelExpression
433     EqualExpression '==' RelExpression
434     EqualExpression '!=' RelExpression
435     EqualExpression 'is' RelExpression
436     EqualExpression '!' 'is' RelExpression
437
438 RelExpression:
439     ShiftExpression
440     RelExpression 'as' ShiftExpression
441     RelExpression 'in' ShiftExpression
442     RelExpression '!' 'in' ShiftExpression
443     RelExpression '<' ShiftExpression
444     RelExpression '<=' ShiftExpression
445     RelExpression '>' ShiftExpression
446     RelExpression '>=' ShiftExpression
447     RelExpression '<=>' ShiftExpression
448
449 ShiftExpression:
450     AddExpression
451     ShiftExpression '<<' AddExpression
452     ShiftExpression '>>' AddExpression
453     ShiftExpression '>>>' AddExpression
454
455 AddExpression:
456     MulExpression
457     AddExpression '+' MulExpression
458     AddExpression '-' MulExpression
459     AddExpression '~' MulExpression
460
461 MulExpression:
462     UnaryExpression
463     MulExpression '*' UnaryExpression
464     MulExpression '/' UnaryExpression
465     MulExpression '%' UnaryExpression
466
467 UnaryExpression:
468     PostfixExpression
469     '-' UnaryExpression
470     '!' UnaryExpression
471     '~' UnaryExpression
472     '#' UnaryExpression
473     'coroutine' UnaryExpression
474
475 PostfixExpression:
476     PrimaryExpression
477     PostfixExpression '[' Expression ']'
478     PostfixExpression '[' [Expression] '..' [Expression] ']'
479     PostfixExpression '.' (Identifier | 'super' | 'class')
480     PostfixExpression '(' [Arguments] ')'
481     PostfixExpression '(' 'with' Arguments ')'
482
483 Arguments:
484     Expression {',' Arguments}
485
486 PrimaryExpression:
487     Identifier
488     'this'
489     'null'
490     'true'
491     'false'
492     'vararg'
493     IntLiteral
494     FloatLiteral
495     CharLiteral
496     StringLiteral
497     'function' [Identifier] Parameters (BlockStatement | Expression)
498     'class' [Identifier] [':' Expression] '{' {ClassMember} '}'
499     '(' Expression ')'
500     TableCtor
501     ArrayCtor
502     NamespaceCtor
503     'yield' '(' [Arguments] ')'
504     'super' ['.' Identifier] '(' [Arguments] ')'
505
506 TableCtor:
507     '{' [TableField {',' TableField}] '}'
508
509 TableField:
510     Identifier '=' Expression
511     '[' Expression ']' '=' Expression
512     SimpleFunctionDeclaration
513
514 ArrayCtor:
515     '[' [Expression {',' Expression}] ']'
516    
517 NamespaceCtor:
518     'namespace' Identifier [':' Expression] '{' {NamespaceMember} '}'
Note: See TracBrowser for help on using the browser.