diff options
| author | Constantin Jucovschi <cj@ubuntu.localdomain> | 2009-03-31 06:18:54 -0400 |
|---|---|---|
| committer | Constantin Jucovschi <cj@ubuntu.localdomain> | 2009-03-31 06:18:54 -0400 |
| commit | 0f1055b8d7f97d86c66fa602c17666bc2ff9c437 (patch) | |
| tree | 9c68fa99a97063bbe4a4231e04fc09329541ac71 /src/syntaxParser/NumericScalarExpr.java | |
Initial commit
Diffstat (limited to 'src/syntaxParser/NumericScalarExpr.java')
| -rw-r--r-- | src/syntaxParser/NumericScalarExpr.java | 51 |
1 files changed, 51 insertions, 0 deletions
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 += "</" + function + ">"; + return result; + } + +} |
