Class ParserCodeGenerator

java.lang.Object
org.javacc.csharp.ParserCodeGenerator
All Implemented Interfaces:
org.javacc.parser.ParserCodeGenerator

class ParserCodeGenerator extends Object implements org.javacc.parser.ParserCodeGenerator
Generate the parser.
  • Field Details

    • parserTemplate

      private static final String parserTemplate
      See Also:
    • phase2list

      private final List 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 List phase3list
    • phase3table

      private final Hashtable phase3table
    • maskIndex

      private int maskIndex
    • jj2Index

      private int jj2Index
    • lookaheadNeeded

      private boolean lookaheadNeeded
    • maskVals

      private List maskVals
    • gensymindex

      private int gensymindex
    • indentamt

      private int indentamt
    • jj2LA

      private boolean jj2LA
    • codeGenerator

      private org.javacc.utils.CodeBuilder.GenericCodeBuilder codeGenerator
    • cline

      private int cline
    • ccol

      private int ccol
    • context

      private final org.javacc.parser.Context context
    • internalNames

      private final Map<org.javacc.parser.Expansion,String> internalNames
    • internalIndexes

      private final Map<org.javacc.parser.Expansion,Integer> internalIndexes
    • parserData

      private org.javacc.parser.ParserData parserData
    • 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

      final int NOOPENSTM
      Constants used in the following method "buildLookaheadChecker".
      See Also:
    • OPENIF

      final int OPENIF
      See Also:
    • OPENSWITCH

      final int OPENSWITCH
      See Also:
    • switchIndex

      private int switchIndex
    • xsp_declared

      private boolean xsp_declared
    • jj3_expansion

      org.javacc.parser.Expansion jj3_expansion
    • generated

      Hashtable generated
  • Constructor Details

    • ParserCodeGenerator

      ParserCodeGenerator(org.javacc.parser.Context context)
  • Method Details

    • 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
    • GenerateCodeProduction

      private void GenerateCodeProduction(org.javacc.parser.CodeProduction production, org.javacc.parser.CodeGeneratorSettings settings, org.javacc.utils.CodeBuilder codeGenerator)
    • processProductions

      private void processProductions(org.javacc.parser.CodeGeneratorSettings settings, org.javacc.utils.CodeBuilder.GenericCodeBuilder codeGenerator)
    • internalName

      private String internalName(org.javacc.parser.Expansion e)
    • internalIndex

      private int internalIndex(org.javacc.parser.Expansion e)
    • 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.
    • dumpLookaheads

      private void dumpLookaheads(org.javacc.parser.Lookahead[] conds, String[] actions)
    • buildLookaheadChecker

      String buildLookaheadChecker(org.javacc.parser.Lookahead[] conds, 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

      void dumpFormattedString(String str)
    • buildPhase1Routine

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

      void phase1NewLine()
    • phase1ExpansionGen

      String phase1ExpansionGen(org.javacc.parser.Expansion e)
    • buildPhase2Routine

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

      String genReturn(boolean value)
    • generate3R

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

      void setupPhase3Builds(Phase3Data inf)
    • getTypeForToken

      private String getTypeForToken()
    • genjj_3Call

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

      void buildPhase3Routine(Phase3Data inf, boolean recursive_call)
    • minimumSize

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

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