User: norbert
Date: 00/05/19 12:28:27
Modified: src/java/org/spyderMQ/selectors Identifier.java
Operator.java Selector.java
Added: src/java/org/spyderMQ/selectors parser.java parserval.java
Log:
Here we are... There's a parser for selctors.
Revision Changes Path
1.2 +19 -1 spyderMQ/src/java/org/spyderMQ/selectors/Identifier.java
Index: Identifier.java
===================================================================
RCS file:
/products/cvs/ejboss/spyderMQ/src/java/org/spyderMQ/selectors/Identifier.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Identifier.java 2000/05/17 23:43:10 1.1
+++ Identifier.java 2000/05/19 19:28:25 1.2
@@ -11,7 +11,7 @@
*
* @author Norbert Lataille ([EMAIL PROTECTED])
*
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class Identifier
{
@@ -23,4 +23,22 @@
this.name=name;
value=null;
}
+
+ public String toString()
+ {
+ return "Identifier@"+name;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof Identifier)
+ if (((Identifier)obj).name.equals(name)) return true;
+ return false;
+ }
+
+ public int hashCode()
+ {
+ return name.hashCode();
+ }
+
}
1.2 +57 -21 spyderMQ/src/java/org/spyderMQ/selectors/Operator.java
Index: Operator.java
===================================================================
RCS file:
/products/cvs/ejboss/spyderMQ/src/java/org/spyderMQ/selectors/Operator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Operator.java 2000/05/17 23:43:10 1.1
+++ Operator.java 2000/05/19 19:28:25 1.2
@@ -11,7 +11,7 @@
*
* @author Norbert Lataille ([EMAIL PROTECTED])
*
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class Operator
{
@@ -20,7 +20,6 @@
Object oper2;
public final static int EQUAL = 0;
- public final static int NOT = 1;
public final static int AND = 2;
public final static int OR = 3;
@@ -31,55 +30,65 @@
this.oper2=oper2;
}
- Object not() throws Exception
- {
- Object arg1=computeArgument(oper1);
- if (arg1 instanceof Boolean) {
- return new Boolean(!((Boolean)arg1).booleanValue());
- }
-
- throw new Exception("Bad object type");
- }
-
Object and() throws Exception
{
Object arg1=computeArgument(oper1);
- if (arg1 instanceof Boolean) {
- if (!(((Boolean)arg1).booleanValue())) return Boolean.FALSE;
+ if (arg1==null) {
+ Object arg2=computeArgument(oper2);
+ if (arg2==null) return null;
+ if (!(arg2 instanceof Boolean)) throw new Exception("AND: Bad
object type");
+ if (!((Boolean)arg2).booleanValue()) return Boolean.FALSE;
+ return null;
+ }
+
+ if (arg1 instanceof Boolean) {
+ if (!((Boolean)arg1).booleanValue()) return Boolean.FALSE;
Object arg2=computeArgument(oper2);
- if (!(arg2 instanceof Boolean)) throw new Exception("Bad
object type");
+ if (arg2==null) return null;
+ if (!(arg2 instanceof Boolean)) throw new Exception("AND: Bad
object type");
return arg2;
}
- throw new Exception("Bad object type");
+ throw new Exception("AND: Bad object type");
}
Object or() throws Exception
{
Object arg1=computeArgument(oper1);
+ if (arg1==null) {
+ Object arg2=computeArgument(oper2);
+ if (arg2==null) return null;
+ if (!(arg2 instanceof Boolean)) throw new Exception("OR: Bad
object type");
+ if (((Boolean)arg2).booleanValue()) return Boolean.TRUE;
+ return null;
+ }
+
if (arg1 instanceof Boolean) {
if (((Boolean)arg1).booleanValue()) return Boolean.TRUE;
Object arg2=computeArgument(oper2);
- if (!(arg2 instanceof Boolean)) throw new Exception("Bad
object type");
+ if (arg2==null) return null;
+ if (!(arg2 instanceof Boolean)) throw new Exception("OR: Bad
object type");
return arg2;
}
- throw new Exception("Bad object type");
+ throw new Exception("OR: Bad object type");
}
Object equal() throws Exception
{
Object arg1=computeArgument(oper1);
+ if (arg1==null) return Boolean.FALSE;
if (arg1 instanceof String) {
Object arg2=computeArgument(oper2);
- if (!(arg2 instanceof String)) throw new Exception("Bad object
type");
+ if (arg2==null) return Boolean.FALSE;
+ if (!(arg2 instanceof String)) throw new Exception("EQUAL:Bad
object type");
return new Boolean(arg1.equals(arg2));
}
- throw new Exception("Bad object type");
+ throw new Exception("EQUAL:Bad object type");
}
Object computeArgument(Object arg) throws Exception
@@ -98,11 +107,38 @@
case EQUAL: return equal();
case AND: return and();
case OR: return or();
- case NOT: return not();
}
throw new Exception("Unknown operation");
}
+ //--
+
+ public String toString()
+ {
+ return print("");
+ }
+
+ public String print(String level)
+ {
+ String st=level+(new Integer(operation)).toString()+"(\n";
+
+ String nextLevel=level+" ";
+
+ if (oper1==null) st+=nextLevel+"null\n";
+ else if (oper1 instanceof Operator) {
+ st += ((Operator)oper1).print(nextLevel);
+ } else st+=nextLevel+oper1.toString()+"\n";
+
+ if (oper2==null) st+=nextLevel+"null\n";
+ else if (oper2 instanceof Operator) {
+ st += ((Operator)oper2).print(nextLevel);
+ } else st+=nextLevel+oper2.toString()+"\n";
+
+ st+=level+")\n";
+
+ return st;
+ }
+
}
1.3 +20 -10 spyderMQ/src/java/org/spyderMQ/selectors/Selector.java
Index: Selector.java
===================================================================
RCS file:
/products/cvs/ejboss/spyderMQ/src/java/org/spyderMQ/selectors/Selector.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Selector.java 2000/05/18 02:10:06 1.2
+++ Selector.java 2000/05/19 19:28:26 1.3
@@ -9,7 +9,7 @@
import org.spydermq.Log;
import org.spydermq.SpyMessage;
import javax.jms.JMSException;
-import java.util.HashSet;
+import java.util.HashMap;
import java.util.Iterator;
/**
@@ -17,18 +17,29 @@
*
* @author Norbert Lataille ([EMAIL PROTECTED])
*
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class Selector
{
- public HashSet identifiers; // HashSet of Identifiers
+ public HashMap identifiers; // HashMap of Identifiers
public Object result;
- public Selector(HashSet identifiers, Object result)
+ public Selector(String sel)
{
- this.identifiers=identifiers;
- this.result=result;
+ parser bob=new parser();
+ identifiers=new HashMap();
+
+ try {
+ Log.log("PARSER: Start with \""+sel+"\"");
+ result=bob.parse(sel,identifiers);
+ } catch (Exception e) {
+ Log.error("Parsing failed");
+ Log.error(e);
+ return;
+ }
+
+ Log.log(result.toString());
}
public boolean test(SpyMessage mes)
@@ -36,7 +47,7 @@
try {
//Set the identifiers values
- Iterator i=identifiers.iterator();
+ Iterator i=identifiers.values().iterator();
while (i.hasNext())
{
@@ -61,10 +72,9 @@
res=((Operator)result).apply();
} else res=result;
- if (res==null) {
- throw new Exception("res==null");
- }
+ if (res==null) throw new Exception("res==null");
if (!(res instanceof Boolean)) throw new Exception("Bad object
type");
+
return ((Boolean)res).booleanValue();
} catch (Exception e) {
1.1 spyderMQ/src/java/org/spyderMQ/selectors/parser.java
Index: parser.java
===================================================================
//### This file created by BYACC 1.8(/Java extension 0.92)
//### Java capabilities added 7 Jan 97, Bob Jamison
//### Updated : 27 Nov 97 -- Bob Jamison, Joe Nieten
//### 01 Jan 98 -- Bob Jamison -- fixed generic semantic constructor
//### 01 Jun 99 -- Bob Jamison -- added Runnable support
//### Please send bug reports to [EMAIL PROTECTED]
//### static char yysccsid[] = "@(#)yaccpar 1.8 (Berkeley) 01/20/90";
//#line 2 "jms.y"
package org.spydermq.selectors;
import java.util.StringTokenizer;
import java.util.HashMap;
//#line 17 "parser.java"
//#####################################################################
// class: parser
// does : encapsulates yacc() parser functionality in a Java
// class for quick code development
//#####################################################################
public class parser
{
boolean yydebug; //do I want debug output?
int yynerrs; //number of errors so far
int yyerrflag; //was there an error?
int yychar; //the current working character
//########## MESSAGES ##########
//###############################################################
// method: debug
//###############################################################
void debug(String msg)
{
if (yydebug)
System.out.println(msg);
}
//########## STATE STACK ##########
final static int YYSTACKSIZE = 500; //maximum stack size
int statestk[],stateptr; //state stack
//###############################################################
// methods: state stack push,pop,drop,peek
//###############################################################
void state_push(int state)
{
if (stateptr>=YYSTACKSIZE) //overflowed?
return;
statestk[++stateptr]=state;
}
int state_pop()
{
if (stateptr<0) //underflowed?
return -1;
return statestk[stateptr--];
}
void state_drop(int cnt)
{
int ptr;
ptr=stateptr-cnt;
if (ptr<0)
return;
stateptr = ptr;
}
int state_peek(int relative)
{
int ptr;
ptr=stateptr-relative;
if (ptr<0)
return -1;
return statestk[ptr];
}
//###############################################################
// method: init_stacks : allocate and prepare stacks
//###############################################################
boolean init_stacks()
{
statestk = new int[YYSTACKSIZE];
stateptr = -1;
val_init();
return true;
}
//###############################################################
// method: dump_stacks : show n levels of the stacks
//###############################################################
void dump_stacks(int count)
{
int i;
System.out.println("=index==state====value= s:"+stateptr+" v:"+valptr);
for (i=0;i<count;i++)
System.out.println(" "+i+" "+statestk[i]+" "+valstk[i]);
System.out.println("======================");
}
//########## SEMANTIC VALUES ##########
//public class parsersemantic is defined in parserval.java
String yytext;//user variable to return contextual strings
parserval yyval; //used to return semantic vals from action routines
parserval yylval;//the 'lval' (result) I got from yylex()
parserval valstk[];
int valptr;
//###############################################################
// methods: value stack push,pop,drop,peek.
//###############################################################
void val_init()
{
valstk=new parserval[YYSTACKSIZE];
yyval=new parserval(0);
yylval=new parserval(0);
valptr=-1;
}
void val_push(parserval val)
{
if (valptr>=YYSTACKSIZE)
return;
valstk[++valptr]=val;
}
parserval val_pop()
{
if (valptr<0)
return new parserval(-1);
return valstk[valptr--];
}
void val_drop(int cnt)
{
int ptr;
ptr=valptr-cnt;
if (ptr<0)
return;
valptr = ptr;
}
parserval val_peek(int relative)
{
int ptr;
ptr=valptr-relative;
if (ptr<0)
return new parserval(-1);
return valstk[ptr];
}
//#### end semantic value section ####
public final static short IDENTIFIER=257;
public final static short OR=258;
public final static short AND=259;
public final static short EQUAL=260;
public final static short YYERRCODE=256;
final static short yylhs[] = { -1,
0, 2, 2, 1, 1, 1, 1,
};
final static short yylen[] = { 2,
2, 1, 3, 1, 3, 3, 3,
};
final static short yydefred[] = { 0,
2, 0, 0, 0, 4, 0, 0, 0, 0, 1,
3, 0, 0, 7,
};
final static short yydgoto[] = { 3,
4, 5,
};
final static short yysindex[] = { -33,
0, -33, 0, -32, 0, -41, -33, -33, -33, 0,
0, -258, -247, 0,
};
final static short yyrindex[] = { 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, -36, -38, 0,
};
final static short yygindex[] = { 0,
2, 0,
};
final static int YYTABLESIZE=228;
final static short yytable[] = { 11,
8, 9, 5, 6, 6, 5, 2, 6, 12, 13,
14, 10, 9, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 7, 8, 9, 5,
5, 6, 0, 1, 0, 7, 8, 9,
};
final static short yycheck[] = { 41,
259, 260, 41, 2, 41, 44, 40, 44, 7, 8,
9, 44, 260, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 258, 259, 260, 258,
259, 258, -1, 257, -1, 258, 259, 260,
};
final static short YYFINAL=3;
final static short YYMAXTOKEN=260;
final static String yyname[] = {
"end-of-file",null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,"'('","')'",null,null,"','",
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,"IDENTIFIER","OR","AND","EQUAL",
};
final static String yyrule[] = {
"$accept : total",
"total : comp ','",
"unary : IDENTIFIER",
"unary : '(' comp ')'",
"comp : unary",
"comp : comp AND comp",
"comp : comp OR comp",
"comp : comp EQUAL comp",
};
//#line 30 "jms.y"
public final static short STRING=257;//
public final static short DOUBLE=258;//
public final static short LONG=259;//
//public final static short IDENTIFIER=261;//
public final static short NULL=262; //
public final static short TRUE=263; //
public final static short FALSE=264; //
public final static short NOT=265; //
//public final static short AND=266; //
//public final static short OR=267; //
public final static short BETWEEN=268; //
public final static short LIKE=269; //
public final static short IN=270; //
public final static short IS=271; //
public final static short ESCAPE=272; //
//public final static short EQUAL=273;//
public final static short GT=274;//
public final static short GE=275;//
public final static short LT=276;//
public final static short LE=277;//
public final static short DIFFERENT=278;//
StringTokenizer st;
String nextToken=null;
Object selector;
HashMap map;
void yyerror(String s)
{
throw new RuntimeException("PARSER ERROR: "+s);
}
void next()
{
if (st.hasMoreTokens()) nextToken=st.nextToken();
else nextToken=null;
}
int yylex()
{
yylval=null;
String s = nextToken;
if (s==null) return 0;
next();
//Whitespace
while (s.equals(" ")) {
s=nextToken;
if (s==null) return 0;
next();
}
//String
if (s.equals("'")) {
String string="";
while ((nextToken!=null)&&(!nextToken.equals("'"))) {
string+=nextToken;
next();
}
if (nextToken==null) return -1;
next();
yylval=new parserval((Object)string);
return STRING;
}
//Is it an integer/double ?
if (Character.isDigit(s.charAt(0))) {
try {
yylval = new parserval(Long.valueOf(s));
return LONG;
} catch (NumberFormatException e) {
}
try {
yylval = new parserval(Double.valueOf(s));
return DOUBLE;
} catch (NumberFormatException e) {
return -1;
}
}
//CST group
if (s.equals("NULL")) return NULL;
if (s.equals("TRUE")) return TRUE;
if (s.equals("FALSE")) return FALSE;
//OPERATOR group
if (s.equals("NOT")) return NOT;
if (s.equals("AND")) return AND;
if (s.equals("OR")) return OR;
if (s.equals("BETWEEN")) return BETWEEN;
if (s.equals("LIKE")) return LIKE;
if (s.equals("IN")) return IN;
if (s.equals("IS")) return IS;
if (s.equals("ESCAPE")) return ESCAPE;
//BRACKET group
if (s.equals("(")) return '(';
if (s.equals(")")) return ')';
if (s.equals(",")) return ',';
//COMP group
if (s.equals("=")) return EQUAL;
if (s.equals(">")) {
if (nextToken!=null&&nextToken.equals("=")) { next(); return
GE; }
return GT;
}
if (s.equals("<")) {
if (nextToken!=null&&nextToken.equals(">")) { next(); return
DIFFERENT; }
if (nextToken!=null&&nextToken.equals("=")) { next(); return
LE; }
return LT;
}
//CALC group
if (s.equals("+")) return '+';
if (s.equals("-")) return '-';
if (s.equals("*")) return '*';
if (s.equals("/")) return '/';
//We should check if s is a _correct_ string
Identifier id=(Identifier)map.get(s);
if (id==null) {
id=new Identifier(s);
map.put(s,id);
}
yylval = new parserval(id);
return IDENTIFIER;
}
Object parse(String sel,HashMap map)
{
selector=null;
nextToken=null;
this.map=map;
sel+=",";
st = new StringTokenizer(sel," '(),=><+-*/",true);
next();
yyparse();
return selector;
}
//#line 361 "parser.java"
//###############################################################
// method: yylexdebug : check lexer state
//###############################################################
void yylexdebug(int state,int ch)
{
String s=null;
if (ch < 0) ch=0;
if (ch <= YYMAXTOKEN) //check index bounds
s = yyname[ch]; //now get it
if (s==null)
s = "illegal-symbol";
debug("state "+state+", reading "+ch+" ("+s+")");
}
//###############################################################
// method: yyparse : parse input and execute indicated items
//###############################################################
int yyparse()
{
int yyn; //next next thing to do
int yym; //
int yystate; //current parsing state from state table
String yys; //current token string
boolean doaction;
init_stacks();
yynerrs = 0;
yyerrflag = 0;
yychar = -1; //impossible char forces a read
yystate=0; //initial state
state_push(yystate); //save it
while (true) //until parsing is done, either correctly, or w/error
{
doaction=true;
if (yydebug) debug("loop");
//#### NEXT ACTION (from reduction table)
for (yyn=yydefred[yystate];yyn==0;yyn=yydefred[yystate])
{
if (yydebug) debug("yyn:"+yyn+" state:"+yystate+" char:"+yychar);
if (yychar < 0) //we want a char?
{
yychar = yylex(); //get next token
//#### ERROR CHECK ####
if (yychar < 0) //it it didn't work/error
{
yychar = 0; //change it to default string (no -1!)
if (yydebug)
yylexdebug(yystate,yychar);
}
}//yychar<0
yyn = yysindex[yystate]; //get amount to shift by (shift index)
if ((yyn != 0) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{
if (yydebug)
debug("state "+yystate+", shifting to state "+yytable[yyn]+"");
//#### NEXT STATE ####
yystate = yytable[yyn];//we are in a new state
state_push(yystate); //save it
val_push(yylval); //push our lval as the input for next rule
yychar = -1; //since we have 'eaten' a token, say we need another
if (yyerrflag > 0) //have we recovered an error?
--yyerrflag; //give ourselves credit
doaction=false; //but don't process yet
break; //quit the yyn=0 loop
}
yyn = yyrindex[yystate]; //reduce
if ((yyn !=0 ) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{ //we reduced!
if (yydebug) debug("reduce");
yyn = yytable[yyn];
doaction=true; //get ready to execute
break; //drop down to actions
}
else //ERROR RECOVERY
{
if (yyerrflag==0)
{
yyerror("syntax error");
yynerrs++;
}
if (yyerrflag < 3) //low error count?
{
yyerrflag = 3;
while (true) //do until break
{
if (stateptr<0) //check for under & overflow here
{
yyerror("stack underflow. aborting..."); //note lower case 's'
return 1;
}
yyn = yysindex[state_peek(0)];
if ((yyn != 0) && (yyn += YYERRCODE) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
{
if (yydebug)
debug("state "+state_peek(0)+", error recovery shifting to state
"+yytable[yyn]+" ");
yystate = yytable[yyn];
state_push(yystate);
val_push(yylval);
doaction=false;
break;
}
else
{
if (yydebug)
debug("error recovery discarding state "+state_peek(0)+" ");
if (stateptr<0) //check for under & overflow here
{
yyerror("Stack underflow. aborting..."); //capital 'S'
return 1;
}
state_pop();
val_pop();
}
}
}
else //discard this token
{
if (yychar == 0)
return 1; //yyabort
if (yydebug)
{
yys = null;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (yys == null) yys = "illegal-symbol";
debug("state "+yystate+", error recovery discards token "+yychar+"
("+yys+")");
}
yychar = -1; //read another
}
}//end error recovery
}//yyn=0 loop
if (!doaction) //any reason not to proceed?
continue; //skip action
yym = yylen[yyn]; //get count of terminals on rhs
if (yydebug)
debug("state "+yystate+", reducing "+yym+" by rule "+yyn+" ("+yyrule[yyn]+")");
if (yym>0) //if count of rhs not 'nil'
yyval = val_peek(yym-1); //get current semantic value
switch(yyn)
{
//########## USER-SUPPLIED ACTIONS ##########
case 1:
//#line 18 "jms.y"
{ selector = val_peek(1).obj; }
break;
case 2:
//#line 20 "jms.y"
{ yyval = val_peek(0); }
break;
case 3:
//#line 21 "jms.y"
{ yyval = val_peek(1); }
break;
case 5:
//#line 25 "jms.y"
{ yyval.obj = new Operator(Operator.AND,val_peek(2).obj,val_peek(0).obj); }
break;
case 6:
//#line 26 "jms.y"
{ yyval.obj = new Operator(Operator.OR,val_peek(2).obj,val_peek(0).obj); }
break;
case 7:
//#line 27 "jms.y"
{ yyval.obj = new Operator(Operator.EQUAL,val_peek(2).obj,val_peek(0).obj); }
break;
//#line 528 "parser.java"
//########## END OF USER-SUPPLIED ACTIONS ##########
}//switch
//#### Now let's reduce... ####
if (yydebug) debug("reduce");
state_drop(yym); //we just reduced yylen states
yystate = state_peek(0); //get new state
val_drop(yym); //corresponding value drop
yym = yylhs[yyn]; //select next TERMINAL(on lhs)
if (yystate == 0 && yym == 0)//done? 'rest' state and at first TERMINAL
{
debug("After reduction, shifting from state 0 to state "+YYFINAL+"");
yystate = YYFINAL; //explicitly say we're done
state_push(YYFINAL); //and save it
val_push(yyval); //also save the semantic value of parsing
if (yychar < 0) //we want another character?
{
yychar = yylex(); //get next character
if (yychar<0) yychar=0; //clean, if necessary
if (yydebug)
yylexdebug(yystate,yychar);
}
if (yychar == 0) //Good exit (if lex returns 0 ;-)
break; //quit the loop--all DONE
}//if yystate
else //else not done yet
{ //get next state and push, for next yydefred[]
yyn = yygindex[yym]; //find out where to go
if ((yyn != 0) && (yyn += yystate) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
yystate = yytable[yyn]; //get new state
else
yystate = yydgoto[yym]; //else go to new defred
debug("after reduction, shifting from state "+state_peek(0)+" to state
"+yystate+"");
state_push(yystate); //going again, so push state & val...
val_push(yyval); //for next action
}
}//main loop
return 0;//yyaccept!!
}
//## end of method parse() ######################################
}
//################### END OF CLASS yaccpar ######################
1.1 spyderMQ/src/java/org/spyderMQ/selectors/parserval.java
Index: parserval.java
===================================================================
//########## SEMANTIC VALUES ##########
public class parserval
{
public int ival;
public double dval;
public String sval;
public Object obj;
public parserval(int val)
{
ival=val;
}
public parserval(double val)
{
dval=val;
}
public parserval(String val)
{
sval=val;
}
public parserval(Object val)
{
obj=val;
}
}//end class