Class Compiler

java.lang.Object
com.maroontress.intexpr.impl.Compiler

public final class Compiler extends Object
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 Details

    • toRpn

      public static List<Instruction> toRpn(Reader reader) throws IOException
      Creates a new list containing Instruction objects 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 Instruction objects.
      Throws:
      IOException - If an I/O error occurs with the reader.
      IllegalArgumentException - If the specified expression has syntax errors, unknown operators, illegal tokens, mismatched parentheses.