1 ///////////////////////////////////////////////////////////////////////////////
2 // This file is generated automatically using Prop (version 2.3.6),
3 // last updated on Nov 2, 1999.
4 // The original source file is "metasyntax.pcc".
5 ///////////////////////////////////////////////////////////////////////////////
7 #line 1 "metasyntax.pcc"
8 ///////////////////////////////////////////////////////////////////////////////
10 // This file implements the meta-syntax compiler.
12 ///////////////////////////////////////////////////////////////////////////////
14 #include "metasyntax.h"
20 ///////////////////////////////////////////////////////////////////////////////
22 // Implementation of the meta syntax compiler
24 ///////////////////////////////////////////////////////////////////////////////
25 class MetaSyntaxCompilerImpl
{
26 MetaSyntaxCompilerImpl(const MetaSyntaxCompilerImpl
&);
27 void operator = (const MetaSyntaxCompilerImpl
&);
30 size_t memory_used
; // total memory used for the parsers and lexers
31 HashTable grammar_map
; // mapping from name to grammar
32 int timer
; // use count timer
34 MetaSyntaxCompilerImpl()
36 grammar_map(string_hash
,string_equal
)
40 ///////////////////////////////////////////////////////////////////////////////
42 // Definition of a grammar record
44 ///////////////////////////////////////////////////////////////////////////////
45 struct GrammarRecord
{
46 Id grammar_name
; // grammar name
47 GramExp grammar_exp
; // grammar expression
48 size_t memory_used
; // memory used for this grammar
49 int last_used
; // time of last use
50 int use_count
; // number of uses
53 ///////////////////////////////////////////////////////////////////////////////
55 // Constructor and destructor
57 ///////////////////////////////////////////////////////////////////////////////
58 MetaSyntaxCompiler:: MetaSyntaxCompiler()
59 : impl(new MetaSyntaxCompilerImpl
)
61 MetaSyntaxCompiler::~MetaSyntaxCompiler()
64 ///////////////////////////////////////////////////////////////////////////////
66 // Method to compile a grammar give it an unique name.
67 // We'll invoke the parser generator subclass to create a new parser.
68 // Then the parser table is stored inside internal tables.
70 ///////////////////////////////////////////////////////////////////////////////
71 void MetaSyntaxCompiler::install_grammar(Id grammar_name
, GramExp grammar
)
72 { gen_parser(grammar_name
, grammar
);
75 ///////////////////////////////////////////////////////////////////////////////
77 // Method to parse the text as an expression.
79 ///////////////////////////////////////////////////////////////////////////////
80 Exp
MetaSyntaxCompiler::parse_exp (Id grammar_name
,
83 { error ("%Lunrecognized quoted expression `%s`\n",text
);
87 ///////////////////////////////////////////////////////////////////////////////
89 // Method to parse the text as a pattern.
91 ///////////////////////////////////////////////////////////////////////////////
92 Pat
MetaSyntaxCompiler::parse_pat (Id grammar_name
,
95 { error ("%Lunrecognized quoted pattern `%s`\n",text
);
99 ///////////////////////////////////////////////////////////////////////////////
101 // Method to flush out a grammar when memory is low.
102 // This is invoked whenever a new grammar is to be compiled
103 // and the total memory used has reached a limit. The least
104 // recently used grammars are flushed in this process.
106 ///////////////////////////////////////////////////////////////////////////////
107 void MetaSyntaxCompiler::flush_grammar (size_t memory_needed
)
108 { long memory_to_free
= memory_needed
;
109 while (memory_to_free
> 0 && impl
->grammar_map
.size() > 0)
110 { GrammarRecord
* kill_candidate
= 0; // the candidate to invalidate.
111 HashTable
& grammar_map
= impl
->grammar_map
;
113 // Locate the least frequently used entry
114 foreach_entry(e
,grammar_map
)
115 { if (kill_candidate
== 0 ||
116 ((GrammarRecord
*)(e
->v
))->use_count
< kill_candidate
->use_count
)
117 kill_candidate
= (GrammarRecord
*)(e
->v
);
119 // Locate the oldest used entry
120 foreach_entry(e
,grammar_map
)
121 { if (kill_candidate
== 0 ||
122 ((GrammarRecord
*)(e
->v
))->last_used
< kill_candidate
->last_used
)
123 kill_candidate
= (GrammarRecord
*)(e
->v
);
125 // Kill entry and update the available memory
127 { if (options
.generate_report
)
128 open_logfile() << "[Invalidating meta-language '"
129 << kill_candidate
->grammar_name
<< "']\n";
130 impl
->memory_used
-= kill_candidate
->memory_used
;
131 memory_to_free
-= kill_candidate
->memory_used
;
136 ///////////////////////////////////////////////////////////////////////////////
138 // Method to generate a report of all the grammars generated.
140 ///////////////////////////////////////////////////////////////////////////////
141 std::ostream
& MetaSyntaxCompiler::print_report(std::ostream
& f
)
145 #line 138 "metasyntax.pcc"
147 ------------------------------- Statistics -------------------------------
148 Merge matching rules = yes
149 Number of DFA nodes merged = 0
150 Number of ifs generated = 0
151 Number of switches generated = 0
154 Adaptive matching = enabled
155 Fast string matching = disabled
156 Inline downcasts = enabled
157 --------------------------------------------------------------------------