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
@@ -0,0 +1,1072 @@
1
+ /*******************************************************************************
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 Camilo Sanchez (Camiloasc1) 2020 Martin Mirchev (Marti2203)
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
7
+ * associated documentation files (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all copies or
13
+ * substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
16
+ * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ * ****************************************************************************
21
+ */
22
+
23
+ // $antlr-format alignTrailingComments true, columnLimit 150, minEmptyLines 1, maxEmptyLinesToKeep 1, reflowComments false, useTab false
24
+ // $antlr-format allowShortRulesOnASingleLine false, allowShortBlocksOnASingleLine true, alignSemicolons hanging, alignColons hanging
25
+
26
+ parser grammar CPP14Parser;
27
+
28
+ options {
29
+ tokenVocab = CPP14Lexer;
30
+ }
31
+
32
+ // Insert here @header for C++ parser.
33
+
34
+ /*Basic concepts*/
35
+
36
+ translationUnit
37
+ : declarationseq? EOF
38
+ ;
39
+
40
+ /*Expressions*/
41
+
42
+ primaryExpression
43
+ : literal+
44
+ | This
45
+ | LeftParen expression RightParen
46
+ | idExpression
47
+ | lambdaExpression
48
+ ;
49
+
50
+ idExpression
51
+ : unqualifiedId
52
+ | qualifiedId
53
+ ;
54
+
55
+ unqualifiedId
56
+ : Identifier
57
+ | operatorFunctionId
58
+ | conversionFunctionId
59
+ | literalOperatorId
60
+ | Tilde (className | decltypeSpecifier)
61
+ | templateId
62
+ ;
63
+
64
+ qualifiedId
65
+ : nestedNameSpecifier Template? unqualifiedId
66
+ ;
67
+
68
+ nestedNameSpecifier
69
+ : (theTypeName | namespaceName | decltypeSpecifier)? Doublecolon
70
+ | nestedNameSpecifier ( Identifier | Template? simpleTemplateId) Doublecolon
71
+ ;
72
+
73
+ lambdaExpression
74
+ : lambdaIntroducer lambdaDeclarator? compoundStatement
75
+ ;
76
+
77
+ lambdaIntroducer
78
+ : LeftBracket lambdaCapture? RightBracket
79
+ ;
80
+
81
+ lambdaCapture
82
+ : captureList
83
+ | captureDefault (Comma captureList)?
84
+ ;
85
+
86
+ captureDefault
87
+ : And
88
+ | Assign
89
+ ;
90
+
91
+ captureList
92
+ : capture (Comma capture)* Ellipsis?
93
+ ;
94
+
95
+ capture
96
+ : simpleCapture
97
+ | initcapture
98
+ ;
99
+
100
+ simpleCapture
101
+ : And? Identifier
102
+ | This
103
+ ;
104
+
105
+ initcapture
106
+ : And? Identifier initializer
107
+ ;
108
+
109
+ lambdaDeclarator
110
+ : LeftParen parameterDeclarationClause? RightParen Mutable? exceptionSpecification? attributeSpecifierSeq? trailingReturnType?
111
+ ;
112
+
113
+ postfixExpression
114
+ : primaryExpression
115
+ | postfixExpression LeftBracket (expression | bracedInitList) RightBracket
116
+ | postfixExpression LeftParen expressionList? RightParen
117
+ | (simpleTypeSpecifier | typeNameSpecifier) (
118
+ LeftParen expressionList? RightParen
119
+ | bracedInitList
120
+ )
121
+ | postfixExpression (Dot | Arrow) (Template? idExpression | pseudoDestructorName)
122
+ | postfixExpression (PlusPlus | MinusMinus)
123
+ | (Dynamic_cast | Static_cast | Reinterpret_cast | Const_cast) Less theTypeId Greater LeftParen expression RightParen
124
+ | typeIdOfTheTypeId LeftParen (expression | theTypeId) RightParen
125
+ ;
126
+
127
+ /*
128
+ add a middle layer to eliminate duplicated function declarations
129
+ */
130
+
131
+ typeIdOfTheTypeId
132
+ : Typeid_
133
+ ;
134
+
135
+ expressionList
136
+ : initializerList
137
+ ;
138
+
139
+ pseudoDestructorName
140
+ : nestedNameSpecifier? (theTypeName Doublecolon)? Tilde theTypeName
141
+ | nestedNameSpecifier Template simpleTemplateId Doublecolon Tilde theTypeName
142
+ | Tilde decltypeSpecifier
143
+ ;
144
+
145
+ unaryExpression
146
+ : postfixExpression
147
+ | (PlusPlus | MinusMinus | unaryOperator | Sizeof) unaryExpression
148
+ | Sizeof (LeftParen theTypeId RightParen | Ellipsis LeftParen Identifier RightParen)
149
+ | Alignof LeftParen theTypeId RightParen
150
+ | noExceptExpression
151
+ | newExpression_
152
+ | deleteExpression
153
+ ;
154
+
155
+ unaryOperator
156
+ : Or
157
+ | Star
158
+ | And
159
+ | Plus
160
+ | Tilde
161
+ | Minus
162
+ | Not
163
+ ;
164
+
165
+ newExpression_
166
+ : Doublecolon? New newPlacement? (newTypeId | LeftParen theTypeId RightParen) newInitializer_?
167
+ ;
168
+
169
+ newPlacement
170
+ : LeftParen expressionList RightParen
171
+ ;
172
+
173
+ newTypeId
174
+ : typeSpecifierSeq newDeclarator_?
175
+ ;
176
+
177
+ newDeclarator_
178
+ : pointerOperator newDeclarator_?
179
+ | noPointerNewDeclarator
180
+ ;
181
+
182
+ noPointerNewDeclarator
183
+ : LeftBracket expression RightBracket attributeSpecifierSeq?
184
+ | noPointerNewDeclarator LeftBracket constantExpression RightBracket attributeSpecifierSeq?
185
+ ;
186
+
187
+ newInitializer_
188
+ : LeftParen expressionList? RightParen
189
+ | bracedInitList
190
+ ;
191
+
192
+ deleteExpression
193
+ : Doublecolon? Delete (LeftBracket RightBracket)? castExpression
194
+ ;
195
+
196
+ noExceptExpression
197
+ : Noexcept LeftParen expression RightParen
198
+ ;
199
+
200
+ castExpression
201
+ : unaryExpression
202
+ | LeftParen theTypeId RightParen castExpression
203
+ ;
204
+
205
+ pointerMemberExpression
206
+ : castExpression ((DotStar | ArrowStar) castExpression)*
207
+ ;
208
+
209
+ multiplicativeExpression
210
+ : pointerMemberExpression ((Star | Div | Mod) pointerMemberExpression)*
211
+ ;
212
+
213
+ additiveExpression
214
+ : multiplicativeExpression ((Plus | Minus) multiplicativeExpression)*
215
+ ;
216
+
217
+ shiftExpression
218
+ : additiveExpression (shiftOperator additiveExpression)*
219
+ ;
220
+
221
+ shiftOperator
222
+ : Greater Greater
223
+ | Less Less
224
+ ;
225
+
226
+ relationalExpression
227
+ : shiftExpression ((Less | Greater | LessEqual | GreaterEqual) shiftExpression)*
228
+ ;
229
+
230
+ equalityExpression
231
+ : relationalExpression ((Equal | NotEqual) relationalExpression)*
232
+ ;
233
+
234
+ andExpression
235
+ : equalityExpression (And equalityExpression)*
236
+ ;
237
+
238
+ exclusiveOrExpression
239
+ : andExpression (Caret andExpression)*
240
+ ;
241
+
242
+ inclusiveOrExpression
243
+ : exclusiveOrExpression (Or exclusiveOrExpression)*
244
+ ;
245
+
246
+ logicalAndExpression
247
+ : inclusiveOrExpression (AndAnd inclusiveOrExpression)*
248
+ ;
249
+
250
+ logicalOrExpression
251
+ : logicalAndExpression (OrOr logicalAndExpression)*
252
+ ;
253
+
254
+ conditionalExpression
255
+ : logicalOrExpression (Question expression Colon assignmentExpression)?
256
+ ;
257
+
258
+ assignmentExpression
259
+ : conditionalExpression
260
+ | logicalOrExpression assignmentOperator initializerClause
261
+ | throwExpression
262
+ ;
263
+
264
+ assignmentOperator
265
+ : Assign
266
+ | StarAssign
267
+ | DivAssign
268
+ | ModAssign
269
+ | PlusAssign
270
+ | MinusAssign
271
+ | RightShiftAssign
272
+ | LeftShiftAssign
273
+ | AndAssign
274
+ | XorAssign
275
+ | OrAssign
276
+ ;
277
+
278
+ expression
279
+ : assignmentExpression (Comma assignmentExpression)*
280
+ ;
281
+
282
+ constantExpression
283
+ : conditionalExpression
284
+ ;
285
+
286
+ /*Statements*/
287
+
288
+ statement
289
+ : labeledStatement
290
+ | declarationStatement
291
+ | attributeSpecifierSeq? (
292
+ expressionStatement
293
+ | compoundStatement
294
+ | selectionStatement
295
+ | iterationStatement
296
+ | jumpStatement
297
+ | tryBlock
298
+ )
299
+ ;
300
+
301
+ labeledStatement
302
+ : attributeSpecifierSeq? (Identifier | Case constantExpression | Default) Colon statement
303
+ ;
304
+
305
+ expressionStatement
306
+ : expression? Semi
307
+ ;
308
+
309
+ compoundStatement
310
+ : LeftBrace statementSeq? RightBrace
311
+ ;
312
+
313
+ statementSeq
314
+ : statement+
315
+ ;
316
+
317
+ selectionStatement
318
+ : If LeftParen condition RightParen statement (Else statement)?
319
+ | Switch LeftParen condition RightParen statement
320
+ ;
321
+
322
+ condition
323
+ : expression
324
+ | attributeSpecifierSeq? declSpecifierSeq declarator (
325
+ Assign initializerClause
326
+ | bracedInitList
327
+ )
328
+ ;
329
+
330
+ iterationStatement
331
+ : While LeftParen condition RightParen statement
332
+ | Do statement While LeftParen expression RightParen Semi
333
+ | For LeftParen (
334
+ forInitStatement condition? Semi expression?
335
+ | forRangeDeclaration Colon forRangeInitializer
336
+ ) RightParen statement
337
+ ;
338
+
339
+ forInitStatement
340
+ : expressionStatement
341
+ | simpleDeclaration
342
+ ;
343
+
344
+ forRangeDeclaration
345
+ : attributeSpecifierSeq? declSpecifierSeq declarator
346
+ ;
347
+
348
+ forRangeInitializer
349
+ : expression
350
+ | bracedInitList
351
+ ;
352
+
353
+ jumpStatement
354
+ : (Break | Continue | Return (expression | bracedInitList)? | Goto Identifier) Semi
355
+ ;
356
+
357
+ declarationStatement
358
+ : blockDeclaration
359
+ ;
360
+
361
+ /*Declarations*/
362
+
363
+ declarationseq
364
+ : declaration+
365
+ ;
366
+
367
+ declaration
368
+ : blockDeclaration
369
+ | functionDefinition
370
+ | templateDeclaration
371
+ | explicitInstantiation
372
+ | explicitSpecialization
373
+ | linkageSpecification
374
+ | namespaceDefinition
375
+ | emptyDeclaration_
376
+ | attributeDeclaration
377
+ ;
378
+
379
+ blockDeclaration
380
+ : simpleDeclaration
381
+ | asmDefinition
382
+ | namespaceAliasDefinition
383
+ | usingDeclaration
384
+ | usingDirective
385
+ | staticAssertDeclaration
386
+ | aliasDeclaration
387
+ | opaqueEnumDeclaration
388
+ ;
389
+
390
+ aliasDeclaration
391
+ : Using Identifier attributeSpecifierSeq? Assign theTypeId Semi
392
+ ;
393
+
394
+ simpleDeclaration
395
+ : declSpecifierSeq? initDeclaratorList? Semi
396
+ | attributeSpecifierSeq declSpecifierSeq? initDeclaratorList Semi
397
+ ;
398
+
399
+ staticAssertDeclaration
400
+ : Static_assert LeftParen constantExpression Comma StringLiteral RightParen Semi
401
+ ;
402
+
403
+ emptyDeclaration_
404
+ : Semi
405
+ ;
406
+
407
+ attributeDeclaration
408
+ : attributeSpecifierSeq Semi
409
+ ;
410
+
411
+ declSpecifier
412
+ : storageClassSpecifier
413
+ | typeSpecifier
414
+ | functionSpecifier
415
+ | Friend
416
+ | Typedef
417
+ | Constexpr
418
+ ;
419
+
420
+ declSpecifierSeq
421
+ : declSpecifier+? attributeSpecifierSeq?
422
+ ;
423
+
424
+ storageClassSpecifier
425
+ : Register
426
+ | Static
427
+ | Thread_local
428
+ | Extern
429
+ | Mutable
430
+ ;
431
+
432
+ functionSpecifier
433
+ : Inline
434
+ | Virtual
435
+ | Explicit
436
+ ;
437
+
438
+ typedefName
439
+ : Identifier
440
+ ;
441
+
442
+ typeSpecifier
443
+ : trailingTypeSpecifier
444
+ | classSpecifier
445
+ | enumSpecifier
446
+ ;
447
+
448
+ trailingTypeSpecifier
449
+ : simpleTypeSpecifier
450
+ | elaboratedTypeSpecifier
451
+ | typeNameSpecifier
452
+ | cvQualifier
453
+ ;
454
+
455
+ typeSpecifierSeq
456
+ : typeSpecifier+ attributeSpecifierSeq?
457
+ ;
458
+
459
+ trailingTypeSpecifierSeq
460
+ : trailingTypeSpecifier+ attributeSpecifierSeq?
461
+ ;
462
+
463
+ simpleTypeLengthModifier
464
+ : Short
465
+ | Long
466
+ ;
467
+
468
+ simpleTypeSignednessModifier
469
+ : Unsigned
470
+ | Signed
471
+ ;
472
+
473
+ simpleTypeSpecifier
474
+ : nestedNameSpecifier? theTypeName
475
+ | nestedNameSpecifier Template simpleTemplateId
476
+ | Char
477
+ | Char16
478
+ | Char32
479
+ | Wchar
480
+ | Bool
481
+ | Short
482
+ | Int
483
+ | Long
484
+ | Float
485
+ | Signed
486
+ | Unsigned
487
+ | Float
488
+ | Double
489
+ | Void
490
+ | Auto
491
+ | decltypeSpecifier
492
+ ;
493
+
494
+ theTypeName
495
+ : className
496
+ | enumName
497
+ | typedefName
498
+ | simpleTemplateId
499
+ ;
500
+
501
+ decltypeSpecifier
502
+ : Decltype LeftParen (expression | Auto) RightParen
503
+ ;
504
+
505
+ elaboratedTypeSpecifier
506
+ : classKey (
507
+ attributeSpecifierSeq? nestedNameSpecifier? Identifier
508
+ | simpleTemplateId
509
+ | nestedNameSpecifier Template? simpleTemplateId
510
+ )
511
+ | Enum nestedNameSpecifier? Identifier
512
+ ;
513
+
514
+ enumName
515
+ : Identifier
516
+ ;
517
+
518
+ enumSpecifier
519
+ : enumHead LeftBrace (enumeratorList Comma?)? RightBrace
520
+ ;
521
+
522
+ enumHead
523
+ : enumkey attributeSpecifierSeq? (nestedNameSpecifier? Identifier)? enumbase?
524
+ ;
525
+
526
+ opaqueEnumDeclaration
527
+ : enumkey attributeSpecifierSeq? Identifier enumbase? Semi
528
+ ;
529
+
530
+ enumkey
531
+ : Enum (Class | Struct)?
532
+ ;
533
+
534
+ enumbase
535
+ : Colon typeSpecifierSeq
536
+ ;
537
+
538
+ enumeratorList
539
+ : enumeratorDefinition (Comma enumeratorDefinition)*
540
+ ;
541
+
542
+ enumeratorDefinition
543
+ : enumerator (Assign constantExpression)?
544
+ ;
545
+
546
+ enumerator
547
+ : Identifier
548
+ ;
549
+
550
+ namespaceName
551
+ : originalNamespaceName
552
+ | namespaceAlias
553
+ ;
554
+
555
+ originalNamespaceName
556
+ : Identifier
557
+ ;
558
+
559
+ namespaceDefinition
560
+ : Inline? Namespace (Identifier | originalNamespaceName)? LeftBrace namespaceBody = declarationseq? RightBrace
561
+ ;
562
+
563
+ namespaceAlias
564
+ : Identifier
565
+ ;
566
+
567
+ namespaceAliasDefinition
568
+ : Namespace Identifier Assign qualifiednamespacespecifier Semi
569
+ ;
570
+
571
+ qualifiednamespacespecifier
572
+ : nestedNameSpecifier? namespaceName
573
+ ;
574
+
575
+ usingDeclaration
576
+ : Using (Typename_? nestedNameSpecifier | Doublecolon) unqualifiedId Semi
577
+ ;
578
+
579
+ usingDirective
580
+ : attributeSpecifierSeq? Using Namespace nestedNameSpecifier? namespaceName Semi
581
+ ;
582
+
583
+ asmDefinition
584
+ : Asm LeftParen StringLiteral RightParen Semi
585
+ ;
586
+
587
+ linkageSpecification
588
+ : Extern StringLiteral (LeftBrace declarationseq? RightBrace | declaration)
589
+ ;
590
+
591
+ attributeSpecifierSeq
592
+ : attributeSpecifier+
593
+ ;
594
+
595
+ attributeSpecifier
596
+ : LeftBracket LeftBracket attributeList? RightBracket RightBracket
597
+ | alignmentspecifier
598
+ ;
599
+
600
+ alignmentspecifier
601
+ : Alignas LeftParen (theTypeId | constantExpression) Ellipsis? RightParen
602
+ ;
603
+
604
+ attributeList
605
+ : attribute (Comma attribute)* Ellipsis?
606
+ ;
607
+
608
+ attribute
609
+ : (attributeNamespace Doublecolon)? Identifier attributeArgumentClause?
610
+ ;
611
+
612
+ attributeNamespace
613
+ : Identifier
614
+ ;
615
+
616
+ attributeArgumentClause
617
+ : LeftParen balancedTokenSeq? RightParen
618
+ ;
619
+
620
+ balancedTokenSeq
621
+ : balancedtoken+
622
+ ;
623
+
624
+ balancedtoken
625
+ : LeftParen balancedTokenSeq RightParen
626
+ | LeftBracket balancedTokenSeq RightBracket
627
+ | LeftBrace balancedTokenSeq RightBrace
628
+ | ~(LeftParen | RightParen | LeftBrace | RightBrace | LeftBracket | RightBracket)+
629
+ ;
630
+
631
+ /*Declarators*/
632
+
633
+ initDeclaratorList
634
+ : initDeclarator (Comma initDeclarator)*
635
+ ;
636
+
637
+ initDeclarator
638
+ : declarator initializer?
639
+ ;
640
+
641
+ declarator
642
+ : pointerDeclarator
643
+ | noPointerDeclarator parametersAndQualifiers trailingReturnType
644
+ ;
645
+
646
+ pointerDeclarator
647
+ : (pointerOperator Const?)* noPointerDeclarator
648
+ ;
649
+
650
+ noPointerDeclarator
651
+ : declaratorid attributeSpecifierSeq?
652
+ | noPointerDeclarator (
653
+ parametersAndQualifiers
654
+ | LeftBracket constantExpression? RightBracket attributeSpecifierSeq?
655
+ )
656
+ | LeftParen pointerDeclarator RightParen
657
+ ;
658
+
659
+ parametersAndQualifiers
660
+ : LeftParen parameterDeclarationClause? RightParen cvqualifierseq? refqualifier? exceptionSpecification? attributeSpecifierSeq?
661
+ ;
662
+
663
+ trailingReturnType
664
+ : Arrow trailingTypeSpecifierSeq abstractDeclarator?
665
+ ;
666
+
667
+ pointerOperator
668
+ : (And | AndAnd) attributeSpecifierSeq?
669
+ | nestedNameSpecifier? Star attributeSpecifierSeq? cvqualifierseq?
670
+ ;
671
+
672
+ cvqualifierseq
673
+ : cvQualifier+
674
+ ;
675
+
676
+ cvQualifier
677
+ : Const
678
+ | Volatile
679
+ ;
680
+
681
+ refqualifier
682
+ : And
683
+ | AndAnd
684
+ ;
685
+
686
+ declaratorid
687
+ : Ellipsis? idExpression
688
+ ;
689
+
690
+ theTypeId
691
+ : typeSpecifierSeq abstractDeclarator?
692
+ ;
693
+
694
+ abstractDeclarator
695
+ : pointerAbstractDeclarator
696
+ | noPointerAbstractDeclarator? parametersAndQualifiers trailingReturnType
697
+ | abstractPackDeclarator
698
+ ;
699
+
700
+ pointerAbstractDeclarator
701
+ : pointerOperator* (noPointerAbstractDeclarator | pointerOperator)
702
+ ;
703
+
704
+ noPointerAbstractDeclarator
705
+ : (parametersAndQualifiers | LeftParen pointerAbstractDeclarator RightParen) (
706
+ parametersAndQualifiers
707
+ | LeftBracket constantExpression? RightBracket attributeSpecifierSeq?
708
+ )*
709
+ ;
710
+
711
+ abstractPackDeclarator
712
+ : pointerOperator* noPointerAbstractPackDeclarator
713
+ ;
714
+
715
+ noPointerAbstractPackDeclarator
716
+ : Ellipsis (
717
+ parametersAndQualifiers
718
+ | LeftBracket constantExpression? RightBracket attributeSpecifierSeq?
719
+ )*
720
+ ;
721
+
722
+ parameterDeclarationClause
723
+ : parameterDeclarationList (Comma? Ellipsis)?
724
+ ;
725
+
726
+ parameterDeclarationList
727
+ : parameterDeclaration (Comma parameterDeclaration)*
728
+ ;
729
+
730
+ parameterDeclaration
731
+ : attributeSpecifierSeq? declSpecifierSeq (declarator | abstractDeclarator?) (
732
+ Assign initializerClause
733
+ )?
734
+ ;
735
+
736
+ functionDefinition
737
+ : attributeSpecifierSeq? declSpecifierSeq? declarator virtualSpecifierSeq? functionBody
738
+ ;
739
+
740
+ functionBody
741
+ : constructorInitializer? compoundStatement
742
+ | functionTryBlock
743
+ | Assign (Default | Delete) Semi
744
+ ;
745
+
746
+ initializer
747
+ : braceOrEqualInitializer
748
+ | LeftParen expressionList RightParen
749
+ ;
750
+
751
+ braceOrEqualInitializer
752
+ : Assign initializerClause
753
+ | bracedInitList
754
+ ;
755
+
756
+ initializerClause
757
+ : assignmentExpression
758
+ | bracedInitList
759
+ ;
760
+
761
+ initializerList
762
+ : initializerClause Ellipsis? (Comma initializerClause Ellipsis?)*
763
+ ;
764
+
765
+ bracedInitList
766
+ : LeftBrace (initializerList Comma?)? RightBrace
767
+ ;
768
+
769
+ /*Classes*/
770
+
771
+ className
772
+ : Identifier
773
+ | simpleTemplateId
774
+ ;
775
+
776
+ classSpecifier
777
+ : classHead LeftBrace memberSpecification? RightBrace
778
+ ;
779
+
780
+ classHead
781
+ : classKey attributeSpecifierSeq? (classHeadName classVirtSpecifier?)? baseClause?
782
+ | Union attributeSpecifierSeq? ( classHeadName classVirtSpecifier?)?
783
+ ;
784
+
785
+ classHeadName
786
+ : nestedNameSpecifier? className
787
+ ;
788
+
789
+ classVirtSpecifier
790
+ : Final
791
+ ;
792
+
793
+ classKey
794
+ : Class
795
+ | Struct
796
+ ;
797
+
798
+ memberSpecification
799
+ : (memberdeclaration | accessSpecifier Colon)+
800
+ ;
801
+
802
+ memberdeclaration
803
+ : attributeSpecifierSeq? declSpecifierSeq? memberDeclaratorList? Semi
804
+ | functionDefinition
805
+ | usingDeclaration
806
+ | staticAssertDeclaration
807
+ | templateDeclaration
808
+ | aliasDeclaration
809
+ | emptyDeclaration_
810
+ ;
811
+
812
+ memberDeclaratorList
813
+ : memberDeclarator (Comma memberDeclarator)*
814
+ ;
815
+
816
+ memberDeclarator
817
+ : declarator (
818
+ virtualSpecifierSeq pureSpecifier?
819
+ | pureSpecifier
820
+ | braceOrEqualInitializer
821
+ )?
822
+ | Identifier? attributeSpecifierSeq? Colon constantExpression
823
+ ;
824
+
825
+ virtualSpecifierSeq
826
+ : virtualSpecifier+
827
+ ;
828
+
829
+ virtualSpecifier
830
+ : Override
831
+ | Final
832
+ ;
833
+
834
+ /*
835
+ purespecifier: Assign '0'//Conflicts with the lexer ;
836
+ */
837
+
838
+ pureSpecifier
839
+ : Assign IntegerLiteral
840
+ ;
841
+
842
+ /*Derived classes*/
843
+
844
+ baseClause
845
+ : Colon baseSpecifierList
846
+ ;
847
+
848
+ baseSpecifierList
849
+ : baseSpecifier Ellipsis? (Comma baseSpecifier Ellipsis?)*
850
+ ;
851
+
852
+ baseSpecifier
853
+ : attributeSpecifierSeq? (
854
+ baseTypeSpecifier
855
+ | Virtual accessSpecifier? baseTypeSpecifier
856
+ | accessSpecifier Virtual? baseTypeSpecifier
857
+ )
858
+ ;
859
+
860
+ classOrDeclType
861
+ : nestedNameSpecifier? className
862
+ | decltypeSpecifier
863
+ ;
864
+
865
+ baseTypeSpecifier
866
+ : classOrDeclType
867
+ ;
868
+
869
+ accessSpecifier
870
+ : Private
871
+ | Protected
872
+ | Public
873
+ ;
874
+
875
+ /*Special member functions*/
876
+
877
+ conversionFunctionId
878
+ : Operator conversionTypeId
879
+ ;
880
+
881
+ conversionTypeId
882
+ : typeSpecifierSeq conversionDeclarator?
883
+ ;
884
+
885
+ conversionDeclarator
886
+ : pointerOperator conversionDeclarator?
887
+ ;
888
+
889
+ constructorInitializer
890
+ : Colon memInitializerList
891
+ ;
892
+
893
+ memInitializerList
894
+ : memInitializer Ellipsis? (Comma memInitializer Ellipsis?)*
895
+ ;
896
+
897
+ memInitializer
898
+ : meminitializerid (LeftParen expressionList? RightParen | bracedInitList)
899
+ ;
900
+
901
+ meminitializerid
902
+ : classOrDeclType
903
+ | Identifier
904
+ ;
905
+
906
+ /*Overloading*/
907
+
908
+ operatorFunctionId
909
+ : Operator theOperator
910
+ ;
911
+
912
+ literalOperatorId
913
+ : Operator (StringLiteral Identifier | UserDefinedStringLiteral)
914
+ ;
915
+
916
+ /*Templates*/
917
+
918
+ templateDeclaration
919
+ : Template Less templateparameterList Greater declaration
920
+ ;
921
+
922
+ templateparameterList
923
+ : templateParameter (Comma templateParameter)*
924
+ ;
925
+
926
+ templateParameter
927
+ : typeParameter
928
+ | parameterDeclaration
929
+ ;
930
+
931
+ typeParameter
932
+ : ((Template Less templateparameterList Greater)? Class | Typename_) (
933
+ Ellipsis? Identifier?
934
+ | Identifier? Assign theTypeId
935
+ )
936
+ ;
937
+
938
+ simpleTemplateId
939
+ : templateName Less templateArgumentList? Greater
940
+ ;
941
+
942
+ templateId
943
+ : simpleTemplateId
944
+ | (operatorFunctionId | literalOperatorId) Less templateArgumentList? Greater
945
+ ;
946
+
947
+ templateName
948
+ : Identifier
949
+ ;
950
+
951
+ templateArgumentList
952
+ : templateArgument Ellipsis? (Comma templateArgument Ellipsis?)*
953
+ ;
954
+
955
+ templateArgument
956
+ : theTypeId
957
+ | constantExpression
958
+ | idExpression
959
+ ;
960
+
961
+ typeNameSpecifier
962
+ : Typename_ nestedNameSpecifier (Identifier | Template? simpleTemplateId)
963
+ ;
964
+
965
+ explicitInstantiation
966
+ : Extern? Template declaration
967
+ ;
968
+
969
+ explicitSpecialization
970
+ : Template Less Greater declaration
971
+ ;
972
+
973
+ /*Exception handling*/
974
+
975
+ tryBlock
976
+ : Try compoundStatement handlerSeq
977
+ ;
978
+
979
+ functionTryBlock
980
+ : Try constructorInitializer? compoundStatement handlerSeq
981
+ ;
982
+
983
+ handlerSeq
984
+ : handler+
985
+ ;
986
+
987
+ handler
988
+ : Catch LeftParen exceptionDeclaration RightParen compoundStatement
989
+ ;
990
+
991
+ exceptionDeclaration
992
+ : attributeSpecifierSeq? typeSpecifierSeq (declarator | abstractDeclarator)?
993
+ | Ellipsis
994
+ ;
995
+
996
+ throwExpression
997
+ : Throw assignmentExpression?
998
+ ;
999
+
1000
+ exceptionSpecification
1001
+ : dynamicExceptionSpecification
1002
+ | noeExceptSpecification
1003
+ ;
1004
+
1005
+ dynamicExceptionSpecification
1006
+ : Throw LeftParen typeIdList? RightParen
1007
+ ;
1008
+
1009
+ typeIdList
1010
+ : theTypeId Ellipsis? (Comma theTypeId Ellipsis?)*
1011
+ ;
1012
+
1013
+ noeExceptSpecification
1014
+ : Noexcept LeftParen constantExpression RightParen
1015
+ | Noexcept
1016
+ ;
1017
+
1018
+ /*Preprocessing directives*/
1019
+
1020
+ /*Lexer*/
1021
+
1022
+ theOperator
1023
+ : New (LeftBracket RightBracket)?
1024
+ | Delete (LeftBracket RightBracket)?
1025
+ | Plus
1026
+ | Minus
1027
+ | Star
1028
+ | Div
1029
+ | Mod
1030
+ | Caret
1031
+ | And
1032
+ | Or
1033
+ | Tilde
1034
+ | Not
1035
+ | Assign
1036
+ | Greater
1037
+ | Less
1038
+ | GreaterEqual
1039
+ | PlusAssign
1040
+ | MinusAssign
1041
+ | StarAssign
1042
+ | ModAssign
1043
+ | XorAssign
1044
+ | AndAssign
1045
+ | OrAssign
1046
+ | Less Less
1047
+ | Greater Greater
1048
+ | RightShiftAssign
1049
+ | LeftShiftAssign
1050
+ | Equal
1051
+ | NotEqual
1052
+ | LessEqual
1053
+ | AndAnd
1054
+ | OrOr
1055
+ | PlusPlus
1056
+ | MinusMinus
1057
+ | Comma
1058
+ | ArrowStar
1059
+ | Arrow
1060
+ | LeftParen RightParen
1061
+ | LeftBracket RightBracket
1062
+ ;
1063
+
1064
+ literal
1065
+ : IntegerLiteral
1066
+ | CharacterLiteral
1067
+ | FloatingLiteral
1068
+ | StringLiteral
1069
+ | BooleanLiteral
1070
+ | PointerLiteral
1071
+ | UserDefinedLiteral
1072
+ ;