Class ParseTree

java.lang.Object
ParseTree

public class ParseTree extends Object
Represents a parse tree node for YaLCC. It can be a leaf or an internal node with children. Each node has a label (Symbol) and a rule number.
  • Field Details

    • label

      private final Symbol label
      The label symbol for this node
    • children

      private final List<ParseTree> children
      The list of child nodes
    • ruleNumber

      private int ruleNumber
      The rule number used to create this node
  • Constructor Details

    • ParseTree

      public ParseTree(Symbol lbl)
      Creates a leaf node with a given symbol. This node has no children, and rule number is set to -1.
      Parameters:
      lbl - the symbol labeling this node
    • ParseTree

      public ParseTree(Symbol lbl, List<ParseTree> chdn, int ruleNum)
      Creates a node with a symbol, a list of children and a rule number.
      Parameters:
      lbl - the symbol labeling this node
      chdn - the list of child nodes
      ruleNum - the rule number used to create this node
  • Method Details

    • addChild

      public void addChild(ParseTree child)
      Adds a child node to this node.
      Parameters:
      child - the child node to add
    • getChildren

      public List<ParseTree> getChildren()
      Returns the list of child nodes
      Returns:
      the list of child nodes
    • getRuleNumber

      public int getRuleNumber()
      Returns the rule number
      Returns:
      the rule number
    • setRuleNumber

      public void setRuleNumber(int ruleNumber)
      Sets the rule number
      Parameters:
      ruleNumber - the rule number to set
    • getLabel

      public Symbol getLabel()
      Returns the label symbol
      Returns:
      the label symbol
    • toLaTexTree

      public String toLaTexTree()
      Writes the tree in LaTeX forest format.
      Returns:
      the tree in LaTeX forest format
    • toTikZ

      public String toTikZ()
      Writes the tree as TikZ code.
      Returns:
      the tree as TikZ code
    • toTikZPicture

      public String toTikZPicture()
      Writes the tree as a TikZ picture. TiKz picture can be used in LaTeX documents.
      Returns:
      the tree as a TikZ picture
    • toForestPicture

      public String toForestPicture()
      Writes the tree as a forest picture. Returns the tree in forest enviroment using the latex code of the tree
      Returns:
      the tree as a forest picture
    • toLaTeX

      public String toLaTeX()
      Writes the tree as a LaTeX document which can be compiled using PDFLaTeX.

      The result can be used with the command:
       pdflatex some-file.tex
       
      Returns:
      the tree as a LaTeX document