Class AssemblyFirstFollow


  • public class AssemblyFirstFollow
    extends java.lang.Object
    A class to compute the first and follow of every non-terminal in a grammar See Alfred V. Aho, Monica S. Lam, Ravi Sethi, Jeffrey D. Ullman, Compilers: Principles, Techniques, & Tools. Bostom, MA: Pearson, 2007, pp. 220-2.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void computeFirsts()
      Compute the first set for each non-terminal
      protected void computeFollows()
      Compute the follow set for each non-terminal
      protected void computeNullable()
      Compute the nullable set
      java.util.Collection<AssemblyTerminal> getFirst​(AssemblyNonTerminal nt)
      Get the first set for a given non-terminal That is the set of all terminals, which through some derivation from the given non-terminal, can appear first in a sentential form.
      java.util.Collection<AssemblyTerminal> getFollow​(AssemblyNonTerminal nt)
      Get the follow set for a given non-terminal That is the set of all terminals, which through some derivation from the start symbol, can appear immediately after the given non-terminal in a sentential form.
      java.util.Collection<AssemblyNonTerminal> getNullable()
      Get the nullable set That is the set of all non-terminals, which through some derivation, can produce epsilon.
      void print​(java.io.PrintStream out)
      For debugging, print out the computed sets to the given stream
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AssemblyFirstFollow

        public AssemblyFirstFollow​(AbstractAssemblyGrammar<?,​?> grammar)
        Compute the first and follow sets for every non-terminal in the given grammar
        Parameters:
        grammar - the grammar
    • Method Detail

      • computeNullable

        protected void computeNullable()
        Compute the nullable set
      • computeFirsts

        protected void computeFirsts()
        Compute the first set for each non-terminal
      • computeFollows

        protected void computeFollows()
        Compute the follow set for each non-terminal
      • getNullable

        public java.util.Collection<AssemblyNonTerminal> getNullable()
        Get the nullable set That is the set of all non-terminals, which through some derivation, can produce epsilon.
        Returns:
        the set
      • getFirst

        public java.util.Collection<AssemblyTerminal> getFirst​(AssemblyNonTerminal nt)
        Get the first set for a given non-terminal That is the set of all terminals, which through some derivation from the given non-terminal, can appear first in a sentential form.
        Parameters:
        nt - the non-terminal
        Returns:
        the set
      • getFollow

        public java.util.Collection<AssemblyTerminal> getFollow​(AssemblyNonTerminal nt)
        Get the follow set for a given non-terminal That is the set of all terminals, which through some derivation from the start symbol, can appear immediately after the given non-terminal in a sentential form.
        Parameters:
        nt - the non-terminal
        Returns:
        the set
      • print

        public void print​(java.io.PrintStream out)
        For debugging, print out the computed sets to the given stream
        Parameters:
        out - the stream