EDU.bmrb.starlibj
Class StarParser

java.lang.Object
  |
  +--EDU.bmrb.starlibj.StarParser
All Implemented Interfaces:
StarParserConstants

public class StarParser
extends java.lang.Object
implements StarParserConstants

This is the class that is used to parse a Star File. This class was generated by the javacc tool from Sun. To parse an input file or stream, do these steps:

  1. Make a new instance of this class, giving the constructor a reference to the stream you wish to parse.

  2. Call the StarFileNodeParse() method to parse in a complete Star File.

  3. Call that object's endResult() method to see the final result of the parse (a StarFileNode).

Here is an example code fragment implementing the above steps:

     StarParser   aParser;
     StarFileNode aStarTree;
     String       fileName = "sample.str";
 
     try
     {
         aParser = new StarParser(
                          new java.io.FileInputStream(fileName) );

         aParser.StarFileNodeParse( aParser );
                       // 'aParser' needs to be sent as a
                       // parameter because javacc makes
                       // static methods that have no 'this'.

         aStarTree = aParser.endResult();
     }
     // (catch() clauses left off to keep the example brief.)
 

Note that is is possible to parse in a smaller subset of the STAR syntax if you are reading from a source that you know is not a complete STAR file. For example, you might want to parse a file that contains only a single SaveFrameNode that was cut from a larger file. To do this, use the appropriate ...Parse() method that goes with the name of the node you are trying to parse. To parse a save frame, use SaveFrameNodeParse(). To parse a loop, use DataLoopNodeParse(), and so on. Regardless of which Parse() method you call, the result is always found by called endResult(). (Which is essentially showing what is at the top of the parse stack after parsing completed.)

To parse multiple files, You must call StarParser.ReInit() between parses, even if you make a new StarParser object. This is because the input stream in StarParse is handled using internal static variables.

StarParser is not thread safe. You should only run one StarParser at a time. Again, this is because of the shared static data in the class. (This is fixable, but only if we create our own handmade stream-like class that implements the interface javacc wants to see and then use that instead of one of the standard java stream classes. When we try to tell javacc to make a non-static parser, it refuses to run on java.io.* stream classes.)


Field Summary
static char doubleMarker
          marks the value as double-quote delimited
static char fieldDelim
          notes the start of a value's column num
static char framecodeMarker
          marks the value as framecode delimited
static Token jj_nt
           
static char lineDelim
          notes the start of a line num
static char nonMarker
          marks the value as non delimited
static int prevLine
           
static char semicolonMarker
          marks the value as semicolon delimited
static char singleMarker
          marks the value as single-quote delimited
static java.lang.String symbolBlockNode
           
static java.lang.String symbolDataItemNode
           
static java.lang.String symbolDataLoopNameListNode
           
static java.lang.String symbolDataNameNode
           
static java.lang.String symbolDataValueNode
           
static java.lang.String symbolHomemadeStringBuffer
           
static java.lang.String symbolLoopTableNode
           
static java.lang.String symbolSaveFrameNode
           
static java.lang.String symbolTinyAbsTypeName
           
static Token token
           
static StarParserTokenManager token_source
           
 
Fields inherited from interface EDU.bmrb.starlibj.StarParserConstants
DATASTART, DEFAULT, DQUOTE, DVNDOUBLE, DVNFRAMECODE, DVNNON, DVNSEMICOLON, DVNSINGLE, EOF, EOLN_PRIV, GLOBALSTART, LINENOSTARTINGSEMI, LOOPSTART, NONBLANK, NONDQUOTE, NONEOLN, NONSQUOTE, NONUNDERSCOREBLANK, SAVEEND, SAVESTART, SQUOTE, STOP, TAGNAME, tokenImage
 
Constructor Summary
StarParser(java.io.InputStream stream)
           
StarParser(java.io.Reader stream)
           
StarParser(StarParserTokenManager tm)
           
 
Method Summary
static void BlockNodeParse(StarParser p)
          This method will parse a single BlockNode (a global_ or data_ block.) You can get to it by calling endResult() after it finishes.
static void DataItemNodeParse(StarParser p)
          This method will parse a single DataItemNode.
static void DataLoopNameListNodeParse(StarParser p)
           
static void DataLoopNodeParse(StarParser p)
          This method will parse a single DataLoopNode.
static void DataNameNodeParse(StarParser p)
          This method will parse a single DataNameNode (a tag).
static void DataNodeParse(StarParser p)
          This method will parse either a single DataItemNode, or a single DataLoopNode, or a single SaveFrameNode.
static void DataValueNodeParse(StarParser p)
          This method will parse a single DataValueNode.
static void disable_tracing()
           
static void enable_tracing()
           
 StarNode endResult()
          This method is depreciated and just is a call to popResult().
static void EpsilonParse()
           
static ParseException generateParseException()
           
static Token getNextToken()
           
 int getNumValsInCurLoopAtLevel(int nest)
          Get the number of values that should be in one row for the nesting level given for the most recently parsed DataLoopNameListNode.
static Token getToken(int index)
           
static void LoopNameListNodeParse(StarParser p)
           
static void LoopRowNodeParse(StarParser p, LoopTableNode tbl, int nest)
          This method parses a single row of values, presuming that the DataLoopNameListNode has already been parsed and is on the stack underneath the current position.
static void LoopTableNodeParse(StarParser p, int nest)
          This method parses a table of values, presuming that the DataLoopNameListNode has already been properly parsed to hold the numbers of values in each nesting level.
static void LoopValuesParse(StarParser p)
           
static void OptionalStopParse(StarParser p)
           
 StarNode popResult()
          Get the StarNode object that was created by the parse.
static void ReInit(java.io.InputStream stream)
           
static void ReInit(java.io.Reader stream)
           
 void ReInit(StarParserTokenManager tm)
           
static void SaveDataNodeParse(StarParser p)
          This method will parse one of the items that is allowed inside a SaveFrameNode.
static void SaveFrameNodeParse(StarParser p)
          This method will parse a single SaveFrameNode.
 void setVerbose(int verboseNum)
          Call this method before parsing to turn on some debugging printing.
static void StarFileNodeParse(StarParser p)
          This method will parse an entire star file.
static void StopParse(StarParser p)
           
static void TinyAbsDataValueNodeParse(StarParser p)
          This method will parse a single TinyAbsDataValueNode.
 void trimToSize()
          Trim the stack after a big deletion.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

prevLine

public static int prevLine

symbolTinyAbsTypeName

public static java.lang.String symbolTinyAbsTypeName

symbolDataValueNode

public static java.lang.String symbolDataValueNode

symbolDataNameNode

public static java.lang.String symbolDataNameNode

symbolDataItemNode

public static java.lang.String symbolDataItemNode

symbolBlockNode

public static java.lang.String symbolBlockNode

symbolSaveFrameNode

public static java.lang.String symbolSaveFrameNode

symbolHomemadeStringBuffer

public static java.lang.String symbolHomemadeStringBuffer

symbolLoopTableNode

public static java.lang.String symbolLoopTableNode

symbolDataLoopNameListNode

public static java.lang.String symbolDataLoopNameListNode

lineDelim

public static char lineDelim
notes the start of a line num

fieldDelim

public static char fieldDelim
notes the start of a value's column num

singleMarker

public static char singleMarker
marks the value as single-quote delimited

doubleMarker

public static char doubleMarker
marks the value as double-quote delimited

semicolonMarker

public static char semicolonMarker
marks the value as semicolon delimited

framecodeMarker

public static char framecodeMarker
marks the value as framecode delimited

nonMarker

public static char nonMarker
marks the value as non delimited

token_source

public static StarParserTokenManager token_source

token

public static Token token

jj_nt

public static Token jj_nt
Constructor Detail

StarParser

public StarParser(java.io.InputStream stream)

StarParser

public StarParser(java.io.Reader stream)

StarParser

public StarParser(StarParserTokenManager tm)
Method Detail

popResult

public StarNode popResult()
Get the StarNode object that was created by the parse. When the parse is complete, if no exceptions were thrown, then this method will return the object that was parsed. The object parsed is the last thing left on the stack. This method will also pop the object off the stack, so only the first call to this method after a parse will work properly. This was necessary to accomodate the Java garbage collector (Otherwise the reference to the item on the top of the stack would live forever and therefore the thing that was parsed (typically a StarFileNode) and all its children would remain in memory forever.)

endResult

public StarNode endResult()
This method is depreciated and just is a call to popResult(). Please use popResult() instead in future coding projects.

setVerbose

public void setVerbose(int verboseNum)
Call this method before parsing to turn on some debugging printing. Mostly this is for internal debugging.
Parameters:
verboseNum - = set to higher numbers for more info, (0 = silent) (Default is false when a StarParser is constructed.)

trimToSize

public void trimToSize()
Trim the stack after a big deletion. Normally there is a lot of overhead in a Vector and it doesn't go away when the elements are removed. The capacity remains large long after the elements are no longer in use. This enforces the throwing away of the deleted elements: Do not call this method while the stack is still expected to grow bigger or it will make things execute very slowly. (This method removes all overhead room from the stack so that on the next insertion it will have to reallocate space again.) For best results, this method is only called when a large deletion from the stack has just been done (for example, a loop node was just made and all the values in it just got popped.)

getNumValsInCurLoopAtLevel

public int getNumValsInCurLoopAtLevel(int nest)
Get the number of values that should be in one row for the nesting level given for the most recently parsed DataLoopNameListNode. This is the count of the number of DataNameNodes at that nesting level, for the DataLoopNameListNode that is closest to the top of the stack. Returns 0 if there is no such nesting level or no such previous loop on the stack.

EpsilonParse

public static final void EpsilonParse()
                               throws ParseException

StarFileNodeParse

public static final void StarFileNodeParse(StarParser p)
                                    throws ParseException
This method will parse an entire star file. You can get to it by calling popResult() after it finishes.

BlockNodeParse

public static final void BlockNodeParse(StarParser p)
                                 throws ParseException
This method will parse a single BlockNode (a global_ or data_ block.) You can get to it by calling endResult() after it finishes.
Parameters:
p - It is necessary to pass the StarParser object itself because when javacc generates this source code, it generates this method with static scope (hence it has no concept of 'this'.)

DataNodeParse

public static final void DataNodeParse(StarParser p)
                                throws ParseException
This method will parse either a single DataItemNode, or a single DataLoopNode, or a single SaveFrameNode. You can get to it by calling endResult() after it finishes. You will need to use the type-aware features of Java in java.lang.Class in order to figure out which of these three kinds of node was returned in endResult().
Parameters:
p - It is necessary to pass the StarParser object itself because when javacc generates this source code, it generates this method with static scope (hence it has no concept of 'this'.)

DataItemNodeParse

public static final void DataItemNodeParse(StarParser p)
                                    throws ParseException
This method will parse a single DataItemNode. You can get to it by calling endResult() after it finishes.
Parameters:
p - It is necessary to pass the StarParser object itself because when javacc generates this source code, it generates this method with static scope (hence it has no concept of 'this'.)

DataNameNodeParse

public static final void DataNameNodeParse(StarParser p)
                                    throws ParseException
This method will parse a single DataNameNode (a tag). You can get to it by calling endResult() after it finishes.
Parameters:
p - It is necessary to pass the StarParser object itself because when javacc generates this source code, it generates this method with static scope (hence it has no concept of 'this'.)

TinyAbsDataValueNodeParse

public static final void TinyAbsDataValueNodeParse(StarParser p)
                                            throws ParseException
This method will parse a single TinyAbsDataValueNode. You can get to it by calling endResult() after it finishes.
Parameters:
p - It is necessary to pass the StarParser object itself because when javacc generates this source code, it generates this method with static scope (hence it has no concept of 'this'.)

DataValueNodeParse

public static final void DataValueNodeParse(StarParser p)
                                     throws ParseException
This method will parse a single DataValueNode. You can get to it by calling endResult() after it finishes.
Parameters:
p - It is necessary to pass the StarParser object itself because when javacc generates this source code, it generates this method with static scope (hence it has no concept of 'this'.)

SaveFrameNodeParse

public static final void SaveFrameNodeParse(StarParser p)
                                     throws ParseException
This method will parse a single SaveFrameNode. You can get to it by calling endResult() after it finishes.
Parameters:
p - It is necessary to pass the StarParser object itself because when javacc generates this source code, it generates this method with static scope (hence it has no concept of 'this'.)

SaveDataNodeParse

public static final void SaveDataNodeParse(StarParser p)
                                    throws ParseException
This method will parse one of the items that is allowed inside a SaveFrameNode. (Either a single DataItemNode, or a single DataLoopNode.) You can get to it by calling endResult() after it finishes. You will need to use the type-aware features of Java in java.lang.Class in order to figure out which of these three kinds of node was returned in endResult().
Parameters:
p - It is necessary to pass the StarParser object itself because when javacc generates this source code, it generates this method with static scope (hence it has no concept of 'this'.)

LoopValuesParse

public static final void LoopValuesParse(StarParser p)
                                  throws ParseException

StopParse

public static final void StopParse(StarParser p)
                            throws ParseException

OptionalStopParse

public static final void OptionalStopParse(StarParser p)
                                    throws ParseException

LoopTableNodeParse

public static final void LoopTableNodeParse(StarParser p,
                                            int nest)
                                     throws ParseException
This method parses a table of values, presuming that the DataLoopNameListNode has already been properly parsed to hold the numbers of values in each nesting level.

LoopRowNodeParse

public static final void LoopRowNodeParse(StarParser p,
                                          LoopTableNode tbl,
                                          int nest)
                                   throws ParseException
This method parses a single row of values, presuming that the DataLoopNameListNode has already been parsed and is on the stack underneath the current position.

DataLoopNodeParse

public static final void DataLoopNodeParse(StarParser p)
                                    throws ParseException
This method will parse a single DataLoopNode. You can get to it by calling endResult() after it finishes.
Parameters:
p - It is necessary to pass the StarParser object itself because when javacc generates this source code, it generates this method with static scope (hence it has no concept of 'this'.)

DataLoopNameListNodeParse

public static final void DataLoopNameListNodeParse(StarParser p)
                                            throws ParseException

LoopNameListNodeParse

public static final void LoopNameListNodeParse(StarParser p)
                                        throws ParseException

ReInit

public static void ReInit(java.io.InputStream stream)

ReInit

public static void ReInit(java.io.Reader stream)

ReInit

public void ReInit(StarParserTokenManager tm)

getNextToken

public static final Token getNextToken()

getToken

public static final Token getToken(int index)

generateParseException

public static final ParseException generateParseException()

enable_tracing

public static final void enable_tracing()

disable_tracing

public static final void disable_tracing()