KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fri > patterns > interpreter > parsergenerator > ParserTables


1 package fri.patterns.interpreter.parsergenerator;
2
3 import java.util.List JavaDoc;
4 import java.util.Map JavaDoc;
5 import java.io.PrintStream JavaDoc;
6 import fri.patterns.interpreter.parsergenerator.syntax.Syntax;
7
8 /**
9     Responsibilities of (bottom-up) parser tables, that must provide:
10     <ul>
11         <li>all terminals, without EPSILON (for the Lexer)</li>
12         <li>the syntax</li>
13         <li>the follow-state from the GOTO-table</li>
14         <li>the follow action from the PARSE-ACTION-table</li>
15         <li>a list of expected terminals</li>
16     </ul>
17
18     @author (c) 2000, Fritz Ritzberger
19 */

20
21 public interface ParserTables
22 {
23     /** Special symbol occuring in a parser table, 0, means: syntax was correct when coming to that cell. */
24     public static final Integer JavaDoc ACCEPT = new Integer JavaDoc(0);
25     
26     /** Special symbol occuring in a parser table, -1, means: error when coming to that cell. */
27     public static final Integer JavaDoc ERROR = new Integer JavaDoc(-1);
28
29     /** Special symbol occuring in a parser table, -2, means: read next token. */
30     public static final Integer JavaDoc SHIFT = new Integer JavaDoc(-2);
31     
32
33     /**
34         Returns the next state from the GOTO-table, for a given state and a received terminal or nonterminal.
35         @param currentState the current parser state
36         @param symbol recently received terminal or nonterminal
37         @return new parser state
38     */

39     public Integer JavaDoc getGotoState(Integer JavaDoc currentState, String JavaDoc symbol);
40
41     /**
42         Returns the action from the PARSE-ACTION-table, for a given state and received terminal.
43         fuer einen gegebenen Zustand und ein Terminal.
44         @param currentState the current parser state
45         @param terminal recently received terminal
46         @return new action to proceed, SHIFT, ACCEPT, ERROR, or anything above zero, meaning REDUCE.
47     */

48     public Integer JavaDoc getParseAction(Integer JavaDoc currentState, String JavaDoc terminal);
49
50     /**
51         Returns the List of treminals, without EPSILON.
52     */

53     public List JavaDoc getTerminals();
54     
55     /**
56         Returns the input syntax.
57     */

58     public Syntax getSyntax();
59
60     /**
61         Dumps rules, GOTO-table, PARSE-ACTION-table, FIRST and FOLLOW sets, ...
62     */

63     public void dump(PrintStream JavaDoc out);
64     
65     /**
66         The keySet of returned Map contains all expected terminals for the current state.
67         These can be used as Lexer hints.
68     */

69     public Map JavaDoc getExpected(Integer JavaDoc state);
70
71 }
72
Popular Tags