以表达式识别为例,包括标识符、and、or,括号
例如:condi1=5 and condi6=6 and (condi7=7 or (condi8=8 and condi9=9))
//Expr.java
public abstract class Expr{
abstract void print();
}
//andExpr.java
public class andExpr extends Expr{
public andExpr(Expr l, Expr r){
lexpr = l;
rexpr = r;
}
public void print(){
lexpr.print();
System.out.print( " and ");
rexpr.print();
}
Expr lexpr;
Expr rexpr;
}
//assignExpr.java
public class assignExpr extends Expr{
public assignExpr(String name, Integer val){
id = name;
num= val;
}
public void print(){
System.out.print(id + " = " + num);
}
String id;
Integer num;
}
//orExpr.java
public class orExpr extends Expr{
public orExpr(Expr l,