pmp.macro.math
Class Eval

java.lang.Object
  extended by pmp.AbstractMacro
      extended by pmp.macro.math.Eval

public class Eval
extends AbstractMacro

Evaluates given expression.

Recognized elements are integers and real numbers, operators +,-,*,/,% (modulo), ^ (power), = (compare for equality), > (compare - greater than), < (compare - less then) brackets (, ) and functions.

Functions are identified by ther name (case-insensitively) and arguments enclosed in brackets and separated by commas. See documentation of enum class Eval.Function for list of available functions.

Table of operator priorities:

^ highest priority - power
*, /, % multiplicative operators
+, - additive operators
=, >, < comparative operators

Whitespace characters are ignored.

Title: PMP: Macroprocessor

Description: Java macroprocessor

Copyright: Copyright (c) 2005

Version:
1.0
Author:
Luděk Hlaváček
To Do:
constants (pi, e, log e, ...) as zero param functions

Nested Class Summary
protected static class Eval.Function
          This enumerated type handles function calling.
 
Field Summary
protected static java.lang.String ID_FORMAT
           
protected static java.lang.String NUMBER_FORMAT_BIN
           
protected static java.lang.String NUMBER_FORMAT_FLOAT
           
protected static java.lang.String NUMBER_FORMAT_HEX
           
static int PARAMS_REQUIRED
           
 
Constructor Summary
Eval()
           
 
Method Summary
(package private)  java.lang.Number parse(java.lang.String arg)
          Parses string expresion.
 java.lang.String run(Macroprocessor mp, java.lang.String[] args)
          Main method of macro.
 
Methods inherited from class pmp.AbstractMacro
getRequiredParams, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PARAMS_REQUIRED

public static final int PARAMS_REQUIRED
See Also:
Constant Field Values

NUMBER_FORMAT_BIN

protected static final java.lang.String NUMBER_FORMAT_BIN
See Also:
Constant Field Values

NUMBER_FORMAT_HEX

protected static final java.lang.String NUMBER_FORMAT_HEX
See Also:
Constant Field Values

NUMBER_FORMAT_FLOAT

protected static final java.lang.String NUMBER_FORMAT_FLOAT
See Also:
Constant Field Values

ID_FORMAT

protected static final java.lang.String ID_FORMAT
See Also:
Constant Field Values
Constructor Detail

Eval

public Eval()
Method Detail

run

public java.lang.String run(Macroprocessor mp,
                            java.lang.String[] args)
Description copied from class: AbstractMacro
Main method of macro. This method is called when this macro is invoked. All subclasses must imlement this method

Specified by:
run in class AbstractMacro
Parameters:
mp - reference to Macroprocessor
args - parameters of macro. In args[0] is stored name of macro. Subclasses are free to modify this array.
Returns:
result of the macro as String

parse

java.lang.Number parse(java.lang.String arg)
                 throws java.lang.IllegalArgumentException
Parses string expresion.

This method is provided for other macros.

Returns:
result of evaluation
Throws:
java.lang.IllegalArgumentException