4 #include "identparent.hh"
5 #include "assoc-iter.hh"
7 #include "input-file.hh"
8 #include "out/parser.hh"
14 #include "source-file.hh"
15 #include "parseconstruct.hh"
17 static Keyword_ent the_key_tab
[]={
24 "duration", DURATIONCOMMAND
,
26 "geometric", GEOMETRIC
,
34 "multivoice", MULTIVOICE
,
35 "octave", OCTAVECOMMAND
,
48 "symboltables", SYMBOLTABLES
,
51 "textstyle", TEXTSTYLE
,
52 "unitspace", UNITSPACE
,
61 My_flex_lexer::My_flex_lexer()
63 keytable_p_
= new Keyword_table(the_key_tab
);
64 identifier_assoc_p_
= new Assoc
<String
, Identifier
*>;
69 My_flex_lexer::lookup_keyword(String s
)
71 return keytable_p_
->lookup(s
);
75 My_flex_lexer::lookup_identifier(String s
)
77 if (!identifier_assoc_p_
->elt_query(s
))
80 return (*identifier_assoc_p_
)[s
];
84 My_flex_lexer::here_ch_c_l()
86 return include_stack_
.top()->sourcefile_l_
->ch_c_l() + yyin
->tellg();
90 My_flex_lexer::add_identifier(Identifier
*i
)
92 delete lookup_identifier(i
->name
);
93 (*identifier_assoc_p_
)[i
->name
] = i
;
96 My_flex_lexer::~My_flex_lexer()
100 for (Assoc_iter
<String
,Identifier
*>
101 ai(*identifier_assoc_p_
); ai
.ok(); ai
++) {
102 mtor
<< "deleting: " << ai
.key()<<'\n';
105 delete identifier_assoc_p_
;
108 My_flex_lexer::print_declarations()const
110 for (Assoc_iter
<String
,Identifier
*> ai(*identifier_assoc_p_
); ai
.ok(); ai
++) {
116 My_flex_lexer::spot()const
118 return include_stack_
.top()->name
+ ": " + String( lineno() );
122 My_flex_lexer::LexerError(const char *s
)
124 if (lexer
->include_stack_
.empty()) {
125 *mlog
<< "error at EOF" << s
<< '\n';
127 char const* ch_c_l
= here_ch_c_l();
130 while ( ( *ch_c_l
== ' ' ) || ( *ch_c_l
== '\t' ) || ( *ch_c_l
== '\n' ) )
139 // set the new input to s, remember old file.
141 My_flex_lexer::new_input(String s
)
143 if (!include_stack_
.empty()) {
144 include_stack_
.top()->line
= lineno();
145 // should this be saved at all?
146 include_stack_
.top()->defined_ch_c_l_
= defined_ch_c_l
;
149 Input_file
*newin
= new Input_file(s
);
150 include_stack_
.push(newin
);
151 switch_streams(newin
->is
);
156 // pop the inputstack.
158 My_flex_lexer::close_input()
160 Input_file
*old
= include_stack_
.pop();
162 if (include_stack_
.empty()) {
165 Input_file
*i
= include_stack_
.top();
166 switch_streams(i
->is
);
168 defined_ch_c_l
= i
->defined_ch_c_l_
;