From 0f1055b8d7f97d86c66fa602c17666bc2ff9c437 Mon Sep 17 00:00:00 2001 From: Constantin Jucovschi Date: Tue, 31 Mar 2009 06:18:54 -0400 Subject: Initial commit --- src/grammar/NumericScalarExpr.java | 96 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/grammar/NumericScalarExpr.java (limited to 'src/grammar/NumericScalarExpr.java') diff --git a/src/grammar/NumericScalarExpr.java b/src/grammar/NumericScalarExpr.java new file mode 100644 index 0000000..2527f21 --- /dev/null +++ b/src/grammar/NumericScalarExpr.java @@ -0,0 +1,96 @@ +package grammar; + +/** + * NumericScalarExpr + * Creation date: (3/3/2003 2:28:43 AM) + * @author: mattia parigiani, Sorin Stancu-Mara, Andrei Aiordachioaie + */ +public class NumericScalarExpr implements IParseTreeNode +{ + String constValue; + String function; + NumericScalarExpr leftNumericScalarExpr, rightNumericScalarExpr; + CondenseExpr condense; + + public NumericScalarExpr(String val) + { + if (val.contains("+i")) + { + ComplexConst cc = new ComplexConst(val); + + constValue = cc.toXML(); + function = "complexConstant"; + } + else + { + constValue = val; + function = "numericConstant"; + } + } + + public NumericScalarExpr(String op, NumericScalarExpr expr) + { + leftNumericScalarExpr = expr; + + if (op.equals("-")) + function = "numericUnaryMinus"; + else + System.err.println("Unary Operator " + op + " is not recognized!"); + } + + public NumericScalarExpr(String op, NumericScalarExpr lbe, NumericScalarExpr rbe) + { + leftNumericScalarExpr = lbe; + rightNumericScalarExpr = rbe; + + if (op.equals("+")) + { + function = "numericAdd"; + } + else if (op.equals("-")) + { + function = "numericMinus"; + } + else if (op.equals("*")) + { + function = "numericMult"; + } + else if (op.equals("/")) + { + function = "numericDiv"; + } + else + { + System.err.println("Operator " + op + " is not recognized!"); + } + } + + public NumericScalarExpr(CondenseExpr c) + { + condense = c; + function = "condense"; + } + + public String toXML() + { + String result; + + if (function.equals("complexConstant")) + return constValue; + + result = "<" + function + ">"; + + if (function.equals("numericConstant")) + result += constValue; + else + { + result += leftNumericScalarExpr.toXML(); + if (rightNumericScalarExpr != null) + result += rightNumericScalarExpr.toXML(); + } + + result += ""; + + return result; + } +} -- cgit