marf.nlp.Parsing
Class Parser

java.lang.Object
  extended by marf.nlp.Parsing.Parser

public class Parser
extends java.lang.Object

Generic Language Parser.

$Id: Parser.java,v 1.25 2008/01/03 03:21:57 mokhov Exp $

Since:
0.3.0.2
Version:
$Revision: 1.25 $
Author:
Serguei Mokhov, mokhov@cs.concordia.ca

Field Summary
protected  boolean bErrorsPresent
          Fact, indicating that there are syntax errors.
protected  java.util.Stack oBracketStack
          Stack for checking mismatched brackets.
private  GrammarCompiler oGrammarCompiler
          Grammar Compiler.
private  LexicalAnalyzer oLexer
          An instance of Lexical Analyzer.
private  java.util.Stack oStack
          Stack needed for Transition State Parsing Algorithm.
protected  java.util.Vector oSyntaxErrors
          A list of Syntax Errors so far.
private  TransitionTable oTT
          Transitional Table for Transition State Parsing Algorithm.
private static SymbolTable soSymTab
          Global Scope Symbol Table.
 
Constructor Summary
Parser(java.lang.String[] argv)
          Constructor with command-line arguments.
 
Method Summary
 boolean areErrorsPresent()
          Allows to query the fact that there were lexical or syntax errors or not.
 GrammarCompiler getGrammarCompiler()
          Allows querying for the grammar compiler used.
 LexicalAnalyzer getLexer()
          Allows querying for the instance of the lexer.
static java.lang.String getMARFSourceCodeRevision()
          Retrieves class' revision.
 java.util.Stack getStack()
          Allows querying for the current stack.
static SymbolTable getSymbolTable()
          Allows querying for the current symbol table.
 java.util.Vector getSyntaxErrors()
          Allows querying for the recorded syntax errors that were found.
 TransitionTable getTransitionTable()
          Allows querying for the current transition table.
private  void inverseMultiplePush(NonTerminal poNonTerminal, Token poToken)
          Pushes multiple tokens on a RHS of a rule into the stack in the reverse order.
 boolean parse()
          Implements State Transition Algorithm for top-down table-driven predictive parser.
 Token popBracket()
          Pops a bracket-type token from the stack.
 void pushBracket(Token poToken)
          Pushes bracket-type token onto the bracket stack.
 void setErrorsPresent(boolean pbErrorsPresent)
          Allows externally setting the fact that there were errors.
 void setGrammarCompiler(GrammarCompiler poGrammarCompiler)
          Allows setting a new grammar compiler to use.
 void setLexer(LexicalAnalyzer poLexer)
          Allows setting a new lexer for scanning.
static void setSymbolTable(SymbolTable poSymTab)
          Allows setting a new symbol table.
 void setTransitionTable(TransitionTable poTT)
          Allows setting a new transition table.
private  void skipErrors()
          Error recovery function.
private  void stackDump()
          Performs textual stack dump.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

oTT

private TransitionTable oTT
Transitional Table for Transition State Parsing Algorithm.


oLexer

private LexicalAnalyzer oLexer
An instance of Lexical Analyzer.


soSymTab

private static SymbolTable soSymTab
Global Scope Symbol Table.


oGrammarCompiler

private GrammarCompiler oGrammarCompiler
Grammar Compiler. Needed to compile source grammar file if TT does not exist.


oStack

private java.util.Stack oStack
Stack needed for Transition State Parsing Algorithm.


oSyntaxErrors

protected java.util.Vector oSyntaxErrors
A list of Syntax Errors so far.


bErrorsPresent

protected boolean bErrorsPresent
Fact, indicating that there are syntax errors.


oBracketStack

protected java.util.Stack oBracketStack
Stack for checking mismatched brackets.

Constructor Detail

Parser

public Parser(java.lang.String[] argv)
       throws CompilerError
Constructor with command-line arguments.

Parameters:
argv - the command-line arguments
Throws:
CompilerError - if there are problems initializing a lexer or a transition table
Method Detail

pushBracket

public void pushBracket(Token poToken)
Pushes bracket-type token onto the bracket stack. Used for further validation of matching brackets, parentheses, and braces.

Parameters:
poToken - the bracket-type token

popBracket

public Token popBracket()
Pops a bracket-type token from the stack.

Returns:
the top bracket-type token

parse

public boolean parse()
              throws SyntaxError,
                     LexicalError
Implements State Transition Algorithm for top-down table-driven predictive parser.

Returns:
true if the parse was successful
Throws:
SyntaxError - if a parsed statement for some reason does not conform the grammar
LexicalError - if an invalid token read off the source character stream

skipErrors

private void skipErrors()
                 throws LexicalError
Error recovery function. Skips syntax errors until next valid symbol in TT.

Throws:
LexicalError - if invalid token is encounterd

inverseMultiplePush

private void inverseMultiplePush(NonTerminal poNonTerminal,
                                 Token poToken)
Pushes multiple tokens on a RHS of a rule into the stack in the reverse order.

Parameters:
poNonTerminal - non-terminal to recover the corresponding rule
poToken - token to recover the corresponding rule

stackDump

private void stackDump()
Performs textual stack dump.


getSymbolTable

public static SymbolTable getSymbolTable()
Allows querying for the current symbol table.

Returns:
the reference to the contained symbol table
Since:
0.3.0.5

setSymbolTable

public static void setSymbolTable(SymbolTable poSymTab)
Allows setting a new symbol table.

Parameters:
poSymTab - the global symbol table to set
Since:
0.3.0.5

areErrorsPresent

public boolean areErrorsPresent()
Allows to query the fact that there were lexical or syntax errors or not.

Returns:
true if there were errors in parsing
Since:
0.3.0.5

setErrorsPresent

public void setErrorsPresent(boolean pbErrorsPresent)
Allows externally setting the fact that there were errors.

Parameters:
pbErrorsPresent - the new value of the flag
Since:
0.3.0.5

getLexer

public LexicalAnalyzer getLexer()
Allows querying for the instance of the lexer.

Returns:
the reference to the lexer used
Since:
0.3.0.5

setLexer

public void setLexer(LexicalAnalyzer poLexer)
Allows setting a new lexer for scanning.

Parameters:
poLexer - the new lexer to be used
Since:
0.3.0.5

getGrammarCompiler

public GrammarCompiler getGrammarCompiler()
Allows querying for the grammar compiler used.

Returns:
the reference to the contained grammar compiler
Since:
0.3.0.5

setGrammarCompiler

public void setGrammarCompiler(GrammarCompiler poGrammarCompiler)
Allows setting a new grammar compiler to use.

Parameters:
poGrammarCompiler - the new grammar compiler
Since:
0.3.0.5

getStack

public java.util.Stack getStack()
Allows querying for the current stack.

Returns:
the current stack data structure
Since:
0.3.0.5

getTransitionTable

public TransitionTable getTransitionTable()
Allows querying for the current transition table.

Returns:
the current transition table data structure
Since:
0.3.0.5

setTransitionTable

public void setTransitionTable(TransitionTable poTT)
Allows setting a new transition table.

Parameters:
poTT - the new transition table data structure to set
Since:
0.3.0.5

getSyntaxErrors

public java.util.Vector getSyntaxErrors()
Allows querying for the recorded syntax errors that were found.

Returns:
the collection of syntax errors
Since:
0.3.0.5

getMARFSourceCodeRevision

public static java.lang.String getMARFSourceCodeRevision()
Retrieves class' revision.

Returns:
revision string


SourceForge Logo