1 ///////////////////////////////////////////////////////////////////////////////
3 // Definition of the Prop parser.
5 ///////////////////////////////////////////////////////////////////////////////
6 #ifndef prop_parser_interface_h
7 #define prop_parser_interface_h
10 #include <AD/automata/iolexerstack.h>
19 ///////////////////////////////////////////////////////////////////////////////
23 ///////////////////////////////////////////////////////////////////////////////
24 datatype LexicalContext = NONE | C | PROP | COMMENT | QUOTE | ANTIQUOTE;
26 ///////////////////////////////////////////////////////////////////////////////
28 // The syntax class PropParser describe the interface to the
29 // parsing/lexing front end.
31 ///////////////////////////////////////////////////////////////////////////////
32 syntax class PropParser
33 { PropParser(const PropParser&);
34 void operator = (const PropParser&);
36 enum { MAX_LEXICAL_DEPTH = 256,
38 MAX_INCLUDE_FILES = 256
41 ////////////////////////////////////////////////////////////////////////////
43 ////////////////////////////////////////////////////////////////////////////
46 ////////////////////////////////////////////////////////////////////////////
47 // Lexical context stack. This is used to keep track of the
48 // current lexical context.
49 ////////////////////////////////////////////////////////////////////////////
50 LexicalContext SCs[MAX_LEXICAL_DEPTH];
52 int levels[MAX_LEXICAL_DEPTH];
54 Decls code_stack[MAX_LEXICAL_DEPTH];
56 void start_sc (LexicalContext); // enter a new lexical context
57 void end_sc (); // leave the current lexical context
59 ////////////////////////////////////////////////////////////////////////////
61 ////////////////////////////////////////////////////////////////////////////
63 const char * file_name;
67 Quote(const char * file, int line, char a, char b)
68 : file_name(file), line_number(line), open(a), close(b) {}
70 Quote quote_stack[MAX_LEXICAL_DEPTH];
72 void start_quote(char, char);
73 char end_quote (char);
74 void start_statement ();
75 void end_statement ();
77 ////////////////////////////////////////////////////////////////////////////
78 // Internal code and documentation buffer.
79 ////////////////////////////////////////////////////////////////////////////
86 void emit (const char *, long = -1);
88 void emit_cons (Id cons_name);
94 ////////////////////////////////////////////////////////////////////////////
95 // Pattern variable environment and match expression stack
96 ////////////////////////////////////////////////////////////////////////////
97 PatternVarEnv pv_env; // pattern variable environment
98 MatchExps me_stack[MAX_LEXICAL_DEPTH]; // match expression stack
99 MatchOptions match_kind[MAX_LEXICAL_DEPTH]; // kind of match construct
100 int me_top; // top of me stack
102 ////////////////////////////////////////////////////////////////////////////
103 // Variable binding stack
104 ////////////////////////////////////////////////////////////////////////////
105 Id var_stack[MAX_ARITY];
106 Pat pat_stack[MAX_ARITY];
109 ////////////////////////////////////////////////////////////////////////////
110 // Include file stack
111 ////////////////////////////////////////////////////////////////////////////
116 std::istream * file_stream;
121 IncludeFile includes[MAX_INCLUDE_FILES];
123 const char * included_files[MAX_INCLUDE_FILES];
126 ////////////////////////////////////////////////////////////////////////////
127 // Miscellaneous flags and counters
128 ////////////////////////////////////////////////////////////////////////////
129 int antecedent_count; // number of antecedents in an inference rule
130 Bool in_rewrite; // are we in rewriting?
131 int rule_count; // number of rules
132 int is_view_def; // are we in a view definition?
133 int symbol_count; // number of symbols in a production
134 int item_count; // number of items in a production
135 int nonterm_count; // number of non-terminals in a production
140 { MatchRuleInfo::RewritingMode mode; // current rewrite mode
141 MatchRuleInfo::RewritingOption option;
143 } rw_stack[MAX_LEXICAL_DEPTH]; // kind of rewriting mode
144 int rw_top; // top of rw stack
145 void push_rw_stack();
148 ////////////////////////////////////////////////////////////////////////////
149 // The program being constructed.
150 ////////////////////////////////////////////////////////////////////////////
153 Compiler * compiler; // the current compiler
154 GraphTypeDef * graphtype_def; // the current graph type definition
157 ////////////////////////////////////////////////////////////////////////////
158 // The public interface
159 ////////////////////////////////////////////////////////////////////////////
160 virtual ~PropParser();
162 int get_token (); // method to retrieve a token
163 int get_token2 (); // method to retrieve a token
164 ErrorAction error_report (const char *); // error reporting.
165 void initialize (Compiler&);
166 void initialize_lexer (const char * file_name);
167 void cleanup_lexer();
168 void print_header(Compiler&);
172 void open_include_file (const char *); // open a new include file
173 void close_include_file (); // close include file
175 Decls mkcode (Decls);
176 Pat mkconspat (Cons);
178 Ty lookup_tyvar (Id);
179 Pat lookup_patvar (Id);
180 void add_parse_stack_binding (int,int,int);
182 // For error explanation
183 void print_user_symbol (std::ostream&, Symbol);
184 void explain_error();