1 %{ // -*-Fundamental-*-
9 #include "inputscore.hh"
12 #include "inputcommand.hh"
14 #include "parseconstruct.hh"
16 #include "identifier.hh"
22 svec<Request*> pre_reqs, post_reqs;
24 Paperdef*default_paper();
31 Input_command *command;
39 Music_general_chord *chord;
45 svec<String> * strvec;
46 svec<Input_command*> *commandvec;
51 Symtables * symtables;
57 Notename_tab *notename_tab;
62 %token VOICE STAFF SCORE TITLE BAR NOTENAME OUTPUT
63 %token CM IN PT MM PAPER WIDTH METER UNITSPACE SKIP COMMANDS
64 %token GEOMETRIC START_T DURATIONCOMMAND OCTAVECOMMAND
65 %token KEY CLEF VIOLIN BASS MULTI TABLE CHORD VOICES
66 %token PARTIAL RHYTHMIC MELODIC MUSIC GROUPING
67 %token END SYMBOLTABLES TEXID TABLE NOTENAMES SCRIPT TEXTSTYLE PLET
69 %token <id> IDENTIFIER
70 %token <string> NEWIDENTIFIER
71 %token <string> PITCHMOD DURATION RESTNAME
74 %token <string> STRING
75 %token <c> OPEN_REQUEST_PARENS CLOSE_REQUEST_PARENS
78 %type <intvec> pitch_list
80 %type <id> declaration
81 %type <string> declarable_identifier
82 %type <paper> paper_block paper_body
85 %type <real> duration_length
86 %type <el> voice_elt full_element
87 %type <command> score_command staff_command skipcommand
88 %type <score> score_block score_body
89 %type <staff> staff_block staff_init staff_body
91 %type <intvec> int_list
92 %type <commandvec> score_commands_block score_commands_body
93 %type <commandvec> staff_commands_block staff_commands_body
94 %type <request> post_request pre_request
95 %type <string> clef_id pitchmod
97 %type <chord> music_chord music_chord_body
99 %type <mvoice> music_voice_body music_voice
101 %type <interval> dinterval
103 %type <symtable> symtable symtable_body
104 %type <lookup> symtables symtables_body
105 %type <symbol> symboldef
106 %type <notename_tab> notename_tab notename_tab_body
108 %type <script> script_definition script_body mudela_script
109 %type <request> script_req textscript_req
110 %type <textdef> mudela_text
116 | mudela score_block {
119 | mudela add_declaration { }
120 | mudela mudela_command {}
124 notename_tab { lexer->set($1); }
130 add_declaration: declaration {
131 lexer->add_identifier($1);
135 declarable_identifier:
136 NEWIDENTIFIER { $$ = $1; }
137 | IDENTIFIER { $$ = new String($1->name); }
141 declarable_identifier '=' staff_block {
142 $$ = new Staff_id(*$1, $3);
143 delete $1; // this sux
145 | declarable_identifier '=' music_voice {
146 $$ = new M_voice_id(*$1, $3);
149 | declarable_identifier '=' script_definition {
150 $$ = new Script_id(*$1, $3);
153 | declarable_identifier '=' music_chord {
154 $$ = new M_chord_id(*$1, $3);
157 | declarable_identifier '=' symtables {
158 $$ = new Lookup_id(*$1, $3);
161 | declarable_identifier '=' notename_tab {
162 $$ = new Notetab_id(*$1, $3);
168 NOTENAMES '{' notename_tab_body '}' { $$ = $3; }
172 $$ = new Notename_tab;
175 $$ = $1->notename_tab(true);
177 | notename_tab_body STRING int int {
178 $$->set($3, $4, *$2);
186 score_block: SCORE '{' score_body '}' { $$ = $3;
188 $$->paper_ = default_paper();
192 score_body: { $$ = new Input_score; }
193 | score_body staff_block { $$->add($2); }
194 | score_body score_commands_block {
198 | score_body paper_block { $$->set($2); }
203 score_commands_block:
204 COMMANDS '{' score_commands_body '}' { $$ =$3;}
207 score_commands_body: { $$ = new svec<Input_command*>; }
208 | score_commands_body score_command {
213 staff_commands_block: COMMANDS '{' staff_commands_body '}' {
218 /* empty */ { $$ = new svec<Input_command*>; }
219 | staff_commands_body staff_command {
226 | KEY pitch_list {/*UGH*/
227 $$ = get_key_interpret_command(*$2);
231 $$ = get_clef_interpret_command(*$2);
238 $$ = wholes($1[0], $1[1]);
243 SKIP int ':' duration_length {
244 $$ = get_skip_command($2, $4);
250 $$ = get_meterchange_command($2, $3);
252 | PARTIAL duration_length {
253 $$ = get_partial_command($2);
255 | GROUPING int_list {
256 $$ = get_grouping_command(*$2);
267 PAPER '{' paper_body '}' { $$ = $3; }
272 $$ = default_paper();
274 | paper_body WIDTH dim { $$->linewidth = $3;}
275 | paper_body OUTPUT STRING { $$->outfile = *$3;
278 | paper_body symtables { $$->set($2); }
279 | paper_body UNITSPACE dim { $$->whole_width = $3; }
280 | paper_body GEOMETRIC REAL { $$->geometric_ = $3; }
287 STAFF '{' staff_body '}' { $$ = $3; }
293 IDENTIFIER { $$ = $1->staff(true); }
295 $$ = new Input_staff("rhythmic");
298 $$ = new Input_staff( "melodic");
307 | staff_body staff_commands_block {
317 music_voice { $$ = $1; }
318 | music_chord { $$ = $1; }
321 music_voice: MUSIC '{' music_voice_body '}' { $$ = $3; }
325 $$ = new Music_voice;
327 | music_voice_body IDENTIFIER {
328 $$->concatenate($2->mvoice());
330 | music_voice_body full_element {
333 | music_voice_body voice_command {
335 | music_voice_body music {
341 music_chord: '{' music_chord_body '}' { $$ = $2; }
345 $$ = new Music_general_chord;
347 | music_chord_body IDENTIFIER {
348 $$->concatenate($2->mchord());
350 | music_chord_body music {
353 | music_chord_body full_element {
363 full_element: pre_requests voice_elt post_requests {
364 add_requests($2, pre_reqs);
365 add_requests($2, post_reqs);
372 assert(post_reqs.empty());
374 | post_requests post_request {
380 CLOSE_REQUEST_PARENS { $$ = get_request($1); }
386 SCRIPT '{' script_body '}' { $$ = $3; }
391 $$ = new Script_def(*$1,$2, $3,$4);
397 script_dir mudela_text { $$ = get_text_req($1,$2); }
401 STRING { $$ = get_text(*$1); delete $1; }
405 script_dir mudela_script { $$ = get_script_req($1, $2); }
409 IDENTIFIER { $$ = $1->script(true); }
410 | script_definition { $$ = $1; }
411 | '^' { $$ = get_scriptdef('^'); }
412 | '+' { $$ = get_scriptdef('+'); }
413 | '-' { $$ = get_scriptdef('-'); }
414 | '|' { $$ = get_scriptdef('|'); }
415 | 'o' { $$ = get_scriptdef('o'); }
416 | '>' { $$ = get_scriptdef('>'); }
417 | '.' { $$ = get_scriptdef('.'); }
419 if ($1>1) error("too many staccato reqs");
420 $$ = get_scriptdef('.');
431 | pre_requests pre_request {
437 OPEN_REQUEST_PARENS { $$ = get_request($1); }
443 PLET '{' INT '/' INT '}' {
446 | DURATIONCOMMAND '{' duration '}' {
447 set_default_duration($3);
449 | OCTAVECOMMAND '{' pitchmod '}' {
450 set_default_octave(*$3);
460 get_default_duration($$);
463 get_default_duration($$);
472 pitchmod: { $$ = new String; }
477 pitchmod NOTENAME duration {
478 $$ = get_note_element(*$1, $2, $3);
481 | RESTNAME duration {
482 $$ = get_rest_element(*$1, $2);
494 | pitch_list NOTENAME {
503 if ( distance($1,Real(int($$)) ) > 1e-8)
504 error("expecting integer number");
519 REAL unit { $$ = convert_dimen($1,$2); }
523 unit: CM { $$ = "cm"; }
530 VIOLIN { $$ = new String("violin"); }
531 | BASS { $$ = new String("bass"); }
537 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
545 $$ = new Lookup(*$1->lookup(true));
547 | symtables_body TEXID STRING {
548 $$->texsetting = *$3;
551 | symtables_body STRING '=' symtable {
558 TABLE '{' symtable_body '}' { $$ = $3; }
562 { $$ = new Symtable; }
563 | symtable_body STRING symboldef {
572 $$ = new Symbol(*$1, *$2);
578 $$ = new Symbol(*$1, b);
584 dinterval dinterval {
585 $$ = new Box(*$1, *$2);
592 $$ = new Interval($1, $2);
601 *mlog << "Parsing ... ";
604 yydebug = !monitor.silence("Parser") && check_debug;
608 lexer->new_input("symbol.ini");
619 lexer->lookup_identifier("default_table")->lookup(true));