root/tags/lastPhobos/minid2.txt

Revision 174, 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 '?' Expression ':' ConditionalExpression
409
410 OrOrExpression:
411     AndAndExpression
412     OrOrExpression '||' AndAndExpression
413
414 AndAndExpression:
415     OrExpression
416     AndAndExpression '&&' OrExpression
417
418 OrExpression:
419     XorExpression
420     OrExpression '|' XorExpression
421
422 XorExpression:
423     AndExpression
424     XorExpression '^' AndExpression
425
426 AndExpression:
427     EqualExpression
428     AndExpression '&' EqualExpression
429
430 EqualExpression:
431     RelExpression
432     EqualExpression '==' RelExpression
433     EqualExpression '!=' RelExpression
434     EqualExpression 'is' RelExpression
435     EqualExpression '!' 'is' RelExpression
436
437 RelExpression:
438     ShiftExpression
439     RelExpression 'as' ShiftExpression
440     RelExpression 'in' ShiftExpression
441     RelExpression '!' 'in' ShiftExpression
442     RelExpression '<' ShiftExpression
443     RelExpression '<=' ShiftExpression
444     RelExpression '>' ShiftExpression
445     RelExpression '>=' ShiftExpression
446     RelExpression '<=>' ShiftExpression
447
448 ShiftExpression:
449     ShiftExpression '<<' AddExpression
450     ShiftExpression '>>' AddExpression
451     ShiftExpression '>>>' AddExpression
452
453 AddExpression:
454     MulExpression
455     AddExpression '+' MulExpression
456     AddExpression '-' MulExpression
457     AddExpression '~' MulExpression
458
459 MulExpression:
460     UnaryExpression
461     MulExpression '*' UnaryExpression
462     MulExpression '/' UnaryExpression
463     MulExpression '%' UnaryExpression
464
465 UnaryExpression:
466     PostfixExpression
467     '-' UnaryExpression
468     '!' UnaryExpression
469     '~' UnaryExpression
470     '#' UnaryExpression
471     'coroutine' UnaryExpression
472
473 PostfixExpression:
474     PrimaryExpression
475     PostfixExpression '[' Expression ']'
476     PostfixExpression '[' [Expression] '..' [Expression] ']'
477     PostfixExpression '.' (Identifier | 'super' | 'class')
478     PostfixExpression '(' [Arguments] ')'
479     PostfixExpression '(' 'with' Arguments ')'
480
481 Arguments:
482     Expression {',' Arguments}
483
484 PrimaryExpression:
485     Identifier
486     'this'
487     'null'
488     'true'
489     'false'
490     'vararg'
491     IntLiteral
492     FloatLiteral
493     CharLiteral
494     StringLiteral
495     'function' [Identifier] Parameters (BlockStatement | Expression)
496     'class' [Identifier] [':' Expression] '{' {ClassMember} '}'
497     '(' Expression ')'
498     TableCtor
499     ArrayCtor
500     NamespaceCtor
501     'yield' '(' [Arguments] ')'
502     'super' ['.' Identifier] '(' [Arguments] ')'
503
504 TableCtor:
505     '{' [TableField {',' TableField}] '}'
506
507 TableField:
508     Identifier '=' Expression
509     '[' Expression ']' '=' Expression
510     SimpleFunctionDeclaration
511
512 ArrayCtor:
513     '[' [Expression {',' Expression}] ']'
514    
515 NamespaceCtor:
516     'namespace' Identifier [':' Expression] '{' {NamespaceMember} '}'
Note: See TracBrowser for help on using the browser.