ParaC-Grammar-File
897 lines
/*
/*
[The "BSD licence"]
The C Antlr 4 grammar was taken as base and reference for this file
Copyright (c) 2013 Sam Harwell
All rights reserved.
Redistribution and use in source and binary forms, with or without
URL: https://github.com/antlr/grammars-v4/blob/master/c/C.g4
modification, are permitted provided that the following conditions
are met:
This means here the BSD Licence will apply here for all content
1. Redistributions of source code must retain the above copyright
[The "BSD licence"]
Copyright (c) 2021 Luna-Klatzer
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
*/
/** C 2011 grammar built from the C11 Spec */
/** C 2011 grammar built from the C11 Spec */
grammar C;
grammar ParaC;
primaryExpression
primaryExpression
: Identifier
: Identifier
| Constant
| Constant
| StringLiteral+
| StringLiteral+
| '(' expression ')'
| '(' expression ')'
| genericSelection
| genericSelection
| '__extension__'? '(' compoundStatement ')' // Blocks (GCC extension)
| '__extension__'? '(' compoundStatement ')' // Blocks (GCC extension)
| '__builtin_va_arg' '(' unaryExpression ',' typeName ')'
| '__builtin_va_arg' '(' unaryExpression ',' typeName ')'
| '__builtin_offsetof' '(' typeName ',' unaryExpression ')'
| '__builtin_offsetof' '(' typeName ',' unaryExpression ')'
;
;
genericSelection
genericSelection
: '_Generic' '(' assignmentExpression ',' genericAssocList ')'
: '_Generic' '(' assignmentExpression ',' genericAssocList ')'
;
;
genericAssocList
genericAssocList
: genericAssociation (',' genericAssociation)*
: genericAssociation (',' genericAssociation)*
;
;
genericAssociation
genericAssociation
: (typeName | 'default') ':' assignmentExpression
: (typeName | 'default') ':' assignmentExpression
;
;
postfixExpression
postfixExpression
:
:
( primaryExpression
( primaryExpression
| '__extension__'? '(' typeName ')' '{' initializerList ','? '}'
| '__extension__'? '(' typeName ')' '{' initializerList ','? '}'
)
)
('[' expression ']'
('[' expression ']'
| '(' argumentExpressionList? ')'
| '(' argumentExpressionList? ')'
| ('.' | '->') Identifier
| ('.' | '->') Identifier
| ('++' | '--')
| ('++' | '--')
)*
)*
;
;
argumentExpressionList
argumentExpressionList
: assignmentExpression (',' assignmentExpression)*
: assignmentExpression (',' assignmentExpression)*
;
;
unaryExpression
unaryExpression
:
:
('++' | '--' | 'sizeof')*
('++' | '--' | 'sizeof')*
(postfixExpression
(postfixExpression
| unaryOperator castExpression
| unaryOperator castExpression
| ('sizeof' | '_Alignof') '(' typeName ')'
| ('sizeof' | '_Alignof') '(' typeName ')'
| '&&' Identifier // GCC extension address of label
| '&&' Identifier // GCC extension address of label
)
)
;
;
unaryOperator
unaryOperator
: '&' | '*' | '+' | '-' | '~' | '!'
: '&' | '*' | '+' | '-' | '~' | '!'
;
;
castExpression
castExpression
: '__extension__'? '(' typeName ')' castExpression
: '__extension__'? '(' typeName ')' castExpression
| unaryExpression
| unaryExpression
| DigitSequence // for
| DigitSequence // for
;
;
multiplicativeExpression
multiplicativeExpression
: castExpression (('*'|'/'|'%') castExpression)*
: castExpression (('*'|'/'|'%') castExpression)*
;
;
additiveExpression
additiveExpression
: multiplicativeExpression (('+'|'-') multiplicativeExpression)*
: multiplicativeExpression (('+'|'-') multiplicativeExpression)*
;
;
shiftExpression
shiftExpression
: additiveExpression (('<<'|'>>') additiveExpression)*
: additiveExpression (('<<'|'>>') additiveExpression)*
;
;
relationalExpression
relationalExpression
: shiftExpression (('<'|'>'|'<='|'>=') shiftExpression)*
: shiftExpression (('<'|'>'|'<='|'>=') shiftExpression)*
;
;
equalityExpression
equalityExpression
: relationalExpression (('=='| '!=') relationalExpression)*
: relationalExpression (('=='| '!=') relationalExpression)*
;
;
andExpression
andExpression
: equalityExpression ( '&' equalityExpression)*
: equalityExpression ( '&' equalityExpression)*
;
;
exclusiveOrExpression
exclusiveOrExpression
: andExpression ('^' andExpression)*
: andExpression ('^' andExpression)*
;
;
inclusiveOrExpression
inclusiveOrExpression
: exclusiveOrExpression ('|' exclusiveOrExpression)*
: exclusiveOrExpression ('|' exclusiveOrExpression)*
;
;
logicalAndExpression
logicalAndExpression
: inclusiveOrExpression ('&&' inclusiveOrExpression)*
: inclusiveOrExpression ('&&' inclusiveOrExpression)*
;
;
logicalOrExpression
logicalOrExpression
: logicalAndExpression ( '||' logicalAndExpression)*
: logicalAndExpression ( '||' logicalAndExpression)*
;
;
conditionalExpression
conditionalExpression
: logicalOrExpression ('?' expression ':' conditionalExpression)?
: logicalOrExpression ('?' expression ':' conditionalExpression)?
;
;
assignmentExpression
assignmentExpression
: conditionalExpression
: conditionalExpression
| unaryExpression assignmentOperator assignmentExpression
| unaryExpression assignmentOperator assignmentExpression
| DigitSequence // for
| DigitSequence // for
;
;
assignmentOperator
assignmentOperator
: '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '&=' | '^=' | '|='
: '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '&=' | '^=' | '|='
;
;
expression
expression
: assignmentExpression (',' assignmentExpression)*
: assignmentExpression (',' assignmentExpression)*
;
;
constantExpression
constantExpression
: conditionalExpression
: conditionalExpression
;
;
declaration
declaration
: declarationSpecifiers initDeclaratorList? ';'
: declarationSpecifiers initDeclaratorList? ';'
| staticAssertDeclaration
| staticAssertDeclaration
;
;
declarationSpecifiers
declarationSpecifiers
: declarationSpecifier+
: declarationSpecifier+
;
;
declarationSpecifiers2
declarationSpecifiers2
: declarationSpecifier+
: declarationSpecifier+
;
;
declarationSpecifier
declarationSpecifier
: storageClassSpecifier
: storageClassSpecifier
| entryPointSpecifider
| typeSpecifier
| typeSpecifier
| typeQualifier
| typeQualifier
| functionSpecifier
| functionSpecifier
| alignmentSpecifier
| alignmentSpecifier
;
;
initDeclaratorList
initDeclaratorList
: initDeclarator (',' initDeclarator)*
: initDeclarator (',' initDeclarator)*
;
;
initDeclarator
initDeclarator
: declarator ('=' initializer)?
: declarator ('=' initializer)?
;
;
entryPointSpecifider
: 'entry' // Hinting the entry function for the program
;
storageClassSpecifier
storageClassSpecifier
: 'typedef'
: 'typedef'
| 'extern'
| 'extern'
| 'static'
| 'static'
| '_Thread_local'
| '_Thread_local'
| 'auto'
| 'auto'
| 'register'
| 'register'
;
;
typeSpecifier
typeSpecifier
: ('void'
: ('void'
| 'char'
| 'char'
| 'short'
| 'short'
| 'int'
| 'int'
| 'status'
| 'long'
| 'long'
| 'float'
| 'float'
| 'double'
| 'double'
| 'signed'
| 'signed'
| 'unsigned'
| 'unsigned'
| '_Bool'
| '_Bool'
| '_Complex'
| '_Complex'
| '__m128'
| '__m128'
| '__m128d'
| '__m128d'
| '__m128i')
| '__m128i')
| '__extension__' '(' ('__m128' | '__m128d' | '__m128i') ')'
| '__extension__' '(' ('__m128' | '__m128d' | '__m128i') ')'
| atomicTypeSpecifier
| atomicTypeSpecifier
| structOrUnionSpecifier
| structOrUnionSpecifier
| enumSpecifier
| enumSpecifier
| typedefName
| typedefName
| '__typeof__' '(' constantExpression ')' // GCC extension
| '__typeof__' '(' constantExpression ')' // GCC extension
| typeSpecifier pointer
| typeSpecifier pointer
;
;
structOrUnionSpecifier
structOrUnionSpecifier
: structOrUnion Identifier? '{' structDeclarationList '}'
: structOrUnion Identifier? '{' structDeclarationList '}'
| structOrUnion Identifier
| structOrUnion Identifier
;
;
structOrUnion
structOrUnion
: 'struct'
: 'struct'
| 'union'
| 'union'
;
;
structDeclarationList
structDeclarationList
: structDeclaration+
: structDeclaration+
;
;
structDeclaration
structDeclaration
: specifierQualifierList structDeclaratorList? ';'
: specifierQualifierList structDeclaratorList? ';'
| staticAssertDeclaration
| staticAssertDeclaration
;
;
specifierQualifierList
specifierQualifierList
: (typeSpecifier| typeQualifier) specifierQualifierList?
: (typeSpecifier| typeQualifier) specifierQualifierList?
;
;
structDeclaratorList
structDeclaratorList
: structDeclarator (',' structDeclarator)*
: structDeclarator (',' structDeclarator)*
;
;
structDeclarator
structDeclarator
: declarator
: declarator
| declarator? ':' constantExpression
| declarator? ':' constantExpression
;
;
enumSpecifier
enumSpecifier
: 'enum' Identifier? '{' enumeratorList ','? '}'
: 'enum' Identifier? '{' enumeratorList ','? '}'
| 'enum' Identifier
| 'enum' Identifier
;
;
enumeratorList
enumeratorList
: enumerator (',' enumerator)*
: enumerator (',' enumerator)*
;
;
enumerator
enumerator
: enumerationConstant ('=' constantExpression)?
: enumerationConstant ('=' constantExpression)?
;
;
enumerationConstant
enumerationConstant
: Identifier
: Identifier
;
;
atomicTypeSpecifier
atomicTypeSpecifier
: '_Atomic' '(' typeName ')'
: '_Atomic' '(' typeName ')'
;
;
typeQualifier
typeQualifier
: 'const'
: 'const'
| 'restrict'
| 'restrict'
| 'volatile'
| 'volatile'
| '_Atomic'
| '_Atomic'
;
;
functionSpecifier
functionSpecifier
: ('inline'
: ('inline'
| '_Noreturn'
| '_Noreturn'
| '__inline__' // GCC extension
| '__inline__' // GCC extension
| '__stdcall')
| '__stdcall')
| gccAttributeSpecifier
| gccAttributeSpecifier
| '__declspec' '(' Identifier ')'
| '__declspec' '(' Identifier ')'
| entryPointSpecifider
;
;
alignmentSpecifier
alignmentSpecifier
: '_Alignas' '(' (typeName | constantExpression) ')'
: '_Alignas' '(' (typeName | constantExpression) ')'
;
;
declarator
declarator
: pointer? directDeclarator gccDeclaratorExtension*
: pointer? directDeclarator gccDeclaratorExtension*
;
;
directDeclarator
directDeclarator
: Identifier
: Identifier
| '(' declarator ')'
| '(' declarator ')'
| directDeclarator '[' typeQualifierList? assignmentExpression? ']'
| directDeclarator '[' typeQualifierList? assignmentExpression? ']'
| directDeclarator '[' 'static' typeQualifierList? assignmentExpression ']'
| directDeclarator '[' 'static' typeQualifierList? assignmentExpression ']'
| directDeclarator '[' typeQualifierList 'static' assignmentExpression ']'
| directDeclarator '[' typeQualifierList 'static' assignmentExpression ']'
| directDeclarator '[' typeQualifierList? '*' ']'
| directDeclarator '[' typeQualifierList? '*' ']'
| directDeclarator '(' parameterTypeList ')'
| directDeclarator '(' parameterTypeList ')'
| directDeclarator '(' identifierList? ')'
| directDeclarator '(' identifierList? ')'
| Identifier ':' DigitSequence // bit field
| Identifier ':' DigitSequence // bit field
| '(' typeSpecifier? pointer directDeclarator ')' // function pointer like: (__cdecl *f)
| '(' typeSpecifier? pointer directDeclarator ')' // function pointer like: (__cdecl *f)
;
;
gccDeclaratorExtension
gccDeclaratorExtension
: '__asm' '(' StringLiteral+ ')'
: '__asm' '(' StringLiteral+ ')'
| gccAttributeSpecifier
| gccAttributeSpecifier
;
;
gccAttributeSpecifier
gccAttributeSpecifier
: '__attribute__' '(' '(' gccAttributeList ')' ')'
: '__attribute__' '(' '(' gccAttributeList ')' ')'
;
;
gccAttributeList
gccAttributeList
: gccAttribute? (',' gccAttribute?)*
: gccAttribute? (',' gccAttribute?)*
;
;
gccAttribute
gccAttribute
: ~(',' | '(' | ')') // relaxed def for "identifier or reserved word"
: ~(',' | '(' | ')') // relaxed def for "identifier or reserved word"
('(' argumentExpressionList? ')')?
('(' argumentExpressionList? ')')?
;
;
nestedParenthesesBlock
nestedParenthesesBlock
: ( ~('(' | ')')
: ( ~('(' | ')')
| '(' nestedParenthesesBlock ')'
| '(' nestedParenthesesBlock ')'
)*
)*
;
;
pointer
pointer
: (('*'|'^') typeQualifierList?)+ // ^ - Blocks language extension
: (('*'|'^') typeQualifierList?)+ // ^ - Blocks language extension
;
;
typeQualifierList
typeQualifierList
: typeQualifier+
: typeQualifier+
;
;
parameterTypeList
parameterTypeList
: parameterList (',' '...')?
: parameterList (',' '...')?
;
;
parameterList
parameterList
: parameterDeclaration (',' parameterDeclaration)*
: parameterDeclaration (',' parameterDeclaration)*
;
;
parameterDeclaration
parameterDeclaration
: declarationSpecifiers declarator
: declarationSpecifiers declarator
| declarationSpecifiers2 abstractDeclarator?
| declarationSpecifiers2 abstractDeclarator?
;
;
identifierList
identifierList
: Identifier (',' Identifier)*
: Identifier (',' Identifier)*
;
;
typeName
typeName
: specifierQualifierList abstractDeclarator?
: specifierQualifierList abstractDeclarator?
;
;
abstractDeclarator
abstractDeclarator
: pointer
: pointer
| pointer? directAbstractDeclarator gccDeclaratorExtension*
| pointer? directAbstractDeclarator gccDeclaratorExtension*
;
;
directAbstractDeclarator
directAbstractDeclarator
: '(' abstractDeclarator ')' gccDeclaratorExtension*
: '(' abstractDeclarator ')' gccDeclaratorExtension*
| '[' typeQualifierList? assignmentExpression? ']'
| '[' typeQualifierList? assignmentExpression? ']'
| '[' 'static' typeQualifierList? assignmentExpression ']'
| '[' 'static' typeQualifierList? assignmentExpression ']'
| '[' typeQualifierList 'static' assignmentExpression ']'
| '[' typeQualifierList 'static' assignmentExpression ']'
| '[' '*' ']'
| '[' '*' ']'
| '(' parameterTypeList? ')' gccDeclaratorExtension*
| '(' parameterTypeList? ')' gccDeclaratorExtension*
| directAbstractDeclarator '[' typeQualifierList? assignmentExpression? ']'
| directAbstractDeclarator '[' typeQualifierList? assignmentExpression? ']'
| directAbstractDeclarator '[' 'static' typeQualifierList? assignmentExpression ']'
| directAbstractDeclarator '[' 'static' typeQualifierList? assignmentExpression ']'
| directAbstractDeclarator '[' typeQualifierList 'static' assignmentExpression ']'
| directAbstractDeclarator '[' typeQualifierList 'static' assignmentExpression ']'
| directAbstractDeclarator '[' '*' ']'
| directAbstractDeclarator '[' '*' ']'
| directAbstractDeclarator '(' parameterTypeList? ')' gccDeclaratorExtension*
| directAbstractDeclarator '(' parameterTypeList? ')' gccDeclaratorExtension*
;
;
typedefName
typedefName
: Identifier
: Identifier
;
;
initializer
initializer
: assignmentExpression
: assignmentExpression
| '{' initializerList ','? '}'
| '{' initializerList ','? '}'
;
;
initializerList
initializerList
: designation? initializer (',' designation? initializer)*
: designation? initializer (',' designation? initializer)*
;
;
designation
designation
: designatorList '='
: designatorList '='
;
;
designatorList
designatorList
: designator+
: designator+
;
;
designator
designator
: '[' constantExpression ']'
: '[' constantExpression ']'
| '.' Identifier
| '.' Identifier
;
;
staticAssertDeclaration
staticAssertDeclaration
: '_Static_assert' '(' constantExpression ',' StringLiteral+ ')' ';'
: '_Static_assert' '(' constantExpression ',' StringLiteral+ ')' ';'
;
;
statement
statement
: labeledStatement
: labeledStatement
| compoundStatement
| compoundStatement
| expressionStatement
| expressionStatement
| selectionStatement
| selectionStatement
| iterationStatement
| iterationStatement
| jumpStatement
| jumpStatement
| ('__asm' | '__asm__') ('volatile' | '__volatile__') '(' (logicalOrExpression (',' logicalOrExpression)*)? (':' (logicalOrExpression (',' logicalOrExpression)*)?)* ')' ';'
| ('__asm' | '__asm__') ('volatile' | '__volatile__') '(' (logicalOrExpression (',' logicalOrExpression)*)? (':' (logicalOrExpression (',' logicalOrExpression)*)?)* ')' ';'
;
;
labeledStatement
labeledStatement
: Identifier ':' statement
: Identifier ':' statement
| 'case' constantExpression ':' statement
| 'case' constantExpression ':' statement
| 'default' ':' statement
| 'default' ':' statement
;
;
compoundStatement
compoundStatement
: '{' blockItemList? '}'
: '{' blockItemList? '}'
;
;
blockItemList
blockItemList
: blockItem+
: blockItem+
;
;
blockItem
blockItem
: statement
: statement
| declaration
| declaration
;
;
expressionStatement
expressionStatement
: expression? ';'
: expression? ';'
;
;
selectionStatement
selectionStatement
: 'if' '(' expression ')' statement ('else' statement)?
: 'if' '(' expression ')' statement ('else' statement)?
| 'switch' '(' expression ')' statement
| 'switch' '(' expression ')' statement
;
;
iterationStatement
iterationStatement
: While '(' expression ')' statement
: While '(' expression ')' statement
| Do statement While '(' expression ')' ';'
| Do statement While '(' expression ')' ';'
| For '(' forCondition ')' statement
| For '(' forCondition ')' statement
;
;
// | 'for' '(' expression? ';' expression? ';' forUpdate? ')' statement
// | 'for' '(' expression? ';' expression? ';' forUpdate? ')' statement
// | For '(' declaration expression? ';' expression? ')' statement
// | For '(' declaration expression? ';' expression? ')' statement
forCondition
forCondition
: (forDeclaration | expression?) ';' forExpression? ';' forExpression?
: (forDeclaration | expression?) ';' forExpression? ';' forExpression?
;
;
forDeclaration
forDeclaration
: declarationSpecifiers initDeclaratorList?
: declarationSpecifiers initDeclaratorList?
;
;
forExpression
forExpression
: assignmentExpression (',' assignmentExpression)*
: assignmentExpression (',' assignmentExpression)*
;
;
jumpStatement
jumpStatement
: ('goto' Identifier
: ('goto' Identifier
| ('continue'| 'break')
| ('continue'| 'break')
| 'return' expression?
| 'return' expression?
| 'goto' unaryExpression // GCC extension
| 'goto' unaryExpression // GCC extension
)
)
';'
';'
;
;
compilationUnit
compilationUnit
: translationUnit? EOF
: translationUnit? EOF
;
;
translationUnit
translationUnit
: externalDeclaration+
: externalDeclaration+
;
;
externalDeclaration
externalDeclaration
: functionDefinition
: functionDefinition
| declaration
| declaration
| ';' // stray ;
| ';' // stray ;
;
;
functionDefinition
functionDefinition
: declarationSpecifiers? declarator declarationList? compoundStatement
: declarationSpecifiers? declarator declarationList? compoundStatement
;
;
declarationList
declarationList
: declaration+
: declaration+
;
;
Auto : 'auto';
Auto : 'auto';
Break : 'break';
Break : 'break';
Case : 'case';
Case : 'case';
Char : 'char';
Char : 'char';
Const : 'const';
Const : 'const';
Continue : 'continue';
Continue : 'continue';
Default : 'default';
Default : 'default';
Do : 'do';
Do : 'do';
Double : 'double';
Double : 'double';
Else : 'else';
Else : 'else';
Entry : 'entry';
Enum : 'enum';
Enum : 'enum';
Extern : 'extern';
Extern : 'extern';
Float : 'float';
Float : 'float';
For : 'for';
For : 'for';
Goto : 'goto';
Goto : 'goto';
If : 'if';
If : 'if';
Inline : 'inline';
Inline : 'inline';
Int : 'int';
Int : 'int';
Long : 'long';
Long : 'long';
Register : 'register';
Register : 'register';
Restrict : 'restrict';
Restrict : 'restrict';
Return : 'return';
Return : 'return';
Short : 'short';
Short : 'short';
Signed : 'signed';
Signed : 'signed';
Sizeof : 'sizeof';
Sizeof : 'sizeof';
Static : 'static';
Static : 'static';
Status : 'status';
Struct : 'struct';
Struct : 'struct';
Switch : 'switch';
Switch : 'switch';
Typedef : 'typedef';
Typedef : 'typedef';
Union : 'union';
Union : 'union';
Unsigned : 'unsigned';
Unsigned : 'unsigned';
Void : 'void';
Void : 'void';
Volatile : 'volatile';
Volatile : 'volatile';
While : 'while';
While : 'while';
Alignas : '_Alignas';
Alignas : '_Alignas';
Alignof : '_Alignof';
Alignof : '_Alignof';
Atomic : '_Atomic';
Atomic : '_Atomic';
Bool : '_Bool';
Bool : '_Bool';
Complex : '_Complex';
Complex : '_Complex';
Generic : '_Generic';
Generic : '_Generic';
Imaginary : '_Imaginary';
Imaginary : '_Imaginary';
Noreturn : '_Noreturn';
Noreturn : '_Noreturn';
StaticAssert : '_Static_assert';
StaticAssert : '_Static_assert';
ThreadLocal : '_Thread_local';
ThreadLocal : '_Thread_local';
LeftParen : '(';
LeftParen : '(';
RightParen : ')';
RightParen : ')';
LeftBracket : '[';
LeftBracket : '[';
RightBracket : ']';
RightBracket : ']';
LeftBrace : '{';
LeftBrace : '{';
RightBrace : '}';
RightBrace : '}';
Less : '<';
Less : '<';
LessEqual : '<=';
LessEqual : '<=';
Greater : '>';
Greater : '>';
GreaterEqual : '>=';
GreaterEqual : '>=';
LeftShift : '<<';
LeftShift : '<<';
RightShift : '>>';
RightShift : '>>';
Plus : '+';
Plus : '+';
PlusPlus : '++';
PlusPlus : '++';
Minus : '-';
Minus : '-';
MinusMinus : '--';
MinusMinus : '--';
Star : '*';
Star : '*';
Div : '/';
Div : '/';
Mod : '%';
Mod : '%';
And : '&';
And : '&';
Or : '|';
Or : '|';
AndAnd : '&&';
AndAnd : '&&';
OrOr : '||';
OrOr : '||';
Caret : '^';
Caret : '^';
Not : '!';
Not : '!';
Tilde : '~';
Tilde : '~';
Question : '?';
Question : '?';
Colon : ':';
Colon : ':';
Semi : ';';
Semi : ';';
Comma : ',';
Comma : ',';
Assign : '=';
Assign : '=';
// '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '&=' | '^=' | '|='
// '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '&=' | '^=' | '|='
StarAssign : '*=';
StarAssign : '*=';
DivAssign : '/=';
DivAssign : '/=';
ModAssign : '%=';
ModAssign : '%=';
PlusAssign : '+=';
PlusAssign : '+=';
MinusAssign : '-=';
MinusAssign : '-=';
LeftShiftAssign : '<<=';
LeftShiftAssign : '<<=';
RightShiftAssign : '>>=';
RightShiftAssign : '>>=';
AndAssign : '&=';
AndAssign : '&=';
XorAssign : '^=';
XorAssign : '^=';
OrAssign : '|=';
OrAssign : '|=';
Equal : '==';
Equal : '==';
NotEqual : '!=';
NotEqual : '!=';
Arrow : '->';
Arrow : '->';
Dot : '.';
Dot : '.';
Ellipsis : '...';
Ellipsis : '...';
Identifier
Identifier
: IdentifierNondigit
: IdentifierNondigit
( IdentifierNondigit
( IdentifierNondigit
| Digit
| Digit
)*
)*
;
;
fragment
fragment
IdentifierNondigit
IdentifierNondigit
: Nondigit
: Nondigit
| UniversalCharacterName
| UniversalCharacterName
//| // other implementation-defined characters...
//| // other implementation-defined characters...
;
;
fragment
fragment
Nondigit
Nondigit
: [a-zA-Z_]
: [a-zA-Z_]
;
;
fragment
fragment
Digit
Digit
: [0-9]
: [0-9]
;
;
fragment
fragment
UniversalCharacterName
UniversalCharacterName
: '\\u' HexQuad
: '\\u' HexQuad
| '\\U' HexQuad HexQuad
| '\\U' HexQuad HexQuad
;
;
fragment
fragment
HexQuad
HexQuad
: HexadecimalDigit HexadecimalDigit HexadecimalDigit HexadecimalDigit
: HexadecimalDigit HexadecimalDigit HexadecimalDigit HexadecimalDigit
;
;
Constant
Constant
: IntegerConstant
: IntegerConstant
| FloatingConstant
| FloatingConstant
//| EnumerationConstant
//| EnumerationConstant
| CharacterConstant
| CharacterConstant
;
;
fragment
fragment
IntegerConstant
IntegerConstant
: DecimalConstant IntegerSuffix?
: DecimalConstant IntegerSuffix?
| OctalConstant IntegerSuffix?
| OctalConstant IntegerSuffix?
| HexadecimalConstant IntegerSuffix?
| HexadecimalConstant IntegerSuffix?
| BinaryConstant
| BinaryConstant
;
;
fragment
fragment
BinaryConstant
BinaryConstant
: '0' [bB] [0-1]+
: '0' [bB] [0-1]+
;
;
fragment
fragment
DecimalConstant
DecimalConstant
: NonzeroDigit Digit*
: NonzeroDigit Digit*
;
;
fragment
fragment
OctalConstant
OctalConstant
: '0' OctalDigit*
: '0' OctalDigit*
;
;
fragment
fragment
HexadecimalConstant
HexadecimalConstant
: HexadecimalPrefix HexadecimalDigit+
: HexadecimalPrefix HexadecimalDigit+
;
;
fragment
fragment
HexadecimalPrefix
HexadecimalPrefix
: '0' [xX]
: '0' [xX]
;
;
fragment
fragment
NonzeroDigit
NonzeroDigit
: [1-9]
: [1-9]
;
;
fragment
fragment
OctalDigit
OctalDigit
: [0-7]
: [0-7]
;
;
fragment
fragment
HexadecimalDigit
HexadecimalDigit
: [0-9a-fA-F]
: [0-9a-fA-F]
;
;
fragment
fragment
IntegerSuffix
IntegerSuffix
: UnsignedSuffix LongSuffix?
: UnsignedSuffix LongSuffix?
| UnsignedSuffix LongLongSuffix
| UnsignedSuffix LongLongSuffix
| LongSuffix UnsignedSuffix?
| LongSuffix UnsignedSuffix?
| LongLongSuffix UnsignedSuffix?
| LongLongSuffix UnsignedSuffix?
;
;
fragment
fragment
UnsignedSuffix
UnsignedSuffix
: [uU]
: [uU]
;
;
fragment
fragment
LongSuffix
LongSuffix
: [lL]
: [lL]
;
;
fragment
fragment
LongLongSuffix
LongLongSuffix
: 'll' | 'LL'
: 'll' | 'LL'
;
;
fragment
fragment
FloatingConstant
FloatingConstant
: DecimalFloatingConstant
: DecimalFloatingConstant
| HexadecimalFloatingConstant
| HexadecimalFloatingConstant
;
;
fragment
fragment
DecimalFloatingConstant
DecimalFloatingConstant
: FractionalConstant ExponentPart? FloatingSuffix?
: FractionalConstant ExponentPart? FloatingSuffix?
| DigitSequence ExponentPart FloatingSuffix?
| DigitSequence ExponentPart FloatingSuffix?
;
;
fragment
fragment
HexadecimalFloatingConstant
HexadecimalFloatingConstant
: HexadecimalPrefix (HexadecimalFractionalConstant | HexadecimalDigitSequence) BinaryExponentPart FloatingSuffix?
: HexadecimalPrefix (HexadecimalFractionalConstant | HexadecimalDigitSequence) BinaryExponentPart FloatingSuffix?
;
;
fragment
fragment
FractionalConstant
FractionalConstant
: DigitSequence? '.' DigitSequence
: DigitSequence? '.' DigitSequence
| DigitSequence '.'
| DigitSequence '.'
;
;
fragment
fragment
ExponentPart
ExponentPart
: [eE] Sign? DigitSequence
: [eE] Sign? DigitSequence
;
;
fragment
fragment
Sign
Sign
: [+-]
: [+-]
;
;
DigitSequence
DigitSequence
: Digit+
: Digit+
;
;
fragment
fragment
HexadecimalFractionalConstant
HexadecimalFractionalConstant
: HexadecimalDigitSequence? '.' HexadecimalDigitSequence
: HexadecimalDigitSequence? '.' HexadecimalDigitSequence
| HexadecimalDigitSequence '.'
| HexadecimalDigitSequence '.'
;
;
fragment
fragment
BinaryExponentPart
BinaryExponentPart
: [pP] Sign? DigitSequence
: [pP] Sign? DigitSequence
;
;
fragment
fragment
HexadecimalDigitSequence
HexadecimalDigitSequence
: HexadecimalDigit+
: HexadecimalDigit+
;
;
fragment
fragment
FloatingSuffix
FloatingSuffix
: [flFL]
: [flFL]
;
;
fragment
fragment
CharacterConstant
CharacterConstant
: '\'' CCharSequence '\''
: '\'' CCharSequence '\''
| 'L\'' CCharSequence '\''
| 'L\'' CCharSequence '\''
| 'u\'' CCharSequence '\''
| 'u\'' CCharSequence '\''
| 'U\'' CCharSequence '\''
| 'U\'' CCharSequence '\''
;
;
fragment
fragment
CCharSequence
CCharSequence
: CChar+
: CChar+
;
;
fragment
fragment
CChar
CChar
: ~['\\\r\n]
: ~['\\\r\n]
| EscapeSequence
| EscapeSequence
;
;
fragment
fragment
EscapeSequence
EscapeSequence
: SimpleEscapeSequence
: SimpleEscapeSequence
| OctalEscapeSequence
| OctalEscapeSequence
| HexadecimalEscapeSequence
| HexadecimalEscapeSequence
| UniversalCharacterName
| UniversalCharacterName
;
;
fragment
fragment
SimpleEscapeSequence
SimpleEscapeSequence
: '\\' ['"?abfnrtv\\]
: '\\' ['"?abfnrtv\\]
;
;
fragment
fragment
OctalEscapeSequence
OctalEscapeSequence
: '\\' OctalDigit OctalDigit? OctalDigit?
: '\\' OctalDigit OctalDigit? OctalDigit?
;
;
fragment
fragment
HexadecimalEscapeSequence
HexadecimalEscapeSequence
: '\\x' HexadecimalDigit+
: '\\x' HexadecimalDigit+
;
;
StringLiteral
StringLiteral
: EncodingPrefix? '"' SCharSequence? '"'
: EncodingPrefix? '"' SCharSequence? '"'
;
;
fragment
fragment
EncodingPrefix
EncodingPrefix
: 'u8'
: 'u8'
| 'u'
| 'u'
| 'U'
| 'U'
| 'L'
| 'L'
;
;
fragment
fragment
SCharSequence
SCharSequence
: SChar+
: SChar+
;
;
fragment
fragment
SChar
SChar
: ~["\\\r\n]
: ~["\\\r\n]
| EscapeSequence
| EscapeSequence
| '\\\n' // Added line
| '\\\n' // Added line
| '\\\r\n' // Added line
| '\\\r\n' // Added line
;
;
ComplexDefine
ComplexDefine
: '#' Whitespace? 'define' ~[#\r\n]*
: '#' Whitespace? 'define' ~[#\r\n]*
-> skip
-> skip
;
;
IncludeDirective
IncludeDirective
: '#' Whitespace? 'include' Whitespace? (('"' ~[\r\n]* '"') | ('<' ~[\r\n]* '>' )) Whitespace? Newline
: '#' Whitespace? 'include' Whitespace? (('"' ~[\r\n]* '"') | ('<' ~[\r\n]* '>' )) Whitespace? Newline
-> skip
-> skip
;
;
// ignore the following asm blocks:
// ignore the following asm blocks:
/*
/*
asm
asm
{
{
mfspr x, 286;
mfspr x, 286;
}
}
*/
*/
AsmBlock
AsmBlock
: 'asm' ~'{'* '{' ~'}'* '}'
: 'asm' ~'{'* '{' ~'}'* '}'
-> skip
-> skip
;
;
// ignore the lines generated by c preprocessor
// ignore the lines generated by c preprocessor
// sample line : '#line 1 "/home/dm/files/dk1.h" 1'
// sample line : '#line 1 "/home/dm/files/dk1.h" 1'
LineAfterPreprocessing
LineAfterPreprocessing
: '#line' Whitespace* ~[\r\n]*
: '#line' Whitespace* ~[\r\n]*
-> skip
-> skip
;
;
LineDirective
LineDirective
: '#' Whitespace? DecimalConstant Whitespace? StringLiteral ~[\r\n]*
: '#' Whitespace? DecimalConstant Whitespace? StringLiteral ~[\r\n]*
-> skip
-> skip
;
;
PragmaDirective
PragmaDirective
: '#' Whitespace? 'pragma' Whitespace ~[\r\n]*
: '#' Whitespace? 'pragma' Whitespace ~[\r\n]*
-> skip
-> skip
;
;
Whitespace
Whitespace
: [ \t]+
: [ \t]+
-> skip
-> skip
;
;
Newline
Newline
: ( '\r' '\n'?
: ( '\r' '\n'?
| '\n'
| '\n'
)
)
-> skip
-> skip
;
;
BlockComment
BlockComment
: '/*' .*? '*/'
: '/*' .*? '*/'
-> skip
-> skip
;
;
LineComment
LineComment
: '//' ~[\r\n]*
: '//' ~[\r\n]*
-> skip
-> skip
;
;