1 %{ // -*-Fundamental-*-
8 #include "inputscore.hh"
11 #include "inputcommand.hh"
13 #include "parseconstruct.hh"
15 #include "identifier.hh"
21 Array<Request*> pre_reqs, post_reqs;
22 sstack<String> define_spots;
24 Paperdef*default_paper();
31 Input_command *command;
39 Music_general_chord *chord;
46 Array<String> * strvec;
47 Array<Input_command*> *commandvec;
52 Symtables * symtables;
58 Notename_tab *notename_tab;
63 %token VOICE STAFF SCORE TITLE BAR NOTENAME OUTPUT
64 %token CM IN PT MM PAPER WIDTH METER UNITSPACE SKIP COMMANDS
65 %token GEOMETRIC START_T DURATIONCOMMAND OCTAVECOMMAND
66 %token KEY CLEF VIOLIN BASS MULTI TABLE CHORD VOICES
67 %token PARTIAL RHYTHMIC MELODIC MUSIC GROUPING CADENZA
68 %token END SYMBOLTABLES TEXID TABLE NOTENAMES SCRIPT TEXTSTYLE PLET
71 %token <id> IDENTIFIER
72 %token <string> NEWIDENTIFIER
73 %token <string> PITCHMOD DURATION RESTNAME
76 %token <string> STRING
80 %type <intvec> pitch_list
81 %type <c> open_request_parens close_request_parens
82 %type <id> declaration
83 %type <string> declarable_identifier
84 %type <paper> paper_block paper_body
87 %type <moment> duration_length
88 %type <el> voice_elt full_element
89 %type <command> score_command staff_command skipcommand
90 %type <score> score_block score_body
91 %type <staff> staff_block staff_init staff_body
93 %type <intvec> int_list
94 %type <commandvec> score_commands_block score_commands_body
95 %type <commandvec> staff_commands_block staff_commands_body
96 %type <request> post_request pre_request
97 %type <string> clef_id pitchmod
99 %type <chord> music_chord music_chord_body
101 %type <mvoice> music_voice_body music_voice
103 %type <interval> dinterval
105 %type <symtable> symtable symtable_body
106 %type <lookup> symtables symtables_body
107 %type <symbol> symboldef
108 %type <notename_tab> notename_tab notename_tab_body
110 %type <script> script_definition script_body mudela_script
111 %type <request> script_req textscript_req
112 %type <textdef> mudela_text
118 | mudela score_block {
121 | mudela add_declaration { }
122 | mudela mudela_command {}
126 notename_tab { lexer->set($1); }
132 add_declaration: declaration {
133 lexer->add_identifier($1);
137 declarable_identifier:
138 NEWIDENTIFIER { $$ = $1; }
139 | IDENTIFIER { $$ = new String($1->name); }
143 declarable_identifier '=' staff_block {
144 $$ = new Staff_id(*$1, $3);
145 delete $1; // this sux
147 | declarable_identifier '=' music_voice {
148 $$ = new M_voice_id(*$1, $3);
151 | declarable_identifier '=' script_definition {
152 $$ = new Script_id(*$1, $3);
155 | declarable_identifier '=' music_chord {
156 $$ = new M_chord_id(*$1, $3);
159 | declarable_identifier '=' symtables {
160 $$ = new Lookup_id(*$1, $3);
163 | declarable_identifier '=' notename_tab {
164 $$ = new Notetab_id(*$1, $3);
170 NOTENAMES '{' notename_tab_body '}' { $$ = $3; }
174 $$ = new Notename_tab;
177 $$ = $1->notename_tab(true);
179 | notename_tab_body STRING int int {
180 $$->set($3, $4, *$2);
189 { define_spots.push(lexer->spot()); }
192 $$->define_spot_str_ = define_spots.pop();
194 $$->paper_ = default_paper();
198 score_body: { $$ = new Input_score; }
199 | score_body staff_block { $$->add($2); }
200 | score_body score_commands_block {
204 | score_body paper_block { $$->set($2); }
209 score_commands_block:
210 COMMANDS '{' score_commands_body '}' { $$ =$3;}
213 score_commands_body: { $$ = new Array<Input_command*>; }
214 | score_commands_body score_command {
219 staff_commands_block: COMMANDS '{' staff_commands_body '}' {
224 /* empty */ { $$ = new Array<Input_command*>; }
225 | staff_commands_body staff_command {
232 | KEY pitch_list {/*UGH*/
233 $$ = get_key_interpret_command(*$2);
237 $$ = get_clef_interpret_command(*$2);
244 $$ = new Moment(wholes($1[0], $1[1]));
247 $$ = new Moment($1 * wholes($3[0], $3[1]));
252 SKIP int ':' duration_length {
253 $$ = get_skip_command($2, *$4);
257 $$ = get_goto_command(*$2);
264 $$ = get_bar_command(*$2);
267 | METER int '*' int {
268 $$ = get_meterchange_command($2, $4);
270 | PARTIAL duration_length {
271 $$ = get_partial_command(*$2);
274 | GROUPING int_list {
275 $$ = get_grouping_command(*$2);
279 $$ = get_cadenza_toggle($2);
291 '{' paper_body '}' { $$ = $3; }
296 $$ = default_paper();
298 | paper_body WIDTH dim { $$->linewidth = $3;}
299 | paper_body OUTPUT STRING { $$->outfile = *$3;
302 | paper_body symtables { $$->set($2); }
303 | paper_body UNITSPACE dim { $$->whole_width = $3; }
304 | paper_body GEOMETRIC REAL { $$->geometric_ = $3; }
311 STAFF { define_spots.push(lexer->spot()); }
312 /*cont*/ '{' staff_body '}' {
314 $$->define_spot_str_ = define_spots.pop();
321 IDENTIFIER { $$ = $1->staff(true); }
323 $$ = new Input_staff("rhythmic");
326 $$ = new Input_staff( "melodic");
335 | staff_body staff_commands_block {
345 music_voice { $$ = $1; }
346 | music_chord { $$ = $1; }
349 music_voice: MUSIC '{' music_voice_body '}' { $$ = $3; }
353 $$ = new Music_voice;
355 | music_voice_body IDENTIFIER {
356 $$->concatenate($2->mvoice());
358 | music_voice_body full_element {
361 | music_voice_body voice_command {
363 | music_voice_body music {
369 music_chord: '{' music_chord_body '}' { $$ = $2; }
373 $$ = new Music_general_chord;
375 | music_chord_body IDENTIFIER {
376 $$->concatenate($2->mchord());
378 | music_chord_body music {
381 | music_chord_body full_element {
391 full_element: pre_requests voice_elt post_requests {
392 add_requests($2, pre_reqs);
393 add_requests($2, post_reqs);
400 assert(post_reqs.empty());
402 | post_requests post_request {
408 close_request_parens { $$ = get_request($1); }
412 close_request_parens:
424 SCRIPT '{' script_body '}' { $$ = $3; }
429 $$ = new Script_def(*$1,$2, $3,$4);
435 script_dir mudela_text { $$ = get_text_req($1,$2); }
439 STRING { $$ = get_text(*$1); delete $1; }
443 script_dir mudela_script { $$ = get_script_req($1, $2); }
447 IDENTIFIER { $$ = $1->script(true); }
448 | script_definition { $$ = $1; }
449 | '^' { $$ = get_scriptdef('^'); }
450 | '+' { $$ = get_scriptdef('+'); }
451 | '-' { $$ = get_scriptdef('-'); }
452 | '|' { $$ = get_scriptdef('|'); }
453 | 'o' { $$ = get_scriptdef('o'); }
454 | '>' { $$ = get_scriptdef('>'); }
455 | '.' { $$ = get_scriptdef('.'); }
457 if ($1>1) error("too many staccato reqs");
458 $$ = get_scriptdef('.');
469 | pre_requests pre_request {
475 open_request_parens { $$ = get_request($1); }
481 PLET '{' INT '/' INT '}' {
484 | DURATIONCOMMAND '{' duration '}' {
485 set_default_duration($3);
487 | OCTAVECOMMAND '{' pitchmod '}' {
488 set_default_octave(*$3);
498 get_default_duration($$);
501 get_default_duration($$);
510 get_default_duration($$);
515 pitchmod: { $$ = new String; }
520 pitchmod NOTENAME duration {
521 $$ = get_note_element(*$1, $2, $3);
524 | RESTNAME duration {
525 $$ = get_rest_element(*$1, $2);
530 $$ = get_mark_element(*$2);
541 | pitch_list NOTENAME {
550 if ( distance($1,Real(int($$)) ) > 1e-8)
551 error("expecting integer number");
566 REAL unit { $$ = convert_dimen($1,$2); }
570 unit: CM { $$ = "cm"; }
577 VIOLIN { $$ = new String("violin"); }
578 | BASS { $$ = new String("bass"); }
584 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
592 $$ = new Lookup(*$1->lookup(true));
594 | symtables_body TEXID STRING {
595 $$->texsetting = *$3;
598 | symtables_body STRING '=' symtable {
605 TABLE '{' symtable_body '}' { $$ = $3; }
609 { $$ = new Symtable; }
610 | symtable_body STRING symboldef {
619 $$ = new Symbol(*$1, *$2);
625 $$ = new Symbol(*$1, b);
631 dinterval dinterval {
632 $$ = new Box(*$1, *$2);
639 $$ = new Interval($1, $2);
648 *mlog << "Parsing ... ";
651 yydebug = !monitor.silence("Parser") && check_debug;
655 lexer->new_input("symbol.ini");
660 assert(define_spots.empty());
667 lexer->lookup_identifier("default_table")->lookup(true));