parser.java
来自「mysql集群」· Java 代码 · 共 1,787 行 · 第 1/4 页
JAVA
1,787 行
/* Generated By:JJTree&JavaCC: Do not edit this line. Parser.java */
package com.meidusa.amoeba.sqljep;
import java.math.BigDecimal;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import com.meidusa.amoeba.sqljep.function.*;
import com.meidusa.amoeba.sqljep.variable.*;
public abstract class Parser/*@bgen(jjtree)*/implements ParserTreeConstants, ParserConstants {/*@bgen(jjtree)*/
protected JJTParserState jjtree = new JJTParserState();
private final static String metachars = "tnrbf\\\"";
private final static String chars = "\t\n\r\b\f\\\"";
public Node parseStream(java.io.Reader stream)
throws ParseException {
ReInit(stream);
// Parse the expression, and return the
return Start().jjtGetChild(0);
}
public abstract PostfixCommandI getFunction(String name);
public abstract boolean containsKey(String key);
private List<String> errorList = new ArrayList<String>();
private Map<String,Integer> columnMapping;
private Map<String,Variable> variableMapping;
public List<String> getErrorList(){
return errorList;
}
public Variable getVariable(String iden){
if(variableMapping == null){
return null;
}else{
return variableMapping.get(iden);
}
}
public void setVariableMapping(Map<String,Variable> variableMapping){
this.variableMapping = variableMapping;
}
public void setColumnMapping(Map<String,Integer> columnMapping){
this.columnMapping = columnMapping;
}
public int findColumn(String name){
if (columnMapping != null) {
Integer v = columnMapping.get(name);
if (v != null) {
return v;
}
}
return -1;
}
private void addToErrorList(String errorStr) {
errorList.add(errorStr);
}
/**
* Translate all escape sequences to characters. Inspired by Rob Millar's
* unescape() method in rcm.util.Str fron the Web Sphinx project.
*
* @param inputStr String containing escape characters.
* @return String with all escape sequences replaced.
*/
private static String replaceEscape(String inputStr) {
int len = inputStr.length();
int p = 0;
int i;
StringBuilder output = new StringBuilder();
while ((i = inputStr.indexOf('\\', p)) != -1) {
output.append(inputStr.substring(p, i));
if (i+1 == len) break;
// find metacharacter
char metac = inputStr.charAt(i+1);
// find the index of the metac
int k = metachars.indexOf(metac);
if (k == -1) {
// didn't find the metachar, leave sequence as found.
// This code should be unreachable if the parser
// is functioning properly because strings containing
// unknown escape characters should not be accepted.
output.append('\\');
output.append(metac);
} else {
// its corresponding true char
output.append(chars.charAt(k));
}
// skip over both escape character & metacharacter
p = i + 2;
}
// add the end of the input string to the output
if (p < len)
output.append(inputStr.substring(p));
return output.toString();
}
/***************************************************************
GRAMMAR START
***************************************************************/
final public ASTStart Start() throws ParseException {
/*@bgen(jjtree) Start */
ASTStart jjtn000 = new ASTStart(JJTSTART);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
try {
if (jj_2_1(1)) {
Expression();
jj_consume_token(0);
jjtree.closeNodeScope(jjtn000, true);
jjtc000 = false;
{if (true) return jjtn000;}
} else {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case 0:
jj_consume_token(0);
jjtree.closeNodeScope(jjtn000, true);
jjtc000 = false;
{if (true) throw new ParseException("No expression entered");}
addToErrorList("No expression entered");
{if (true) return null;}
break;
default:
jj_la1[0] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
{if (true) throw (RuntimeException)jjte000;}
}
if (jjte000 instanceof ParseException) {
{if (true) throw (ParseException)jjte000;}
}
{if (true) throw (Error)jjte000;}
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
throw new Error("Missing return statement in function");
}
/****
Expression with boolean result
*/
final public void Expression() throws ParseException {
OrExpression();
}
final public void OrExpression() throws ParseException {
AndExpression();
label_1:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case OR:
;
break;
default:
jj_la1[1] = jj_gen;
break label_1;
}
ASTFunNode jjtn001 = new ASTFunNode(JJTFUNNODE);
boolean jjtc001 = true;
jjtree.openNodeScope(jjtn001);
try {
jj_consume_token(OR);
AndExpression();
jjtree.closeNodeScope(jjtn001, 2);
jjtc001 = false;
jjtn001.setFunction(tokenImage[OR], new LogicalOR());
} catch (Throwable jjte001) {
if (jjtc001) {
jjtree.clearNodeScope(jjtn001);
jjtc001 = false;
} else {
jjtree.popNode();
}
if (jjte001 instanceof RuntimeException) {
{if (true) throw (RuntimeException)jjte001;}
}
if (jjte001 instanceof ParseException) {
{if (true) throw (ParseException)jjte001;}
}
{if (true) throw (Error)jjte001;}
} finally {
if (jjtc001) {
jjtree.closeNodeScope(jjtn001, 2);
}
}
}
}
final public void AndExpression() throws ParseException {
EqualExpression();
label_2:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case AND:
;
break;
default:
jj_la1[2] = jj_gen;
break label_2;
}
ASTFunNode jjtn001 = new ASTFunNode(JJTFUNNODE);
boolean jjtc001 = true;
jjtree.openNodeScope(jjtn001);
try {
jj_consume_token(AND);
EqualExpression();
jjtree.closeNodeScope(jjtn001, 2);
jjtc001 = false;
jjtn001.setFunction(tokenImage[AND], new LogicalAND());
} catch (Throwable jjte001) {
if (jjtc001) {
jjtree.clearNodeScope(jjtn001);
jjtc001 = false;
} else {
jjtree.popNode();
}
if (jjte001 instanceof RuntimeException) {
{if (true) throw (RuntimeException)jjte001;}
}
if (jjte001 instanceof ParseException) {
{if (true) throw (ParseException)jjte001;}
}
{if (true) throw (Error)jjte001;}
} finally {
if (jjtc001) {
jjtree.closeNodeScope(jjtn001, 2);
}
}
}
}
final public void EqualExpression() throws ParseException {
RelationalExpression();
label_3:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case EQ:
case NE:
;
break;
default:
jj_la1[3] = jj_gen;
break label_3;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case NE:
ASTFunNode jjtn001 = new ASTFunNode(JJTFUNNODE);
boolean jjtc001 = true;
jjtree.openNodeScope(jjtn001);
try {
jj_consume_token(NE);
RelationalExpression();
jjtree.closeNodeScope(jjtn001, 2);
jjtc001 = false;
jjtn001.setFunction(tokenImage[NE], new ComparativeNE());
} catch (Throwable jjte001) {
if (jjtc001) {
jjtree.clearNodeScope(jjtn001);
jjtc001 = false;
} else {
jjtree.popNode();
}
if (jjte001 instanceof RuntimeException) {
{if (true) throw (RuntimeException)jjte001;}
}
if (jjte001 instanceof ParseException) {
{if (true) throw (ParseException)jjte001;}
}
{if (true) throw (Error)jjte001;}
} finally {
if (jjtc001) {
jjtree.closeNodeScope(jjtn001, 2);
}
}
break;
case EQ:
ASTFunNode jjtn002 = new ASTFunNode(JJTFUNNODE);
boolean jjtc002 = true;
jjtree.openNodeScope(jjtn002);
try {
jj_consume_token(EQ);
RelationalExpression();
jjtree.closeNodeScope(jjtn002, 2);
jjtc002 = false;
jjtn002.setFunction(tokenImage[EQ], new ComparativeEQ());
} catch (Throwable jjte002) {
if (jjtc002) {
jjtree.clearNodeScope(jjtn002);
jjtc002 = false;
} else {
jjtree.popNode();
}
if (jjte002 instanceof RuntimeException) {
{if (true) throw (RuntimeException)jjte002;}
}
if (jjte002 instanceof ParseException) {
{if (true) throw (ParseException)jjte002;}
}
{if (true) throw (Error)jjte002;}
} finally {
if (jjtc002) {
jjtree.closeNodeScope(jjtn002, 2);
}
}
break;
default:
jj_la1[4] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
}
final public void RelationalExpression() throws ParseException {
PostfixExpression();
label_4:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case GT:
case LT:
case LE:
case GE:
;
break;
default:
jj_la1[5] = jj_gen;
break label_4;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case LT:
ASTFunNode jjtn001 = new ASTFunNode(JJTFUNNODE);
boolean jjtc001 = true;
jjtree.openNodeScope(jjtn001);
try {
jj_consume_token(LT);
PostfixExpression();
jjtree.closeNodeScope(jjtn001, 2);
jjtc001 = false;
jjtn001.setFunction(tokenImage[LT], new ComparativeLT());
} catch (Throwable jjte001) {
if (jjtc001) {
jjtree.clearNodeScope(jjtn001);
jjtc001 = false;
} else {
jjtree.popNode();
}
if (jjte001 instanceof RuntimeException) {
{if (true) throw (RuntimeException)jjte001;}
}
if (jjte001 instanceof ParseException) {
{if (true) throw (ParseException)jjte001;}
}
{if (true) throw (Error)jjte001;}
} finally {
if (jjtc001) {
jjtree.closeNodeScope(jjtn001, 2);
}
}
break;
case GT:
ASTFunNode jjtn002 = new ASTFunNode(JJTFUNNODE);
boolean jjtc002 = true;
jjtree.openNodeScope(jjtn002);
try {
jj_consume_token(GT);
PostfixExpression();
jjtree.closeNodeScope(jjtn002, 2);
jjtc002 = false;
jjtn002.setFunction(tokenImage[GT], new ComparativeGT());
} catch (Throwable jjte002) {
if (jjtc002) {
jjtree.clearNodeScope(jjtn002);
jjtc002 = false;
} else {
jjtree.popNode();
}
if (jjte002 instanceof RuntimeException) {
{if (true) throw (RuntimeException)jjte002;}
}
if (jjte002 instanceof ParseException) {
{if (true) throw (ParseException)jjte002;}
}
{if (true) throw (Error)jjte002;}
} finally {
if (jjtc002) {
jjtree.closeNodeScope(jjtn002, 2);
}
}
break;
case LE:
ASTFunNode jjtn003 = new ASTFunNode(JJTFUNNODE);
boolean jjtc003 = true;
jjtree.openNodeScope(jjtn003);
try {
jj_consume_token(LE);
PostfixExpression();
jjtree.closeNodeScope(jjtn003, 2);
jjtc003 = false;
jjtn003.setFunction(tokenImage[LE], new ComparativeLE());
} catch (Throwable jjte003) {
if (jjtc003) {
jjtree.clearNodeScope(jjtn003);
jjtc003 = false;
} else {
jjtree.popNode();
}
if (jjte003 instanceof RuntimeException) {
{if (true) throw (RuntimeException)jjte003;}
}
if (jjte003 instanceof ParseException) {
{if (true) throw (ParseException)jjte003;}
}
{if (true) throw (Error)jjte003;}
} finally {
if (jjtc003) {
jjtree.closeNodeScope(jjtn003, 2);
}
}
break;
case GE:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?