// $ANTLR 2.7.7 (2006-11-01): "CSharp.g" -> "CSharpParser.java"$
package jp.ac.osaka_u.ist.sel.metricstool.main.parse;
import antlr.CommonAST;
import jp.ac.osaka_u.ist.sel.metricstool.main.ast.csharp.CSharpASTNodeFactory;
import antlr.TokenBuffer;
import antlr.TokenStreamException;
import antlr.TokenStreamIOException;
import antlr.ANTLRException;
import antlr.LLkParser;
import antlr.Token;
import antlr.TokenStream;
import antlr.RecognitionException;
import antlr.NoViableAltException;
import antlr.MismatchedTokenException;
import antlr.SemanticException;
import antlr.ParserSharedInputState;
import antlr.collections.impl.BitSet;
import antlr.collections.AST;
import java.util.Hashtable;
import antlr.ASTFactory;
import antlr.ASTPair;
import antlr.collections.impl.ASTArray;
/** cSharp Recognizer
*
* Based heavily on the Grammer example that comes with ANTLR. See
* http://www.antlr.org.
*
* This grammar is in the PUBLIC DOMAIN
*/
public class CSharpParser extends antlr.LLkParser implements CSharpTokenTypes
{
private CSharpASTNodeFactory astNode;
public CSharpParser(final CSharpLexer lexer) {
this(lexer,2);
this.astNode = new CSharpASTNodeFactory(this.getASTFactory());
}
@Override
public void setASTFactory(ASTFactory f) {
super.setASTFactory(f);
this.astNode.setAstFactory(f);
}
protected CSharpParser(TokenBuffer tokenBuf, int k) {
super(tokenBuf,k);
tokenNames = _tokenNames;
buildTokenTypeASTClassMap();
astFactory = new ASTFactory(getTokenTypeToASTClassMap());
}
public CSharpParser(TokenBuffer tokenBuf) {
this(tokenBuf,2);
}
protected CSharpParser(TokenStream lexer, int k) {
super(lexer,k);
tokenNames = _tokenNames;
buildTokenTypeASTClassMap();
astFactory = new ASTFactory(getTokenTypeToASTClassMap());
}
public CSharpParser(TokenStream lexer) {
this(lexer,2);
}
public CSharpParser(ParserSharedInputState state) {
super(state,2);
tokenNames = _tokenNames;
buildTokenTypeASTClassMap();
astFactory = new ASTFactory(getTokenTypeToASTClassMap());
}
public final void compilationUnit() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
CommonAST compilationUnit_AST = null;
try { // for error handling
{
_loop3:
do {
if ((LA(1)==HASH) && (LA(2)==LITERAL_define)) {
symbolDefinition();
astFactory.addASTChild(currentAST, returnAST);
}
else {
break _loop3;
}
} while (true);
}
{
_loop5:
do {
if ((LA(1)==HASH) && (_tokenSet_0.member(LA(2)))) {
region();
}
else {
break _loop5;
}
} while (true);
}
{
_loop7:
do {
if ((LA(1)==LITERAL_using)) {
usingDefinition();
astFactory.addASTChild(currentAST, returnAST);
}
else {
break _loop7;
}
} while (true);
}
{
_loop9:
do {
if ((LA(1)==HASH) && (_tokenSet_0.member(LA(2)))) {
region();
}
else {
break _loop9;
}
} while (true);
}
{
_loop11:
do {
if ((LA(1)==HASH||LA(1)==LBRACK) && (_tokenSet_1.member(LA(2)))) {
customAttribute();
}
else {
break _loop11;
}
} while (true);
}
{
_loop13:
do {
if ((LA(1)==HASH) && (_tokenSet_0.member(LA(2)))) {
region();
}
else {
break _loop13;
}
} while (true);
}
{
_loop15:
do {
if ((LA(1)==LITERAL_namespace)) {
packageDefinition();
astFactory.addASTChild(currentAST, returnAST);
}
else if ((_tokenSet_2.member(LA(1))) && (_tokenSet_3.member(LA(2)))) {
typeDefinition();
astFactory.addASTChild(currentAST, returnAST);
}
else {
break _loop15;
}
} while (true);
}
{
_loop17:
do {
if ((LA(1)==HASH)) {
region();
}
else {
break _loop17;
}
} while (true);
}
match(Token.EOF_TYPE);
compilationUnit_AST = (CommonAST)currentAST.root;
}
catch (RecognitionException ex) {
if (inputState.guessing==0) {
reportError(ex);
recover(ex,_tokenSet_4);
} else {
throw ex;
}
}
returnAST = compilationUnit_AST;
}
public final void symbolDefinition() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
CommonAST symbolDefinition_AST = null;
try { // for error handling
match(HASH);
CommonAST tmp3_AST = null;
tmp3_AST = (CommonAST)astFactory.create(LT(1));
astFactory.makeASTRoot(currentAST, tmp3_AST);
match(LITERAL_define);
identifier();
astFactory.addASTChild(currentAST, returnAST);
symbolDefinition_AST = (CommonAST)currentAST.root;
}
catch (RecognitionException ex) {
if (inputState.guessing==0) {
reportError(ex);
recover(ex,_tokenSet_5);
} else {
throw ex;
}
}
returnAST = symbolDefinition_AST;
}
public final void region() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
CommonAST region_AST = null;
try { // for error handling
CommonAST tmp4_AST = null;
tmp4_AST = (CommonAST)astFactory.create(LT(1));
astFactory.addASTChild(currentAST, tmp4_AST);
match(HASH);
{
switch ( LA(1)) {
case IDENT:
{
CommonAST tmp5_AST = null;
tmp5_AST = (CommonAST)astFactory.create(LT(1));
astFactory.addASTChild(currentAST, tmp5_AST);
match(IDENT);
break;
}
case LITERAL_if:
{
{
CommonAST tmp6_AST = null;
tmp6_AST = (CommonAST)astFactory.create(LT(1));
astFactory.addASTChild(currentAST, tmp6_AST);
match(LITERAL_if);
CommonAST tmp7_AST = null;
tmp7_AST = (CommonAST)astFactory.create(LT(1));
astFactory.addASTChild(currentAST, tmp7_AST);
match(IDENT);
}
break;
}
case LITERAL_elif:
{
CommonAST tmp8_AST = null;
tmp8_AST = (CommonAST)astFactory.create(LT(1));
astFactory.addASTChild(currentAST, tmp8_AST);
match(LITERAL_elif);
break;
}
case LITERAL_else:
{
CommonAST tmp9_AST = null;
tmp9_AST = (CommonAST)astFactory.create(LT(1));
astFactory.addASTChild(currentAST, tmp9_AST);
match(LITERAL_else);
break;
}
case LITERAL_endif:
{
CommonAST tmp10_AST = null;
tmp10_AST = (CommonAST)astFactory.create(LT(1));
astFactory.addASTChild(currentAST, tmp10_AST);
match(LITERAL_endif);
break;
}
default:
{
throw new NoViableAltException(LT(1), getFilename());
}
}
}
region_AST = (CommonAST)currentAST.root;
}
catch (RecognitionException ex) {
if (inputState.guessing==0) {
reportError(ex);
recover(ex,_tokenSet_6);
} else {
throw ex;
}
}
returnAST = region_AST;
}
public final void usingDefinition() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
CommonAST usingDefinition_AST = null;
Token i = null;
CommonAST i_AST = null;
try { // for error handling
i = LT(1);
i_AST = (CommonAST)astFactory.create(i);
astFactory.makeASTRoot(currentAST, i_AST);
match(LITERAL_using);
{
if ((LA(1)==IDENT) && (LA(2)==ASSIGN)) {
CommonAST tmp11_AST = null;
tmp11_AST = (CommonAST)astFactory.create(LT(1));
astFactory.addASTChild(currentAST, tmp11_AST);
match(IDENT);
CommonAST tmp12_AST = null;
tmp12_AST = (CommonAST)astFactory.create(LT(1));
astFactory.addASTChild(currentAST, tmp12_AST);
match(ASSIGN);
}
else if ((LA(1)==IDENT) && (LA(2)==SEMI||LA(2)==DOT)) {
}
else {
throw new NoViableAltException(LT(1), getFilename());
}
}
if ( inputState.guessing==0 ) {
i_AST.setType(IMPORT);
}
identifierStar();
astFactory.addASTChild(currentAST, returnAST);
match(SEMI);
usingDefinition_AST = (CommonAST)currentAST.root;
}
catch (RecognitionException ex) {
if (inputState.guessing==0) {
reportError(ex);
recover(ex,_toke
评论0
最新资源