| 1 |
/* https://github.com/antlr/grammars-v4/raw/master/c/C.g4 |
| 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 |
grammar C; |
| 31 |
|
| 32 |
primaryExpression |
| 33 |
: Identifier |
| 34 |
| Constant |
| 35 |
| StringLiteral+ |
| 36 |
| '(' expression ')' |
| 37 |
| genericSelection |
| 38 |
| '__extension__'? '(' compoundStatement ')' // Blocks (GCC extension) |
| 39 |
| '__builtin_va_arg' '(' unaryExpression ',' typeName ')' |
| 40 |
| '__builtin_offsetof' '(' typeName ',' unaryExpression ')' |
| 41 |
; |
| 42 |
|
| 43 |
genericSelection |
| 44 |
: '_Generic' '(' assignmentExpression ',' genericAssocList ')' |
| 45 |
; |
| 46 |
|
| 47 |
genericAssocList |
| 48 |
: genericAssociation |
| 49 |
| genericAssocList ',' genericAssociation |
| 50 |
; |
| 51 |
|
| 52 |
genericAssociation |
| 53 |
: typeName ':' assignmentExpression |
| 54 |
| 'default' ':' assignmentExpression |
| 55 |
; |
| 56 |
|
| 57 |
postfixExpression |
| 58 |
: primaryExpression |
| 59 |
| postfixExpression '[' expression ']' |
| 60 |
| postfixExpression '(' argumentExpressionList? ')' |
| 61 |
| postfixExpression '.' Identifier |
| 62 |
| postfixExpression '->' Identifier |
| 63 |
| postfixExpression '++' |
| 64 |
| postfixExpression '--' |
| 65 |
| '(' typeName ')' '{' initializerList '}' |
| 66 |
| '(' typeName ')' '{' initializerList ',' '}' |
| 67 |
| '__extension__' '(' typeName ')' '{' initializerList '}' |
| 68 |
| '__extension__' '(' typeName ')' '{' initializerList ',' '}' |
| 69 |
; |
| 70 |
|
| 71 |
argumentExpressionList |
| 72 |
: assignmentExpression |
| 73 |
| argumentExpressionList ',' assignmentExpression |
| 74 |
; |
| 75 |
|
| 76 |
unaryExpression |
| 77 |
: postfixExpression |
| 78 |
| '++' unaryExpression |
| 79 |
| '--' unaryExpression |
| 80 |
| unaryOperator castExpression |
| 81 |
| 'sizeof' unaryExpression |
| 82 |
| 'sizeof' '(' typeName ')' |
| 83 |
| '_Alignof' '(' typeName ')' |
| 84 |
| '&&' Identifier // GCC extension address of label |
| 85 |
; |
| 86 |
|
| 87 |
unaryOperator |
| 88 |
: '&' | '*' | '+' | '-' | '~' | '!' |
| 89 |
; |
| 90 |
|
| 91 |
castExpression |
| 92 |
: unaryExpression |
| 93 |
| '(' typeName ')' castExpression |
| 94 |
| '__extension__' '(' typeName ')' castExpression |
| 95 |
| DigitSequence // for |
| 96 |
; |
| 97 |
|
| 98 |
multiplicativeExpression |
| 99 |
: castExpression |
| 100 |
| multiplicativeExpression '*' castExpression |
| 101 |
| multiplicativeExpression '/' castExpression |
| 102 |
| multiplicativeExpression '%' castExpression |
| 103 |
; |
| 104 |
|
| 105 |
additiveExpression |
| 106 |
: multiplicativeExpression |
| 107 |
| additiveExpression '+' multiplicativeExpression |
| 108 |
| additiveExpression '-' multiplicativeExpression |
| 109 |
; |
| 110 |
|
| 111 |
shiftExpression |
| 112 |
: additiveExpression |
| 113 |
| shiftExpression '<<' additiveExpression |
| 114 |
| shiftExpression '>>' additiveExpression |
| 115 |
; |
| 116 |
|
| 117 |
relationalExpression |
| 118 |
: shiftExpression |
| 119 |
| relationalExpression '<' shiftExpression |
| 120 |
| relationalExpression '>' shiftExpression |
| 121 |
| relationalExpression '<=' shiftExpression |
| 122 |
| relationalExpression '>=' shiftExpression |
| 123 |
; |
| 124 |
|
| 125 |
equalityExpression |
| 126 |
: relationalExpression |
| 127 |
| equalityExpression '==' relationalExpression |
| 128 |
| equalityExpression '!=' relationalExpression |
| 129 |
; |
| 130 |
|
| 131 |
andExpression |
| 132 |
: equalityExpression |
| 133 |
| andExpression '&' equalityExpression |
| 134 |
; |
| 135 |
|
| 136 |
exclusiveOrExpression |
| 137 |
: andExpression |
| 138 |
| exclusiveOrExpression '^' andExpression |
| 139 |
; |
| 140 |
|
| 141 |
inclusiveOrExpression |
| 142 |
: exclusiveOrExpression |
| 143 |
| inclusiveOrExpression '|' exclusiveOrExpression |
| 144 |
; |
| 145 |
|
| 146 |
logicalAndExpression |
| 147 |
: inclusiveOrExpression |
| 148 |
| logicalAndExpression '&&' inclusiveOrExpression |
| 149 |
; |
| 150 |
|
| 151 |
logicalOrExpression |
| 152 |
: logicalAndExpression |
| 153 |
| logicalOrExpression '||' logicalAndExpression |
| 154 |
; |
| 155 |
|
| 156 |
conditionalExpression |
| 157 |
: logicalOrExpression ('?' expression ':' conditionalExpression)? |
| 158 |
; |
| 159 |
|
| 160 |
assignmentExpression |
| 161 |
: conditionalExpression |
| 162 |
| unaryExpression assignmentOperator assignmentExpression |
| 163 |
| DigitSequence // for |
| 164 |
; |
| 165 |
|
| 166 |
assignmentOperator |
| 167 |
: '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '&=' | '^=' | '|=' |
| 168 |
; |
| 169 |
|
| 170 |
expression |
| 171 |
: assignmentExpression |
| 172 |
| expression ',' assignmentExpression |
| 173 |
; |
| 174 |
|
| 175 |
constantExpression |
| 176 |
: conditionalExpression |
| 177 |
; |
| 178 |
|
| 179 |
declaration |
| 180 |
: declarationSpecifiers initDeclaratorList ';' |
| 181 |
| declarationSpecifiers ';' |
| 182 |
| staticAssertDeclaration |
| 183 |
; |
| 184 |
|
| 185 |
declarationSpecifiers |
| 186 |
: declarationSpecifier+ |
| 187 |
; |
| 188 |
|
| 189 |
declarationSpecifiers2 |
| 190 |
: declarationSpecifier+ |
| 191 |
; |
| 192 |
|
| 193 |
declarationSpecifier |
| 194 |
: storageClassSpecifier |
| 195 |
| typeSpecifier |
| 196 |
| typeQualifier |
| 197 |
| functionSpecifier |
| 198 |
| alignmentSpecifier |
| 199 |
; |
| 200 |
|
| 201 |
initDeclaratorList |
| 202 |
: initDeclarator |
| 203 |
| initDeclaratorList ',' initDeclarator |
| 204 |
; |
| 205 |
|
| 206 |
initDeclarator |
| 207 |
: declarator |
| 208 |
| declarator '=' initializer |
| 209 |
; |
| 210 |
|
| 211 |
storageClassSpecifier |
| 212 |
: 'typedef' |
| 213 |
| 'extern' |
| 214 |
| 'static' |
| 215 |
| '_Thread_local' |
| 216 |
| 'auto' |
| 217 |
| 'register' |
| 218 |
; |
| 219 |
|
| 220 |
typeSpecifier |
| 221 |
: ('void' |
| 222 |
| 'char' |
| 223 |
| 'short' |
| 224 |
| 'int' |
| 225 |
| 'long' |
| 226 |
| 'float' |
| 227 |
| 'double' |
| 228 |
| 'signed' |
| 229 |
| 'unsigned' |
| 230 |
| '_Bool' |
| 231 |
| '_Complex' |
| 232 |
| '__m128' |
| 233 |
| '__m128d' |
| 234 |
| '__m128i') |
| 235 |
| '__extension__' '(' ('__m128' | '__m128d' | '__m128i') ')' |
| 236 |
| atomicTypeSpecifier |
| 237 |
| structOrUnionSpecifier |
| 238 |
| enumSpecifier |
| 239 |
| typedefName |
| 240 |
| '__typeof__' '(' constantExpression ')' // GCC extension |
| 241 |
; |
| 242 |
|
| 243 |
structOrUnionSpecifier |
| 244 |
: structOrUnion Identifier? '{' structDeclarationList '}' |
| 245 |
| structOrUnion Identifier |
| 246 |
; |
| 247 |
|
| 248 |
structOrUnion |
| 249 |
: 'struct' |
| 250 |
| 'union' |
| 251 |
; |
| 252 |
|
| 253 |
structDeclarationList |
| 254 |
: structDeclaration |
| 255 |
| structDeclarationList structDeclaration |
| 256 |
; |
| 257 |
|
| 258 |
structDeclaration |
| 259 |
: specifierQualifierList structDeclaratorList? ';' |
| 260 |
| staticAssertDeclaration |
| 261 |
; |
| 262 |
|
| 263 |
specifierQualifierList |
| 264 |
: typeSpecifier specifierQualifierList? |
| 265 |
| typeQualifier specifierQualifierList? |
| 266 |
; |
| 267 |
|
| 268 |
structDeclaratorList |
| 269 |
: structDeclarator |
| 270 |
| structDeclaratorList ',' structDeclarator |
| 271 |
; |
| 272 |
|
| 273 |
structDeclarator |
| 274 |
: declarator |
| 275 |
| declarator? ':' constantExpression |
| 276 |
; |
| 277 |
|
| 278 |
enumSpecifier |
| 279 |
: 'enum' Identifier? '{' enumeratorList '}' |
| 280 |
| 'enum' Identifier? '{' enumeratorList ',' '}' |
| 281 |
| 'enum' Identifier |
| 282 |
; |
| 283 |
|
| 284 |
enumeratorList |
| 285 |
: enumerator |
| 286 |
| enumeratorList ',' enumerator |
| 287 |
; |
| 288 |
|
| 289 |
enumerator |
| 290 |
: enumerationConstant |
| 291 |
| enumerationConstant '=' constantExpression |
| 292 |
; |
| 293 |
|
| 294 |
enumerationConstant |
| 295 |
: Identifier |
| 296 |
; |
| 297 |
|
| 298 |
atomicTypeSpecifier |
| 299 |
: '_Atomic' '(' typeName ')' |
| 300 |
; |
| 301 |
|
| 302 |
typeQualifier |
| 303 |
: 'const' |
| 304 |
| 'restrict' |
| 305 |
| 'volatile' |
| 306 |
| '_Atomic' |
| 307 |
; |
| 308 |
|
| 309 |
functionSpecifier |
| 310 |
: ('inline' |
| 311 |
| '_Noreturn' |
| 312 |
| '__inline__' // GCC extension |
| 313 |
| '__stdcall') |
| 314 |
| gccAttributeSpecifier |
| 315 |
| '__declspec' '(' Identifier ')' |
| 316 |
; |
| 317 |
|
| 318 |
alignmentSpecifier |
| 319 |
: '_Alignas' '(' typeName ')' |
| 320 |
| '_Alignas' '(' constantExpression ')' |
| 321 |
; |
| 322 |
|
| 323 |
declarator |
| 324 |
: pointer? directDeclarator gccDeclaratorExtension* |
| 325 |
; |
| 326 |
|
| 327 |
directDeclarator |
| 328 |
: Identifier |
| 329 |
| '(' declarator ')' |
| 330 |
| directDeclarator '[' typeQualifierList? assignmentExpression? ']' |
| 331 |
| directDeclarator '[' 'static' typeQualifierList? assignmentExpression ']' |
| 332 |
| directDeclarator '[' typeQualifierList 'static' assignmentExpression ']' |
| 333 |
| directDeclarator '[' typeQualifierList? '*' ']' |
| 334 |
| directDeclarator '(' parameterTypeList ')' |
| 335 |
| directDeclarator '(' identifierList? ')' |
| 336 |
| Identifier ':' DigitSequence // bit field |
| 337 |
; |
| 338 |
|
| 339 |
gccDeclaratorExtension |
| 340 |
: '__asm' '(' StringLiteral+ ')' |
| 341 |
| gccAttributeSpecifier |
| 342 |
; |
| 343 |
|
| 344 |
gccAttributeSpecifier |
| 345 |
: '__attribute__' '(' '(' gccAttributeList ')' ')' |
| 346 |
; |
| 347 |
|
| 348 |
gccAttributeList |
| 349 |
: gccAttribute (',' gccAttribute)* |
| 350 |
| // empty |
| 351 |
; |
| 352 |
|
| 353 |
gccAttribute |
| 354 |
: ~(',' | '(' | ')') // relaxed def for "identifier or reserved word" |
| 355 |
('(' argumentExpressionList? ')')? |
| 356 |
| // empty |
| 357 |
; |
| 358 |
|
| 359 |
nestedParenthesesBlock |
| 360 |
: ( ~('(' | ')') |
| 361 |
| '(' nestedParenthesesBlock ')' |
| 362 |
)* |
| 363 |
; |
| 364 |
|
| 365 |
pointer |
| 366 |
: '*' typeQualifierList? |
| 367 |
| '*' typeQualifierList? pointer |
| 368 |
| '^' typeQualifierList? // Blocks language extension |
| 369 |
| '^' typeQualifierList? pointer // Blocks language extension |
| 370 |
; |
| 371 |
|
| 372 |
typeQualifierList |
| 373 |
: typeQualifier |
| 374 |
| typeQualifierList typeQualifier |
| 375 |
; |
| 376 |
|
| 377 |
parameterTypeList |
| 378 |
: parameterList |
| 379 |
| parameterList ',' '...' |
| 380 |
; |
| 381 |
|
| 382 |
parameterList |
| 383 |
: parameterDeclaration |
| 384 |
| parameterList ',' parameterDeclaration |
| 385 |
; |
| 386 |
|
| 387 |
parameterDeclaration |
| 388 |
: declarationSpecifiers declarator |
| 389 |
| declarationSpecifiers2 abstractDeclarator? |
| 390 |
; |
| 391 |
|
| 392 |
identifierList |
| 393 |
: Identifier |
| 394 |
| identifierList ',' Identifier |
| 395 |
; |
| 396 |
|
| 397 |
typeName |
| 398 |
: specifierQualifierList abstractDeclarator? |
| 399 |
; |
| 400 |
|
| 401 |
abstractDeclarator |
| 402 |
: pointer |
| 403 |
| pointer? directAbstractDeclarator gccDeclaratorExtension* |
| 404 |
; |
| 405 |
|
| 406 |
directAbstractDeclarator |
| 407 |
: '(' abstractDeclarator ')' gccDeclaratorExtension* |
| 408 |
| '[' typeQualifierList? assignmentExpression? ']' |
| 409 |
| '[' 'static' typeQualifierList? assignmentExpression ']' |
| 410 |
| '[' typeQualifierList 'static' assignmentExpression ']' |
| 411 |
| '[' '*' ']' |
| 412 |
| '(' parameterTypeList? ')' gccDeclaratorExtension* |
| 413 |
| directAbstractDeclarator '[' typeQualifierList? assignmentExpression? ']' |
| 414 |
| directAbstractDeclarator '[' 'static' typeQualifierList? assignmentExpression ']' |
| 415 |
| directAbstractDeclarator '[' typeQualifierList 'static' assignmentExpression ']' |
| 416 |
| directAbstractDeclarator '[' '*' ']' |
| 417 |
| directAbstractDeclarator '(' parameterTypeList? ')' gccDeclaratorExtension* |
| 418 |
; |
| 419 |
|
| 420 |
typedefName |
| 421 |
: Identifier |
| 422 |
; |
| 423 |
|
| 424 |
initializer |
| 425 |
: assignmentExpression |
| 426 |
| '{' initializerList '}' |
| 427 |
| '{' initializerList ',' '}' |
| 428 |
; |
| 429 |
|
| 430 |
initializerList |
| 431 |
: designation? initializer |
| 432 |
| initializerList ',' designation? initializer |
| 433 |
; |
| 434 |
|
| 435 |
designation |
| 436 |
: designatorList '=' |
| 437 |
; |
| 438 |
|
| 439 |
designatorList |
| 440 |
: designator |
| 441 |
| designatorList designator |
| 442 |
; |
| 443 |
|
| 444 |
designator |
| 445 |
: '[' constantExpression ']' |
| 446 |
| '.' Identifier |
| 447 |
; |
| 448 |
|
| 449 |
staticAssertDeclaration |
| 450 |
: '_Static_assert' '(' constantExpression ',' StringLiteral+ ')' ';' |
| 451 |
; |
| 452 |
|
| 453 |
statement |
| 454 |
: labeledStatement |
| 455 |
| compoundStatement |
| 456 |
| expressionStatement |
| 457 |
| selectionStatement |
| 458 |
| iterationStatement |
| 459 |
| jumpStatement |
| 460 |
| ('__asm' | '__asm__') ('volatile' | '__volatile__') '(' (logicalOrExpression (',' logicalOrExpression)*)? (':' (logicalOrExpression (',' logicalOrExpression)*)?)* ')' ';' |
| 461 |
; |
| 462 |
|
| 463 |
labeledStatement |
| 464 |
: Identifier ':' statement |
| 465 |
| 'case' constantExpression ':' statement |
| 466 |
| 'default' ':' statement |
| 467 |
; |
| 468 |
|
| 469 |
compoundStatement |
| 470 |
: '{' blockItemList? '}' |
| 471 |
; |
| 472 |
|
| 473 |
blockItemList |
| 474 |
: blockItem |
| 475 |
| blockItemList blockItem |
| 476 |
; |
| 477 |
|
| 478 |
blockItem |
| 479 |
: declaration |
| 480 |
| statement |
| 481 |
; |
| 482 |
|
| 483 |
expressionStatement |
| 484 |
: expression? ';' |
| 485 |
; |
| 486 |
|
| 487 |
selectionStatement |
| 488 |
: 'if' '(' expression ')' statement ('else' statement)? |
| 489 |
| 'switch' '(' expression ')' statement |
| 490 |
; |
| 491 |
|
| 492 |
iterationStatement |
| 493 |
: While '(' expression ')' statement |
| 494 |
| Do statement While '(' expression ')' ';' |
| 495 |
| For '(' forCondition ')' statement |
| 496 |
; |
| 497 |
|
| 498 |
// | 'for' '(' expression? ';' expression? ';' forUpdate? ')' statement |
| 499 |
// | For '(' declaration expression? ';' expression? ')' statement |
| 500 |
|
| 501 |
forCondition |
| 502 |
: forDeclaration ';' forExpression? ';' forExpression? |
| 503 |
| expression? ';' forExpression? ';' forExpression? |
| 504 |
; |
| 505 |
|
| 506 |
forDeclaration |
| 507 |
: declarationSpecifiers initDeclaratorList |
| 508 |
| declarationSpecifiers |
| 509 |
; |
| 510 |
|
| 511 |
forExpression |
| 512 |
: assignmentExpression |
| 513 |
| forExpression ',' assignmentExpression |
| 514 |
; |
| 515 |
|
| 516 |
jumpStatement |
| 517 |
: 'goto' Identifier ';' |
| 518 |
| 'continue' ';' |
| 519 |
| 'break' ';' |
| 520 |
| 'return' expression? ';' |
| 521 |
| 'goto' unaryExpression ';' // GCC extension |
| 522 |
; |
| 523 |
|
| 524 |
compilationUnit |
| 525 |
: translationUnit? EOF |
| 526 |
; |
| 527 |
|
| 528 |
translationUnit |
| 529 |
: externalDeclaration |
| 530 |
| translationUnit externalDeclaration |
| 531 |
; |
| 532 |
|
| 533 |
externalDeclaration |
| 534 |
: functionDefinition |
| 535 |
| declaration |
| 536 |
| ';' // stray ; |
| 537 |
; |
| 538 |
|
| 539 |
functionDefinition |
| 540 |
: declarationSpecifiers? declarator declarationList? compoundStatement |
| 541 |
; |
| 542 |
|
| 543 |
declarationList |
| 544 |
: declaration |
| 545 |
| declarationList declaration |
| 546 |
; |
| 547 |
|
| 548 |
Auto : 'auto'; |
| 549 |
Break : 'break'; |
| 550 |
Case : 'case'; |
| 551 |
Char : 'char'; |
| 552 |
Const : 'const'; |
| 553 |
Continue : 'continue'; |
| 554 |
Default : 'default'; |
| 555 |
Do : 'do'; |
| 556 |
Double : 'double'; |
| 557 |
Else : 'else'; |
| 558 |
Enum : 'enum'; |
| 559 |
Extern : 'extern'; |
| 560 |
Float : 'float'; |
| 561 |
For : 'for'; |
| 562 |
Goto : 'goto'; |
| 563 |
If : 'if'; |
| 564 |
Inline : 'inline'; |
| 565 |
Int : 'int'; |
| 566 |
Long : 'long'; |
| 567 |
Register : 'register'; |
| 568 |
Restrict : 'restrict'; |
| 569 |
Return : 'return'; |
| 570 |
Short : 'short'; |
| 571 |
Signed : 'signed'; |
| 572 |
Sizeof : 'sizeof'; |
| 573 |
Static : 'static'; |
| 574 |
Struct : 'struct'; |
| 575 |
Switch : 'switch'; |
| 576 |
Typedef : 'typedef'; |
| 577 |
Union : 'union'; |
| 578 |
Unsigned : 'unsigned'; |
| 579 |
Void : 'void'; |
| 580 |
Volatile : 'volatile'; |
| 581 |
While : 'while'; |
| 582 |
|
| 583 |
Alignas : '_Alignas'; |
| 584 |
Alignof : '_Alignof'; |
| 585 |
Atomic : '_Atomic'; |
| 586 |
Bool : '_Bool'; |
| 587 |
Complex : '_Complex'; |
| 588 |
Generic : '_Generic'; |
| 589 |
Imaginary : '_Imaginary'; |
| 590 |
Noreturn : '_Noreturn'; |
| 591 |
StaticAssert : '_Static_assert'; |
| 592 |
ThreadLocal : '_Thread_local'; |
| 593 |
|
| 594 |
LeftParen : '('; |
| 595 |
RightParen : ')'; |
| 596 |
LeftBracket : '['; |
| 597 |
RightBracket : ']'; |
| 598 |
LeftBrace : '{'; |
| 599 |
RightBrace : '}'; |
| 600 |
|
| 601 |
Less : '<'; |
| 602 |
LessEqual : '<='; |
| 603 |
Greater : '>'; |
| 604 |
GreaterEqual : '>='; |
| 605 |
LeftShift : '<<'; |
| 606 |
RightShift : '>>'; |
| 607 |
|
| 608 |
Plus : '+'; |
| 609 |
PlusPlus : '++'; |
| 610 |
Minus : '-'; |
| 611 |
MinusMinus : '--'; |
| 612 |
Star : '*'; |
| 613 |
Div : '/'; |
| 614 |
Mod : '%'; |
| 615 |
|
| 616 |
And : '&'; |
| 617 |
Or : '|'; |
| 618 |
AndAnd : '&&'; |
| 619 |
OrOr : '||'; |
| 620 |
Caret : '^'; |
| 621 |
Not : '!'; |
| 622 |
Tilde : '~'; |
| 623 |
|
| 624 |
Question : '?'; |
| 625 |
Colon : ':'; |
| 626 |
Semi : ';'; |
| 627 |
Comma : ','; |
| 628 |
|
| 629 |
Assign : '='; |
| 630 |
// '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '&=' | '^=' | '|=' |
| 631 |
StarAssign : '*='; |
| 632 |
DivAssign : '/='; |
| 633 |
ModAssign : '%='; |
| 634 |
PlusAssign : '+='; |
| 635 |
MinusAssign : '-='; |
| 636 |
LeftShiftAssign : '<<='; |
| 637 |
RightShiftAssign : '>>='; |
| 638 |
AndAssign : '&='; |
| 639 |
XorAssign : '^='; |
| 640 |
OrAssign : '|='; |
| 641 |
|
| 642 |
Equal : '=='; |
| 643 |
NotEqual : '!='; |
| 644 |
|
| 645 |
Arrow : '->'; |
| 646 |
Dot : '.'; |
| 647 |
Ellipsis : '...'; |
| 648 |
|
| 649 |
Identifier |
| 650 |
: IdentifierNondigit |
| 651 |
( IdentifierNondigit |
| 652 |
| Digit |
| 653 |
)* |
| 654 |
; |
| 655 |
|
| 656 |
fragment |
| 657 |
IdentifierNondigit |
| 658 |
: Nondigit |
| 659 |
| UniversalCharacterName |
| 660 |
//| // other implementation-defined characters... |
| 661 |
; |
| 662 |
|
| 663 |
fragment |
| 664 |
Nondigit |
| 665 |
: [a-zA-Z_] |
| 666 |
; |
| 667 |
|
| 668 |
fragment |
| 669 |
Digit |
| 670 |
: [0-9] |
| 671 |
; |
| 672 |
|
| 673 |
fragment |
| 674 |
UniversalCharacterName |
| 675 |
: '\\u' HexQuad |
| 676 |
| '\\U' HexQuad HexQuad |
| 677 |
; |
| 678 |
|
| 679 |
fragment |
| 680 |
HexQuad |
| 681 |
: HexadecimalDigit HexadecimalDigit HexadecimalDigit HexadecimalDigit |
| 682 |
; |
| 683 |
|
| 684 |
Constant |
| 685 |
: IntegerConstant |
| 686 |
| FloatingConstant |
| 687 |
//| EnumerationConstant |
| 688 |
| CharacterConstant |
| 689 |
; |
| 690 |
|
| 691 |
fragment |
| 692 |
IntegerConstant |
| 693 |
: DecimalConstant IntegerSuffix? |
| 694 |
| OctalConstant IntegerSuffix? |
| 695 |
| HexadecimalConstant IntegerSuffix? |
| 696 |
| BinaryConstant |
| 697 |
; |
| 698 |
|
| 699 |
fragment |
| 700 |
BinaryConstant |
| 701 |
: '0' [bB] [0-1]+ |
| 702 |
; |
| 703 |
|
| 704 |
fragment |
| 705 |
DecimalConstant |
| 706 |
: NonzeroDigit Digit* |
| 707 |
; |
| 708 |
|
| 709 |
fragment |
| 710 |
OctalConstant |
| 711 |
: '0' OctalDigit* |
| 712 |
; |
| 713 |
|
| 714 |
fragment |
| 715 |
HexadecimalConstant |
| 716 |
: HexadecimalPrefix HexadecimalDigit+ |
| 717 |
; |
| 718 |
|
| 719 |
fragment |
| 720 |
HexadecimalPrefix |
| 721 |
: '0' [xX] |
| 722 |
; |
| 723 |
|
| 724 |
fragment |
| 725 |
NonzeroDigit |
| 726 |
: [1-9] |
| 727 |
; |
| 728 |
|
| 729 |
fragment |
| 730 |
OctalDigit |
| 731 |
: [0-7] |
| 732 |
; |
| 733 |
|
| 734 |
fragment |
| 735 |
HexadecimalDigit |
| 736 |
: [0-9a-fA-F] |
| 737 |
; |
| 738 |
|
| 739 |
fragment |
| 740 |
IntegerSuffix |
| 741 |
: UnsignedSuffix LongSuffix? |
| 742 |
| UnsignedSuffix LongLongSuffix |
| 743 |
| LongSuffix UnsignedSuffix? |
| 744 |
| LongLongSuffix UnsignedSuffix? |
| 745 |
; |
| 746 |
|
| 747 |
fragment |
| 748 |
UnsignedSuffix |
| 749 |
: [uU] |
| 750 |
; |
| 751 |
|
| 752 |
fragment |
| 753 |
LongSuffix |
| 754 |
: [lL] |
| 755 |
; |
| 756 |
|
| 757 |
fragment |
| 758 |
LongLongSuffix |
| 759 |
: 'll' | 'LL' |
| 760 |
; |
| 761 |
|
| 762 |
fragment |
| 763 |
FloatingConstant |
| 764 |
: DecimalFloatingConstant |
| 765 |
| HexadecimalFloatingConstant |
| 766 |
; |
| 767 |
|
| 768 |
fragment |
| 769 |
DecimalFloatingConstant |
| 770 |
: FractionalConstant ExponentPart? FloatingSuffix? |
| 771 |
| DigitSequence ExponentPart FloatingSuffix? |
| 772 |
; |
| 773 |
|
| 774 |
fragment |
| 775 |
HexadecimalFloatingConstant |
| 776 |
: HexadecimalPrefix HexadecimalFractionalConstant BinaryExponentPart FloatingSuffix? |
| 777 |
| HexadecimalPrefix HexadecimalDigitSequence BinaryExponentPart FloatingSuffix? |
| 778 |
; |
| 779 |
|
| 780 |
fragment |
| 781 |
FractionalConstant |
| 782 |
: DigitSequence? '.' DigitSequence |
| 783 |
| DigitSequence '.' |
| 784 |
; |
| 785 |
|
| 786 |
fragment |
| 787 |
ExponentPart |
| 788 |
: 'e' Sign? DigitSequence |
| 789 |
| 'E' Sign? DigitSequence |
| 790 |
; |
| 791 |
|
| 792 |
fragment |
| 793 |
Sign |
| 794 |
: '+' | '-' |
| 795 |
; |
| 796 |
|
| 797 |
fragment |
| 798 |
DigitSequence |
| 799 |
: Digit+ |
| 800 |
; |
| 801 |
|
| 802 |
fragment |
| 803 |
HexadecimalFractionalConstant |
| 804 |
: HexadecimalDigitSequence? '.' HexadecimalDigitSequence |
| 805 |
| HexadecimalDigitSequence '.' |
| 806 |
; |
| 807 |
|
| 808 |
fragment |
| 809 |
BinaryExponentPart |
| 810 |
: 'p' Sign? DigitSequence |
| 811 |
| 'P' Sign? DigitSequence |
| 812 |
; |
| 813 |
|
| 814 |
fragment |
| 815 |
HexadecimalDigitSequence |
| 816 |
: HexadecimalDigit+ |
| 817 |
; |
| 818 |
|
| 819 |
fragment |
| 820 |
FloatingSuffix |
| 821 |
: 'f' | 'l' | 'F' | 'L' |
| 822 |
; |
| 823 |
|
| 824 |
fragment |
| 825 |
CharacterConstant |
| 826 |
: '\'' CCharSequence '\'' |
| 827 |
| 'L\'' CCharSequence '\'' |
| 828 |
| 'u\'' CCharSequence '\'' |
| 829 |
| 'U\'' CCharSequence '\'' |
| 830 |
; |
| 831 |
|
| 832 |
fragment |
| 833 |
CCharSequence |
| 834 |
: CChar+ |
| 835 |
; |
| 836 |
|
| 837 |
fragment |
| 838 |
CChar |
| 839 |
: ~['\\\r\n] |
| 840 |
| EscapeSequence |
| 841 |
; |
| 842 |
|
| 843 |
fragment |
| 844 |
EscapeSequence |
| 845 |
: SimpleEscapeSequence |
| 846 |
| OctalEscapeSequence |
| 847 |
| HexadecimalEscapeSequence |
| 848 |
| UniversalCharacterName |
| 849 |
; |
| 850 |
|
| 851 |
fragment |
| 852 |
SimpleEscapeSequence |
| 853 |
: '\\' ['"?abfnrtv\\] |
| 854 |
; |
| 855 |
|
| 856 |
fragment |
| 857 |
OctalEscapeSequence |
| 858 |
: '\\' OctalDigit |
| 859 |
| '\\' OctalDigit OctalDigit |
| 860 |
| '\\' OctalDigit OctalDigit OctalDigit |
| 861 |
; |
| 862 |
|
| 863 |
fragment |
| 864 |
HexadecimalEscapeSequence |
| 865 |
: '\\x' HexadecimalDigit+ |
| 866 |
; |
| 867 |
|
| 868 |
StringLiteral |
| 869 |
: EncodingPrefix? '"' SCharSequence? '"' |
| 870 |
; |
| 871 |
|
| 872 |
fragment |
| 873 |
EncodingPrefix |
| 874 |
: 'u8' |
| 875 |
| 'u' |
| 876 |
| 'U' |
| 877 |
| 'L' |
| 878 |
; |
| 879 |
|
| 880 |
fragment |
| 881 |
SCharSequence |
| 882 |
: SChar+ |
| 883 |
; |
| 884 |
|
| 885 |
fragment |
| 886 |
SChar |
| 887 |
: ~["\\\r\n] |
| 888 |
| EscapeSequence |
| 889 |
| '\\\n' // Added line |
| 890 |
| '\\\r\n' // Added line |
| 891 |
; |
| 892 |
|
| 893 |
ComplexDefine |
| 894 |
: '#' Whitespace? 'define' ~[#]* |
| 895 |
-> skip |
| 896 |
; |
| 897 |
|
| 898 |
// ignore the following asm blocks: |
| 899 |
/* |
| 900 |
asm |
| 901 |
{ |
| 902 |
mfspr x, 286; |
| 903 |
} |
| 904 |
*/ |
| 905 |
AsmBlock |
| 906 |
: 'asm' ~'{'* '{' ~'}'* '}' |
| 907 |
-> skip |
| 908 |
; |
| 909 |
|
| 910 |
// ignore the lines generated by c preprocessor |
| 911 |
// sample line : '#line 1 "/home/dm/files/dk1.h" 1' |
| 912 |
LineAfterPreprocessing |
| 913 |
: '#line' Whitespace* ~[\r\n]* |
| 914 |
-> skip |
| 915 |
; |
| 916 |
|
| 917 |
LineDirective |
| 918 |
: '#' Whitespace? DecimalConstant Whitespace? StringLiteral ~[\r\n]* |
| 919 |
-> skip |
| 920 |
; |
| 921 |
|
| 922 |
PragmaDirective |
| 923 |
: '#' Whitespace? 'pragma' Whitespace ~[\r\n]* |
| 924 |
-> skip |
| 925 |
; |
| 926 |
|
| 927 |
Whitespace |
| 928 |
: [ \t]+ |
| 929 |
-> skip |
| 930 |
; |
| 931 |
|
| 932 |
Newline |
| 933 |
: ( '\r' '\n'? |
| 934 |
| '\n' |
| 935 |
) |
| 936 |
-> skip |
| 937 |
; |
| 938 |
|
| 939 |
BlockComment |
| 940 |
: '/*' .*? '*/' |
| 941 |
-> skip |
| 942 |
; |
| 943 |
|
| 944 |
LineComment |
| 945 |
: '//' ~[\r\n]* |
| 946 |
-> skip |
| 947 |
; |