#include "identifier.hh"
#include "my-lily-lexer.hh"
#include "debug.hh"
-
#include "symtable.hh"
#include "lookup.hh"
#include "script-def.hh"
Identifier::~Identifier()
{
if (!accessed_b_ && !init_b_)
- warning("Variable not used");
+ warning ("Variable not used");
}
void
-Identifier::error(String expect)
+Identifier::error (String expect)
{
- String e("Wrong identifier type: ");
- e += String(name()) + "(expected " + expect + ")";
- ::error(e);
+ String e ("Wrong identifier type: ");
+ e += String (name()) + "(expected " + expect + ")";
+ ::error (e);
}
-Identifier::Identifier(String n, int code)
- : name_str_(n)
+Identifier::Identifier ( int code)
{
token_code_i_ = code;
- data = 0;
accessed_b_ = 0;
init_b_ = 0;
}
void
Identifier::print()const
{
- mtor << "identifier \'" << name_str_ << "\'=";
+ DOUT << "identifier ";
do_print();
}
#define DEFAULT_PRINT(Class, Content_type, accessor) \
void \
Class::do_print() const { \
- ((Class*)this)->accessor(false)->print(); \
+ ((Class*)this)->accessor()->print(); \
} \
class Class
void
Real_id::do_print() const
{
- mtor << *((Real_id*)this)->real(false)<< "\n";
+ DOUT << *data_p_<< "\n";
}
void
Int_id::do_print() const
{
- mtor << *((Int_id*)this)->intid(false)<< "\n";
+ DOUT << *data_p_<< "\n";
}
-#define default_accessor(Idclass, Class, accessor)\
+#define DEFAULT_ACCESSOR(Idclass, Class, accessor)\
Class*\
-Idclass::accessor(bool copy) {\
- if (copy){ \
- accessed_b_ = true;\
- return new Class(* (Class*) data);\
- }else\
- return (Class*) data;\
- }\
-
-#define virtual_accessor(Idclass, Class, accessor)\
+Idclass::accessor () {\
+ accessed_b_ = true;\
+ return new Class (*data_p_);\
+}
+
+#define VIRTUAL_ACCESSOR(Idclass, Class, accessor)\
Class*\
-Idclass::accessor(bool copy) {\
- if (copy){ \
- accessed_b_ = true;\
- return (Class*) ((Class*) data)->clone();\
- }else\
- return (Class*) data;\
- }\
-
-
-#define implement_id_class(Idclass, Class, accessor) \
-IMPLEMENT_IS_TYPE_B1(Idclass,Identifier)\
-Idclass::~Idclass() { delete accessor(false); }\
-Idclass::Idclass(String s, Class*st, int code):Identifier(s,code) { data = st; }\
-
-
-implement_id_class(Input_translator_id, Input_translator, input_translator);
-implement_id_class(Int_id, int, intid);
-implement_id_class(Real_id, Real, real);
-implement_id_class(Script_id, General_script_def, script);
-implement_id_class(Lookup_id, Lookup, lookup);
-implement_id_class(Symtables_id, Symtables, symtables);
-implement_id_class(Music_id, Music, music);
-implement_id_class(Score_id, Score, score);
-implement_id_class(Request_id, Request, request);
-implement_id_class(Midi_def_id, Midi_def, mididef);
-implement_id_class(Paper_def_id, Paper_def, paperdef);
-
-Identifier::Identifier(Identifier const&)
+Idclass::accessor () {\
+ accessed_b_ = true;\
+ return (Class*)data_p_->clone();\
+}
+
+#define IMPLEMENT_ID_CLASS(Idclass, Class, accessor) \
+ IMPLEMENT_IS_TYPE_B1(Idclass,Identifier)\
+ Idclass::~Idclass() { delete data_p_; }\
+ Idclass::Idclass (Class*st, int code):Identifier (code) { data_p_ = st; }\
+
+
+IMPLEMENT_ID_CLASS(Input_translator_id, Input_translator, input_translator);
+IMPLEMENT_ID_CLASS(Int_id, int, intid);
+IMPLEMENT_ID_CLASS(Real_id, Real, real);
+IMPLEMENT_ID_CLASS(Script_id, General_script_def, script);
+IMPLEMENT_ID_CLASS(Lookup_id, Lookup, lookup);
+IMPLEMENT_ID_CLASS(Symtables_id, Symtables, symtables);
+IMPLEMENT_ID_CLASS(Music_id, Music, music);
+IMPLEMENT_ID_CLASS(Score_id, Score, score);
+IMPLEMENT_ID_CLASS(Request_id, Request, request);
+IMPLEMENT_ID_CLASS(Midi_def_id, Midi_def, mididef);
+IMPLEMENT_ID_CLASS(Paper_def_id, Paper_def, paperdef);
+
+Identifier::Identifier (Identifier const&)
{
- assert(false);
+ assert (false);
}
-default_accessor(Input_translator_id,Input_translator, input_translator);
-default_accessor(Int_id, int, intid);
-default_accessor(Real_id, Real, real);
-virtual_accessor(Script_id, General_script_def, script);
-default_accessor(Lookup_id, Lookup, lookup);
-default_accessor(Symtables_id, Symtables, symtables);
-virtual_accessor(Music_id, Music, music);
-default_accessor(Score_id, Score, score);
-virtual_accessor(Request_id, Request, request);
-default_accessor(Midi_def_id, Midi_def, mididef);
-default_accessor(Paper_def_id, Paper_def, paperdef);
+
+DEFAULT_ACCESSOR(Input_translator_id,Input_translator, input_translator);
+DEFAULT_ACCESSOR(Int_id, int, intid);
+DEFAULT_ACCESSOR(Real_id, Real, real);
+VIRTUAL_ACCESSOR(Script_id, General_script_def, script);
+DEFAULT_ACCESSOR(Lookup_id, Lookup, lookup);
+DEFAULT_ACCESSOR(Symtables_id, Symtables, symtables);
+VIRTUAL_ACCESSOR(Music_id, Music, music);
+DEFAULT_ACCESSOR(Score_id, Score, score);
+VIRTUAL_ACCESSOR(Request_id, Request, request);
+DEFAULT_ACCESSOR(Midi_def_id, Midi_def, mididef);
+DEFAULT_ACCESSOR(Paper_def_id, Paper_def, paperdef);
#include "input.hh"
#include "virtual-methods.hh"
-/* boolean argument to accesor is copy_b..*/
#define IDACCESSOR( Input_staff, staff)\
- virtual Input_staff * staff(bool) { error(#Input_staff); return 0; }
+ virtual Input_staff * staff () { error (#Input_staff); return 0; }
+/**
+ A declarable data structure in mudela.
+
+ */
struct Identifier : public Input {
- void *data;
- String name_str_;
bool init_b_;
bool accessed_b_;
int token_code_i_;
- Identifier(String n, int code) ;
+ Identifier (int code) ;
virtual ~Identifier() ;
void print()const;
DECLARE_MY_RUNTIME_TYPEINFO;
- void error(String);
+ void error (String);
IDACCESSOR(Input_translator, input_translator)
IDACCESSOR(Music, music)
IDACCESSOR(General_script_def, script)
protected:
virtual void do_print()const=0;
private:
- Identifier(Identifier const&);
+ Identifier (Identifier const&);
};
-#define declare_id_class(Idclass, Class, accessor) \
+#define DECLARE_ID_CLASS(Idclass, Class, accessor) \
struct Idclass : Identifier {\
+ Class *data_p_; \
DECLARE_MY_RUNTIME_TYPEINFO; \
- Idclass(String s, Class*st, int code);\
- virtual Class* accessor(bool copy);\
+ Idclass (Class*st, int code);\
+ virtual Class* accessor ();\
~Idclass();\
virtual void do_print()const; \
}\
-declare_id_class(Input_translator_id, Input_translator, input_translator);
-declare_id_class(Real_id, Real, real);
-declare_id_class(Script_id, General_script_def, script);
-declare_id_class(Lookup_id, Lookup, lookup);
-declare_id_class(Symtables_id, Symtables, symtables);
-declare_id_class(Music_id, Music, music);
-declare_id_class(Int_id, int, intid);
-declare_id_class(Score_id, Score, score);
-declare_id_class(Request_id, Request, request);
-declare_id_class(Paper_def_id,Paper_def, paperdef);
-declare_id_class(Midi_def_id,Midi_def, mididef);
+DECLARE_ID_CLASS(Input_translator_id, Input_translator, input_translator);
+DECLARE_ID_CLASS(Real_id, Real, real);
+DECLARE_ID_CLASS(Script_id, General_script_def, script);
+DECLARE_ID_CLASS(Lookup_id, Lookup, lookup);
+DECLARE_ID_CLASS(Symtables_id, Symtables, symtables);
+DECLARE_ID_CLASS(Music_id, Music, music);
+DECLARE_ID_CLASS(Int_id, int, intid);
+DECLARE_ID_CLASS(Score_id, Score, score);
+DECLARE_ID_CLASS(Request_id, Request, request);
+DECLARE_ID_CLASS(Paper_def_id,Paper_def, paperdef);
+DECLARE_ID_CLASS(Midi_def_id,Midi_def, mididef);
#endif // IDENTIFIER_
/// lexer for Mudela
class My_lily_lexer : public Includable_lexer {
- int lookup_keyword(String);
- int scan_bare_word(String);
- int scan_escaped_word(String);
+ int lookup_keyword (String);
+ int scan_bare_word (String);
+ int scan_escaped_word (String);
bool post_quotes_b_;
public:
/* *************** */
void clear_notenames();
- Identifier*lookup_identifier(String s);
- Melodic_req* lookup_melodic_req_l(String s);
+ Identifier*lookup_identifier (String s);
+ Melodic_req* lookup_melodic_req_l (String s);
void push_note_state();
void push_lyric_state();
void pop_state();
- void LexerError(char const *);
+ void LexerError (char const *);
My_lily_lexer();
- void add_identifier(Identifier*i);
+ void set_identifier (String,Identifier*i);
~My_lily_lexer();
int yylex();
- void print_declarations(bool init_b) const;
- void add_notename(String, Melodic_req*);
+ void print_declarations (bool init_b) const;
+ void add_notename (String, Melodic_req*);
bool note_state_b() const;
bool lyric_state_b() const;
};
My_lily_lexer::My_lily_lexer()
{
- keytable_p_ = new Keyword_table(the_key_tab);
+ keytable_p_ = new Keyword_table (the_key_tab);
identifier_assoc_p_ = new Assoc<String, Identifier*>;
errorlevel_i_ = 0;
post_quotes_b_ = false;
}
int
-My_lily_lexer::lookup_keyword(String s)
+My_lily_lexer::lookup_keyword (String s)
{
- return keytable_p_->lookup(s);
+ return keytable_p_->lookup (s);
}
Identifier*
-My_lily_lexer::lookup_identifier(String s)
+My_lily_lexer::lookup_identifier (String s)
{
- if (!identifier_assoc_p_->elt_b(s))
+ if (!identifier_assoc_p_->elt_b (s))
return 0;
return (*identifier_assoc_p_)[s];
void
-My_lily_lexer::add_identifier(Identifier*i)
+My_lily_lexer::set_identifier (String name_str, Identifier*i)
{
- delete lookup_identifier(i->name_str_);
- (*identifier_assoc_p_)[i->name_str_] = i;
+ Identifier *old = lookup_identifier (name_str);
+ if (old) {
+ old->warning( "redeclaration of \\" + name_str);
+ delete old;
+ }
+ (*identifier_assoc_p_)[name_str] = i;
}
My_lily_lexer::~My_lily_lexer()
delete keytable_p_;
for (Assoc_iter<String,Identifier*>
- ai(*identifier_assoc_p_); ai.ok(); ai++) {
- mtor << "deleting: " << ai.key()<<'\n';
+ ai (*identifier_assoc_p_); ai.ok(); ai++) {
+ DOUT << "deleting: " << ai.key()<<'\n';
delete ai.val();
}
delete note_tab_p_;
delete identifier_assoc_p_;
}
void
-My_lily_lexer::print_declarations(bool init_b)const
+My_lily_lexer::print_declarations (bool init_b)const
{
- for (Assoc_iter<String,Identifier*> ai(*identifier_assoc_p_); ai.ok();
+ for (Assoc_iter<String,Identifier*> ai (*identifier_assoc_p_); ai.ok();
ai++) {
- if (ai.val()->init_b_ == init_b)
- ai.val()->print();
+ if (ai.val()->init_b_ == init_b) {
+ DOUT << ai.key() << '=';
+ ai.val()->print ();
+ }
}
}
void
-My_lily_lexer::LexerError(char const *s)
+My_lily_lexer::LexerError (char const *s)
{
if (include_stack_.empty()) {
*mlog << "error at EOF" << s << '\n';
} else {
errorlevel_i_ |= 1;
- Input spot(source_file_l(),here_ch_C());
+ Input spot (source_file_l(),here_ch_C());
- spot.error( s );
+ spot.error (s);
}
}
Melodic_req*
-My_lily_lexer::lookup_melodic_req_l(String s)
+My_lily_lexer::lookup_melodic_req_l (String s)
{
- return note_tab_p_->get_l(s);
+ return note_tab_p_->get_l (s);
}
void
-My_lily_lexer::add_notename(String s, Melodic_req *p)
+My_lily_lexer::add_notename (String s, Melodic_req *p)
{
- note_tab_p_->add(s,p);
+ note_tab_p_->add (s,p);
}
void
%type <music> simple_element music_elt full_element lyrics_elt command_elt
%type <i> int
%type <i> script_dir
-%type <id> declaration
+%type <id> identifier_init
%type <duration> explicit_duration notemode_duration entered_notemode_duration
%type <interval> dinterval
%type <intvec> intastint_list
%type <score> score_block score_body
%type <script> script_definition script_body mudela_script gen_script_def
%type <textdef> text_def
-%type <string> declarable_identifier
%type <string> script_abbreviation
-%type <id> old_identifier
%type <symbol> symboldef
%type <symtable> symtable symtable_body
%type <itrans> input_translator_spec input_translator_spec_body
/*
DECLARATIONS
*/
-add_declaration: declaration {
- THIS->lexer_p_->add_identifier($1);
- $1->init_b_ = THIS->init_parse_b_;
- $1->set_spot(THIS->pop_spot());
- }
- ;
-declarable_identifier:
+add_declaration:
STRING {
THIS->remember_spot();
- $$ = $1;
}
- | old_identifier {
- THIS->remember_spot();
- $$ = new String($1->name_str_);
- THIS->here_input().warning("redeclaration of `" + *$$ + "'");
+ /* cont */ '=' identifier_init {
+ THIS->lexer_p_->set_identifier(*$1, $4);
+ $4->init_b_ = THIS->init_parse_b_;
+ $4->set_spot(THIS->pop_spot());
}
;
-
-
-old_identifier:
- IDENTIFIER
- | INPUT_TRANS_IDENTIFIER
- | MELODIC_REQUEST_IDENTIFIER
- | POST_REQUEST_IDENTIFIER
- | SCRIPT_IDENTIFIER
- | REAL_IDENTIFIER
- | SCORE_IDENTIFIER
- | REQUEST_IDENTIFIER
- ;
-
-declaration:
- declarable_identifier '=' score_block {
- $$ = new Score_id(*$1, $3, SCORE_IDENTIFIER);
- delete $1;
+identifier_init:
+ score_block {
+ $$ = new Score_id($1, SCORE_IDENTIFIER);
+
}
- | declarable_identifier '=' paper_block {
- $$ = new Paper_def_id(*$1, $3, PAPER_IDENTIFIER);
- delete $1;
+ | paper_block {
+ $$ = new Paper_def_id($1, PAPER_IDENTIFIER);
+
}
- | declarable_identifier '=' midi_block {
- $$ = new Midi_def_id(*$1, $3, MIDI_IDENTIFIER);
- delete $1;
+ | midi_block {
+ $$ = new Midi_def_id($1, MIDI_IDENTIFIER);
+
}
- | declarable_identifier '=' script_definition {
- $$ = new Script_id(*$1, $3, SCRIPT_IDENTIFIER);
- delete $1;
+ | script_definition {
+ $$ = new Script_id($1, SCRIPT_IDENTIFIER);
+
}
- | declarable_identifier '=' Music {
- $$ = new Music_id(*$1, $3, MUSIC_IDENTIFIER);
- delete $1;
+ | Music {
+ $$ = new Music_id($1, MUSIC_IDENTIFIER);
+
}
- | declarable_identifier '=' symtables {
- $$ = new Lookup_id(*$1, $3, IDENTIFIER);
- delete $1;
+ | symtables {
+ $$ = new Lookup_id($1, IDENTIFIER);
+
}
- | declarable_identifier '=' real {
- $$ = new Real_id(*$1, new Real($3), REAL_IDENTIFIER);
- delete $1;
+ | real {
+ $$ = new Real_id(new Real($1), REAL_IDENTIFIER);
+
}
- | declarable_identifier '=' int {
- $$ = new Int_id(*$1, new int($3), INT_IDENTIFIER);
- delete $1;
+ | int {
+ $$ = new Int_id(new int($1), INT_IDENTIFIER);
+
}
- | declarable_identifier '=' post_request {
- $$ = new Request_id(*$1, $3, POST_REQUEST_IDENTIFIER);
- delete $1;
+ | post_request {
+ $$ = new Request_id($1, POST_REQUEST_IDENTIFIER);
+
}
- | declarable_identifier '=' melodic_request {
- $$ = new Request_id(*$1, $3, MELODIC_REQUEST_IDENTIFIER);
- delete $1;
+ | melodic_request {
+ $$ = new Request_id($1, MELODIC_REQUEST_IDENTIFIER);
+
}
- | declarable_identifier '=' input_translator_spec {
- $$ = new Input_translator_id ( *$1, $3, INPUT_TRANS_IDENTIFIER);
- delete $1;
+ | input_translator_spec {
+ $$ = new Input_translator_id ( $1, INPUT_TRANS_IDENTIFIER);
}
;
input_translator_spec_body:
INPUT_TRANS_IDENTIFIER {
- $$ = $1->input_translator(true);
+ $$ = $1->input_translator();
$$-> set_spot( THIS->here_input() );
}
| STRING STRING {
$$ = new Score;
}
| SCORE_IDENTIFIER {
- $$ = $1->score(true);
+ $$ = $1->score();
}
| score_body Music {
$$->music_p_ = $2;
| Voice { $$ = $1; }
| Chord { $$ = $1; }
| transposed_music { $$ = $1; }
- | MUSIC_IDENTIFIER { $$ = $1->music(true); }
+ | MUSIC_IDENTIFIER { $$ = $1->music(); }
| MELODIC
{ THIS->lexer_p_->push_note_state(); }
Music
$$ = new Barcheck_req;
}
| COMMAND_IDENTIFIER {
- $$ = $1->request(true);
+ $$ = $1->request();
}
;
post_request:
POST_REQUEST_IDENTIFIER {
- $$ = (Request*)$1->request(true);
+ $$ = (Request*)$1->request();
}
|close_request_parens {
$$ = THIS->get_parens_request($1);
;
mudela_script:
- SCRIPT_IDENTIFIER { $$ = $1->script(true); }
+ SCRIPT_IDENTIFIER { $$ = $1->script(); }
| script_definition { $$ = $1; }
| script_abbreviation {
- $$ = THIS->lexer_p_->lookup_identifier(*$1)->script(true);
+ $$ = THIS->lexer_p_->lookup_identifier(*$1)->script();
delete $1;
}
;
$$ = $1;
}
| INT_IDENTIFIER {
- $$ = * $1->intid(0);
+ int *i_p = $1->intid();
+ $$ = *i_p;
+ delete i_p;
}
;
$$ = $1;
}
| REAL_IDENTIFIER {
- $$ = * $1->real(0);
+ Real *r_p = $1->real();
+ $$ = * r_p;
+ delete r_p;
}
;
$$ = new Lookup;
}
| IDENTIFIER {
- $$ = $1->lookup(true);
+ $$ = $1->lookup();
}
| symtables_body TEXID STRING {
$$->texsetting = *$3;
My_lily_parser::default_paper()
{
Identifier *id = lexer_p_->lookup_identifier( "default_paper" );
- return id ? id->paperdef(true) : new Paper_def ;
+ return id ? id->paperdef() : new Paper_def ;
}
Midi_def*
My_lily_parser::default_midi()
{
Identifier *id = lexer_p_->lookup_identifier( "default_midi" );
- return id ? id->mididef(true) : new Midi_def ;
+ return id ? id->mididef() : new Midi_def ;
}