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;
23 Paperdef*default_paper();
30 Input_command *command;
38 Music_general_chord *chord;
44 Array<String> * strvec;
45 Array<Input_command*> *commandvec;
50 Symtables * symtables;
56 Notename_tab *notename_tab;
61 %token VOICE STAFF SCORE TITLE BAR NOTENAME OUTPUT
62 %token CM IN PT MM PAPER WIDTH METER UNITSPACE SKIP COMMANDS
63 %token GEOMETRIC START_T DURATIONCOMMAND OCTAVECOMMAND
64 %token KEY CLEF VIOLIN BASS MULTI TABLE CHORD VOICES
65 %token PARTIAL RHYTHMIC MELODIC MUSIC GROUPING
66 %token END SYMBOLTABLES TEXID TABLE NOTENAMES SCRIPT TEXTSTYLE PLET
68 %token <id> IDENTIFIER
69 %token <string> NEWIDENTIFIER
70 %token <string> PITCHMOD DURATION RESTNAME
73 %token <string> STRING
77 %type <intvec> pitch_list
78 %type <c> open_request_parens close_request_parens
79 %type <id> declaration
80 %type <string> declarable_identifier
81 %type <paper> paper_block paper_body
84 %type <real> duration_length
85 %type <el> voice_elt full_element
86 %type <command> score_command staff_command skipcommand
87 %type <score> score_block score_body
88 %type <staff> staff_block staff_init staff_body
90 %type <intvec> int_list
91 %type <commandvec> score_commands_block score_commands_body
92 %type <commandvec> staff_commands_block staff_commands_body
93 %type <request> post_request pre_request
94 %type <string> clef_id pitchmod
96 %type <chord> music_chord music_chord_body
98 %type <mvoice> music_voice_body music_voice
100 %type <interval> dinterval
102 %type <symtable> symtable symtable_body
103 %type <lookup> symtables symtables_body
104 %type <symbol> symboldef
105 %type <notename_tab> notename_tab notename_tab_body
107 %type <script> script_definition script_body mudela_script
108 %type <request> script_req textscript_req
109 %type <textdef> mudela_text
115 | mudela score_block {
118 | mudela add_declaration { }
119 | mudela mudela_command {}
123 notename_tab { lexer->set($1); }
129 add_declaration: declaration {
130 lexer->add_identifier($1);
134 declarable_identifier:
135 NEWIDENTIFIER { $$ = $1; }
136 | IDENTIFIER { $$ = new String($1->name); }
140 declarable_identifier '=' staff_block {
141 $$ = new Staff_id(*$1, $3);
142 delete $1; // this sux
144 | declarable_identifier '=' music_voice {
145 $$ = new M_voice_id(*$1, $3);
148 | declarable_identifier '=' script_definition {
149 $$ = new Script_id(*$1, $3);
152 | declarable_identifier '=' music_chord {
153 $$ = new M_chord_id(*$1, $3);
156 | declarable_identifier '=' symtables {
157 $$ = new Lookup_id(*$1, $3);
160 | declarable_identifier '=' notename_tab {
161 $$ = new Notetab_id(*$1, $3);
167 NOTENAMES '{' notename_tab_body '}' { $$ = $3; }
171 $$ = new Notename_tab;
174 $$ = $1->notename_tab(true);
176 | notename_tab_body STRING int int {
177 $$->set($3, $4, *$2);
185 score_block: SCORE '{' score_body '}' { $$ = $3;
187 $$->paper_ = default_paper();
191 score_body: { $$ = new Input_score; }
192 | score_body staff_block { $$->add($2); }
193 | score_body score_commands_block {
197 | score_body paper_block { $$->set($2); }
202 score_commands_block:
203 COMMANDS '{' score_commands_body '}' { $$ =$3;}
206 score_commands_body: { $$ = new Array<Input_command*>; }
207 | score_commands_body score_command {
212 staff_commands_block: COMMANDS '{' staff_commands_body '}' {
217 /* empty */ { $$ = new Array<Input_command*>; }
218 | staff_commands_body staff_command {
225 | KEY pitch_list {/*UGH*/
226 $$ = get_key_interpret_command(*$2);
230 $$ = get_clef_interpret_command(*$2);
237 $$ = wholes($1[0], $1[1]);
242 SKIP int ':' duration_length {
243 $$ = get_skip_command($2, $4);
249 $$ = get_bar_command(*$2);
253 $$ = get_meterchange_command($2, $3);
255 | PARTIAL duration_length {
256 $$ = get_partial_command($2);
258 | GROUPING int_list {
259 $$ = get_grouping_command(*$2);
270 PAPER '{' paper_body '}' { $$ = $3; }
275 $$ = default_paper();
277 | paper_body WIDTH dim { $$->linewidth = $3;}
278 | paper_body OUTPUT STRING { $$->outfile = *$3;
281 | paper_body symtables { $$->set($2); }
282 | paper_body UNITSPACE dim { $$->whole_width = $3; }
283 | paper_body GEOMETRIC REAL { $$->geometric_ = $3; }
290 STAFF '{' staff_body '}' { $$ = $3; }
296 IDENTIFIER { $$ = $1->staff(true); }
298 $$ = new Input_staff("rhythmic");
301 $$ = new Input_staff( "melodic");
310 | staff_body staff_commands_block {
320 music_voice { $$ = $1; }
321 | music_chord { $$ = $1; }
324 music_voice: MUSIC '{' music_voice_body '}' { $$ = $3; }
328 $$ = new Music_voice;
330 | music_voice_body IDENTIFIER {
331 $$->concatenate($2->mvoice());
333 | music_voice_body full_element {
336 | music_voice_body voice_command {
338 | music_voice_body music {
344 music_chord: '{' music_chord_body '}' { $$ = $2; }
348 $$ = new Music_general_chord;
350 | music_chord_body IDENTIFIER {
351 $$->concatenate($2->mchord());
353 | music_chord_body music {
356 | music_chord_body full_element {
366 full_element: pre_requests voice_elt post_requests {
367 add_requests($2, pre_reqs);
368 add_requests($2, post_reqs);
375 assert(post_reqs.empty());
377 | post_requests post_request {
383 close_request_parens { $$ = get_request($1); }
387 close_request_parens:
399 SCRIPT '{' script_body '}' { $$ = $3; }
404 $$ = new Script_def(*$1,$2, $3,$4);
410 script_dir mudela_text { $$ = get_text_req($1,$2); }
414 STRING { $$ = get_text(*$1); delete $1; }
418 script_dir mudela_script { $$ = get_script_req($1, $2); }
422 IDENTIFIER { $$ = $1->script(true); }
423 | script_definition { $$ = $1; }
424 | '^' { $$ = get_scriptdef('^'); }
425 | '+' { $$ = get_scriptdef('+'); }
426 | '-' { $$ = get_scriptdef('-'); }
427 | '|' { $$ = get_scriptdef('|'); }
428 | 'o' { $$ = get_scriptdef('o'); }
429 | '>' { $$ = get_scriptdef('>'); }
430 | '.' { $$ = get_scriptdef('.'); }
432 if ($1>1) error("too many staccato reqs");
433 $$ = get_scriptdef('.');
444 | pre_requests pre_request {
450 open_request_parens { $$ = get_request($1); }
456 PLET '{' INT '/' INT '}' {
459 | DURATIONCOMMAND '{' duration '}' {
460 set_default_duration($3);
462 | OCTAVECOMMAND '{' pitchmod '}' {
463 set_default_octave(*$3);
473 get_default_duration($$);
476 get_default_duration($$);
485 pitchmod: { $$ = new String; }
490 pitchmod NOTENAME duration {
491 $$ = get_note_element(*$1, $2, $3);
494 | RESTNAME duration {
495 $$ = get_rest_element(*$1, $2);
507 | pitch_list NOTENAME {
516 if ( distance($1,Real(int($$)) ) > 1e-8)
517 error("expecting integer number");
532 REAL unit { $$ = convert_dimen($1,$2); }
536 unit: CM { $$ = "cm"; }
543 VIOLIN { $$ = new String("violin"); }
544 | BASS { $$ = new String("bass"); }
550 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
558 $$ = new Lookup(*$1->lookup(true));
560 | symtables_body TEXID STRING {
561 $$->texsetting = *$3;
564 | symtables_body STRING '=' symtable {
571 TABLE '{' symtable_body '}' { $$ = $3; }
575 { $$ = new Symtable; }
576 | symtable_body STRING symboldef {
585 $$ = new Symbol(*$1, *$2);
591 $$ = new Symbol(*$1, b);
597 dinterval dinterval {
598 $$ = new Box(*$1, *$2);
605 $$ = new Interval($1, $2);
614 *mlog << "Parsing ... ";
617 yydebug = !monitor.silence("Parser") && check_debug;
621 lexer->new_input("symbol.ini");
632 lexer->lookup_identifier("default_table")->lookup(true));