org.extex.ocpware.compiler.arith
Class ArithExpr

java.lang.Object
  extended by org.extex.ocpware.compiler.arith.ArithExpr
Direct Known Subclasses:
BinaryOp, Char, Constant, LastChar, TableRef

public abstract class ArithExpr
extends java.lang.Object

This is the abstract base class for arithmetic expressions. It provides some methods for parsing and pretty-printing.

The arithmetic expression has the following syntax:

    ⟨arith expression⟩
      → ⟨n⟩
       | \⟨n⟩
       | \$
       | \($-⟨n⟩)
       | ⟨arith expression⟩ + ⟨arith expression⟩
       | ⟨arith expression⟩ - ⟨arith expression⟩
       | ⟨arith expression⟩ * ⟨arith expression⟩
       | ⟨arith expression⟩ div: ⟨arith expression⟩
       | ⟨arith expression⟩ mod: ⟨arith expression⟩
       | ⟨id⟩[⟨arith expression⟩]
       | (⟨arith expression⟩)  

Version:
$Revision:6007 $
Author:
Gerd Neugebauer

Constructor Summary
ArithExpr()
          Creates a new object.
 
Method Summary
 boolean needsParen()
          Return the indicator that parentheses are needed when printed in a wider arithmetic context.
static ArithExpr parse(ParserStream s)
          Parse an arithmetic expression.
static java.lang.String toString(ArithExpr x, java.lang.String op, ArithExpr y)
          Create a string representation for an binary operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArithExpr

public ArithExpr()
Creates a new object.

Method Detail

parse

public static ArithExpr parse(ParserStream s)
                       throws java.io.IOException,
                              SyntaxException
Parse an arithmetic expression.

Parameters:
s - the input stream
Returns:
the term found
Throws:
java.io.IOException - in case of an I/O error
SyntaxException - in case of a syntax error

toString

public static java.lang.String toString(ArithExpr x,
                                        java.lang.String op,
                                        ArithExpr y)
Create a string representation for an binary operation.

Parameters:
x - the first argument
op - the operator
y - the second argument
Returns:
the string representation

needsParen

public boolean needsParen()
Return the indicator that parentheses are needed when printed in a wider arithmetic context.

Returns:
the indicator