Class JJTASPParserState

java.lang.Object
org.tweetyproject.lp.asp.parser.JJTASPParserState

public class JJTASPParserState extends Object
Manages the state of the abstract syntax tree (AST) during parsing in the ASP parser.

This class handles the stack of nodes being constructed as part of the parsing process, including operations such as pushing and popping nodes, managing marks that indicate different node scopes, and tracking whether nodes have been created.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new JJTASPParserState object with an empty node stack and mark list.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears the current node scope by popping all nodes from the stack that belong to the current scope.
    void
    closeNodeScope(Node n, boolean condition)
    A conditional node is constructed if its condition is true.
    void
    closeNodeScope(Node n, int num)
    Closes the current node scope and constructs a definite node from a specified number of children.
    int
    Returns the number of children on the stack in the current node scope.
    boolean
    Determines whether the current node was actually closed and pushed onto the stack.
    void
    Opens a new node scope by marking the current stack position.
    Returns the node currently on the top of the stack without removing it.
    Returns the node on the top of the stack and removes it from the stack.
    void
    Pushes a node onto the stack.
    void
    Reinitializes the node stack and mark list.
    Returns the root node of the AST.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JJTASPParserState

      public JJTASPParserState()
      Constructs a new JJTASPParserState object with an empty node stack and mark list.
  • Method Details

    • nodeCreated

      public boolean nodeCreated()
      Determines whether the current node was actually closed and pushed onto the stack.

      This method should only be called in the final user action of a node scope.

      Returns:
      true if the current node was closed and pushed, false otherwise.
    • reset

      public void reset()
      Reinitializes the node stack and mark list. This method is called automatically by the parser's ReInit() method.
    • rootNode

      public Node rootNode()
      Returns the root node of the AST. This method should only be called after a successful parse.
      Returns:
      The root Node of the AST.
    • pushNode

      public void pushNode(Node n)
      Pushes a node onto the stack.
      Parameters:
      n - The Node to be pushed onto the stack.
    • popNode

      public Node popNode()
      Returns the node on the top of the stack and removes it from the stack.
      Returns:
      The Node on the top of the stack.
    • peekNode

      public Node peekNode()
      Returns the node currently on the top of the stack without removing it.
      Returns:
      The Node currently on the top of the stack.
    • nodeArity

      public int nodeArity()
      Returns the number of children on the stack in the current node scope.
      Returns:
      The number of children on the stack in the current node scope.
    • clearNodeScope

      public void clearNodeScope(Node n)
      Clears the current node scope by popping all nodes from the stack that belong to the current scope.
      Parameters:
      n - The Node representing the current scope to be cleared.
    • openNodeScope

      public void openNodeScope(Node n)
      Opens a new node scope by marking the current stack position.
      Parameters:
      n - The Node representing the new scope being opened.
    • closeNodeScope

      public void closeNodeScope(Node n, int num)
      Closes the current node scope and constructs a definite node from a specified number of children.

      The specified number of nodes are popped from the stack and made the children of the definite node. The definite node is then pushed onto the stack.

      Parameters:
      n - The Node representing the node scope being closed.
      num - The number of children nodes to be added to the closed node.
    • closeNodeScope

      public void closeNodeScope(Node n, boolean condition)
      A conditional node is constructed if its condition is true. Allthe nodes that have been pushed since the node was opened are made children of the conditional node, which is then pushed on to the stack. If the condition is false the node is notconstructed and they are left on the stack
      Parameters:
      n - node
      condition - condition