Class AST

java.lang.Object
com.hypixel.hytale.server.npc.util.expression.compile.ast.AST
Direct Known Subclasses:
ASTOperand, ASTOperator

public abstract class AST extends Object
The AST (=Abstract Syntax Tree) is an intermediate form of the parsed expression suitable for high level optimisations and type checking. The AST represents a node in the expression tree and can have a variable amount of children as operands. Parser feeds the AST operators and operands in Reverse Polish Notation. Does simple optimisations like constant folding on direct child nodes.
  • Constructor Details

    • AST

      public AST(@Nonnull ValueType valueType, @Nonnull Token token, int tokenPosition)
  • Method Details

    • getParent

      public AST getParent()
    • setParent

      public void setParent(AST parent)
    • getValueType

      @Nonnull public ValueType getValueType()
    • getToken

      @Nonnull public Token getToken()
    • getTokenPosition

      public int getTokenPosition()
    • getCodeGen

      @Nullable public Function<Scope, ExecutionContext.Instruction> getCodeGen()
    • isConstant

      public abstract boolean isConstant()
    • asOperand

      public ExecutionContext.Operand asOperand()
    • getString

      public String getString()
    • getBoolean

      public boolean getBoolean()
    • getNumber

      public double getNumber()
    • returnType

      @Nonnull public ValueType returnType()
    • genCode

      public ValueType genCode(@Nonnull List<ExecutionContext.Instruction> list, Scope scope)
      Generate an instruction list from AST.

      If provided a scope as argument any references to function and variables are resolved to suppliers/functions from this scope, making the instructions only run with the same scope/context. This makes it possible to bind instructions to a specific object and eliminates the need to update the symbol table, as values can be read directly from the bound objects(s) using the suppliers.

      If the provided scope is null then variables and functions are looked up in the scope passed as argument when executing the instructions.

      Parameters:
      list - List to append instructions to
      scope - if not null does deep resolve of variables and functions
      Returns:
      Result type of expression