import antlr.TokenBuffer;
import antlr.TokenStreamException;
import antlr.Token;
import antlr.TokenStream;
import antlr.RecognitionException;
import antlr.NoViableAltException;
import antlr.ParserSharedInputState;
import antlr.collections.impl.BitSet;
import antlr.collections.AST;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import antlr.ASTFactory;
import antlr.ASTPair;
import antlr.collections.impl.ASTArray;
//sql解析
public class SqlParser extends antlr.LLkParser implements SqlTokenTypes
{
protected SqlParser(TokenBuffer tokenBuf, int k) {
super(tokenBuf,k);
tokenNames = _tokenNames;
buildTokenTypeASTClassMap();
astFactory = new ASTFactory(getTokenTypeToASTClassMap());
}
public SqlParser(TokenBuffer tokenBuf) {
this(tokenBuf,4);
}
protected SqlParser(TokenStream lexer, int k) {
super(lexer,k);
tokenNames = _tokenNames;
buildTokenTypeASTClassMap();
astFactory = new ASTFactory(getTokenTypeToASTClassMap());
}
public SqlParser(TokenStream lexer) {
this(lexer,4);
columnNameSet = new LinkedHashSet<String>();
}
public SqlParser(ParserSharedInputState state) {
super(state,4);
tokenNames = _tokenNames;
buildTokenTypeASTClassMap();
astFactory = new ASTFactory(getTokenTypeToASTClassMap());
}
public final void start_rule() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST start_rule_AST = null;
try { // for error handling
{
_loop3:
do {
if ((_tokenSet_0.member(LA(1)))) {
sql_statement();
astFactory.addASTChild(currentAST, returnAST);
}
else {
break _loop3;
}
} while (true);
}
AST tmp1_AST = null;
tmp1_AST = astFactory.create(LT(1));
astFactory.addASTChild(currentAST, tmp1_AST);
match(Token.EOF_TYPE);
start_rule_AST = (AST)currentAST.root;
}
catch (RecognitionException ex) {
if (inputState.guessing==0) {
reportError(ex);
recover(ex,_tokenSet_1);
} else {
throw ex;
}
}
returnAST = start_rule_AST;
}
public final void sql_statement() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST sql_statement_AST = null;
try { // for error handling
sql_command();
astFactory.addASTChild(currentAST, returnAST);
{
switch ( LA(1)) {
case SEMI:
{
AST tmp2_AST = null;
tmp2_AST = astFactory.create(LT(1));
astFactory.addASTChild(currentAST, tmp2_AST);
match(SEMI);
break;
}
case EOF:
case OPEN_PAREN:
case LITERAL_select:
case LITERAL_update:
case LITERAL_delete:
{
break;
}
default:
{
throw new NoViableAltException(LT(1), getFilename());
}
}
}
if ( inputState.guessing==0 ) {
sql_statement_AST = (AST)currentAST.root;
sql_statement_AST = (AST)astFactory.make( (new ASTArray(2)).add(astFactory.create(SQL_STATEMENT,"sql_statement")).add(sql_statement_AST));
currentAST.root = sql_statement_AST;
currentAST.child = sql_statement_AST!=null &&sql_statement_AST.getFirstChild()!=null ?
sql_statement_AST.getFirstChild() : sql_statement_AST;
currentAST.advanceChildToEnd();
}
sql_statement_AST = (AST)currentAST.root;
}
catch (RecognitionException ex) {
if (inputState.guessing==0) {
reportError(ex);
recover(ex,_tokenSet_2);
} else {
throw ex;
}
}
returnAST = sql_statement_AST;
}
public final void sql_command() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST sql_command_AST = null;
try { // for error handling
to_modify_data();
astFactory.addASTChild(currentAST, returnAST);
sql_command_AST = (AST)currentAST.root;
}
catch (RecognitionException ex) {
if (inputState.guessing==0) {
reportError(ex);
recover(ex,_tokenSet_3);
} else {
throw ex;
}
}
returnAST = sql_command_AST;
}
public final void to_modify_data() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST to_modify_data_AST = null;
try { // for error handling
switch ( LA(1)) {
case OPEN_PAREN:
case LITERAL_select:
{
select_command();
astFactory.addASTChild(currentAST, returnAST);
to_modify_data_AST = (AST)currentAST.root;
break;
}
case LITERAL_update:
{
update_command();
astFactory.addASTChild(currentAST, returnAST);
to_modify_data_AST = (AST)currentAST.root;
break;
}
case LITERAL_delete:
{
delete_command();
astFactory.addASTChild(currentAST, returnAST);
to_modify_data_AST = (AST)currentAST.root;
break;
}
default:
{
throw new NoViableAltException(LT(1), getFilename());
}
}
}
catch (RecognitionException ex) {
if (inputState.guessing==0) {
reportError(ex);
recover(ex,_tokenSet_3);
} else {
throw ex;
}
}
returnAST = to_modify_data_AST;
}
public final void select_command() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST select_command_AST = null;
try { // for error handling
select_statement();
astFactory.addASTChild(currentAST, returnAST);
{
_loop10:
do {
if ((LA(1)==LITERAL_union) && (LA(2)==OPEN_PAREN||LA(2)==LITERAL_select) && (_tokenSet_4.member(LA(3))) && (_tokenSet_5.member(LA(4)))) {
AST tmp3_AST = null;
tmp3_AST = astFactory.create(LT(1));
astFactory.addASTChild(currentAST, tmp3_AST);
match(LITERAL_union);
select_statement();
astFactory.addASTChild(currentAST, returnAST);
}
else {
break _loop10;
}
} while (true);
}
select_command_AST = (AST)currentAST.root;
}
catch (RecognitionException ex) {
if (inputState.guessing==0) {
reportError(ex);
recover(ex,_tokenSet_6);
} else {
throw ex;
}
}
returnAST = select_command_AST;
}
public final void update_command() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST update_command_AST = null;
try { // for error handling
boolean synPredMatched212 = false;
if (((LA(1)==LITERAL_update) && (_tokenSet_7.member(LA(2))) && (_tokenSet_8.member(LA(3))) && (_tokenSet_9.member(LA(4))))) {
int _m212 = mark();
synPredMatched212 = true;
inputState.guessing++;
try {
{
subquery_update();
}
}
catch (RecognitionException pe) {
synPredMatched212 = false;
}
rewind(_m212);
inputState.guessing--;
}
if ( synPredMatched212 ) {
subquery_update();
astFactory.addASTChild(currentAST, returnAST);
update_command_AST = (AST)currentAST.root;
}
else if ((LA(1)==LITERAL_update) && (_tokenSet_7.member(LA(2))) && (_tokenSet_8.member(LA(3))) && (_tokenSet_10.member(LA(4)))) {
simple_update();
astFactory.addASTChild(currentAST, returnAST);
update_command_AST = (AST)currentAST.root;
}
else {
throw new NoViableAltException(LT(1), getFilename());
}
}
catch (RecognitionException ex) {
if (inputState.guessing==0) {
reportError(ex);
recover(ex,_tokenSet_3);
} else {
throw ex;
}
}
returnAST = update_command_AST;
}
public final void delete_command() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST delete_command_AST = null;
try { // for error handling
AST tmp4_AST = null;
tmp4_AST = as