|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectSLR
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 |
public char[] expression
public int position
public java.util.Stack stack
public Grammar G
public Alphabet alphabet
public int[][] LRShiftTable
public int[][] LRReduceTable
| Method Detail |
public void advance()
public short current()
public void push(short c)
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.
c - the input character
next(p,c)public InfoNFA LRAutomaton()
public int[][] LRShiftTable(InfoDFA a)
public int[][] LRReduceTable(InfoDFA a)
throws java.lang.Exception
java.lang.Exception
public static void main(java.lang.String[] args)
throws java.io.IOException
java.io.IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||