📄 expandednescemitter.g
字号:
;
includeFileNameList :( includeFileName
( c:COMMA { print( c ); }
includeFileName
)*
)
;
includeFileName :#( NIncludeFileName
i:ID { print( i ); }
// TODO: optionally we can get the includeFileAST attribute of the ID node
// and start processing the AST of the included file here
)
;
interfaceDeclaration :#(lc:NInterface
i:"interface" { print( i ); }
id:ID { print( id ); }
{ print( lc ); newline(); tabs++;}
declarationList
rc:RCURLY { tabs--; print( rc ); newline();}
)
;
moduleFile :#(NModuleFile
(includes)*
module
)
;
module :#( m:NModule
{ print( m ); }
i:ID { print( i ); }
interfaceDescription
moduleImplementation
)
;
interfaceDescription :#( lc:NInterfaceDescription { print( lc ); newline(); tabs++;}
(
uses
| provides
)*
rc:RCURLY { tabs--; print( rc ); newline(); }
)
;
uses :#( u:NUses { print( u ); }
interfaceDescriptionItemList
)
;
provides :#( p:NProvides { print( p ); }
interfaceDescriptionItemList
)
;
interfaceDescriptionItemList :interfaceDescriptionItem
| (
lc:LCURLY { print( lc ); newline(); tabs++;}
(interfaceDescriptionItem)+
rc:RCURLY { tabs--; print( rc ); newline(); }
)
;
interfaceDescriptionItem :declaration
|
i:"interface" { print( i ); }
interfaceIdentifier (interfaceParameters)?
{ print( ";" ); newline();}
;
interfaceIdentifier :(i:ID { print( i ); }
( a:"as" { print( a ); }
r:ID { print( r ); }
)?
// TODO: optionally we can get the interfaceFileAST attribute of the ID node
// and start processing the AST of the interface file here
)
;
interfaceParameters :l:LBRACKET { print( l ); }
parameterTypeList
r:RBRACKET { print( r ); }
;
moduleImplementation :#( i:NImplementation { print( i ); }
lc:LCURLY
{ print( lc ); newline(); tabs++; }
externalList
rc:RCURLY { tabs--; print( rc ); newline(); }
)
;
externalList :( externalDef | textNode )+
;
textNode :n:NText { print( n ); }
;
externalDef :declaration
| functionDef
| asm_expr
| typelessDeclaration
| s:SEMI { print( s ); newline();}
;
typelessDeclaration :#(NTypeMissing initDeclList s: SEMI) { print( s ); newline(); }
;
asm_expr :#( a:"asm" { print( a ); }
( v:"volatile" { print( v ); }
)?
lc:LCURLY { print( lc ); newline(); tabs++; }
expr
rc:RCURLY { tabs--; print( rc ); newline();}
s:SEMI { print( s ); newline();}
)
;
declaration :#( NDeclaration
declSpecifiers
(
initDeclList
)?
( s:SEMI { print( s ); newline(); } )+
)
;
declSpecifiers :( storageClassSpecifier
| typeQualifier
| typeSpecifier
)+
;
storageClassSpecifier :a:"auto" { print( a ); }
| b:"register" { print( b ); }
| c:"typedef" { print( c ); }
| d:"norace" { print( d ); }
| functionStorageClassSpecifier
;
functionStorageClassSpecifier :a:"extern" { print( a ); }
| b:"static" { print( b ); }
| c:"inline" { print( c ); }
| d:"async" { print( d ); }
| e:"default" { print( e ); }
| f:"command" { print( f ); }
| g:"event" { print( g ); }
| h:"task" { print( h ); }
;
typeQualifier :a:"const" { print( a ); }
| b:"volatile" { print( b ); }
;
typeSpecifier :a:"void" { print( a ); }
| b:"char" { print( b ); }
| c:"short" { print( c ); }
| d:"int" { print( d ); }
| e:"long" { print( e ); }
| f:"float" { print( f ); }
| g:"double" { print( g ); }
| h:"signed" { print( h ); }
| i:"unsigned" { print( i ); }
| structSpecifier ( attributeDecl )*
| unionSpecifier ( attributeDecl )*
| enumSpecifier
| typedefName
| #(n:"typeof" lp:LPAREN { print( n ); print( lp ); }
( (typeName )=> typeName
| expr
)
rp:RPAREN { print( rp ); }
)
| p:"__complex" { print( p ); }
;
typedefName :#(NTypedefName i:ID { print( i ); } )
;
structSpecifier :#( a:"struct" { print( a ); }
structOrUnionBody
)
;
unionSpecifier :#( a:"union" { print( a ); }
structOrUnionBody
)
;
structOrUnionBody :( (ID LCURLY) => i1:ID lc1:LCURLY { print( i1 ); print ( "{" ); tabs++; }
( structDeclarationList )?
rc1:RCURLY { tabs--; print( rc1 ); }
| lc2:LCURLY { print( "{" ); tabs++; }
( structDeclarationList )?
rc2:RCURLY { tabs--; print( rc2 ); }
| i2:ID { print( i2 ); }
)
;
structDeclarationList :( structDeclaration { print( ";" ); newline();}
)+
;
structDeclaration :specifierQualifierList structDeclaratorList
;
specifierQualifierList :(
typeSpecifier
| typeQualifier
)+
;
structDeclaratorList :structDeclarator
( { print(","); newline();} structDeclarator )*
;
structDeclarator :#( NStructDeclarator
( declarator )?
( c:COLON { print( c ); } expr )?
( attributeDecl )*
)
;
enumSpecifier :#( a:"enum" { print( a ); }
( i:ID { print( i ); } )?
( lc:LCURLY { print( lc ); tabs++; }
enumList
rc:RCURLY { tabs--; print( rc ); }
)?
( attributeDecl )*
)
;
enumList :enumerator ( {print(","); newline(); } enumerator)*
;
enumerator :i:ID { print( i ); }
( b:ASSIGN { print( b ); }
expr
)?
;
attributeDecl :#( a:"__attribute" { print( a ); }
(b:. { print( b ); } )*
)
| #( n:NAsmAttribute { print( n ); }
lp:LPAREN { print( lp ); }
expr { print( ")" ); }
rp:RPAREN { print( rp ); }
)
;
initDeclList :initDecl
( { print( "," ); } initDecl )*
;
initDecl { String declName = ""; }
:#(NInitDecl
declarator
( attributeDecl )*
( a:ASSIGN { print( a ); }
initializer
| b:COLON { print( b ); }
expr
)?
)
;
pointerGroup :#( NPointerGroup
( a:STAR { print( a ); }
( typeQualifier )*
)+
)
;
idList :i:ID { print( i ); }
( c:COMMA { print( c ); }
id:ID { print( id ); }
)*
;
initializer :#( NInitializer (initializerElementLabel)? expr )
| lcurlyInitializer
;
initializerElementLabel :#( NInitializerElementLabel
(
( l:LBRACKET { print( l ); }
expr
r:RBRACKET { print( r ); }
(a1:ASSIGN { print( a1 ); } )?
)
| i1:ID c:COLON { print( i1 ); print( c ); }
| d:DOT i2:ID a2:ASSIGN { print( d ); print( i2 ); print( a2 ); }
)
)
;
lcurlyInitializer :#(n:NLcurlyInitializer { print( n ); tabs++; }
initializerList
rc:RCURLY { tabs--; print( rc ); }
)
;
initializerList :( i:initializer { commaSep( i ); }
)*
;
declarator :#( NDeclarator
( pointerGroup )?
(
(
id:ID { printns( id ); }
(DOT id2:ID { printns( "." ); printns( id2 ); }
)? { printns( " " );}
)
| lp:LPAREN { print( lp ); } declarator rp:RPAREN { print( rp ); }
)
( #(ip:NInterfaceParameterList { print( ip ); }
(
parameterTypeList
| idList
)
rbr:RBRACKET { print( rbr ); }
)
)?
( #( n:NParameterTypeList { print( n ); }
(
parameterTypeList
| (idList)?
)
r:RPAREN { print( r ); }
)
| lb:LBRACKET { print( lb );} ( expr )? rb:RBRACKET { print( rb ); }
)*
)
;
parameterTypeList :( parameterDeclaration
( c:COMMA { print( c ); }
| s:SEMI { print( s ); }
)?
)+
( v:VARARGS { print( v ); } )?
;
parameterDeclaration :#( NParameterDeclaration
declSpecifiers
(declarator | nonemptyAbstractDeclarator)?
)
;
functionDef :#( NFunctionDef
( functionDeclSpecifiers)?
declarator
(declaration
| v:VARARGS { print( v ); }
)*
( attributeDecl )*
compoundStatement
)
;
functionDeclSpecifiers :( functionStorageClassSpecifier
| typeQualifier
| typeSpecifier
)+
;
declarationList :( //ANTLR doesn't know that declarationList properly eats all the declarations
//so it warns about the ambiguity
options {
warnWhenFollowAmbig = false;
} :
localLabelDecl
| declaration
)+
;
localLabelDecl :#(a:"__label__" { print( a ); }
( i:ID { commaSep( i ); }
)+
{ print( ";" ); }
)
;
compoundStatement :#( cs:NCompoundStatement { print( cs ); newline(); tabs++;
}
( declarationList
| functionDef
)*
( statementList )?
rc:RCURLY {
tabs--; print( rc ); newline();
}
)
;
statementList :( statement )+
;
statement :( ("atomic") => a:"atomic" { print( a ); }
statementBody
| statementBody )
;
statementBody :s:SEMI { print( s ); newline(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -