Class SLR

java.lang.Object
  extended bySLR

public class SLR
extends java.lang.Object

This class implements the SLR(0) method for syntax analysis. Usage:
java SLR "input" grammar.
For instance,
java SLR "(1+2)*3" ../Data/ETF.txt produces the successive stack contents during the analysis of the expression (1+2)*3 using the ETF grammar. If the grammar is not SLR, an error message "Grammar not SLR: S/R conflict" or "Grammar not SLR: S/R conflict" is issued. If the expression is not correct, an error message "syntax error" or "end of input reached" is issued.


Field Summary
 Alphabet alphabet
          The input alphabet;
 char[] expression
          The expression to analyze.
 Grammar G
          The current context-free grammar.
 int[][] LRReduceTable
           
 int[][] LRShiftTable
          The shift table.
 int position
          The current index.
 java.util.Stack stack
          The stack used to store the LR states.
 
Method Summary
 void advance()
          Advance one character to the right on input.
 short current()
          Returns the current token of the input.
 InfoNFA LRAutomaton()
          Computes the LR(0) automaton.
 int[][] LRReduceTable(InfoDFA a)
           
 int[][] LRShiftTable(InfoDFA a)
          Computes the SLR(0) shift table.
static void main(java.lang.String[] args)
           
 void push(short c)
          Push the character c on the stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

expression

public char[] expression
The expression to analyze.


position

public int position
The current index.


stack

public java.util.Stack stack
The stack used to store the LR states.


G

public Grammar G
The current context-free grammar.


alphabet

public Alphabet alphabet
The input alphabet;


LRShiftTable

public int[][] LRShiftTable
The shift table.


LRReduceTable

public int[][] LRReduceTable
Method Detail

advance

public void advance()
Advance one character to the right on input.


current

public short current()
Returns the current token of the input. Discards possible space characters.


push

public void push(short c)
Push the character c on the stack. Actually push the state reached in the LR automaton from the state p at top of the stack under input c.

Parameters:
c - the input character
Returns:
the state next(p,c)

LRAutomaton

public InfoNFA LRAutomaton()
Computes the LR(0) automaton.


LRShiftTable

public int[][] LRShiftTable(InfoDFA a)
Computes the SLR(0) shift table. The positive values correspond to the shift part, the negative ones to the reduce part.


LRReduceTable

public int[][] LRReduceTable(InfoDFA a)
                      throws java.lang.Exception
Throws:
java.lang.Exception

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Throws:
java.io.IOException