fr.umlv.tatoo.runtime.tools
Class ToolsProcessor<R,B extends LexerBuffer,T,N,P>

java.lang.Object
  extended by fr.umlv.tatoo.runtime.tools.ToolsProcessor<R,B,T,N,P>
Type Parameters:
R - type of rules.
B - type of buffer.
T - type of terminals.
N - type of non terminals.
P - type of productions.
All Implemented Interfaces:
ParserListener<T,N,P>

public class ToolsProcessor<R,B extends LexerBuffer,T,N,P>
extends Object
implements ParserListener<T,N,P>

Glue between lexer and parser. How lexer's rules are transformed to parser's terminal is described by ToolsTable. A mini-tools processor is created using the factory method createProcessor(ToolsListener). This processor called a unique listener ToolsListener for both lexer events and parser events. This processor is itself a ParserListener and createLexerListener(SimpleParser, ToolsTable) is able to create a LexerListener that submit its rules transformed to terminal to a parser.

Author:
Remi Forax

Method Summary
 void accept(N nonTerminal)
          Notifies that the accept action is performed by the parser on the start non terminaL.
 LexerListener<R,B> createLexerListener(SimpleParser<? super T> parser, ToolsTable<? super R,? extends T> table)
          Create a ToolsProcessor.LexerHandler from a ToolsTable and a parser.
static
<R,B extends LexerBuffer,T,N,P>
ToolsProcessor<R,B,T,N,P>
createProcessor(ToolsListener<? super R,? super B,? super T,? super N,? super P> listener)
          Creates a new processor that acts as a parser listener and is able to create a lexer listener and a lifecycle handler.
 void reduce(P production)
          Notifies that a reduce action is performed by the parser.
 void shift(T terminal)
          Notifies that a shift action is performed by the parser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createProcessor

public static <R,B extends LexerBuffer,T,N,P> ToolsProcessor<R,B,T,N,P> createProcessor(ToolsListener<? super R,? super B,? super T,? super N,? super P> listener)
Creates a new processor that acts as a parser listener and is able to create a lexer listener and a lifecycle handler.

Type Parameters:
R - type of rules
B - type of buffer.
T - type of terminals.
N - type of non terminals
P - type of productions.
Parameters:
listener - a listener that will be called each time a rule is not send as a terminal, a shift/reduce is performed, the grammar is accepted.
Returns:
a new mini-tools processor.

createLexerListener

public LexerListener<R,B> createLexerListener(SimpleParser<? super T> parser,
                                              ToolsTable<? super R,? extends T> table)
Create a ToolsProcessor.LexerHandler from a ToolsTable and a parser.

Parameters:
parser - a parser.
table - a tools table.
Returns:
a new lexer handler.

shift

public void shift(T terminal)
Description copied from interface: ParserListener
Notifies that a shift action is performed by the parser.

Specified by:
shift in interface ParserListener<T,N,P>
Parameters:
terminal - shifted terminal.

reduce

public void reduce(P production)
Description copied from interface: ParserListener
Notifies that a reduce action is performed by the parser.

Specified by:
reduce in interface ParserListener<T,N,P>
Parameters:
production - reduced production.

accept

public void accept(N nonTerminal)
Description copied from interface: ParserListener
Notifies that the accept action is performed by the parser on the start non terminaL.

Specified by:
accept in interface ParserListener<T,N,P>
Parameters:
nonTerminal - accepted non terminal.
See Also:
Parser.getStartNonTerminal()