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/syntaxParser/NumericScalarExpr.java | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/syntaxParser/NumericScalarExpr.java (limited to 'src/syntaxParser/NumericScalarExpr.java') diff --git a/src/syntaxParser/NumericScalarExpr.java b/src/syntaxParser/NumericScalarExpr.java new file mode 100644 index 0000000..049c3b9 --- /dev/null +++ b/src/syntaxParser/NumericScalarExpr.java @@ -0,0 +1,51 @@ +package syntaxParser; +/** + * NumericScalarExpr + * Creation date: (3/3/2003 2:28:43 AM) + * @author: mattia parigiani, Sorin Stancu-Mara + */ +class NumericScalarExpr implements IParseTreeNode { + NumericScalarExpr leftNumericScalarExpr, rightNumericScalarExpr; + String function; + String constValue; + + public NumericScalarExpr(String scalar){ + constValue = scalar; + function = "scalar"; + } + + + public NumericScalarExpr(String op, NumericScalarExpr expr) throws Exception{ + leftNumericScalarExpr = expr; + if (op.equals("+")) function = "scalarUnaryPlus"; + else if (op.equals("-")) function = "scalarUnaryMinus"; + else if (op.equals("abs")) function = "scalarAbs"; + else throw new Exception("Operator " + op + " is not recognized!"); + } + + public NumericScalarExpr(String op, NumericScalarExpr lbe, NumericScalarExpr rbe) throws Exception { + leftNumericScalarExpr = lbe ; + rightNumericScalarExpr = rbe ; + if (op.equals("+")) function = "scalarPlus"; + else if (op.equals("-")) function = "scalarMinus"; + else if (op.equals("*")) function = "scalarMult"; + else if (op.equals("/")) function = "scalarDiv"; + else throw new Exception("Operator " + op + " is not recognized!"); + } + + public String toXML() { + String result; + result = "<" + function + ">"; + if (function.equals("scalar")) { + result += constValue; + } else { + result += leftNumericScalarExpr.toXML(); + if (rightNumericScalarExpr != null) { + result += rightNumericScalarExpr.toXML(); + } + } + result += ""; + return result; + } + +} -- cgit