root/branches/v2/minid2.txt

Revision 313, 11.0 kB (checked in by JarrettBillingsley, 4 months ago)

Comparison and equality operators are now all at the same precedence as in D.

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     '\\'
92     '->'
93     '$'
94     EOF
95
96 Identifier:
97     IdentifierStart {IdentifierChar}
98
99 IdentifierStart:
100     '_'
101     Letter
102
103 IdentifierChar:
104     IdentifierStart
105     DecimalDigit
106
107 Keyword:
108     'as'
109     'assert'
110     'break'
111     'case'
112     'catch'
113     'continue'
114     'coroutine'
115     'default'
116     'do'
117     'else'
118     'false'
119     'finally'
120     'for'
121     'foreach'
122     'function'
123     'global'
124     'if'
125     'import'
126     'in'
127     'is'
128     'local'
129     'module'
130     'namespace'
131     'null'
132     'object'
133     'return'
134     'super'
135     'switch'
136     'this'
137     'throw'
138     'true'
139     'try'
140     'vararg'
141     'while'
142     'with'
143     'yield'
144
145 CharLiteral:
146     "'" (Character | EscapeSequence) "'"
147
148 StringLiteral:
149     RegularString
150     WysiwygString
151     AltWysiwygString
152
153 RegularString:
154     '"' {Character | EscapeSequence | EndOfLine} '"'
155
156 EscapeSequence:
157     '\''
158     '\"'
159     '\\'
160     '\a'
161     '\b'
162     '\f'
163     '\n'
164     '\r'
165     '\t'
166     '\v'
167     '\x' HexDigit HexDigit
168     '\u' HexDigit HexDigit HexDigit HexDigit
169     '\U' HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit
170     '\ ' DecimalDigit [DecimalDigit [DecimalDigit]]
171
172 WysiwygString:
173     '@"' {Character | EndOfLine | '""'} '"'
174
175 AltWysiwygString:
176     '`' {Character | EndOfLine | '``'} '`'
177
178 IntLiteral:
179     Decimal
180     Binary
181     Octal
182     Hexadecimal
183
184 Decimal:
185     DecimalDigit {DecimalDigit | '_'}
186
187 DecimalDigit:
188     '0'
189     '1'
190     '2'
191     '3'
192     '4'
193     '5'
194     '6'
195     '7'
196     '8'
197     '9'
198
199 Binary:
200     '0' ('b' | 'B') (BinaryDigit | '_') {BinaryDigit | '_'}
201
202 BinaryDigit:
203     '0'
204     '1'
205
206 Octal:
207     '0' ('c' | 'C') (OctalDigit | '_') {OctalDigit | '_'}
208
209 OctalDigit:
210     '0'
211     '1'
212     '2'
213     '3'
214     '4'
215     '5'
216     '6'
217     '7'
218
219 Hexadecimal:
220     '0' ('x' | 'X') (HexDigit | '_') {HexDigit | '_'}
221
222 HexDigit:
223     '0'
224     '1'
225     '2'
226     '3'
227     '4'
228     '5'
229     '6'
230     '7'
231     '8'
232     '9'
233     'A'
234     'a'
235     'B'
236     'b'
237     'C'
238     'c'
239     'D'
240     'd'
241     'E'
242     'e'
243     'F'
244     'f'
245
246 FloatLiteral:
247     [DecimalDigit {DecimalDigit | '_'}] '.' (DecimalDigit | '_') {DecimalDigit | '_'} [Exponent]
248     DecimalDigit {DecimalDigit | '_'} [Exponent]
249
250 Exponent:
251     ('e' | 'E')['+' | '-'] (DecimalDigit | '_') {DecimalDigit | '_'}
252
253 // -----------------------------------------------------------------------------------------------------------------
254 // -----------------------------------------------------------------------------------------------------------------
255 // -----------------------------------------------------------------------------------------------------------------
256
257 // Syntax
258
259 Module:
260     ModuleDeclaration {Statement} EOF
261
262 ModuleDeclaration:
263     [AttributeTable] 'module' Identifier {'.' Identifier} StatementTerminator
264
265 StatementTerminator:
266     ';'
267     EndOfLine // not consumed
268     '}' // not consumed
269     ')' // not consumed
270     ']' // not consumed
271
272 Statement:
273     AssertStatement
274     ImportStatement
275     BlockStatement
276     ExpressionStatement
277     DeclarationStatement
278     IfStatement
279     WhileStatement
280     DoWhileStatement
281     ForStatement
282     ForeachStatement
283     SwitchStatement
284     ContinueStatement
285     BreakStatement
286     ReturnStatement
287     TryCatchStatement
288     ThrowStatement
289    
290 AssertStatement:
291     'assert' '(' Expression [',' Expression] ')' StatementTerminator
292
293 ImportStatement:
294     'import' [Identifier '='] Identifier {'.' Identifier} [SelectiveImports] StatementTerminator
295     'import' [Identifier '='] '(' Expression ')' [SelectiveImports] StatementTerminator
296
297 SelectiveImports:
298     ':' SelectiveImport {',' SelectiveImport}
299
300 SelectiveImport:
301     [Identifier '='] Identifier
302
303 BlockStatement:
304     '{' {Statement} '}'
305
306 ExpressionStatement:
307     BaseExpression StatementTerminator
308
309 DeclarationStatement:
310     VariableDeclaration StatementTerminator
311     [AttributeTable] OtherDeclaration
312    
313 AttributeTable:
314     '</' [TableField {[','] TableField}] '/>'
315
316 OtherDeclaration:
317     FunctionDeclaration
318     ObjectDeclaration
319     NamespaceDeclaration
320
321 VariableDeclaration:
322     LocalVarDeclaration
323     GlobalVarDeclaration
324
325 LocalVarDeclaration:
326     'local' Identifier {',' Identifier} ['=' Expression]
327
328 GlobalVarDeclaration:
329     'global' Identifier {',' Identifier} ['=' Expression]
330
331 FunctionDeclaration:
332     ['local' | 'global'] SimpleFunctionDeclaration
333
334 SimpleFunctionDeclaration:
335     'function' Identifier FunctionBody
336
337 FunctionBody:
338     Parameters (Statement | '=' Expression)
339
340 Parameters:
341     '(' [('this' ':' Type | Parameter) {',' Parameter} [',' 'vararg']] ')'
342     '(' 'vararg' ')'
343
344 Parameter:
345     Identifier [':' Type] ['=' Expression]
346    
347 Type:
348     BasicType
349     '!' 'null'
350     'any'
351
352 BasicType:
353     BasicType '|' BasicType
354     'null'
355     'bool'
356     'int'
357     'float'
358     'char'
359     'string'
360     'table'
361     'array'
362     'function'
363     'object' [(Identifier {'.' Identifier}) | ('(' Expression')')]
364     Identifier {'.' Identifier}
365     'namespace'
366     'thread'
367
368 ObjectDeclaration:
369     ['local' | 'global'] 'object' Identifier [':' Expression] '{' {ObjectMember} '}'
370
371 ObjectMember:
372     [AttributeTable] SimpleFunctionDeclaration
373     Identifier ['=' Expression] StatementTerminator
374
375 NamespaceDeclaration:
376     ['local' | 'global'] 'namespace' Identifier [':' Expression] '{' {NamespaceMember} '}'
377    
378 NamespaceMember:
379     SimpleFunctionDeclaration
380     Identifier ['=' Expression] StatementTerminator
381
382 IfStatement:
383     'if' '(' ['local' Identifier '='] Expression ')' Statement ['else' Statement]
384
385 WhileStatement:
386     'while' '(' ['local' Identifier '='] Expression ')' Statement
387
388 DoWhileStatement:
389     'do' Statement 'while' '(' Expression ')'
390
391 ForStatement:
392     'for' '(' [ForInitializer {',' ForInitializer}] ';' [Expression] ';' [BaseExpression {',' BaseExpression}] ')' Statement
393     'for' '(' Identifier (':' | ';') Expression '..' Expression [',' Expression] ')' Statement
394
395 ForInitializer:
396     BaseExpression
397     LocalVarDeclaration
398
399 ForeachStatement:
400     'foreach' '(' Identifier {',' Identifier} ';' Expression [',' Expression [',' Expression]] ')' Statement
401    
402 SwitchStatement:
403     'switch' '(' Expression ')' '{' CaseStatement {CaseStatement} [DefaultStatement] '}'
404
405 CaseStatement:
406     'case' Expression {',' Expression} ':' {Statement}
407
408 DefaultStatement:
409     'default' ':' {Statement}
410    
411 ContinueStatement:
412     'continue' StatementTerminator
413
414 BreakStatement:
415     'break' StatementTerminator
416    
417 ReturnStatement:
418     'return' [Expression {',' Expression}] StatementTerminator
419
420 TryCatchStatement:
421     'try' Statement (('catch' '(' Identifier ')' Statement) || ('finally' Statement))
422    
423 ThrowStatement:
424     'throw' Expression StatementTerminator
425
426 BaseExpression:
427     Assignment
428     Expression
429
430 Assignment:
431     AssignmentLHS {',' AssignmentLHS} '=' Expression
432     AssignmentLHS '+=' Expression
433     AssignmentLHS '-=' Expression
434     AssignmentLHS '~=' Expression
435     AssignmentLHS '*=' Expression
436     AssignmentLHS '/=' Expression
437     AssignmentLHS '%=' Expression
438     AssignmentLHS '<<=' Expression
439     AssignmentLHS '>>=' Expression
440     AssignmentLHS '>>>=' Expression
441     AssignmentLHS '|=' Expression
442     AssignmentLHS '^=' Expression
443     AssignmentLHS '&=' Expression
444     AssignmentLHS '?=' Expression
445     '++' PrimaryExpression
446     '--' PrimaryExpression
447     PrimaryExpression '++'
448     PrimaryExpression '--'
449
450 AssignmentLHS:
451     Identifier
452     // Note - for these, the PostfixExpression must start with Identifier, 'this', or '#'.
453     PostfixExpression '[' ']'
454     PostfixExpression '[' Expression ']'
455     PostfixExpression '[' [Expression] '..' [Expression] ']'
456     DotExpression
457
458 Expression:
459     ConditionalExpression
460    
461 ConditionalExpression:
462     OrOrExpression
463     OrOrExpression '?' Expression ':' ConditionalExpression
464
465 OrOrExpression:
466     AndAndExpression
467     OrOrExpression '||' AndAndExpression
468
469 AndAndExpression:
470     OrExpression
471     AndAndExpression '&&' OrExpression
472
473 OrExpression:
474     XorExpression
475     OrExpression '|' XorExpression
476
477 XorExpression:
478     AndExpression
479     XorExpression '^' AndExpression
480
481 AndExpression:
482     EqualExpression
483     AndExpression '&' EqualExpression
484
485 EqualExpression:
486     RelExpression
487     EqualExpression '==' RelExpression
488     EqualExpression '!=' RelExpression
489     EqualExpression 'is' RelExpression
490     EqualExpression '!' 'is' RelExpression
491
492 RelExpression:
493     ShiftExpression
494     RelExpression 'as' ShiftExpression
495     RelExpression 'in' ShiftExpression
496     RelExpression '!' 'in' ShiftExpression
497     RelExpression '<' ShiftExpression
498     RelExpression '<=' ShiftExpression
499     RelExpression '>' ShiftExpression
500     RelExpression '>=' ShiftExpression
501     RelExpression '<=>' ShiftExpression
502
503 ShiftExpression:
504     AddExpression
505     ShiftExpression '<<' AddExpression
506     ShiftExpression '>>' AddExpression
507     ShiftExpression '>>>' AddExpression
508
509 AddExpression:
510     MulExpression
511     AddExpression '+' MulExpression
512     AddExpression '-' MulExpression
513     AddExpression '~' MulExpression
514
515 MulExpression:
516     UnaryExpression
517     MulExpression '*' UnaryExpression
518     MulExpression '/' UnaryExpression
519     MulExpression '%' UnaryExpression
520
521 UnaryExpression:
522     PostfixExpression
523     '-' UnaryExpression
524     '!' UnaryExpression
525     '~' UnaryExpression
526     '#' UnaryExpression
527     'coroutine' UnaryExpression
528
529 PostfixExpression:
530     PrimaryExpression
531     CallExpression
532     PostfixExpression '[' ']'
533     PostfixExpression '[' Expression ']'
534     PostfixExpression '[' [Expression] '..' [Expression] ']'
535     PostfixExpression '.' 'super'
536     DotExpression
537
538 DotExpression:
539     PostfixExpression '.' (Identifier | '(' Expression ')')
540
541 CallExpression:
542     PostfixExpression ArgumentsWith
543     DotExpression ArgumentsWith
544     'super' '.' (Identifier | '(' Expression ')') Arguments
545
546 ArgumentsWith:
547     Arguments
548     '(' 'with' ExpressionList ')'
549
550 Arguments:
551     '(' [ExpressionList] ')'
552     '$' ExpressionList
553
554 ExpressionList:
555     Expression {',' Expression}
556
557 PrimaryExpression:
558     Identifier
559     'this'
560     'null'
561     'true'
562     'false'
563     'vararg'
564     IntLiteral
565     FloatLiteral
566     CharLiteral
567     StringLiteral
568     ':' (Identifier | 'super' | '(' Expression ')')
569     'function' [Identifier] FunctionBody
570     '\\' (Identifier | 'vararg' | Parameters) '->' Expression
571     'object' [Identifier] [':' Expression] '{' {ObjectMember} '}'
572     '(' Expression ')'
573     TableCtorExp
574     ArrayLiteral
575     'namespace' Identifier [':' Expression] '{' {NamespaceMember} '}'
576     'yield' '(' [Arguments] ')'
577
578 ArrayLiteral:
579     '[' [Expression {[','] Expression}] ']'
580     '[' Expression ForComprehension ']'
581
582 TableCtorExp:
583     '{' [TableField {[','] TableField}] '}'
584     '{' PlainTableField ForComprehension '}'
585
586 TableField:
587     Identifier '=' Expression
588     PlainTableField
589     SimpleFunctionDeclaration
590
591 PlainTableField:
592     '[' Expression ']' '=' Expression
593
594 ForComprehension:
595     'for' Identifier {',' Identifier} 'in' Expression [',' Expression [',' Expression]] [IfComprehension] [ForComprehension]
596     'for' Identifier 'in' Expression '..' Expression [',' Expression] [IfComprehension] [ForComprehension]
597
598 IfComprehension:
599     'if' Expression
Note: See TracBrowser for help on using the browser.