|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object marf.Storage.StorageManager marf.nlp.Parsing.GrammarCompiler.GrammarCompiler
public class GrammarCompiler
Grammar compiler -- compiles source grammar file and produces a corresponding transition table for a given language denoted by the grammar.
$Id: GrammarCompiler.java,v 1.30 2007/12/18 21:37:57 mokhov Exp $
Field Summary | |
---|---|
protected Grammar |
oGrammar
Instance of the grammar as a set of production Rules, First and Follow sets. |
protected GrammarAnalyzer |
oGrammarAnalyzer
Lexical Analyzer for the grammar. |
protected GrammarElement |
oGrammarElement
Current grammar element. |
protected Rule |
oRule
Current grammar rule. |
protected Token |
oToken
Current lexical token. |
private static long |
serialVersionUID
For serialization versioning. |
protected static TransitionTable |
soTransitionTable
Instance of the TransitionTable, generated upon the need from the source grammar file. |
protected java.lang.String |
strGrammarFileName
Source grammar filename. |
static java.lang.String |
TOKEN_ACTION_BREAK
Action for adding a next token to the RHS of the current rule signifying to stop. |
static java.lang.String |
TOKEN_ACTION_CONTINUE
Action for adding a next token to the RHS of the current rule signifying to continue and skip to the next token. |
static java.lang.String |
TOKEN_ACTION_PROCEED
Action for adding a next token to the RHS of the current rule signifying to proceed to add the current token to the RHS. |
Fields inherited from class marf.Storage.StorageManager |
---|
bDumpOnNotFound, iCurrentDumpMode, oObjectToSerialize, strFilename |
Fields inherited from interface marf.Storage.IStorageManager |
---|
DUMP_BINARY, DUMP_CSV_TEXT, DUMP_GZIP_BINARY, DUMP_HTML, DUMP_SQL, DUMP_XML, MARF_INTERFACE_CODE_REVISION, STORAGE_FILE_EXTENSIONS |
Constructor Summary | |
---|---|
GrammarCompiler()
Default Constructor. |
|
GrammarCompiler(java.lang.String pstrGrammarFileName)
Constructor with the grammar filename. |
Method Summary | |
---|---|
protected boolean |
addIDToken()
Adds a non-terminal grammar ID token type to the RHS of the current rule. |
protected void |
addNextRHSElement()
Adds next element to the RHS of the current rule. |
protected void |
addTerminalToken()
Adds a terminal token type to the RHS of the current rule. |
protected void |
checkUndefinedNonTerminals()
Checks for undefined non-terminals in the grammar. |
void |
compileGrammar()
Compiles grammar. |
protected void |
createEOFTerminal()
Creates and end-of-file indicator terminal. |
protected void |
createEpsilonToken()
Creates an instance of an empty (epsilon) token. |
protected void |
createGrammarAnalyzer()
Instantiates grammar analyzer. |
protected boolean |
createNextNonTerminal()
Creates the next non-terminal of a rule from the upcoming token. |
protected void |
createRule()
Creates an embryo of a rule given the LHS non-terminal and the rule operator `::='. |
private void |
fillInTransitionTable()
Fills in TransitionalTable data structure. |
protected void |
getBusted()
Dies on unexpected grammar token type. |
Grammar |
getGrammar()
Allows querying for inner instance of the grammar. |
protected GrammarElement |
getGrammarElement(java.lang.String pstrName)
Returns a grammar element object by it's name (lexeme) if it exists; null otherwise. |
java.lang.String |
getGrammarFileName()
Allows querying for the filename of the grammar. |
static java.lang.String |
getMARFSourceCodeRevision()
Retrieves class' revision. |
protected java.lang.String |
getNextRHSToken()
Acquires the next RHS token for a rule from the token stream. |
static TransitionTable |
getTransitionTable()
Allows querying for the inner transition table data structure. |
static TransitionTable |
loadTT(java.lang.String pstrTTFileName)
Loads (previously serialized) state of the TT. |
protected void |
outputStats()
Outputs statistics by serializing the grammar analyzer to a file as well as errors if any to the the error log file. |
protected void |
parseGrammar()
Parses grammar and outputs stats at the end. |
boolean |
serialize(int piOperation)
Text serialization routine for grammar compilation. |
Methods inherited from class marf.Storage.StorageManager |
---|
backSynchronizeObject, clone, dump, dumpBinary, dumpCSV, dumpGzipBinary, dumpHTML, dumpSQL, dumpXML, enableDumpOnNotFound, equals, getDefaultExtension, getDefaultExtension, getDumpMode, getFilename, getObjectToSerialize, hashCode, restore, restoreBinary, restoreCSV, restoreGzipBinary, restoreHTML, restoreSQL, restoreXML, setDumpMode, setFilename, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String TOKEN_ACTION_BREAK
public static final java.lang.String TOKEN_ACTION_CONTINUE
public static final java.lang.String TOKEN_ACTION_PROCEED
protected Grammar oGrammar
protected java.lang.String strGrammarFileName
protected GrammarAnalyzer oGrammarAnalyzer
protected static TransitionTable soTransitionTable
protected GrammarElement oGrammarElement
protected Token oToken
protected Rule oRule
private static final long serialVersionUID
serialver
tool that comes with JDK.
Constructor Detail |
---|
public GrammarCompiler() throws CompilerError
grammar-original.txt
as the filename.
CompilerError
- if initialization failedpublic GrammarCompiler(java.lang.String pstrGrammarFileName) throws CompilerError
pstrGrammarFileName
- the filename of the grammar to compile
CompilerError
- if initialization failedMethod Detail |
---|
protected void createGrammarAnalyzer()
public void compileGrammar() throws CompilerError
CompilerError
- in case there was a lexical or syntax errorprotected void createEpsilonToken()
protected boolean createNextNonTerminal() throws CompilerError
true
if the token was created; and false
if the end of file was reached
CompilerError
- -- either a SyntaxError
or LexicalError
SyntaxError
,
LexicalError
protected void createRule() throws CompilerError
CompilerError
- -- either a SyntaxError
or LexicalError
SyntaxError
,
LexicalError
protected void outputStats()
GrammarAnalyzer.serialize(int)
,
GrammarAnalyzer.getLexicalGrammarErrors()
,
GenericLexicalAnalyzer.getErrorsPresent()
,
GenericLexicalAnalyzer.getErrorLogFilename()
protected java.lang.String getNextRHSToken() throws CompilerError
CompilerError
- -- either a SyntaxError
or LexicalError
SyntaxError
,
LexicalError
protected void addNextRHSElement() throws SyntaxError
SyntaxError
- if unrecognized token type foundprotected boolean addIDToken()
true
if the current token type is really
of type GrammarTokenType.GRAMMAR_ID
GrammarTokenType.GRAMMAR_ID
protected void addTerminalToken()
protected void getBusted() throws SyntaxError
SyntaxError
- indicated unexpected token type.protected void createEOFTerminal()
protected void checkUndefinedNonTerminals() throws SemanticError
SemanticError
- if there were undefined non-terminalsprotected void parseGrammar() throws CompilerError
CompilerError
- in case of lexical, syntax, or semantic errorsGrammar
,
Rule
protected GrammarElement getGrammarElement(java.lang.String pstrName)
pstrName
- the name of the element
private void fillInTransitionTable() throws CompilerError
CompilerError
- if either list of terminals, or non-terminals
or rules is emptypublic static TransitionTable loadTT(java.lang.String pstrTTFileName) throws StorageException
pstrTTFileName
- filename of a file with previously stored transition table
StorageException
- if there was any problem loading the table from filepublic boolean serialize(int piOperation)
piOperation
- 0 for load and 1 for save
true
if the I/O operation was successfulpublic final Grammar getGrammar()
public final java.lang.String getGrammarFileName()
public static final TransitionTable getTransitionTable()
public static java.lang.String getMARFSourceCodeRevision()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |