예제 #1
0
  public WhileStatement(CommonTree MyTree, Model MyModel) {
    setLine(MyTree.getLine());
    this.MyModel = MyModel;

    Comparison = ExpressionFactory.getExpression((CommonTree) MyTree.getChild(0), MyModel);
    if (MyTree.getChildCount() > 1) {
      for (int i = 1; i < MyTree.getChildCount(); i++)
        Statements.add(StatementFactory.getStatement((CommonTree) MyTree.getChild(i), MyModel));
    }
  }
 public static Expression getExpression(CommonTree Child, Model MyModel) {
   Expression returnMe = null;
   int Type = Child.getType();
   if (Type == Constants.NOT
       || Type == Constants.CAST_EXPRESSION
       || Type == Constants.MINUS
       || Type == Constants.PLUS
       || Type == Constants.POWER_EXPRESSION
       || Type == Constants.TIMES
       || Type == Constants.MOD
       || Type == Constants.DIV
       || Type == Constants.AND
       || Type == Constants.OR
       || Type == Constants.NOT_EQUALS
       || Type == Constants.GTE
       || Type == Constants.LT
       || Type == Constants.GT
       || Type == Constants.EQUALS
       || Type == Constants.LTE
       || Type == Constants.INCREMENT
       || Type == Constants.DECREMENT) {
     if (Type != Constants.CAST_EXPRESSION)
       returnMe = (Expression) (new ArithmeticExpression(Child, MyModel, Type));
     else { // We must be attempting to cast move one step farther into tree.
       if (Child.getChildCount() > 0) {
         Type = ((CommonTree) Child.getChild(0)).getType();
         returnMe = (Expression) (new ArithmeticExpression(Child, MyModel, Type));
       }
     }
   } else if (Type == Constants.DOUBLE) {
     returnMe = new TypeFloat(new Float(Child.toString()));
   } else if (Type == Constants.STRING_LITERAL) {
     returnMe = new TypeString(Child.toString().substring(1, Child.toString().length() - 1));
   } else if (Type == Constants.INTEGER_LITERAL) {
     returnMe = new TypeInteger(new Integer(Child.toString()));
   } else if (Type == Constants.BOOLEAN_LITERAL) {
     returnMe = new TypeBoolean(new Boolean(Child.toString()));
   } else if (Type == Constants.IDENTIFIER) {
     returnMe = new TypeIdentifier(Child.toString());
   } else if (Type == Constants.ARRAY_IDENTIFIER) {
     returnMe = new TypeIdentifier(Child, MyModel);
   } else if (Type == Constants.ARRAY_DECLARE) {
     returnMe = new ArrayDeclareExpression(Child, MyModel);
   } else if (Type == Constants.PROCEDURE) {
     returnMe = new ProcedureExpression(Child, MyModel);
   }
   return (returnMe);
 }