Class ScopeTable

java.lang.Object
technology.sola.script.runtime.ScopeTable

@NullMarked public class ScopeTable extends Object
ScopeTable holds variable resolutions at various depths of scope.
  • Constructor Details

    • ScopeTable

      public ScopeTable()
  • Method Details

    • getDistance

      public @Nullable Integer getDistance(Expr expr)
      Gets the distance needed to resolve the correct value for the desired variable.
      Parameters:
      expr - the Expr to get the value for
      Returns:
      the distance to resolve the variable's value
    • beginScope

      public void beginScope()
      Begins a new scope for variables to be resolved.
    • endScope

      public void endScope()
      Ends the current scope for variables to be resolved.
    • resolveLocal

      public void resolveLocal(Expr expr, Token name)
      Resolves the nested depth of a local variable usage for an Expr.
      Parameters:
      expr - the expression to resolve the local variable usage for
      name - the Token for the name of the variable
    • declare

      public void declare(Token name)
      Marks a variable as declared for the current scope. A declared variable cannot be used to initialize itself.
      Parameters:
      name - the Token for the name of the variable
    • define

      public void define(Token name)
      Marks a variable is defined for the current scope.
      Parameters:
      name - the Token for the name of the variable
    • define

      public void define(String name)
      Marks a variable is defined for the current scope.
      Parameters:
      name - the name of the variable
    • isDeclaredInScope

      public boolean isDeclaredInScope(Token name)
      Checks if a variable has been declared in the current scope or not. Return false if there has been no scope started.
      Parameters:
      name - the Token for the name of the variable
      Returns:
      true if the variable has already been declared in the current scope
    • isDefinedInScope

      public boolean isDefinedInScope(Token name)
      Checks if a variable has been defined in the current scope or not. Return false if there has been no scope started.
      Parameters:
      name - the Token for the name of the variable
      Returns:
      true if the variable has already been defined in the current scope
    • isSelfReferenceVariableInitialization

      public boolean isSelfReferenceVariableInitialization(Expr.Variable expression)
      Utility method to check if a Expr.Variable expression is being used to initialize itself.
      Parameters:
      expression - the variable expression
      Returns:
      true if it is a self referencing variable initialization