4 #include "identifier.hh"
5 #include "assoc-iter.hh"
6 #include "input-file.hh"
7 #include "out/parser.hh"
10 #include "my-lily-lexer.hh"
12 #include "source-file.hh"
13 #include "parseconstruct.hh"
15 static Keyword_ent the_key_tab[]={
20 "duration", DURATIONCOMMAND,
22 "geometric", GEOMETRIC,
30 "multivoice", MULTIVOICE,
31 "octave", OCTAVECOMMAND,
44 "symboltables", SYMBOLTABLES,
47 "textstyle", TEXTSTYLE,
48 "transpose", TRANSPOSE,
49 "unitspace", UNITSPACE,
56 My_lily_lexer::My_lily_lexer()
58 keytable_p_ = new Keyword_table(the_key_tab);
59 identifier_assoc_p_ = new Assoc<String, Identifier*>;
64 My_lily_lexer::lookup_keyword(String s)
66 return keytable_p_->lookup(s);
70 My_lily_lexer::lookup_identifier(String s)
72 if (!identifier_assoc_p_->elt_query(s))
75 return (*identifier_assoc_p_)[s];
79 My_lily_lexer::here_ch_c_l()
81 return include_stack_.top()->sourcefile_l_->ch_c_l() + yyin->tellg();
85 My_lily_lexer::add_identifier(Identifier*i)
87 delete lookup_identifier(i->name);
88 (*identifier_assoc_p_)[i->name] = i;
91 My_lily_lexer::~My_lily_lexer()
95 for (Assoc_iter<String,Identifier*>
96 ai(*identifier_assoc_p_); ai.ok(); ai++) {
97 mtor << "deleting: " << ai.key()<<'\n';
98 Identifier *i_p = ai.val();
99 if (!i_p->accessed_b_ && !i_p->init_b_)
100 warning("Variable not used", i_p->defined_ch_C_);
104 delete identifier_assoc_p_;
107 My_lily_lexer::print_init_declarations()const
109 for (Assoc_iter<String,Identifier*> ai(*identifier_assoc_p_); ai.ok();
111 if (ai.val()->init_b_)
116 My_lily_lexer::print_user_declarations()const
118 for (Assoc_iter<String,Identifier*> ai(*identifier_assoc_p_); ai.ok(); ai++) {
119 if (!ai.val()->init_b_)
125 My_lily_lexer::spot()const
127 return include_stack_.top()->name + ": " + String( lineno() );
131 My_lily_lexer::LexerError(char const *s)
133 if (lexer->include_stack_.empty()) {
134 *mlog << "error at EOF" << s << '\n';
136 char const* ch_c_l = here_ch_c_l();
139 while ( ( *ch_c_l == ' ' ) || ( *ch_c_l == '\t' ) || ( *ch_c_l == '\n' ) )
148 // set the new input to s, remember old file.
150 My_lily_lexer::new_input(String s)
152 if (!include_stack_.empty()) {
153 include_stack_.top()->line = lineno();
154 // should this be saved at all?
155 include_stack_.top()->defined_ch_c_l_ = defined_ch_c_l;
158 Input_file *newin = new Input_file(s);
159 include_stack_.push(newin);
160 switch_streams(newin->is);
165 // pop the inputstack.
167 My_lily_lexer::close_input()
169 Input_file *old = include_stack_.pop();
171 if (include_stack_.empty()) {
174 Input_file *i = include_stack_.top();
175 switch_streams(i->is);
177 defined_ch_c_l = i->defined_ch_c_l_;