1 %{ // -*-Fundamental-*-
9 #include "inputscore.hh"
13 #include "parseconstruct.hh"
15 #include "identifier.hh"
16 #include "commandrequest.hh"
17 #include "musicalrequest.hh"
23 Array<Request*> pre_reqs, post_reqs;
24 Array<const char *> define_spots;
25 Paperdef*default_paper();
26 char const* defined_ch_c_l;
27 char const* req_defined_ch_c_l;
28 int fatal_error_i = 0;
44 Music_general_chord *chord;
51 Array<String> * strvec;
53 Array<Melodic_req*> *melreqvec;
56 Symtables * symtables;
62 Notename_tab *notename_tab;
67 %token VOICE STAFF SCORE TITLE BAR OUTPUT MULTIVOICE
68 %token CM_T IN_T PT_T MM_T PAPER WIDTH METER UNITSPACE SKIP COMMANDS COMMAND
69 %token GEOMETRIC START_T DURATIONCOMMAND OCTAVECOMMAND
70 %token KEY CLEF TABLE VOICES STEM
71 %token PARTIAL MUSIC GROUPING CADENZA
72 %token END SYMBOLTABLES TEXID TABLE NOTENAMES SCRIPT TEXTSTYLE PLET
76 %token <id> IDENTIFIER
77 %token <string> PITCHMOD DURATION RESTNAME
80 %token <string> STRING
84 %type <melreqvec> pitch_list
85 %type <c> open_request_parens close_request_parens close_plet_parens
86 %type <id> declaration
87 %type <string> declarable_identifier
88 %type <paper> paper_block paper_body
89 %type <midi> midi_block midi_body
91 %type <ii> default_duration explicit_duration notemode_duration mudela_duration
93 %type <moment> duration_length
94 %type <el> voice_elt full_element lyrics_elt command_elt
96 %type <score> score_block score_body
97 %type <staff> staff_block staff_init staff_body
99 %type <intvec> intastint_list
100 %type <request> post_request pre_request command_req
101 %type <string> pitchmod
103 %type <chord> music_chord music_chord_body
105 %type <mvoice> music_voice_body music_voice
107 %type <interval> dinterval
109 %type <symtable> symtable symtable_body
110 %type <lookup> symtables symtables_body
111 %type <symbol> symboldef
112 %type <notename_tab> notename_tab notename_tab_body
114 %type <script> script_definition script_body mudela_script
115 %type <request> script_req textscript_req
116 %type <textdef> mudela_text
122 | mudela score_block {
125 | mudela add_declaration { }
126 | mudela mudela_command {}
130 notename_tab { lexer->set($1); }
136 add_declaration: declaration {
137 lexer->add_identifier($1);
141 declarable_identifier:
143 | IDENTIFIER { $$ = new String($1->name); }
147 declarable_identifier '=' staff_block {
148 $$ = new Staff_id(*$1, $3);
151 | declarable_identifier '=' music_voice {
152 $$ = new M_voice_id(*$1, $3);
155 | declarable_identifier '=' script_definition {
156 $$ = new Script_id(*$1, $3);
159 | declarable_identifier '=' music_chord {
160 $$ = new M_chord_id(*$1, $3);
163 | declarable_identifier '=' symtables {
164 $$ = new Lookup_id(*$1, $3);
167 | declarable_identifier '=' notename_tab {
168 $$ = new Notetab_id(*$1, $3);
171 | declarable_identifier '=' real {
172 $$ = new Real_id(*$1, new Real($3));
175 | declarable_identifier error '}' {
181 NOTENAMES '{' notename_tab_body '}' { $$ = $3; }
185 $$ = new Notename_tab;
188 $$ = $1->notename_tab(true);
190 | notename_tab_body STRING int int {
191 $$->set($3, $4, *$2);
200 SCORE { define_spots.push(lexer->here_ch_c_l()); }
201 /*cont*/ '{' score_body '}' {
203 $$->defined_ch_c_l_ = define_spots.pop();
205 $$->paper_p_ = default_paper();
207 /* handle error levels. */
208 $$->errorlevel_i_ = lexer->errorlevel_i_;
209 lexer->errorlevel_i_ = 0;
214 $$ = new Input_score;
216 | score_body staff_block { $$->add($2); }
217 | score_body COMMANDS '{' music_voice_body '}' {
220 | score_body paper_block { $$->set($2); }
221 | score_body midi_block { $$->set($2); }
228 /* */ { $$ =new Array<int>; }
229 | intastint_list int '*' int {
230 $$->push($2); $$->push($4);
241 '{' paper_body '}' { $$ = $3; }
246 $$ = default_paper();
248 | paper_body WIDTH dim { $$->linewidth = $3;}
249 | paper_body OUTPUT STRING { $$->outfile = *$3;
252 | paper_body symtables { $$->set($2); }
253 | paper_body UNITSPACE dim { $$->whole_width = $3; }
254 | paper_body GEOMETRIC REAL { $$->geometric_ = $3; }
266 '{' midi_body '}' { $$ = $3; }
272 | midi_body OUTPUT STRING {
273 $$->outfile_str_ = *$3;
276 | midi_body TEMPO mudela_duration ':' int {
277 $$->set_tempo( wholes( $3[0], $3[1] ), $5 );
288 STAFF { define_spots.push(lexer->here_ch_c_l()); }
289 /*cont*/ '{' staff_body '}' {
291 $$-> defined_ch_c_l_ = define_spots.pop();
298 IDENTIFIER { $$ = $1->staff(true); }
300 $$ = new Input_staff(*$1);
304 $$ = new Input_staff("midi");
310 | staff_body COMMANDS '{' music_voice_body '}' {
311 $$->set_score_wide($4);
314 $2->set_default_group( "staff_music" + String($$->music_.size()));
325 music_voice { $$ = $1; }
326 | music_chord { $$ = $1; }
329 music_voice: MUSIC '{' music_voice_body '}' { $$ = $3; }
334 $$ = new Music_voice;
336 | music_voice_body IDENTIFIER {
337 $$->concatenate($2->mvoice(true));
339 | music_voice_body full_element {
342 | music_voice_body voice_command {
344 | music_voice_body music {
347 | music_voice_body error {
351 music_chord: '{' music_chord_body '}' { $$ = $2; }
356 $$ = new Voice_group_chord;
359 $$ = new Multi_voice_chord;
361 | music_chord_body IDENTIFIER {
362 $$->concatenate($2->mchord(true));
364 | music_chord_body music {
367 | music_chord_body full_element {
370 | music_chord_body error {
378 full_element: pre_requests voice_elt post_requests {
379 add_requests($2, pre_reqs);
380 add_requests($2, post_reqs);
383 | pre_requests lyrics_elt post_requests {
384 add_requests($2, pre_reqs);
385 add_requests($2, post_reqs);
393 $$ = new Voice_element;
394 $$-> defined_ch_c_l_ = lexer->here_ch_c_l();
398 $2-> defined_ch_c_l_ = $$->defined_ch_c_l_;
406 $$ = new Barcheck_req;
409 $$ = new Bar_req(*$2);
412 | METER '{' int '*' int '}' {
413 Meter_change_req *m = new Meter_change_req;
417 | SKIP '{' duration_length '}' {
418 Skip_req * skip_p = new Skip_req;
419 skip_p->duration_ = *$3;
423 | CADENZA '{' int '}' {
424 $$ = new Cadenza_req($3);
426 | PARTIAL '{' duration_length '}' {
427 $$ = new Partial_measure_req(*$3);
431 $$ = get_stemdir_req($3);
434 $$ = new Clef_change_req(*$2);
437 | KEY '{' pitch_list '}' {
438 Key_change_req *key_p= new Key_change_req;
439 key_p->melodic_p_arr_ = *$3;
443 | GROUPING '{' intastint_list '}' {
444 $$ = get_grouping_req(*$3); delete $3;
450 assert(post_reqs.empty());
452 | post_requests post_request {
453 $2->defined_ch_c_l_ = lexer->here_ch_c_l();
456 | post_requests close_plet_parens INT '/' INT {
457 post_reqs.push( get_request($2) );
458 req_defined_ch_c_l = lexer->here_ch_c_l();
459 post_reqs.push( get_plet_request( $2, $3, $5 ) );
464 close_request_parens {
465 $$ = get_request($1);
473 req_defined_ch_c_l = lexer->here_ch_c_l();
478 close_request_parens:
497 SCRIPT '{' script_body '}' { $$ = $3; }
502 $$ = new Script_def(*$1,$2, $3,$4);
508 script_dir mudela_text { $$ = get_text_req($1,$2); }
513 defined_ch_c_l = lexer->here_ch_c_l();
520 script_dir mudela_script {
521 $$ = get_script_req($1, $2);
526 IDENTIFIER { $$ = $1->script(true); }
527 | script_definition { $$ = $1; }
528 | '^' { $$ = get_scriptdef('^'); }
529 | '+' { $$ = get_scriptdef('+'); }
530 | '-' { $$ = get_scriptdef('-'); }
531 | '|' { $$ = get_scriptdef('|'); }
532 | 'o' { $$ = get_scriptdef('o'); }
533 | '>' { $$ = get_scriptdef('>'); }
534 | '.' { $$ = get_scriptdef('.'); }
537 warning( "too many staccato dots", lexer->here_ch_c_l() );
538 $$ = get_scriptdef('.');
541 $$ = get_scriptdef('.');
553 | pre_requests pre_request {
555 $2->defined_ch_c_l_ = lexer->here_ch_c_l();
560 open_request_parens {
561 defined_ch_c_l = lexer->here_ch_c_l();
562 $$ = get_request($1);
567 PLET '{' INT '/' INT '}' {
570 | DURATIONCOMMAND '{' STRING '}' {
571 set_duration_mode(*$3);
574 | DURATIONCOMMAND '{' notemode_duration '}' {
575 set_default_duration($3);
577 | OCTAVECOMMAND '{' pitchmod '}' {
578 set_default_octave(*$3);
589 $$ = new Moment(wholes($1[0], $1[1]));
591 |int '*' mudela_duration {
592 $$ = new Moment(Rational($1) * wholes($3[0], $3[1]));
625 get_default_duration($$);
632 get_default_duration($$);
637 defined_ch_c_l = lexer->here_ch_c_l();
641 defined_ch_c_l = lexer->here_ch_c_l();
651 pitchmod notename notemode_duration {
652 $$ = get_note_element(*$1, $2, $3);
655 | RESTNAME notemode_duration {
656 $$ = get_rest_element(*$1, $2);
663 mudela_text notemode_duration {
664 $$ = get_word_element($1, $2);
671 $$ = new Array<Melodic_req*>;
673 | pitch_list NOTENAME {
674 Melodic_req *m_p = new Melodic_req;
675 m_p->notename_i_ = $2[0];
676 m_p->accidental_i_ = $2[1];
684 if ( distance($1,Real(int($$)) ) > 1e-8)
685 error( "integer expected", lexer->here_ch_c_l() );
704 real unit { $$ = $1*$2; }
708 unit: CM_T { $$ = 1 CM; }
709 |IN_T { $$ = 1 INCH; }
718 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
726 $$ = new Lookup(*$1->lookup(true));
728 | symtables_body TEXID STRING {
729 $$->texsetting = *$3;
732 | symtables_body STRING '=' symtable {
739 TABLE '{' symtable_body '}' { $$ = $3; }
743 { $$ = new Symtable; }
744 | symtable_body STRING symboldef {
753 $$ = new Symbol(*$1, *$2);
759 $$ = new Symbol(*$1, b);
765 dinterval dinterval {
766 $$ = new Box(*$1, *$2);
773 $$ = new Interval($1, $2);
780 yyerror(const char *s)
782 lexer->LexerError(s);
785 exit( fatal_error_i );
789 parse_file(String init, String s)
791 *mlog << "Parsing ... ";
792 lexer = new My_flex_lexer;
795 yydebug = !monitor->silence("InitParser") && check_debug;
796 lexer->set_debug( !monitor->silence("InitLexer") && check_debug);
799 lexer->new_input(init);
803 yydebug = !monitor->silence("Parser") && check_debug;
804 lexer->set_debug( !monitor->silence("Lexer") && check_debug);
812 if(!define_spots.empty())
813 warning("Braces don't match.",0);
820 lexer->lookup_identifier("default_table")->lookup(true));