java.lang.Object
com.maroontress.intexpr.impl.Compiler
This class provides a tiny compiler that translates code written in the
little language into
Instructions that the Interpreter
class can execute.
The code is of integer expressions specified in infix notation. The
expression has some similarities in the syntax to the C programming
language, containing operators and operands. The operators specified in
OperatorSpec and parentheses are available in the expressions.
The numbers that the expression includes and represents are 32-bit signed
integers in two's-complement notation. The constants are non-negative
integers.
The compiled Instructions consist of Constants and
Operators in Reverse Polish notation to execute with the stack
machine.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic List<Instruction> Creates a new list containingInstructionobjects from the expression that the specified reader provides.
-
Method Details
-
toRpn
Creates a new list containingInstructionobjects from the expression that the specified reader provides.The list contains the operators and operands in Reverse Polish notation, so it does not include any parentheses.
- Parameters:
reader- The reader that provides the expression to evaluate.- Returns:
- The new list containing
Instructionobjects. - Throws:
IOException- If an I/O error occurs with thereader.IllegalArgumentException- If the specified expression has syntax errors, unknown operators, illegal tokens, mismatched parentheses.
-