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 COMMAND
65 %token GEOMETRIC START_T DURATIONCOMMAND OCTAVECOMMAND
66 o%token KEY CLEF MULTI TABLE CHORD VOICES
67 %token PARTIAL RHYTHMIC MELODIC MUSIC LYRIC 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 lyrics_elt
89 %type <command> score_command staff_command position_command
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> 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 {
217 | score_commands_body position_command {
222 staff_commands_block: COMMANDS '{' staff_commands_body '}' {
227 /* empty */ { $$ = new Array<Input_command*>; }
228 | staff_commands_body staff_command {
231 | staff_commands_body position_command {
237 KEY pitch_list {/*UGH*/
238 $$ = get_key_interpret_command(*$2);
242 $$ = get_clef_interpret_command(*$2);
249 $$ = new Moment(wholes($1[0], $1[1]));
252 $$ = new Moment($1 * wholes($3[0], $3[1]));
257 SKIP int ':' duration_length {
258 $$ = get_skip_command($2, *$4);
262 $$ = get_goto_command(*$2);
269 $$ = get_bar_command(*$2);
272 | METER int '*' int {
273 $$ = get_meterchange_command($2, $4);
275 | PARTIAL duration_length {
276 $$ = get_partial_command(*$2);
279 | GROUPING int_list {
280 $$ = get_grouping_command(*$2);
284 $$ = get_cadenza_toggle($2);
296 '{' paper_body '}' { $$ = $3; }
301 $$ = default_paper();
303 | paper_body WIDTH dim { $$->linewidth = $3;}
304 | paper_body OUTPUT STRING { $$->outfile = *$3;
307 | paper_body symtables { $$->set($2); }
308 | paper_body UNITSPACE dim { $$->whole_width = $3; }
309 | paper_body GEOMETRIC REAL { $$->geometric_ = $3; }
316 STAFF { define_spots.push(lexer->spot()); }
317 /*cont*/ '{' staff_body '}' {
319 $$->define_spot_str_ = define_spots.pop();
326 IDENTIFIER { $$ = $1->staff(true); }
328 $$ = new Input_staff("rhythmic");
331 $$ = new Input_staff( "melodic");
334 $$ = new Input_staff( "lyric");
343 | staff_body staff_commands_block {
353 music_voice { $$ = $1; }
354 | music_chord { $$ = $1; }
357 music_voice: MUSIC '{' music_voice_body '}' { $$ = $3; }
361 $$ = new Music_voice;
363 | music_voice_body IDENTIFIER {
364 $$->concatenate($2->mvoice());
366 | music_voice_body full_element {
369 | music_voice_body voice_command {
371 | music_voice_body music {
376 music_chord: '{' music_chord_body '}' { $$ = $2; }
380 $$ = new Music_general_chord;
382 | music_chord_body IDENTIFIER {
383 $$->concatenate($2->mchord());
385 | music_chord_body music {
388 | music_chord_body full_element {
398 full_element: pre_requests voice_elt post_requests {
399 add_requests($2, pre_reqs);
400 add_requests($2, post_reqs);
404 $$ = get_mark_element(*$2);
407 | COMMAND '{' staff_command '}' { $$=get_command_element($3); }
408 | COMMAND '{' score_command '}' { $$=get_command_element($3); }
409 | '|' { $$ = get_barcheck_element(); }
415 assert(post_reqs.empty());
417 | post_requests post_request {
423 close_request_parens { $$ = get_request($1); }
427 close_request_parens:
438 SCRIPT '{' script_body '}' { $$ = $3; }
443 $$ = new Script_def(*$1,$2, $3,$4);
449 script_dir mudela_text { $$ = get_text_req($1,$2); }
453 STRING { $$ = get_text(*$1); delete $1; }
457 script_dir mudela_script { $$ = get_script_req($1, $2); }
461 IDENTIFIER { $$ = $1->script(true); }
462 | script_definition { $$ = $1; }
463 | '^' { $$ = get_scriptdef('^'); }
464 | '+' { $$ = get_scriptdef('+'); }
465 | '-' { $$ = get_scriptdef('-'); }
466 | '|' { $$ = get_scriptdef('|'); }
467 | 'o' { $$ = get_scriptdef('o'); }
468 | '>' { $$ = get_scriptdef('>'); }
469 | '.' { $$ = get_scriptdef('.'); }
471 if ($1>1) error("too many staccato reqs");
472 $$ = get_scriptdef('.');
483 | pre_requests pre_request {
489 open_request_parens { $$ = get_request($1); }
495 PLET '{' INT '/' INT '}' {
498 | DURATIONCOMMAND '{' duration '}' {
499 set_default_duration($3);
501 | OCTAVECOMMAND '{' pitchmod '}' {
502 set_default_octave(*$3);
512 get_default_duration($$);
515 get_default_duration($$);
524 get_default_duration($$);
529 pitchmod: { $$ = new String; }
534 pitchmod NOTENAME duration {
535 $$ = get_note_element(*$1, $2, $3);
538 | RESTNAME duration {
539 $$ = get_rest_element(*$1, $2);
546 mudela_text duration {
547 $$ = get_word_element($1, $2);
556 | pitch_list NOTENAME {
565 if ( distance($1,Real(int($$)) ) > 1e-8)
566 error("expecting integer number");
581 REAL unit { $$ = convert_dimen($1,$2); }
585 unit: CM { $$ = "cm"; }
595 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
603 $$ = new Lookup(*$1->lookup(true));
605 | symtables_body TEXID STRING {
606 $$->texsetting = *$3;
609 | symtables_body STRING '=' symtable {
616 TABLE '{' symtable_body '}' { $$ = $3; }
620 { $$ = new Symtable; }
621 | symtable_body STRING symboldef {
630 $$ = new Symbol(*$1, *$2);
636 $$ = new Symbol(*$1, b);
642 dinterval dinterval {
643 $$ = new Box(*$1, *$2);
650 $$ = new Interval($1, $2);
659 *mlog << "Parsing ... ";
662 yydebug = !monitor.silence("InitParser") && check_debug;
666 lexer->new_input("symbol.ini");
670 yydebug = !monitor.silence("Parser") && check_debug;
676 assert(define_spots.empty());
683 lexer->lookup_identifier("default_table")->lookup(true));