Class Preprocessor


  • public class Preprocessor
    extends java.lang.Object
    This class should be extended if new pragmas are desired. If the preprocessor encounters a pragma name which it doesn't recognize (anything other than ID, prefix, or version), it calls the method otherPragmas. This is the only method which need be overridden. The Preprocessor base class has a number of utility-like methods which can be used by the overridden otherPragmas method.
    • Field Detail

      • PragmaIDs

        private final java.util.Vector<SymtabEntry> PragmaIDs
      • pragmaHandlers

        private final java.util.Vector<PragmaHandler> pragmaHandlers
      • lastWasMacroID

        private boolean lastWasMacroID
      • parser

        private Parser parser
      • symbols

        private java.util.Hashtable<java.lang.String,​java.lang.String> symbols
      • macros

        private java.util.Vector<java.lang.String> macros
      • alreadyProcessedABranch

        private final java.util.Stack<java.lang.Boolean> alreadyProcessedABranch
      • indent

        private static java.lang.String indent
    • Constructor Detail

      • Preprocessor

        Preprocessor()
        Public zero-argument constructor.
    • Method Detail

      • init

        void init​(Parser p)
      • clone

        protected java.lang.Object clone()
        Overrides:
        clone in class java.lang.Object
      • ifDefine

        private void ifDefine​(boolean inParens,
                              boolean not)
                       throws java.io.IOException,
                              ParseException
        Throws:
        java.io.IOException
        ParseException
      • skipToEndiforElse

        private void skipToEndiforElse()
                                throws java.io.IOException,
                                       ParseException
        Throws:
        java.io.IOException
        ParseException
      • localServantPragma

        private void localServantPragma()
                                 throws java.io.IOException,
                                        ParseException
        Throws:
        java.io.IOException
        ParseException
      • otherPragmas

        private void otherPragmas​(java.lang.String pragmaType,
                                  java.lang.String currentToken)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • currentToken

        java.lang.String currentToken()
        Get the current token.
        Returns:
        the current token
      • getEntryForName

        SymtabEntry getEntryForName​(java.lang.String string)
        This method, given an entry name, returns the entry with that name. It can take fully or partially qualified names and returns the appropriate entry defined within the current scope. If no entry exists, null is returned.
        Parameters:
        string - entry name to look for
        Returns:
        entry with that name or null if no entry
      • getStringToEOL

        java.lang.String getStringToEOL()
                                 throws java.io.IOException
        This method returns a string of all of the characters from the input file from the current position up to, but not including, the end-of-line character(s).
        Returns:
        String from current position
        Throws:
        java.io.IOException
      • getUntil

        java.lang.String getUntil​(char c)
                           throws java.io.IOException
        This method returns a string of all of the characters from the input file from the current position up to, but not including, the given character. It encapsulates parenthesis and quoted strings, meaning it does not stop if the given character is found within parentheses or quotes. For instance, given the input of `start(inside)end', getUntil ('n') will return "start(inside)e"
        Parameters:
        c - token to read up to. The token itself will not be read.
        Throws:
        java.io.IOException
      • tokenToString

        private java.lang.String tokenToString()
      • nextToken

        java.lang.String nextToken()
                            throws java.io.IOException
        This method returns the next token String from the input file.
        Returns:
        the next token String
        Throws:
        java.io.IOException
      • scopedName

        SymtabEntry scopedName()
                        throws java.io.IOException
        This method assumes that the current token marks the beginning of a scoped name. It then parses the subsequent identifier and double colon tokens, builds the scoped name, and finds the symbol table entry with that name.
        Returns:
        a SymtabEntry of the name
        Throws:
        java.io.IOException
      • skipToEOL

        void skipToEOL()
                throws java.io.IOException
        Skip to the end of the line.
        Throws:
        java.io.IOException
      • skipUntil

        java.lang.String skipUntil​(char c)
                            throws java.io.IOException
        This method skips the data in the input file until the specified character is encountered, then it returns the next token.
        Parameters:
        c - token to indicate end of skipping
        Throws:
        java.io.IOException
      • parseException

        void parseException​(java.lang.String message)
        This method displays a Parser Exception complete with line number and position information with the given message string.
        Parameters:
        message - message to display as part of the Exception
        See Also:
        Throwable.getMessage()
      • expandMacro

        java.lang.String expandMacro​(java.lang.String macroDef,
                                     Token t)
                              throws java.io.IOException,
                                     ParseException
        Throws:
        java.io.IOException
        ParseException
      • getParmValues

        private java.util.Vector<java.lang.String> getParmValues()
                                                          throws java.io.IOException,
                                                                 ParseException
        Throws:
        java.io.IOException
        ParseException
      • macroParmValues

        private void macroParmValues​(java.util.Vector<java.lang.String> values)
                              throws java.io.IOException,
                                     ParseException
        Throws:
        java.io.IOException
        ParseException
      • macro

        private void macro​(java.util.Vector<java.lang.String> parmNames)
                    throws java.io.IOException,
                           ParseException
        Throws:
        java.io.IOException
        ParseException
      • macroParms

        private void macroParms​(java.util.Vector<java.lang.String> parmNames)
                         throws java.io.IOException,
                                ParseException
        Throws:
        java.io.IOException
        ParseException
      • macroParms2

        private void macroParms2​(java.util.Vector<java.lang.String> parmNames)
                          throws java.io.IOException,
                                 ParseException
        Throws:
        java.io.IOException
        ParseException
      • replaceAll

        private java.lang.String replaceAll​(java.lang.String string,
                                            java.lang.String from,
                                            java.lang.String to)
      • embedded

        private boolean embedded​(java.lang.String string,
                                 int index,
                                 int endIndex)
      • inQuotes

        private boolean inQuotes​(java.lang.String string,
                                 int index)
      • removeDoublePound

        private java.lang.String removeDoublePound​(java.lang.String string)
        Remove any occurrences of ##.
      • getFilename

        private java.lang.String getFilename​(java.lang.String name)
                                      throws java.io.FileNotFoundException
        Throws:
        java.io.FileNotFoundException
      • openScope

        void openScope​(SymtabEntry entry)
        This method is called when the parser encounters a left curly brace. An extender of PragmaHandler may find scope information useful. For example, the prefix pragma takes effect as soon as it is encountered and stays in effect until the current scope is closed. If a similar pragma extension is desired, then the openScope and closeScope methods are available for overriding.
        Parameters:
        entry - the symbol table entry whose scope has just been opened. Be aware that, since the scope has just been entered, this entry is incomplete at this point.
      • closeScope

        void closeScope​(SymtabEntry entry)
        This method is called when the parser encounters a right curly brace. An extender of PragmaHandler may find scope information useful. For example, the prefix pragma takes effect as soon as it is encountered and stays in effect until the current scope is closed. If a similar pragma extension is desired, then the openScope and closeScope methods are available for overriding.
        Parameters:
        entry - the symbol table entry whose scope has just been closed.