Class ParserCodeGenerator

  • All Implemented Interfaces:
    org.javacc.parser.ParserCodeGenerator

    class ParserCodeGenerator
    extends java.lang.Object
    implements org.javacc.parser.ParserCodeGenerator
    Generate the parser.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private CppCodeBuilder codeGenerator  
      private org.javacc.parser.Context context
      These lists are used to maintain expansions for which code generation in phase 2 and phase 3 is required.
      private boolean[] firstSet
      An array used to store the first sets generated by the following method.
      private int gensymindex  
      private int indentamt  
      private java.util.Map<org.javacc.parser.Expansion,​java.lang.Integer> internalIndexes  
      private java.util.Map<org.javacc.parser.Expansion,​java.lang.String> internalNames  
      private boolean jj2LA  
      private org.javacc.parser.Expansion jj3_expansion  
      private int NOOPENSTM
      Constants used in the following method "buildLookaheadChecker".
      private int OPENIF  
      private int OPENSWITCH  
      private java.util.List<org.javacc.parser.Lookahead> phase2list
      These lists are used to maintain expansions for which code generation in phase 2 and phase 3 is required.
      private java.util.List<Phase3Data> phase3list  
      private java.util.Hashtable<org.javacc.parser.Expansion,​Phase3Data> phase3table  
      private boolean xsp_declared  
    • Constructor Summary

      Constructors 
      Constructor Description
      ParserCodeGenerator​(org.javacc.parser.Context context)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.String addTokenNamespace​(java.lang.String token)  
      private void build​(CppCodeBuilder codeGenerator)  
      private java.lang.String buildLookaheadChecker​(org.javacc.parser.Lookahead[] conds, java.lang.String[] actions)
      This method takes two parameters - an array of Lookahead's "conds", and an array of String's "actions".
      private void buildPhase1Routine​(org.javacc.parser.BNFProduction p)  
      private void buildPhase2Routine​(org.javacc.parser.Lookahead la)  
      private void buildPhase3Routine​(Phase3Data inf, boolean recursive_call)  
      private void dumpFormattedString​(java.lang.String str)  
      void finish​(org.javacc.parser.CodeGeneratorSettings settings, org.javacc.parser.ParserData parserData)  
      private void generate3R​(org.javacc.parser.Expansion e, Phase3Data inf)  
      void generateCode​(org.javacc.parser.CodeGeneratorSettings settings, org.javacc.parser.ParserData parserData)  
      private java.lang.String generateCPPMethodheader​(org.javacc.parser.BNFProduction p, org.javacc.parser.Token t)  
      private void genFirstSet​(org.javacc.parser.Expansion exp)
      Sets up the array "firstSet" above based on the Expansion argument passed to it.
      private java.lang.String genjj_3Call​(org.javacc.parser.Expansion e)  
      private java.lang.String genReturn​(boolean value)  
      private void genStackCheck​(boolean voidReturn)  
      private static java.lang.String getTokenImages()  
      private static java.lang.String getTokenLabels()  
      private java.lang.String getTokenType()  
      private java.lang.String getTokenTypePointer()  
      private boolean javaCodeCheck​(org.javacc.parser.Expansion exp)
      Returns true if there is a JAVACODE production that the argument expansion may directly expand to (without consuming tokens or encountering lookahead).
      private int minimumSize​(org.javacc.parser.Expansion e)  
      private int minimumSize​(org.javacc.parser.Expansion e, int oldMin)  
      private java.lang.String phase1ExpansionGen​(org.javacc.parser.Expansion e)  
      private void phase1NewLine()  
      (package private) void printInclude​(java.lang.String include)  
      private void setupPhase3Builds​(Phase3Data inf)  
      • Methods inherited from class java.lang.Object

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

      • context

        private final org.javacc.parser.Context context
        These lists are used to maintain expansions for which code generation in phase 2 and phase 3 is required. Whenever a call is generated to a phase 2 or phase 3 routine, a corresponding entry is added here if it has not already been added. The phase 3 routines have been optimized in version 0.7pre2. Essentially only those methods (and only those portions of these methods) are generated that are required. The lookahead amount is used to determine this. This change requires the use of a hash table because it is now possible for the same phase 3 routine to be requested multiple times with different lookaheads. The hash table provides a easily searchable capability to determine the previous requests. The phase 3 routines now are performed in a two step process - the first step gathers the requests (replacing requests with lower lookaheads with those requiring larger lookaheads). The second step then generates these methods. This optimization and the hashtable makes it look like we do not need the flag "phase3done" any more. But this has not been removed yet.
      • internalNames

        private final java.util.Map<org.javacc.parser.Expansion,​java.lang.String> internalNames
      • internalIndexes

        private final java.util.Map<org.javacc.parser.Expansion,​java.lang.Integer> internalIndexes
      • gensymindex

        private int gensymindex
      • indentamt

        private int indentamt
      • jj2LA

        private boolean jj2LA
      • phase2list

        private final java.util.List<org.javacc.parser.Lookahead> phase2list
        These lists are used to maintain expansions for which code generation in phase 2 and phase 3 is required. Whenever a call is generated to a phase 2 or phase 3 routine, a corresponding entry is added here if it has not already been added. The phase 3 routines have been optimized in version 0.7pre2. Essentially only those methods (and only those portions of these methods) are generated that are required. The lookahead amount is used to determine this. This change requires the use of a hash table because it is now possible for the same phase 3 routine to be requested multiple times with different lookaheads. The hash table provides a easily searchable capability to determine the previous requests. The phase 3 routines now are performed in a two step process - the first step gathers the requests (replacing requests with lower lookaheads with those requiring larger lookaheads). The second step then generates these methods. This optimization and the hashtable makes it look like we do not need the flag "phase3done" any more. But this has not been removed yet.
      • phase3list

        private final java.util.List<Phase3Data> phase3list
      • phase3table

        private final java.util.Hashtable<org.javacc.parser.Expansion,​Phase3Data> phase3table
      • firstSet

        private boolean[] firstSet
        An array used to store the first sets generated by the following method. A true entry means that the corresponding token is in the first set.
      • NOOPENSTM

        private final int NOOPENSTM
        Constants used in the following method "buildLookaheadChecker".
        See Also:
        Constant Field Values
      • xsp_declared

        private boolean xsp_declared
      • jj3_expansion

        private org.javacc.parser.Expansion jj3_expansion
    • Constructor Detail

      • ParserCodeGenerator

        ParserCodeGenerator​(org.javacc.parser.Context context)
    • Method Detail

      • printInclude

        void printInclude​(java.lang.String include)
      • generateCode

        public void generateCode​(org.javacc.parser.CodeGeneratorSettings settings,
                                 org.javacc.parser.ParserData parserData)
        Specified by:
        generateCode in interface org.javacc.parser.ParserCodeGenerator
      • finish

        public void finish​(org.javacc.parser.CodeGeneratorSettings settings,
                           org.javacc.parser.ParserData parserData)
        Specified by:
        finish in interface org.javacc.parser.ParserCodeGenerator
      • javaCodeCheck

        private boolean javaCodeCheck​(org.javacc.parser.Expansion exp)
        Returns true if there is a JAVACODE production that the argument expansion may directly expand to (without consuming tokens or encountering lookahead).
      • genFirstSet

        private void genFirstSet​(org.javacc.parser.Expansion exp)
        Sets up the array "firstSet" above based on the Expansion argument passed to it. Since this is a recursive function, it assumes that "firstSet" has been reset before the first call.
      • buildLookaheadChecker

        private java.lang.String buildLookaheadChecker​(org.javacc.parser.Lookahead[] conds,
                                                       java.lang.String[] actions)
        This method takes two parameters - an array of Lookahead's "conds", and an array of String's "actions". "actions" contains exactly one element more than "conds". "actions" are Java source code, and "conds" translate to conditions - so lets say "f(conds[i])" is true if the lookahead required by "conds[i]" is indeed the case. This method returns a string corresponding to the Java code for: if (f(conds[0]) actions[0] else if (f(conds[1]) actions[1] . . . else actions[action.length-1] A particular action entry ("actions[i]") can be null, in which case, a noop is generated for that action.
      • dumpFormattedString

        private void dumpFormattedString​(java.lang.String str)
      • generateCPPMethodheader

        private java.lang.String generateCPPMethodheader​(org.javacc.parser.BNFProduction p,
                                                         org.javacc.parser.Token t)
      • genStackCheck

        private void genStackCheck​(boolean voidReturn)
      • buildPhase1Routine

        private void buildPhase1Routine​(org.javacc.parser.BNFProduction p)
      • phase1NewLine

        private void phase1NewLine()
      • phase1ExpansionGen

        private java.lang.String phase1ExpansionGen​(org.javacc.parser.Expansion e)
      • buildPhase2Routine

        private void buildPhase2Routine​(org.javacc.parser.Lookahead la)
      • genReturn

        private java.lang.String genReturn​(boolean value)
      • getTokenImages

        private static java.lang.String getTokenImages()
      • getTokenLabels

        private static java.lang.String getTokenLabels()
      • generate3R

        private void generate3R​(org.javacc.parser.Expansion e,
                                Phase3Data inf)
      • setupPhase3Builds

        private void setupPhase3Builds​(Phase3Data inf)
      • addTokenNamespace

        private static java.lang.String addTokenNamespace​(java.lang.String token)
      • getTokenType

        private java.lang.String getTokenType()
      • getTokenTypePointer

        private java.lang.String getTokenTypePointer()
      • genjj_3Call

        private java.lang.String genjj_3Call​(org.javacc.parser.Expansion e)
      • buildPhase3Routine

        private void buildPhase3Routine​(Phase3Data inf,
                                        boolean recursive_call)
      • minimumSize

        private int minimumSize​(org.javacc.parser.Expansion e)
      • minimumSize

        private int minimumSize​(org.javacc.parser.Expansion e,
                                int oldMin)