📄 expandednescparser.g
字号:
// inherited from grammar GnuCParser
attributeList :attribute ( options{warnWhenFollowAmbig=false;}: COMMA attribute)* ( COMMA )?
;
// inherited from grammar GnuCParser
attribute :( ~(LPAREN | RPAREN | COMMA)
| LPAREN attributeList RPAREN
)*
;
// inherited from grammar GnuCParser
compoundStatement[String scopeName] :LCURLY^
{
pushScope(scopeName);
}
( //this ambiguity is ok, declarationList and nestedFunctionDef end properly
options {
warnWhenFollowAmbig = false;
} :
( "typedef" | "__label__" | declaration )=> declarationList
| (nestedFunctionDef)=> nestedFunctionDef
)*
( statementList )?
{ popScope(); }
RCURLY
{ ##.setType( NCompoundStatement ); ##.setAttribute( "scopeName", scopeName ); }
;
// inherited from grammar GnuCParser
conditionalExpr :logicalOrExpr
( QUESTION^ (expr)? COLON conditionalExpr )?
;
// inherited from grammar GnuCParser
rangeExpr :constExpr VARARGS constExpr
{ ## = #(#[NRangeExpr], ##); }
;
// inherited from grammar GnuCParser
castExpr :( LPAREN typeName RPAREN )=>
LPAREN^ typeName RPAREN ( castExpr | lcurlyInitializer )
{ ##.setType(NCast); }
| unaryExpr
;
// inherited from grammar GnuCParser
nonemptyAbstractDeclarator :(
pointerGroup
( (LPAREN
( nonemptyAbstractDeclarator
| parameterTypeList
)?
( COMMA! )?
RPAREN)
| (LBRACKET (expr)? RBRACKET)
)*
| ( (LPAREN
( nonemptyAbstractDeclarator
| parameterTypeList
)?
( COMMA! )?
RPAREN)
| (LBRACKET (expr)? RBRACKET)
)+
)
{ ## = #( #[NNonemptyAbstractDeclarator], ## ); }
;
// inherited from grammar GnuCParser
unaryExpr :postfixExpr
| INC^ castExpr
| DEC^ castExpr
| u:unaryOperator castExpr { ## = #( #[NUnaryExpr], ## ); }
| "sizeof"^
( ( LPAREN typeName )=> LPAREN typeName RPAREN
| unaryExpr
)
| "__alignof"^
( ( LPAREN typeName )=> LPAREN typeName RPAREN
| unaryExpr
)
| gnuAsmExpr
;
// inherited from grammar GnuCParser
unaryOperator :BAND
| STAR
| PLUS
| MINUS
| BNOT //also stands for complex conjugation
| LNOT
| LAND //for label dereference (&&label)
| "__real"
| "__imag"
;
// inherited from grammar GnuCParser
gnuAsmExpr :"asm"^ ("volatile")?
LPAREN stringConst
( options { warnWhenFollowAmbig = false; }:
COLON (strOptExprPair ( COMMA strOptExprPair)* )?
( options { warnWhenFollowAmbig = false; }:
COLON (strOptExprPair ( COMMA strOptExprPair)* )?
)?
)?
( COLON stringConst ( COMMA stringConst)* )?
RPAREN
{ ##.setType(NGnuAsmExpr); }
;
// inherited from grammar GnuCParser
strOptExprPair :stringConst ( LPAREN expr RPAREN )?
;
// inherited from grammar GnuCParser
primaryExpr :ID
| Number
| charConst
| stringConst
// JTC:
// ID should catch the enumerator
// leaving it in gives ambiguous err
// | enumerator
| (LPAREN LCURLY) => LPAREN^ compoundStatement[getAScopeName()] RPAREN
| LPAREN^ expr RPAREN { ##.setType(NExpressionGroup); }
;
// inherited from grammar StdCParser
externalList :( externalDef )+
;
// inherited from grammar StdCParser
declSpecifiers { int specCount=0; }
:( options { // this loop properly aborts when
// it finds a non-typedefName ID MBZ
warnWhenFollowAmbig = false;
} :
s:storageClassSpecifier
| typeQualifier
| ( "struct" | "union" | "enum" | typeSpecifier[specCount] )=>
specCount = typeSpecifier[specCount]
)+
;
// inherited from grammar StdCParser
typeQualifier :"const"
| "volatile"
;
// inherited from grammar StdCParser
typedefName :{ isTypedefName ( LT(1).getText() ) }?
i:ID { ## = #(#[NTypedefName], #i); }
;
// inherited from grammar StdCParser
structOrUnion :"struct"
| "union"
;
// inherited from grammar StdCParser
structDeclarationList :( structDeclaration )+
;
// inherited from grammar StdCParser
specifierQualifierList { int specCount = 0; }
:( options { // this loop properly aborts when
// it finds a non-typedefName ID MBZ
warnWhenFollowAmbig = false;
} :
( "struct" | "union" | "enum" | typeSpecifier[specCount] )=>
specCount = typeSpecifier[specCount]
| typeQualifier
)+
;
// inherited from grammar StdCParser
pointerGroup :( STAR ( typeQualifier )* )+ { ## = #( #[NPointerGroup], ##); }
;
// inherited from grammar StdCParser
functionDeclSpecifiers { int specCount = 0; }
:( options { // this loop properly aborts when
// it finds a non-typedefName ID MBZ
warnWhenFollowAmbig = false;
} :
functionStorageClassSpecifier
| typeQualifier
| ( "struct" | "union" | "enum" | typeSpecifier[specCount] )=>
specCount = typeSpecifier[specCount]
)+
;
// inherited from grammar StdCParser
declarationPredictor :(options { //only want to look at declaration if I don't see typedef
warnWhenFollowAmbig = false;
}:
"typedef"
| declaration
)
;
// inherited from grammar StdCParser
statementList :( statement )+
;
// inherited from grammar StdCParser
expr :assignExpr (options {
/* MBZ:
COMMA is ambiguous between comma expressions and
argument lists. argExprList should get priority,
and it does by being deeper in the expr rule tree
and using (COMMA assignExpr)*
*/
warnWhenFollowAmbig = false;
} :
c:COMMA^ { #c.setType(NCommaExpr); } assignExpr
)*
;
// inherited from grammar StdCParser
assignExpr :conditionalExpr ( a:assignOperator! assignExpr { ## = #( #a, ## );} )?
;
// inherited from grammar StdCParser
assignOperator :ASSIGN
| DIV_ASSIGN
| PLUS_ASSIGN
| MINUS_ASSIGN
| STAR_ASSIGN
| MOD_ASSIGN
| RSHIFT_ASSIGN
| LSHIFT_ASSIGN
| BAND_ASSIGN
| BOR_ASSIGN
| BXOR_ASSIGN
;
// inherited from grammar StdCParser
constExpr :conditionalExpr
;
// inherited from grammar StdCParser
logicalOrExpr :logicalAndExpr ( LOR^ logicalAndExpr )*
;
// inherited from grammar StdCParser
logicalAndExpr :inclusiveOrExpr ( LAND^ inclusiveOrExpr )*
;
// inherited from grammar StdCParser
inclusiveOrExpr :exclusiveOrExpr ( BOR^ exclusiveOrExpr )*
;
// inherited from grammar StdCParser
exclusiveOrExpr :bitAndExpr ( BXOR^ bitAndExpr )*
;
// inherited from grammar StdCParser
bitAndExpr :equalityExpr ( BAND^ equalityExpr )*
;
// inherited from grammar StdCParser
equalityExpr :relationalExpr
( ( EQUAL^ | NOT_EQUAL^ ) relationalExpr )*
;
// inherited from grammar StdCParser
relationalExpr :shiftExpr
( ( LT^ | LTE^ | GT^ | GTE^ ) shiftExpr )*
;
// inherited from grammar StdCParser
shiftExpr :additiveExpr
( ( LSHIFT^ | RSHIFT^ ) additiveExpr )*
;
// inherited from grammar StdCParser
additiveExpr :multExpr
( ( PLUS^ | MINUS^ ) multExpr )*
;
// inherited from grammar StdCParser
multExpr :castExpr
( ( STAR^ | DIV^ | MOD^ ) castExpr )*
;
// inherited from grammar StdCParser
typeName :specifierQualifierList (nonemptyAbstractDeclarator)?
;
// inherited from grammar StdCParser
postfixSuffix :( PTR ID
| DOT ID
| functionCall
| LBRACKET expr RBRACKET
| INC
| DEC
)+
;
// inherited from grammar StdCParser
functionCall :LPAREN^ (a:argExprList)? RPAREN
{
##.setType( NFunctionCallArgs );
}
;
// inherited from grammar StdCParser
argExprList :assignExpr ( COMMA! assignExpr )*
;
// inherited from grammar StdCParser
protected charConst :CharLiteral
;
// inherited from grammar StdCParser
protected stringConst :(StringLiteral)+ { ## = #(#[NStringSeq], ##); }
;
// inherited from grammar StdCParser
protected intConst :IntOctalConst
| LongOctalConst
| UnsignedOctalConst
| IntIntConst
| LongIntConst
| UnsignedIntConst
| IntHexConst
| LongHexConst
| UnsignedHexConst
;
// inherited from grammar StdCParser
protected floatConst :FloatDoubleConst
| DoubleDoubleConst
| LongDoubleConst
;
// inherited from grammar StdCParser
dummy :NTypedefName
| NInitDecl
| NDeclarator
| NStructDeclarator
| NDeclaration
| NCast
| NPointerGroup
| NExpressionGroup
| NFunctionCallArgs
| NNonemptyAbstractDeclarator
| NInitializer
| NStatementExpr
| NEmptyExpression
| NParameterTypeList
| NFunctionDef
| NCompoundStatement
| NParameterDeclaration
| NCommaExpr
| NUnaryExpr
| NLabel
| NPostfixExpr
| NRangeExpr
| NStringSeq
| NInitializerElementLabel
| NLcurlyInitializer
| NAsmAttribute
| NGnuAsmExpr
| NTypeMissing
;
{
import isis.anp.common.CToken;
import isis.anp.common.LineObject;
import isis.anp.common.PreprocessorInfoChannel;
import java.io.InputStream;
import java.io.Reader;
import java.util.Hashtable;
import antlr.ANTLRHashString;
import antlr.ByteBuffer;
import antlr.CharBuffer;
import antlr.CharStreamException;
import antlr.CharStreamIOException;
import antlr.InputBuffer;
import antlr.LexerSharedInputState;
import antlr.NoViableAltForCharException;
import antlr.RecognitionException;
import antlr.SemanticException;
import antlr.Token;
import antlr.TokenStream;
import antlr.TokenStreamException;
import antlr.TokenStreamIOException;
import antlr.TokenStreamRecognitionException;
import antlr.collections.impl.BitSet;
}class NesCLexer extends Lexer;
options {
k= 3;
importVocab= NesC;
testLiterals= false;
}
tokens {
LITERAL___extension__ = "__extension__";
}{
public void initialize(String src)
{
setOriginalSource(src);
initialize();
}
public void initialize()
{
literals.put(new ANTLRHashString("__alignof__", this), new Integer(LITERAL___alignof));
literals.put(new ANTLRHashString("__asm", this), new Integer(LITERAL_asm));
literals.put(new ANTLRHashString("__asm__", this), new Integer(LITERAL_asm));
literals.put(new ANTLRHashString("__attribute__", this), new Integer(LITERAL___attribute));
literals.put(new ANTLRHashString("__complex__", this), new Integer(LITERAL___complex));
literals.put(new ANTLRHashString("__const", this), new Integer(LITERAL_const));
literals.put(new ANTLRHashString("__const__", this), new Integer(LITERAL_const));
literals.put(new ANTLRHashString("__imag__", this), new Integer(LITERAL___imag));
literals.put(new ANTLRHashString("__inline", this), new Integer(LITERAL_inline));
literals.put(new ANTLRHashString("__inline__", this), new Integer(LITERAL_inline));
literals.put(new ANTLRHashString("__real__", this), new Integer(LITERAL___real));
literals.put(new ANTLRHashString("__signed", this), new Integer(LITERAL_signed));
literals.put(new ANTLRHashString("__signed__", this), new Integer(LITERAL_signed));
literals.put(new ANTLRHashString("__typeof", this), new Integer(LITERAL_typeof));
literals.put(new ANTLRHashString("__typeof__", this), new Integer(LITERAL_typeof));
literals.put(new ANTLRHashString("__volatile", this), new Integer(LITERAL_volatile));
literals.put(new ANTLRHashString("__volatile__", this), new Integer(LITERAL_volatile));
}
LineObject lineObject = new LineObject();
String originalSource = "";
PreprocessorInfoChannel preprocessorInfoChannel = new PreprocessorInfoChannel();
int tokenNumber = 0;
boolean countingTokens = true;
int deferredLineCount = 0;
public void setCountingTokens(boolean ct)
{
countingTokens = ct;
if ( countingTokens ) {
tokenNumber = 0;
}
else {
tokenNumber = 1;
}
}
public void setOriginalSource(String src)
{
originalSource = src;
lineObject.setSource(src);
}
public void setSource(String src)
{
lineObject.setSource(src);
}
public PreprocessorInfoChannel getPreprocessorInfoChannel()
{
return preprocessorInfoChannel;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -