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/grammar/NumericScalarExpr.java | |
Initial commit
Diffstat (limited to 'src/grammar/NumericScalarExpr.java')
| -rw-r--r-- | src/grammar/NumericScalarExpr.java | 96 |
1 files changed, 96 insertions, 0 deletions
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 += "</" + function + ">"; + + return result; + } +} |
