fri.patterns.interpreter.parsergenerator.parsertables
Class SLRParserTables

java.lang.Object
  |
  +--fri.patterns.interpreter.parsergenerator.parsertables.AbstractParserTables
        |
        +--fri.patterns.interpreter.parsergenerator.parsertables.SLRParserTables
All Implemented Interfaces:
ParserTables, java.io.Serializable
Direct Known Subclasses:
LRParserTables

public class SLRParserTables
extends AbstractParserTables

A table generator, building SLR bottom-up parser tables from a syntax.

An artifical START-node gets inserted. Lists of nonterminals and terminals are created. Syntax nodes are created, from which the parser GOTO and PARSE-ACTION tables get built.

This class contains dump methods for syntax nodes and FIRST/FOLLOW sets.

Author:
(c) 2000, Fritz Ritzberger
See Also:
Serialized Form

Field Summary
protected  fri.patterns.interpreter.parsergenerator.parsertables.FirstSets firstSets
           
protected  fri.patterns.interpreter.parsergenerator.parsertables.FollowSets followSets
           
protected  java.util.List syntaxNodes
           
 
Fields inherited from class fri.patterns.interpreter.parsergenerator.parsertables.AbstractParserTables
CELLWIDTH, gotoTable, nonterminals, parseTable, symbols, syntax, terminals, terminalsWithoutEpsilon
 
Fields inherited from interface fri.patterns.interpreter.parsergenerator.ParserTables
ACCEPT, ERROR, SHIFT
 
Constructor Summary
SLRParserTables(Syntax syntax)
          Appends START symbol and retrieves all symbols.
 
Method Summary
 void dump(java.io.PrintStream out)
          Implements ParserTables: output of rules, FIRST/FOLLOW sets, syntax nodes, GOTO-table, PARSE-ACTON-table.
 void dumpFirstSet(java.io.PrintStream out)
           
 void dumpFollowSet(java.io.PrintStream out)
           
 void dumpSet(java.lang.String header, java.util.Map set, java.io.PrintStream out)
           
 void dumpSyntaxNode(int i, fri.patterns.interpreter.parsergenerator.parsertables.SLRSyntaxNode node, java.io.PrintStream out)
           
 void dumpSyntaxNodes(java.io.PrintStream out)
           
 void freeSyntaxNodes()
          Enable garbage collection of builder variables.
protected  java.util.List generateGoto(java.util.List syntaxNodes)
          Creates GOTO table of follow states.
protected  java.util.List generateParseAction(java.util.List syntaxNodes)
          Erzeugen der Parse-Action-Tabelle fuer shift/reduce Aktionen.
protected  java.util.List getAllSymbols()
          Returns all symbols (terminals and nonterminals).
protected  void init()
          Builds SLR bottom-up parser tables.
protected  void insertTableLine(int i, java.util.Map line, java.util.List table, java.util.Map hash)
          Compression of tables: Look for an identical table line.
static void main(java.lang.String[] args)
          Test main dumping arithmetic expression tables.
 void report(java.io.PrintStream out)
          Overridden to report better.
 
Methods inherited from class fri.patterns.interpreter.parsergenerator.parsertables.AbstractParserTables
construct, dumpGoto, dumpParseAction, dumpRule, dumpSyntax, dumpTable, dumpTables, getExpected, getGotoState, getParseAction, getSyntax, getTerminals, toSourceFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

syntaxNodes

protected transient java.util.List syntaxNodes

firstSets

protected transient fri.patterns.interpreter.parsergenerator.parsertables.FirstSets firstSets

followSets

protected transient fri.patterns.interpreter.parsergenerator.parsertables.FollowSets followSets
Constructor Detail

SLRParserTables

public SLRParserTables(Syntax syntax)
                throws ParserBuildException
Appends START symbol and retrieves all symbols. Calls init then. All parser table types run through this constructor.

Method Detail

init

protected void init()
             throws ParserBuildException
Builds SLR bottom-up parser tables.

ParserBuildException

getAllSymbols

protected java.util.List getAllSymbols()
                                throws ParserBuildException
Returns all symbols (terminals and nonterminals). Builds lists. Called only once on construction.

ParserBuildException

generateGoto

protected java.util.List generateGoto(java.util.List syntaxNodes)
Creates GOTO table of follow states.


generateParseAction

protected java.util.List generateParseAction(java.util.List syntaxNodes)
Erzeugen der Parse-Action-Tabelle fuer shift/reduce Aktionen.


insertTableLine

protected void insertTableLine(int i,
                               java.util.Map line,
                               java.util.List table,
                               java.util.Map hash)
Compression of tables: Look for an identical table line.

Returns:
identical line Zeile, or passed line when not found.

freeSyntaxNodes

public void freeSyntaxNodes()
Enable garbage collection of builder variables. CAUTION: dump methods work reduced after this call.


report

public void report(java.io.PrintStream out)
Overridden to report better.

Overrides:
report in class AbstractParserTables

dump

public void dump(java.io.PrintStream out)
Implements ParserTables: output of rules, FIRST/FOLLOW sets, syntax nodes, GOTO-table, PARSE-ACTON-table.

Specified by:
dump in interface ParserTables
Overrides:
dump in class AbstractParserTables

dumpSyntaxNodes

public void dumpSyntaxNodes(java.io.PrintStream out)

dumpSyntaxNode

public void dumpSyntaxNode(int i,
                           fri.patterns.interpreter.parsergenerator.parsertables.SLRSyntaxNode node,
                           java.io.PrintStream out)

dumpFirstSet

public void dumpFirstSet(java.io.PrintStream out)

dumpFollowSet

public void dumpFollowSet(java.io.PrintStream out)

dumpSet

public void dumpSet(java.lang.String header,
                    java.util.Map set,
                    java.io.PrintStream out)

main

public static void main(java.lang.String[] args)
Test main dumping arithmetic expression tables.