1 %{ // -*-Fundamental-*-
5 #include "script-def.hh"
9 #include "my-lily-lexer.hh"
10 #include "paper-def.hh"
11 #include "midi-def.hh"
13 #include "input-score.hh"
14 #include "input-staff.hh"
15 #include "input-music.hh"
18 #include "parseconstruct.hh"
20 #include "identifier.hh"
21 #include "command-request.hh"
22 #include "musical-request.hh"
23 #include "voice-element.hh"
24 #include "my-lily-parser.hh"
25 #include "text-def.hh"
26 #include "input-register.hh"
32 #define YYERROR_VERBOSE 1
34 #define YYPARSE_PARAM my_lily_parser_l
35 #define YYLEX_PARAM my_lily_parser_l
36 #define THIS ((My_lily_parser *) my_lily_parser_l)
38 #define yyerror THIS->parser_error
44 Array<Melodic_req*> *melreqvec;/* should clean up naming */
45 Array<String> * strvec;
50 Input_register * iregs;
59 Music_general_chord *chord;
69 Symtables * symtables;
81 yylex(YYSTYPE *s, void * v_l)
83 My_lily_parser *pars_l = (My_lily_parser*) v_l;
84 My_lily_lexer * lex_l = pars_l->lexer_p_;
85 lex_l->lexval_l = (void*) s;
86 return lex_l->yylex();
93 /* tokens which are not keywords */
100 %token DURATIONCOMMAND
111 %token MELODIC_REQUEST
142 %token <id> REGS_IDENTIFIER
143 %token <id> IDENTIFIER
144 %token <id> MELODIC_REQUEST_IDENTIFIER
145 %token <id> CHORD_IDENTIFIER
146 %token <id> VOICE_IDENTIFIER
147 %token <id> POST_REQUEST_IDENTIFIER
148 %token <id> SCRIPT_IDENTIFIER
149 %token <id> STAFF_IDENTIFIER
150 %token <id> REAL_IDENTIFIER
151 %token <id> SCORE_IDENTIFIER
152 %token <id> REQUEST_IDENTIFIER
154 %token <string> DURATION RESTNAME
155 %token <string> STRING
156 %token <i> POST_QUOTES
157 %token <i> PRE_QUOTES
161 %type <c> open_request_parens close_request_parens close_plet_parens
162 %type <chord> music_chord music_chord_body init_music_chord
163 %type <el> voice_elt full_element lyrics_elt command_elt
166 %type <id> declaration
167 %type <duration> explicit_duration notemode_duration
168 %type <interval> dinterval
169 %type <intvec> intastint_list
170 %type <lookup> symtables symtables_body
171 %type <melreq> melodic_request steno_melodic_req
172 %type <notereq> steno_note_req
173 %type <melreqvec> pitch_list
174 %type <midi> midi_block midi_body
175 %type <moment> duration_length
176 %type <music> init_music
177 %type <mvoice> transposed_music_voice init_lyrics_voice
178 %type <mvoice> music_voice_body music_voice init_music_voice
179 %type <paper> paper_block paper_body
180 %type <real> dim real
182 %type <request> post_request pre_request command_req
183 %type <request> pure_post_request pure_post_request_choice
184 %type <request> script_req textscript_req dynamic_req
185 %type <score> score_block score_body
186 %type <script> script_definition script_body mudela_script
187 %type <staff> staff_block staff_init staff_body
188 %type <string> declarable_identifier
189 %type <string> script_abbreviation
190 %type <id> old_identifier
191 %type <symbol> symboldef
192 %type <symtable> symtable symtable_body
193 %type <textdef> mudela_text
194 %type <iregs> input_regs input_regs_body
198 %expect 1 /* have to fix this. */
203 | mudela score_block {
206 | mudela add_declaration { }
214 add_declaration: declaration {
215 THIS->lexer_p_->add_identifier($1);
216 $1->init_b_ = THIS->init_parse_b_;
217 $1->set_spot(THIS->pop_spot());
221 declarable_identifier:
223 THIS->remember_spot();
227 THIS->remember_spot();
228 $$ = new String($1->name);
229 THIS->here_input().warning("redeclaration of `" + *$$ + "'");
236 | MELODIC_REQUEST_IDENTIFIER
239 | POST_REQUEST_IDENTIFIER
249 declarable_identifier '=' score_block {
250 $$ = new Score_id(*$1, $3, SCORE_IDENTIFIER);
253 | declarable_identifier '=' staff_block {
254 $$ = new Staff_id(*$1, $3, STAFF_IDENTIFIER);
257 | declarable_identifier '=' init_music_voice {
258 $$ = new M_voice_id(*$1, $3, VOICE_IDENTIFIER);
261 | declarable_identifier '=' init_lyrics_voice {
262 $$ = new M_voice_id(*$1, $3, VOICE_IDENTIFIER);
265 | declarable_identifier '=' script_definition {
266 $$ = new Script_id(*$1, $3, SCRIPT_IDENTIFIER);
269 | declarable_identifier '=' init_music_chord {
270 $$ = new M_chord_id(*$1, $3, CHORD_IDENTIFIER);
273 | declarable_identifier '=' symtables {
274 $$ = new Lookup_id(*$1, $3, IDENTIFIER);
277 | declarable_identifier '=' real {
278 $$ = new Real_id(*$1, new Real($3), REAL_IDENTIFIER);
282 | declarable_identifier '=' pure_post_request {
283 $$ = new Request_id(*$1, $3, POST_REQUEST_IDENTIFIER);
286 | declarable_identifier '=' melodic_request {
287 $$ = new Request_id(*$1, $3, MELODIC_REQUEST_IDENTIFIER);
290 | declarable_identifier '=' input_regs {
291 $$ = new Input_regs_id(*$1, $3, REGS_IDENTIFIER);
299 { THIS->remember_spot(); }
300 '{' input_regs_body '}'
303 $$->set_spot(THIS->pop_spot());
309 $$ = $1->iregs(true);
312 $$ = new Input_register;
315 | input_regs_body input_regs {
324 SCORE { THIS->remember_spot(); }
325 /*cont*/ '{' score_body '}' {
327 $$->set_spot(THIS->pop_spot());
328 if (!$$->paper_p_ && ! $$->midi_p_)
329 $$->paper_p_ = THIS->default_paper();
331 /* handle error levels. */
332 $$->errorlevel_i_ = THIS->error_level_i_;
333 THIS->error_level_i_ = 0;
338 $$ = new Input_score;
341 $$ = $1->score(true);
343 | score_body staff_block { $$->add($2); }
344 | score_body paper_block { $$->set($2); }
345 | score_body midi_block { $$->set($2); }
352 /* */ { $$ =new Array<int>; }
353 | intastint_list int '*' int {
354 $$->push($2); $$->push($4);
364 '{' paper_body '}' { $$ = $3; }
369 $$ = THIS->default_paper();
372 | paper_body WIDTH dim { $$->linewidth = $3;}
373 | paper_body OUTPUT STRING { $$->outfile = *$3;
376 | paper_body symtables { $$->set($2); }
377 | paper_body UNITSPACE dim { $$->whole_width = $3; }
378 | paper_body GEOMETRIC REAL { $$->geometric_ = $3; }
390 '{' midi_body '}' { $$ = $3; }
396 | midi_body OUTPUT STRING {
397 $$->outfile_str_ = *$3;
400 | midi_body TEMPO notemode_duration ':' int {
401 $$->set_tempo( $3->length(), $5 );
412 STAFF { THIS->remember_spot(); }
413 /*cont*/ '{' staff_body '}' {
415 $$-> set_spot(THIS->pop_spot());
417 | { THIS->remember_spot(); }
418 /*cont*/ STAFF_IDENTIFIER {
419 $$ = $2->staff(true);
420 $$-> set_spot(THIS->pop_spot());
428 $$ = new Input_staff;
429 $$->ireg_p_ = $1->iregs(true);
432 $$ = new Input_staff;
439 | staff_body init_music {
441 $2->set_default_group( "staff_music" + String($$->music_.size()));
449 let the lexer switch mode.
452 init_music_voice { $$ = $1; }
453 | init_music_chord { $$ = $1; }
454 | init_lyrics_voice { $$ = $1; }
456 $$ = $1->mvoice(true);
461 LYRIC { THIS->lexer_p_->push_lyric_state(); }
462 music_voice { $$ = $3; THIS->lexer_p_->pop_state(); }
466 MELODIC { THIS->lexer_p_->push_note_state(); }
467 /* cont*/ music_voice
468 { $$=$3; THIS->lexer_p_->pop_state(); }
471 { THIS->lexer_p_->push_note_state(); }
472 /* cont*/ music_chord
473 { $$=$2; THIS->lexer_p_->pop_state(); }
481 transposed_music_voice:
482 steno_melodic_req music_voice {
489 music_voice: '{' music_voice_body '}' { $$ = $2; }
490 | TRANSPOSE '{' transposed_music_voice '}' {
497 $$ = $1->mvoice(true);
500 $$ = new Music_voice;
502 | music_voice_body full_element {
505 | music_voice_body voice_command {
507 | music_voice_body music_chord {
510 | music_voice_body CONCAT music_voice {
511 $$->add($3);/* niet echt */
513 | music_voice_body error {
515 | music_voice_body '>' {
516 THIS->fatal_error_i_ = 1;
517 THIS->parser_error("Confused by errors: bailing out");
521 music_chord: '<' music_chord_body '>' { $$ = $2; }
529 $$ = new Voice_group_chord;
532 $$ = new Multi_voice_chord;
534 | music_chord_body music_voice {
537 | music_chord_body full_element {
540 | music_chord_body '}' {
541 THIS->fatal_error_i_ = 1;
542 THIS->parser_error("Confused by errors: bailing out");
544 | music_chord_body error {
551 full_element: pre_requests voice_elt post_requests {
552 THIS->add_requests($2);
555 | pre_requests lyrics_elt post_requests {
556 THIS->add_requests($2);
564 $$ = new Voice_element;
565 $$-> set_spot( THIS->here_input());
569 $2-> set_spot( THIS->here_input());
577 $$ = new Barcheck_req;
580 $$ = new Bar_req(*$2);
583 | METER '{' int '/' int '}' {
584 Meter_change_req *m = new Meter_change_req;
586 // sorry hw, i need meter at output of track,
587 // but don-t know where to get it... statics should go.
588 // HW : default: 4/4, meterchange reqs may change it.
590 Midi_def::num_i_s = $3;
591 Midi_def::den_i_s = $5;
594 | SKIP '{' duration_length '}' {
595 Skip_req * skip_p = new Skip_req;
596 skip_p->duration_ = *$3;
600 | CADENZA '{' int '}' {
601 $$ = new Cadenza_req($3);
603 | PARTIAL '{' duration_length '}' {
604 $$ = new Partial_measure_req(*$3);
608 $$ = get_stemdir_req($3);
611 $$ = new Clef_change_req(*$2);
614 | KEY '{' pitch_list '}' {
615 Key_change_req *key_p= new Key_change_req;
616 key_p->melodic_p_arr_ = *$3;
620 | GROUPING '{' intastint_list '}' {
621 $$ = get_grouping_req(*$3); delete $3;
624 $$ = new Group_change_req;
625 $$ -> command()->groupchange()->newgroup_str_ = *$2;
632 assert(THIS->post_reqs.empty());
634 | post_requests post_request {
635 $2->set_spot( THIS->here_input());
636 THIS->post_reqs.push($2);
638 | post_requests close_plet_parens INT '/' INT {
639 THIS->post_reqs.push( THIS->get_parens_request($2) );
640 THIS->post_reqs.push( get_plet_request( $2, $3, $5 ) );
646 | POST_REQUEST_IDENTIFIER {
647 $$ = $1->request(false)->clone();
652 pure_post_request_choice {
654 $$->set_spot( THIS->here_input());
657 pure_post_request_choice:
658 close_request_parens {
659 $$ = THIS->get_parens_request($1);
672 MELODIC_REQUEST_IDENTIFIER {
673 $$ = $1->request(false)->clone()->melodic();
674 $$->octave_i_ += THIS->default_octave_i_;
676 | steno_melodic_req POST_QUOTES {
677 $$-> octave_i_ += $2;
679 | PRE_QUOTES steno_melodic_req {
681 $2-> octave_i_ -= $1;
688 * (Melodic_req *) $$ = *$1;
691 | steno_note_req '!' {
692 $$->forceacc_b_ = ! $$->forceacc_b_;
694 /* have to duration here. */
698 MELODIC_REQUEST '{' int int int '}' {/* ugh */
699 $$ = new Melodic_req;
701 $$->notename_i_ = $4;
702 $$->accidental_i_ = $5;
707 ABSDYNAMIC '{' int '}' {
708 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
709 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
712 |SPANDYNAMIC '{' int int '}' {
713 Span_dynamic_req * sp_p = new Span_dynamic_req;
715 sp_p-> dynamic_dir_i_ = $3;
726 close_request_parens:
745 SCRIPT '{' script_body '}' { $$ = $3; }
750 $$ = new Script_def(*$1,$2, $3,$4);
756 script_dir mudela_text { $$ = get_text_req($1,$2); }
764 $$->style_str_ = THIS->textstyle_str_;
769 script_dir mudela_script {
770 $$ = get_script_req($1, $2);
774 '^' { $$ = get_scriptdef('^'); }
775 | '+' { $$ = get_scriptdef('+'); }
776 | '-' { $$ = get_scriptdef('-'); }
777 | '|' { $$ = get_scriptdef('|'); }
778 | 'o' { $$ = get_scriptdef('o'); }
779 | '>' { $$ = get_scriptdef('>'); }
782 THIS->here_input().warning( "too many staccato dots" );
783 $$ = get_scriptdef('.');
788 SCRIPT_IDENTIFIER { $$ = $1->script(true); }
789 | script_definition { $$ = $1; }
790 | script_abbreviation {
791 $$ = THIS->lexer_p_->lookup_identifier(*$1)->script(true);
803 | pre_requests pre_request {
804 THIS->pre_reqs.push($2);
805 $2->set_spot( THIS->here_input());
810 open_request_parens {
811 $$ = THIS->get_parens_request($1);
816 PLET '{' INT '/' INT '}' {
817 THIS->default_duration_.set_plet($3,$5);
819 | DURATIONCOMMAND '{' STRING '}' {
820 THIS->set_duration_mode(*$3);
823 | DURATIONCOMMAND '{' notemode_duration '}' {
824 THIS->default_duration_ = *$3;
827 | OCTAVECOMMAND { THIS->default_octave_i_ = 2; }
829 '{' steno_melodic_req '}' {
830 THIS->default_octave_i_ = $4->octave_i_;
833 THIS->textstyle_str_ = *$2;
840 $$ = new Moment(0,1);
842 | duration_length explicit_duration {
849 $$ = new Duration(THIS->default_duration_);
852 $$ = new Duration(THIS->default_duration_);
855 | explicit_duration {
856 THIS->set_last_duration($1);
866 | explicit_duration DOTS {
869 | explicit_duration '*' int {
870 $$->plet_.iso_i_ *= $3;
872 | explicit_duration '/' int {
873 $$->plet_.type_i_ *= $3;
879 steno_note_req notemode_duration {
880 if (!THIS->lexer_p_->note_state_b())
881 THIS->parser_error("have to be in Note mode for notes");
882 $$ = THIS->get_note_element($1, $2);
884 | RESTNAME notemode_duration {
885 $$ = THIS->get_rest_element(*$1, $2);
891 mudela_text notemode_duration {
892 if (!THIS->lexer_p_->lyric_state_b())
893 THIS->parser_error("Have to be in Lyric mode for lyrics");
894 $$ = THIS->get_word_element($1, $2);
902 $$ = new Array<Melodic_req*>;
904 | pitch_list MELODIC_REQUEST_IDENTIFIER {
905 $$->push($2->request(false)->clone()->melodic());
912 if ( distance($1,Real(int($$)) ) > 1e-8)
913 yyerror( "integer expected" );
932 real unit { $$ = $1*$2; }
936 unit: CM_T { $$ = 1 CM; }
937 |IN_T { $$ = 1 INCH; }
946 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
954 $$ = new Lookup(*$1->lookup(true));
956 | symtables_body TEXID STRING {
957 $$->texsetting = *$3;
960 | symtables_body STRING '=' symtable {
967 TABLE '{' symtable_body '}' { $$ = $3; }
971 { $$ = new Symtable; }
972 | symtable_body STRING symboldef {
981 $$ = new Symbol(*$1, *$2);
987 $$ = new Symbol(*$1, b);
993 dinterval dinterval {
994 $$ = new Box(*$1, *$2);
1000 dinterval: dim dim {
1001 $$ = new Interval($1, $2);
1008 My_lily_parser::set_yydebug(bool b )
1015 My_lily_parser::do_yyparse()
1017 yyparse((void*)this);
1021 My_lily_parser::default_paper()
1023 return new Paper_def(
1024 lexer_p_->lookup_identifier("default_table")->lookup(true));