Package org.tweetyproject.lp.asp.parser
Class JJTASPParserState
java.lang.Object
org.tweetyproject.lp.asp.parser.JJTASPParserState
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
ConstructorDescriptionConstructs a newJJTASPParserState
object with an empty node stack and mark list. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.peekNode()
Returns the node currently on the top of the stack without removing it.popNode()
Returns the node on the top of the stack and removes it from the stack.void
Pushes a node onto the stack.void
reset()
Reinitializes the node stack and mark list.rootNode()
Returns the root node of the AST.
-
Constructor Details
-
JJTASPParserState
public JJTASPParserState()Constructs a newJJTASPParserState
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'sReInit()
method. -
rootNode
-
pushNode
-
popNode
-
peekNode
-
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
-
openNodeScope
-
closeNodeScope
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
- TheNode
representing the node scope being closed.num
- The number of children nodes to be added to the closed node.
-
closeNodeScope
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
- nodecondition
- condition
-