c-next 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +726 -0
  2. package/bin/cnext.js +5 -0
  3. package/grammar/C.g4 +1112 -0
  4. package/grammar/CNext.g4 +817 -0
  5. package/grammar/CPP14Lexer.g4 +282 -0
  6. package/grammar/CPP14Parser.g4 +1072 -0
  7. package/package.json +85 -0
  8. package/src/analysis/DivisionByZeroAnalyzer.ts +378 -0
  9. package/src/analysis/FunctionCallAnalyzer.ts +526 -0
  10. package/src/analysis/InitializationAnalyzer.ts +725 -0
  11. package/src/analysis/NullCheckAnalyzer.ts +427 -0
  12. package/src/analysis/types/IDivisionByZeroError.ts +25 -0
  13. package/src/analysis/types/IFunctionCallError.ts +17 -0
  14. package/src/analysis/types/IInitializationError.ts +55 -0
  15. package/src/analysis/types/INullCheckError.ts +25 -0
  16. package/src/codegen/CodeGenerator.ts +7945 -0
  17. package/src/codegen/CommentExtractor.ts +240 -0
  18. package/src/codegen/CommentFormatter.ts +155 -0
  19. package/src/codegen/HeaderGenerator.ts +265 -0
  20. package/src/codegen/TypeResolver.ts +365 -0
  21. package/src/codegen/types/ECommentType.ts +10 -0
  22. package/src/codegen/types/IComment.ts +21 -0
  23. package/src/codegen/types/ICommentError.ts +15 -0
  24. package/src/codegen/types/TOverflowBehavior.ts +6 -0
  25. package/src/codegen/types/TParameterInfo.ts +13 -0
  26. package/src/codegen/types/TTypeConstants.ts +94 -0
  27. package/src/codegen/types/TTypeInfo.ts +22 -0
  28. package/src/index.ts +518 -0
  29. package/src/lib/IncludeDiscovery.ts +131 -0
  30. package/src/lib/InputExpansion.ts +121 -0
  31. package/src/lib/PlatformIODetector.ts +162 -0
  32. package/src/lib/transpiler.ts +439 -0
  33. package/src/lib/types/ITranspileResult.ts +80 -0
  34. package/src/parser/c/grammar/C.interp +338 -0
  35. package/src/parser/c/grammar/C.tokens +229 -0
  36. package/src/parser/c/grammar/CLexer.interp +415 -0
  37. package/src/parser/c/grammar/CLexer.tokens +229 -0
  38. package/src/parser/c/grammar/CLexer.ts +750 -0
  39. package/src/parser/c/grammar/CListener.ts +976 -0
  40. package/src/parser/c/grammar/CParser.ts +9663 -0
  41. package/src/parser/c/grammar/CVisitor.ts +626 -0
  42. package/src/parser/cpp/grammar/CPP14Lexer.interp +478 -0
  43. package/src/parser/cpp/grammar/CPP14Lexer.tokens +264 -0
  44. package/src/parser/cpp/grammar/CPP14Lexer.ts +848 -0
  45. package/src/parser/cpp/grammar/CPP14Parser.interp +492 -0
  46. package/src/parser/cpp/grammar/CPP14Parser.tokens +264 -0
  47. package/src/parser/cpp/grammar/CPP14Parser.ts +19961 -0
  48. package/src/parser/cpp/grammar/CPP14ParserListener.ts +2120 -0
  49. package/src/parser/cpp/grammar/CPP14ParserVisitor.ts +1354 -0
  50. package/src/parser/grammar/CNext.interp +340 -0
  51. package/src/parser/grammar/CNext.tokens +214 -0
  52. package/src/parser/grammar/CNextLexer.interp +374 -0
  53. package/src/parser/grammar/CNextLexer.tokens +214 -0
  54. package/src/parser/grammar/CNextLexer.ts +668 -0
  55. package/src/parser/grammar/CNextListener.ts +1020 -0
  56. package/src/parser/grammar/CNextParser.ts +9239 -0
  57. package/src/parser/grammar/CNextVisitor.ts +654 -0
  58. package/src/preprocessor/Preprocessor.ts +301 -0
  59. package/src/preprocessor/ToolchainDetector.ts +225 -0
  60. package/src/preprocessor/types/IPreprocessResult.ts +39 -0
  61. package/src/preprocessor/types/IToolchain.ts +27 -0
  62. package/src/project/FileDiscovery.ts +236 -0
  63. package/src/project/Project.ts +425 -0
  64. package/src/project/types/IProjectConfig.ts +64 -0
  65. package/src/symbols/CNextSymbolCollector.ts +326 -0
  66. package/src/symbols/CSymbolCollector.ts +457 -0
  67. package/src/symbols/CppSymbolCollector.ts +362 -0
  68. package/src/symbols/SymbolTable.ts +312 -0
  69. package/src/symbols/types/IConflict.ts +20 -0
  70. package/src/types/ESourceLanguage.ts +10 -0
  71. package/src/types/ESymbolKind.ts +20 -0
  72. package/src/types/ISymbol.ts +45 -0
package/grammar/C.g4 ADDED
@@ -0,0 +1,1112 @@
1
+ /*
2
+ [The "BSD licence"]
3
+ Copyright (c) 2013 Sam Harwell
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions
8
+ are met:
9
+ 1. Redistributions of source code must retain the above copyright
10
+ notice, this list of conditions and the following disclaimer.
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+ 3. The name of the author may not be used to endorse or promote products
15
+ derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+
29
+ /** C 2011 grammar built from the C11 Spec */
30
+
31
+ // $antlr-format alignTrailingComments true, columnLimit 150, minEmptyLines 1, maxEmptyLinesToKeep 1, reflowComments false, useTab false
32
+ // $antlr-format allowShortRulesOnASingleLine false, allowShortBlocksOnASingleLine true, alignSemicolons hanging, alignColons hanging
33
+
34
+ grammar C;
35
+
36
+ primaryExpression
37
+ : Identifier
38
+ | Constant
39
+ | StringLiteral+
40
+ | '(' expression ')'
41
+ | genericSelection
42
+ | '__extension__'? '(' compoundStatement ')' // Blocks (GCC extension)
43
+ | '__builtin_va_arg' '(' unaryExpression ',' typeName ')'
44
+ | '__builtin_offsetof' '(' typeName ',' unaryExpression ')'
45
+ ;
46
+
47
+ genericSelection
48
+ : '_Generic' '(' assignmentExpression ',' genericAssocList ')'
49
+ ;
50
+
51
+ genericAssocList
52
+ : genericAssociation (',' genericAssociation)*
53
+ ;
54
+
55
+ genericAssociation
56
+ : (typeName | 'default') ':' assignmentExpression
57
+ ;
58
+
59
+ postfixExpression
60
+ : (primaryExpression | '__extension__'? '(' typeName ')' '{' initializerList ','? '}') (
61
+ '[' expression ']'
62
+ | '(' argumentExpressionList? ')'
63
+ | ('.' | '->') Identifier
64
+ | '++'
65
+ | '--'
66
+ )*
67
+ ;
68
+
69
+ argumentExpressionList
70
+ : assignmentExpression (',' assignmentExpression)*
71
+ ;
72
+
73
+ unaryExpression
74
+ : ('++' | '--' | 'sizeof')* (
75
+ postfixExpression
76
+ | unaryOperator castExpression
77
+ | ('sizeof' | '_Alignof') '(' typeName ')'
78
+ | '&&' Identifier // GCC extension address of label
79
+ )
80
+ ;
81
+
82
+ unaryOperator
83
+ : '&'
84
+ | '*'
85
+ | '+'
86
+ | '-'
87
+ | '~'
88
+ | '!'
89
+ ;
90
+
91
+ castExpression
92
+ : '__extension__'? '(' typeName ')' castExpression
93
+ | unaryExpression
94
+ | DigitSequence // for
95
+ ;
96
+
97
+ multiplicativeExpression
98
+ : castExpression (('*' | '/' | '%') castExpression)*
99
+ ;
100
+
101
+ additiveExpression
102
+ : multiplicativeExpression (('+' | '-') multiplicativeExpression)*
103
+ ;
104
+
105
+ shiftExpression
106
+ : additiveExpression (('<<' | '>>') additiveExpression)*
107
+ ;
108
+
109
+ relationalExpression
110
+ : shiftExpression (('<' | '>' | '<=' | '>=') shiftExpression)*
111
+ ;
112
+
113
+ equalityExpression
114
+ : relationalExpression (('==' | '!=') relationalExpression)*
115
+ ;
116
+
117
+ andExpression
118
+ : equalityExpression ('&' equalityExpression)*
119
+ ;
120
+
121
+ exclusiveOrExpression
122
+ : andExpression ('^' andExpression)*
123
+ ;
124
+
125
+ inclusiveOrExpression
126
+ : exclusiveOrExpression ('|' exclusiveOrExpression)*
127
+ ;
128
+
129
+ logicalAndExpression
130
+ : inclusiveOrExpression ('&&' inclusiveOrExpression)*
131
+ ;
132
+
133
+ logicalOrExpression
134
+ : logicalAndExpression ('||' logicalAndExpression)*
135
+ ;
136
+
137
+ conditionalExpression
138
+ : logicalOrExpression ('?' expression ':' conditionalExpression)?
139
+ ;
140
+
141
+ assignmentExpression
142
+ : conditionalExpression
143
+ | unaryExpression assignmentOperator assignmentExpression
144
+ | DigitSequence // for
145
+ ;
146
+
147
+ assignmentOperator
148
+ : '='
149
+ | '*='
150
+ | '/='
151
+ | '%='
152
+ | '+='
153
+ | '-='
154
+ | '<<='
155
+ | '>>='
156
+ | '&='
157
+ | '^='
158
+ | '|='
159
+ ;
160
+
161
+ expression
162
+ : assignmentExpression (',' assignmentExpression)*
163
+ ;
164
+
165
+ constantExpression
166
+ : conditionalExpression
167
+ ;
168
+
169
+ declaration
170
+ : declarationSpecifiers initDeclaratorList? ';'
171
+ | staticAssertDeclaration
172
+ ;
173
+
174
+ declarationSpecifiers
175
+ : declarationSpecifier+
176
+ ;
177
+
178
+ declarationSpecifiers2
179
+ : declarationSpecifier+
180
+ ;
181
+
182
+ declarationSpecifier
183
+ : storageClassSpecifier
184
+ | typeSpecifier
185
+ | typeQualifier
186
+ | functionSpecifier
187
+ | alignmentSpecifier
188
+ ;
189
+
190
+ initDeclaratorList
191
+ : initDeclarator (',' initDeclarator)*
192
+ ;
193
+
194
+ initDeclarator
195
+ : declarator ('=' initializer)?
196
+ ;
197
+
198
+ storageClassSpecifier
199
+ : 'typedef'
200
+ | 'extern'
201
+ | 'static'
202
+ | '_Thread_local'
203
+ | 'auto'
204
+ | 'register'
205
+ ;
206
+
207
+ typeSpecifier
208
+ : 'void'
209
+ | 'char'
210
+ | 'short'
211
+ | 'int'
212
+ | 'long'
213
+ | 'float'
214
+ | 'double'
215
+ | 'signed'
216
+ | 'unsigned'
217
+ | '_Bool'
218
+ | '_Complex'
219
+ | '__m128'
220
+ | '__m128d'
221
+ | '__m128i'
222
+ | '__extension__' '(' ('__m128' | '__m128d' | '__m128i') ')'
223
+ | atomicTypeSpecifier
224
+ | structOrUnionSpecifier
225
+ | enumSpecifier
226
+ | typedefName
227
+ | '__typeof__' '(' constantExpression ')' // GCC extension
228
+ ;
229
+
230
+ structOrUnionSpecifier
231
+ : structOrUnion Identifier? '{' structDeclarationList '}'
232
+ | structOrUnion Identifier
233
+ ;
234
+
235
+ structOrUnion
236
+ : 'struct'
237
+ | 'union'
238
+ ;
239
+
240
+ structDeclarationList
241
+ : structDeclaration+
242
+ ;
243
+
244
+ structDeclaration // The first two rules have priority order and cannot be simplified to one expression.
245
+ : specifierQualifierList structDeclaratorList ';'
246
+ | specifierQualifierList ';'
247
+ | staticAssertDeclaration
248
+ ;
249
+
250
+ specifierQualifierList
251
+ : (typeSpecifier | typeQualifier) specifierQualifierList?
252
+ ;
253
+
254
+ structDeclaratorList
255
+ : structDeclarator (',' structDeclarator)*
256
+ ;
257
+
258
+ structDeclarator
259
+ : declarator
260
+ | declarator? ':' constantExpression
261
+ ;
262
+
263
+ enumSpecifier
264
+ : 'enum' Identifier? '{' enumeratorList ','? '}'
265
+ | 'enum' Identifier
266
+ ;
267
+
268
+ enumeratorList
269
+ : enumerator (',' enumerator)*
270
+ ;
271
+
272
+ enumerator
273
+ : enumerationConstant ('=' constantExpression)?
274
+ ;
275
+
276
+ enumerationConstant
277
+ : Identifier
278
+ ;
279
+
280
+ atomicTypeSpecifier
281
+ : '_Atomic' '(' typeName ')'
282
+ ;
283
+
284
+ typeQualifier
285
+ : 'const'
286
+ | 'restrict'
287
+ | 'volatile'
288
+ | '_Atomic'
289
+ ;
290
+
291
+ functionSpecifier
292
+ : 'inline'
293
+ | '_Noreturn'
294
+ | '__inline__' // GCC extension
295
+ | '__stdcall'
296
+ | gccAttributeSpecifier
297
+ | '__declspec' '(' Identifier ')'
298
+ ;
299
+
300
+ alignmentSpecifier
301
+ : '_Alignas' '(' (typeName | constantExpression) ')'
302
+ ;
303
+
304
+ declarator
305
+ : pointer? directDeclarator gccDeclaratorExtension*
306
+ ;
307
+
308
+ directDeclarator
309
+ : Identifier
310
+ | '(' declarator ')'
311
+ | directDeclarator '[' typeQualifierList? assignmentExpression? ']'
312
+ | directDeclarator '[' 'static' typeQualifierList? assignmentExpression ']'
313
+ | directDeclarator '[' typeQualifierList 'static' assignmentExpression ']'
314
+ | directDeclarator '[' typeQualifierList? '*' ']'
315
+ | directDeclarator '(' parameterTypeList ')'
316
+ | directDeclarator '(' identifierList? ')'
317
+ | Identifier ':' DigitSequence // bit field
318
+ | vcSpecificModifer Identifier // Visual C Extension
319
+ | '(' vcSpecificModifer declarator ')' // Visual C Extension
320
+ ;
321
+
322
+ vcSpecificModifer
323
+ : '__cdecl'
324
+ | '__clrcall'
325
+ | '__stdcall'
326
+ | '__fastcall'
327
+ | '__thiscall'
328
+ | '__vectorcall'
329
+ ;
330
+
331
+ gccDeclaratorExtension
332
+ : '__asm' '(' StringLiteral+ ')'
333
+ | gccAttributeSpecifier
334
+ ;
335
+
336
+ gccAttributeSpecifier
337
+ : '__attribute__' '(' '(' gccAttributeList ')' ')'
338
+ ;
339
+
340
+ gccAttributeList
341
+ : gccAttribute? (',' gccAttribute?)*
342
+ ;
343
+
344
+ gccAttribute
345
+ : ~(',' | '(' | ')') // relaxed def for "identifier or reserved word"
346
+ ('(' argumentExpressionList? ')')?
347
+ ;
348
+
349
+ pointer
350
+ : (('*' | '^') typeQualifierList?)+ // ^ - Blocks language extension
351
+ ;
352
+
353
+ typeQualifierList
354
+ : typeQualifier+
355
+ ;
356
+
357
+ parameterTypeList
358
+ : parameterList (',' '...')?
359
+ ;
360
+
361
+ parameterList
362
+ : parameterDeclaration (',' parameterDeclaration)*
363
+ ;
364
+
365
+ parameterDeclaration
366
+ : declarationSpecifiers declarator
367
+ | declarationSpecifiers2 abstractDeclarator?
368
+ ;
369
+
370
+ identifierList
371
+ : Identifier (',' Identifier)*
372
+ ;
373
+
374
+ typeName
375
+ : specifierQualifierList abstractDeclarator?
376
+ ;
377
+
378
+ abstractDeclarator
379
+ : pointer
380
+ | pointer? directAbstractDeclarator gccDeclaratorExtension*
381
+ ;
382
+
383
+ directAbstractDeclarator
384
+ : '(' abstractDeclarator ')' gccDeclaratorExtension*
385
+ | '[' typeQualifierList? assignmentExpression? ']'
386
+ | '[' 'static' typeQualifierList? assignmentExpression ']'
387
+ | '[' typeQualifierList 'static' assignmentExpression ']'
388
+ | '[' '*' ']'
389
+ | '(' parameterTypeList? ')' gccDeclaratorExtension*
390
+ | directAbstractDeclarator '[' typeQualifierList? assignmentExpression? ']'
391
+ | directAbstractDeclarator '[' 'static' typeQualifierList? assignmentExpression ']'
392
+ | directAbstractDeclarator '[' typeQualifierList 'static' assignmentExpression ']'
393
+ | directAbstractDeclarator '[' '*' ']'
394
+ | directAbstractDeclarator '(' parameterTypeList? ')' gccDeclaratorExtension*
395
+ ;
396
+
397
+ typedefName
398
+ : Identifier
399
+ ;
400
+
401
+ initializer
402
+ : assignmentExpression
403
+ | '{' initializerList ','? '}'
404
+ ;
405
+
406
+ initializerList
407
+ : designation? initializer (',' designation? initializer)*
408
+ ;
409
+
410
+ designation
411
+ : designatorList '='
412
+ ;
413
+
414
+ designatorList
415
+ : designator+
416
+ ;
417
+
418
+ designator
419
+ : '[' constantExpression ']'
420
+ | '.' Identifier
421
+ ;
422
+
423
+ staticAssertDeclaration
424
+ : '_Static_assert' '(' constantExpression ',' StringLiteral+ ')' ';'
425
+ ;
426
+
427
+ statement
428
+ : labeledStatement
429
+ | compoundStatement
430
+ | expressionStatement
431
+ | selectionStatement
432
+ | iterationStatement
433
+ | jumpStatement
434
+ | ('__asm' | '__asm__') ('volatile' | '__volatile__') '(' (
435
+ logicalOrExpression (',' logicalOrExpression)*
436
+ )? (':' (logicalOrExpression (',' logicalOrExpression)*)?)* ')' ';'
437
+ ;
438
+
439
+ labeledStatement
440
+ : Identifier ':' statement?
441
+ | 'case' constantExpression ':' statement
442
+ | 'default' ':' statement
443
+ ;
444
+
445
+ compoundStatement
446
+ : '{' blockItemList? '}'
447
+ ;
448
+
449
+ blockItemList
450
+ : blockItem+
451
+ ;
452
+
453
+ blockItem
454
+ : statement
455
+ | declaration
456
+ ;
457
+
458
+ expressionStatement
459
+ : expression? ';'
460
+ ;
461
+
462
+ selectionStatement
463
+ : 'if' '(' expression ')' statement ('else' statement)?
464
+ | 'switch' '(' expression ')' statement
465
+ ;
466
+
467
+ iterationStatement
468
+ : While '(' expression ')' statement
469
+ | Do statement While '(' expression ')' ';'
470
+ | For '(' forCondition ')' statement
471
+ ;
472
+
473
+ // | 'for' '(' expression? ';' expression? ';' forUpdate? ')' statement
474
+ // | For '(' declaration expression? ';' expression? ')' statement
475
+
476
+ forCondition
477
+ : (forDeclaration | expression?) ';' forExpression? ';' forExpression?
478
+ ;
479
+
480
+ forDeclaration
481
+ : declarationSpecifiers initDeclaratorList?
482
+ ;
483
+
484
+ forExpression
485
+ : assignmentExpression (',' assignmentExpression)*
486
+ ;
487
+
488
+ jumpStatement
489
+ : (
490
+ 'goto' Identifier
491
+ | 'continue'
492
+ | 'break'
493
+ | 'return' expression?
494
+ | 'goto' unaryExpression // GCC extension
495
+ ) ';'
496
+ ;
497
+
498
+ compilationUnit
499
+ : translationUnit? EOF
500
+ ;
501
+
502
+ translationUnit
503
+ : externalDeclaration+
504
+ ;
505
+
506
+ externalDeclaration
507
+ : functionDefinition
508
+ | declaration
509
+ | ';' // stray ;
510
+ ;
511
+
512
+ functionDefinition
513
+ : declarationSpecifiers? declarator declarationList? compoundStatement
514
+ ;
515
+
516
+ declarationList
517
+ : declaration+
518
+ ;
519
+
520
+ Auto
521
+ : 'auto'
522
+ ;
523
+
524
+ Break
525
+ : 'break'
526
+ ;
527
+
528
+ Case
529
+ : 'case'
530
+ ;
531
+
532
+ Char
533
+ : 'char'
534
+ ;
535
+
536
+ Const
537
+ : 'const'
538
+ ;
539
+
540
+ Continue
541
+ : 'continue'
542
+ ;
543
+
544
+ Default
545
+ : 'default'
546
+ ;
547
+
548
+ Do
549
+ : 'do'
550
+ ;
551
+
552
+ Double
553
+ : 'double'
554
+ ;
555
+
556
+ Else
557
+ : 'else'
558
+ ;
559
+
560
+ Enum
561
+ : 'enum'
562
+ ;
563
+
564
+ Extern
565
+ : 'extern'
566
+ ;
567
+
568
+ Float
569
+ : 'float'
570
+ ;
571
+
572
+ For
573
+ : 'for'
574
+ ;
575
+
576
+ Goto
577
+ : 'goto'
578
+ ;
579
+
580
+ If
581
+ : 'if'
582
+ ;
583
+
584
+ Inline
585
+ : 'inline'
586
+ ;
587
+
588
+ Int
589
+ : 'int'
590
+ ;
591
+
592
+ Long
593
+ : 'long'
594
+ ;
595
+
596
+ Register
597
+ : 'register'
598
+ ;
599
+
600
+ Restrict
601
+ : 'restrict'
602
+ ;
603
+
604
+ Return
605
+ : 'return'
606
+ ;
607
+
608
+ Short
609
+ : 'short'
610
+ ;
611
+
612
+ Signed
613
+ : 'signed'
614
+ ;
615
+
616
+ Sizeof
617
+ : 'sizeof'
618
+ ;
619
+
620
+ Static
621
+ : 'static'
622
+ ;
623
+
624
+ Struct
625
+ : 'struct'
626
+ ;
627
+
628
+ Switch
629
+ : 'switch'
630
+ ;
631
+
632
+ Typedef
633
+ : 'typedef'
634
+ ;
635
+
636
+ Union
637
+ : 'union'
638
+ ;
639
+
640
+ Unsigned
641
+ : 'unsigned'
642
+ ;
643
+
644
+ Void
645
+ : 'void'
646
+ ;
647
+
648
+ Volatile
649
+ : 'volatile'
650
+ ;
651
+
652
+ While
653
+ : 'while'
654
+ ;
655
+
656
+ Alignas
657
+ : '_Alignas'
658
+ ;
659
+
660
+ Alignof
661
+ : '_Alignof'
662
+ ;
663
+
664
+ Atomic
665
+ : '_Atomic'
666
+ ;
667
+
668
+ Bool
669
+ : '_Bool'
670
+ ;
671
+
672
+ Complex
673
+ : '_Complex'
674
+ ;
675
+
676
+ Generic
677
+ : '_Generic'
678
+ ;
679
+
680
+ Imaginary
681
+ : '_Imaginary'
682
+ ;
683
+
684
+ Noreturn
685
+ : '_Noreturn'
686
+ ;
687
+
688
+ StaticAssert
689
+ : '_Static_assert'
690
+ ;
691
+
692
+ ThreadLocal
693
+ : '_Thread_local'
694
+ ;
695
+
696
+ LeftParen
697
+ : '('
698
+ ;
699
+
700
+ RightParen
701
+ : ')'
702
+ ;
703
+
704
+ LeftBracket
705
+ : '['
706
+ ;
707
+
708
+ RightBracket
709
+ : ']'
710
+ ;
711
+
712
+ LeftBrace
713
+ : '{'
714
+ ;
715
+
716
+ RightBrace
717
+ : '}'
718
+ ;
719
+
720
+ Less
721
+ : '<'
722
+ ;
723
+
724
+ LessEqual
725
+ : '<='
726
+ ;
727
+
728
+ Greater
729
+ : '>'
730
+ ;
731
+
732
+ GreaterEqual
733
+ : '>='
734
+ ;
735
+
736
+ LeftShift
737
+ : '<<'
738
+ ;
739
+
740
+ RightShift
741
+ : '>>'
742
+ ;
743
+
744
+ Plus
745
+ : '+'
746
+ ;
747
+
748
+ PlusPlus
749
+ : '++'
750
+ ;
751
+
752
+ Minus
753
+ : '-'
754
+ ;
755
+
756
+ MinusMinus
757
+ : '--'
758
+ ;
759
+
760
+ Star
761
+ : '*'
762
+ ;
763
+
764
+ Div
765
+ : '/'
766
+ ;
767
+
768
+ Mod
769
+ : '%'
770
+ ;
771
+
772
+ And
773
+ : '&'
774
+ ;
775
+
776
+ Or
777
+ : '|'
778
+ ;
779
+
780
+ AndAnd
781
+ : '&&'
782
+ ;
783
+
784
+ OrOr
785
+ : '||'
786
+ ;
787
+
788
+ Caret
789
+ : '^'
790
+ ;
791
+
792
+ Not
793
+ : '!'
794
+ ;
795
+
796
+ Tilde
797
+ : '~'
798
+ ;
799
+
800
+ Question
801
+ : '?'
802
+ ;
803
+
804
+ Colon
805
+ : ':'
806
+ ;
807
+
808
+ Semi
809
+ : ';'
810
+ ;
811
+
812
+ Comma
813
+ : ','
814
+ ;
815
+
816
+ Assign
817
+ : '='
818
+ ;
819
+
820
+ // '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '&=' | '^=' | '|='
821
+ StarAssign
822
+ : '*='
823
+ ;
824
+
825
+ DivAssign
826
+ : '/='
827
+ ;
828
+
829
+ ModAssign
830
+ : '%='
831
+ ;
832
+
833
+ PlusAssign
834
+ : '+='
835
+ ;
836
+
837
+ MinusAssign
838
+ : '-='
839
+ ;
840
+
841
+ LeftShiftAssign
842
+ : '<<='
843
+ ;
844
+
845
+ RightShiftAssign
846
+ : '>>='
847
+ ;
848
+
849
+ AndAssign
850
+ : '&='
851
+ ;
852
+
853
+ XorAssign
854
+ : '^='
855
+ ;
856
+
857
+ OrAssign
858
+ : '|='
859
+ ;
860
+
861
+ Equal
862
+ : '=='
863
+ ;
864
+
865
+ NotEqual
866
+ : '!='
867
+ ;
868
+
869
+ Arrow
870
+ : '->'
871
+ ;
872
+
873
+ Dot
874
+ : '.'
875
+ ;
876
+
877
+ Ellipsis
878
+ : '...'
879
+ ;
880
+
881
+ Identifier
882
+ : IdentifierNondigit (IdentifierNondigit | Digit)*
883
+ ;
884
+
885
+ fragment IdentifierNondigit
886
+ : Nondigit
887
+ | UniversalCharacterName
888
+ //| // other implementation-defined characters...
889
+ ;
890
+
891
+ fragment Nondigit
892
+ : [a-zA-Z_]
893
+ ;
894
+
895
+ fragment Digit
896
+ : [0-9]
897
+ ;
898
+
899
+ fragment UniversalCharacterName
900
+ : '\\u' HexQuad
901
+ | '\\U' HexQuad HexQuad
902
+ ;
903
+
904
+ fragment HexQuad
905
+ : HexadecimalDigit HexadecimalDigit HexadecimalDigit HexadecimalDigit
906
+ ;
907
+
908
+ Constant
909
+ : IntegerConstant
910
+ | FloatingConstant
911
+ //| EnumerationConstant
912
+ | CharacterConstant
913
+ ;
914
+
915
+ fragment IntegerConstant
916
+ : DecimalConstant IntegerSuffix?
917
+ | OctalConstant IntegerSuffix?
918
+ | HexadecimalConstant IntegerSuffix?
919
+ | BinaryConstant
920
+ ;
921
+
922
+ fragment BinaryConstant
923
+ : '0' [bB] [0-1]+
924
+ ;
925
+
926
+ fragment DecimalConstant
927
+ : NonzeroDigit Digit*
928
+ ;
929
+
930
+ fragment OctalConstant
931
+ : '0' OctalDigit*
932
+ ;
933
+
934
+ fragment HexadecimalConstant
935
+ : HexadecimalPrefix HexadecimalDigit+
936
+ ;
937
+
938
+ fragment HexadecimalPrefix
939
+ : '0' [xX]
940
+ ;
941
+
942
+ fragment NonzeroDigit
943
+ : [1-9]
944
+ ;
945
+
946
+ fragment OctalDigit
947
+ : [0-7]
948
+ ;
949
+
950
+ fragment HexadecimalDigit
951
+ : [0-9a-fA-F]
952
+ ;
953
+
954
+ fragment IntegerSuffix
955
+ : UnsignedSuffix LongSuffix?
956
+ | UnsignedSuffix LongLongSuffix
957
+ | LongSuffix UnsignedSuffix?
958
+ | LongLongSuffix UnsignedSuffix?
959
+ ;
960
+
961
+ fragment UnsignedSuffix
962
+ : [uU]
963
+ ;
964
+
965
+ fragment LongSuffix
966
+ : [lL]
967
+ ;
968
+
969
+ fragment LongLongSuffix
970
+ : 'll'
971
+ | 'LL'
972
+ ;
973
+
974
+ fragment FloatingConstant
975
+ : DecimalFloatingConstant
976
+ | HexadecimalFloatingConstant
977
+ ;
978
+
979
+ fragment DecimalFloatingConstant
980
+ : FractionalConstant ExponentPart? FloatingSuffix?
981
+ | DigitSequence ExponentPart FloatingSuffix?
982
+ ;
983
+
984
+ fragment HexadecimalFloatingConstant
985
+ : HexadecimalPrefix (HexadecimalFractionalConstant | HexadecimalDigitSequence) BinaryExponentPart FloatingSuffix?
986
+ ;
987
+
988
+ fragment FractionalConstant
989
+ : DigitSequence? '.' DigitSequence
990
+ | DigitSequence '.'
991
+ ;
992
+
993
+ fragment ExponentPart
994
+ : [eE] Sign? DigitSequence
995
+ ;
996
+
997
+ fragment Sign
998
+ : [+-]
999
+ ;
1000
+
1001
+ DigitSequence
1002
+ : Digit+
1003
+ ;
1004
+
1005
+ fragment HexadecimalFractionalConstant
1006
+ : HexadecimalDigitSequence? '.' HexadecimalDigitSequence
1007
+ | HexadecimalDigitSequence '.'
1008
+ ;
1009
+
1010
+ fragment BinaryExponentPart
1011
+ : [pP] Sign? DigitSequence
1012
+ ;
1013
+
1014
+ fragment HexadecimalDigitSequence
1015
+ : HexadecimalDigit+
1016
+ ;
1017
+
1018
+ fragment FloatingSuffix
1019
+ : [flFL]
1020
+ ;
1021
+
1022
+ fragment CharacterConstant
1023
+ : '\'' CCharSequence '\''
1024
+ | 'L\'' CCharSequence '\''
1025
+ | 'u\'' CCharSequence '\''
1026
+ | 'U\'' CCharSequence '\''
1027
+ ;
1028
+
1029
+ fragment CCharSequence
1030
+ : CChar+
1031
+ ;
1032
+
1033
+ fragment CChar
1034
+ : ~['\\\r\n]
1035
+ | EscapeSequence
1036
+ ;
1037
+
1038
+ fragment EscapeSequence
1039
+ : SimpleEscapeSequence
1040
+ | OctalEscapeSequence
1041
+ | HexadecimalEscapeSequence
1042
+ | UniversalCharacterName
1043
+ ;
1044
+
1045
+ fragment SimpleEscapeSequence
1046
+ : '\\' ['"?abfnrtv\\]
1047
+ ;
1048
+
1049
+ fragment OctalEscapeSequence
1050
+ : '\\' OctalDigit OctalDigit? OctalDigit?
1051
+ ;
1052
+
1053
+ fragment HexadecimalEscapeSequence
1054
+ : '\\x' HexadecimalDigit+
1055
+ ;
1056
+
1057
+ StringLiteral
1058
+ : EncodingPrefix? '"' SCharSequence? '"'
1059
+ ;
1060
+
1061
+ fragment EncodingPrefix
1062
+ : 'u8'
1063
+ | 'u'
1064
+ | 'U'
1065
+ | 'L'
1066
+ ;
1067
+
1068
+ fragment SCharSequence
1069
+ : SChar+
1070
+ ;
1071
+
1072
+ fragment SChar
1073
+ : ~["\\\r\n]
1074
+ | EscapeSequence
1075
+ | '\\\n' // Added line
1076
+ | '\\\r\n' // Added line
1077
+ ;
1078
+
1079
+ MultiLineMacro
1080
+ : '#' (~[\n]*? '\\' '\r'? '\n')+ ~ [\n]+ -> channel (HIDDEN)
1081
+ ;
1082
+
1083
+ Directive
1084
+ : '#' ~ [\n]* -> channel (HIDDEN)
1085
+ ;
1086
+
1087
+ // ignore the following asm blocks:
1088
+ /*
1089
+ asm
1090
+ {
1091
+ mfspr x, 286;
1092
+ }
1093
+ */
1094
+ AsmBlock
1095
+ : 'asm' ~'{'* '{' ~'}'* '}' -> channel(HIDDEN)
1096
+ ;
1097
+
1098
+ Whitespace
1099
+ : [ \t]+ -> channel(HIDDEN)
1100
+ ;
1101
+
1102
+ Newline
1103
+ : ('\r' '\n'? | '\n') -> channel(HIDDEN)
1104
+ ;
1105
+
1106
+ BlockComment
1107
+ : '/*' .*? '*/' -> channel(HIDDEN)
1108
+ ;
1109
+
1110
+ LineComment
1111
+ : '//' ~[\r\n]* -> channel(HIDDEN)
1112
+ ;