1 %{ // -*-Fundamental-*-
4 #define MUDELA_VERSION "0.0.58"
6 #include "script-def.hh"
10 #include "my-lily-lexer.hh"
11 #include "paper-def.hh"
12 #include "midi-def.hh"
14 #include "input-score.hh"
15 #include "input-staff.hh"
16 #include "input-music.hh"
19 #include "parseconstruct.hh"
21 #include "identifier.hh"
22 #include "command-request.hh"
23 #include "musical-request.hh"
24 #include "voice-element.hh"
25 #include "my-lily-parser.hh"
26 #include "text-def.hh"
27 #include "input-register.hh"
33 #define YYERROR_VERBOSE 1
35 #define YYPARSE_PARAM my_lily_parser_l
36 #define YYLEX_PARAM my_lily_parser_l
37 #define THIS ((My_lily_parser *) my_lily_parser_l)
39 #define yyerror THIS->parser_error
45 Array<Melodic_req*> *melreqvec;/* should clean up naming */
46 Array<String> * strvec;
51 Input_register * iregs;
60 Music_general_chord *chord;
70 Symtables * symtables;
82 yylex(YYSTYPE *s, void * v_l)
84 My_lily_parser *pars_l = (My_lily_parser*) v_l;
85 My_lily_lexer * lex_l = pars_l->lexer_p_;
87 if (pars_l->first_b_) {
88 pars_l->first_b_ = false;
89 pars_l->do_init_file();
92 lex_l->lexval_l = (void*) s;
93 return lex_l->yylex();
100 /* tokens which are not keywords */
108 %token DURATIONCOMMAND
121 %token MELODIC_REQUEST
153 %token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
157 %token <melreq> NOTENAME_ID
158 %token <id> REGS_IDENTIFIER
159 %token <id> IDENTIFIER
160 %token <id> MELODIC_REQUEST_IDENTIFIER
161 %token <id> CHORD_IDENTIFIER
162 %token <id> VOICE_IDENTIFIER
163 %token <id> POST_REQUEST_IDENTIFIER
164 %token <id> SCRIPT_IDENTIFIER
165 %token <id> STAFF_IDENTIFIER
166 %token <id> REAL_IDENTIFIER
167 %token <id> SCORE_IDENTIFIER
168 %token <id> REQUEST_IDENTIFIER
170 %token <string> DURATION RESTNAME
171 %token <string> STRING
172 %token <i> POST_QUOTES
173 %token <i> PRE_QUOTES
177 %type <c> open_request_parens close_request_parens
178 %type <c> open_plet_parens close_plet_parens
179 %type <chord> music_chord music_chord_body init_music_chord
180 %type <el> voice_elt full_element lyrics_elt command_elt
183 %type <id> declaration
184 %type <duration> explicit_duration notemode_duration
185 %type <interval> dinterval
186 %type <intvec> intastint_list
187 %type <lookup> symtables symtables_body
188 %type <melreq> melodic_request steno_melodic_req
189 %type <notereq> steno_note_req
190 %type <melreqvec> pitch_list
191 %type <midi> midi_block midi_body
192 %type <moment> duration_length
193 %type <music> init_music
194 %type <mvoice> simple_horizontal_music horizontal_music horizontal_music_body
195 %type <mvoice> transposed_music_voice init_lyrics_voice
196 %type <mvoice> music_voice_body init_music_voice
197 %type <paper> paper_block paper_body
198 %type <real> dim real
200 %type <request> post_request pre_request command_req verbose_command_req abbrev_command_req
201 %type <request> pure_post_request pure_post_request_choice
202 %type <request> script_req textscript_req dynamic_req
203 %type <score> score_block score_body
204 %type <script> script_definition script_body mudela_script
205 %type <staff> staff_block staff_init staff_body
206 %type <string> declarable_identifier
207 %type <string> script_abbreviation
208 %type <id> old_identifier
209 %type <symbol> symboldef
210 %type <symtable> symtable symtable_body
211 %type <textdef> mudela_text
212 %type <iregs> input_regs input_regs_body
216 %expect 1 /* have to fix this. */
221 | mudela score_block {
224 | mudela add_declaration { }
226 | mudela check_version { }
227 | mudela add_notenames { }
231 init_end: INIT_END ';' {
232 THIS->print_declarations();
233 THIS->init_parse_b_ = false;
239 if (*$2 != MUDELA_VERSION) {
240 if (THIS->ignore_version_b_) {
241 THIS->here_input().error("Incorrect mudela version");
243 THIS->fatal_error_i_ = 1;
244 THIS->parser_error("Incorrect mudela version");
251 NOTENAMES '{' notenames_body '}'
256 | notenames_body CLEAR {
257 THIS->clear_notenames();
259 | notenames_body STRING '=' melodic_request {
260 THIS->add_notename(*$2, $4);
267 add_declaration: declaration {
268 THIS->lexer_p_->add_identifier($1);
269 $1->init_b_ = THIS->init_parse_b_;
270 $1->set_spot(THIS->pop_spot());
274 declarable_identifier:
276 THIS->remember_spot();
280 THIS->remember_spot();
281 $$ = new String($1->name_str_);
282 THIS->here_input().warning("redeclaration of `" + *$$ + "'");
289 | MELODIC_REQUEST_IDENTIFIER
292 | POST_REQUEST_IDENTIFIER
302 declarable_identifier '=' score_block {
303 $$ = new Score_id(*$1, $3, SCORE_IDENTIFIER);
306 | declarable_identifier '=' staff_block {
307 $$ = new Staff_id(*$1, $3, STAFF_IDENTIFIER);
310 | declarable_identifier '=' init_music_voice {
311 $$ = new M_voice_id(*$1, $3, VOICE_IDENTIFIER);
314 | declarable_identifier '=' init_lyrics_voice {
315 $$ = new M_voice_id(*$1, $3, VOICE_IDENTIFIER);
318 | declarable_identifier '=' script_definition {
319 $$ = new Script_id(*$1, $3, SCRIPT_IDENTIFIER);
322 | declarable_identifier '=' init_music_chord {
323 $$ = new M_chord_id(*$1, $3, CHORD_IDENTIFIER);
326 | declarable_identifier '=' symtables {
327 $$ = new Lookup_id(*$1, $3, IDENTIFIER);
330 | declarable_identifier '=' real {
331 $$ = new Real_id(*$1, new Real($3), REAL_IDENTIFIER);
335 | declarable_identifier '=' pure_post_request {
336 $$ = new Request_id(*$1, $3, POST_REQUEST_IDENTIFIER);
339 | declarable_identifier '=' melodic_request {
340 $$ = new Request_id(*$1, $3, MELODIC_REQUEST_IDENTIFIER);
343 | declarable_identifier '=' input_regs {
344 $$ = new Input_regs_id(*$1, $3, REGS_IDENTIFIER);
352 { THIS->remember_spot(); }
353 '{' input_regs_body '}'
356 $$->set_spot(THIS->pop_spot());
362 $$ = $1->iregs(true);
365 $$ = new Input_register;
368 | input_regs_body input_regs {
377 SCORE { THIS->remember_spot(); }
378 /*cont*/ '{' score_body '}' {
380 $$->set_spot(THIS->pop_spot());
381 if (!$$->paper_p_ && ! $$->midi_p_)
382 $$->paper_p_ = THIS->default_paper();
384 /* handle error levels. */
385 $$->errorlevel_i_ = THIS->error_level_i_;
386 THIS->error_level_i_ = 0;
391 $$ = new Input_score;
394 $$ = $1->score(true);
396 | score_body staff_block { $$->add($2); }
397 | score_body paper_block { $$->set($2); }
398 | score_body midi_block { $$->set($2); }
405 /* */ { $$ =new Array<int>; }
406 | intastint_list int '*' int {
407 $$->push($2); $$->push($4);
417 '{' paper_body '}' { $$ = $3; }
422 $$ = THIS->default_paper();
425 | paper_body WIDTH dim { $$->linewidth = $3;}
426 | paper_body OUTPUT STRING { $$->outfile = *$3;
429 | paper_body symtables { $$->set($2); }
430 | paper_body UNITSPACE dim { $$->whole_width = $3; }
431 | paper_body GEOMETRIC REAL { $$->geometric_ = $3; }
443 '{' midi_body '}' { $$ = $3; }
449 | midi_body OUTPUT STRING {
450 $$->outfile_str_ = *$3;
453 | midi_body TEMPO notemode_duration ':' int {
454 $$->set_tempo( $3->length(), $5 );
465 STAFF { THIS->remember_spot(); }
466 /*cont*/ '{' staff_body '}' {
468 $$-> set_spot(THIS->pop_spot());
470 | { THIS->remember_spot(); }
471 /*cont*/ STAFF_IDENTIFIER {
472 $$ = $2->staff(true);
473 $$-> set_spot(THIS->pop_spot());
481 $$ = $1->staff(true);
484 $$ = new Input_staff;
485 $$->ireg_p_ = $1->iregs(true);
488 $$ = new Input_staff;
495 | staff_body init_music {
497 $2->set_default_group( "staff_music" + String($$->music_.size()));
505 let the lexer switch mode.
508 init_music_voice { $$ = $1; }
509 | init_music_chord { $$ = $1; }
510 | init_lyrics_voice { $$ = $1; }
512 $$ = $1->mvoice(true);
517 LYRIC { THIS->lexer_p_->push_lyric_state(); }
518 horizontal_music { $$ = $3; THIS->lexer_p_->pop_state(); }
522 MELODIC { THIS->lexer_p_->push_note_state(); }
523 /* cont*/ horizontal_music
524 { $$=$3; THIS->lexer_p_->pop_state(); }
528 { THIS->lexer_p_->push_note_state(); }
529 /* cont*/ music_chord
530 { $$=$2; THIS->lexer_p_->pop_state(); }
537 '{' horizontal_music_body '}' {
542 horizontal_music_body:
543 simple_horizontal_music {
546 | horizontal_music_body CONCAT simple_horizontal_music {
547 $$->add($3);/* niet echt */
552 simple_horizontal_music:
553 TRANSPOSE '{' transposed_music_voice '}' {
557 $$ = $1->mvoice(true);
565 transposed_music_voice:
566 steno_melodic_req horizontal_music {
576 $$ = new Music_voice;
578 | music_voice_body full_element {
581 | music_voice_body voice_command ';' {
583 | music_voice_body music_chord {
586 | music_voice_body error {
588 | music_voice_body '>' {
589 THIS->fatal_error_i_ = 1;
590 THIS->parser_error("Confused by errors: bailing out");
594 music_chord: '<' music_chord_body '>' { $$ = $2; }
602 $$ = new Voice_group_chord;
605 $$ = new Multi_voice_chord;
607 | music_chord_body horizontal_music {
610 | music_chord_body full_element {
613 | music_chord_body '}' {
614 THIS->fatal_error_i_ = 1;
615 THIS->parser_error("Confused by errors: bailing out");
617 | music_chord_body error {
624 full_element: pre_requests voice_elt post_requests {
625 THIS->add_requests($2);
628 | pre_requests lyrics_elt post_requests {
629 THIS->add_requests($2);
637 $$ = new Voice_element;
638 $$-> set_spot( THIS->here_input());
642 $2-> set_spot( THIS->here_input());
650 | verbose_command_req ';' { $$ = $1; }
655 $$ = new Barcheck_req;
661 $$ = new Bar_req(*$2);
664 | METER int '/' int {
665 Meter_change_req *m = new Meter_change_req;
667 // sorry hw, i need meter at output of track,
668 // but don-t know where to get it... statics should go.
669 // HW : default: 4/4, meterchange reqs may change it.
671 Midi_def::num_i_s = $2;
672 Midi_def::den_i_s = $4;
675 | SKIP duration_length {
676 Skip_req * skip_p = new Skip_req;
677 skip_p->duration_ = *$2;
682 $$ = new Cadenza_req($2);
684 | PARTIAL duration_length {
685 $$ = new Partial_measure_req(*$2);
689 $$ = get_stemdir_req($2);
692 $$ = get_hshift_req($2);
695 $$ = new Clef_change_req(*$2);
699 Key_change_req *key_p= new Key_change_req;
700 key_p->melodic_p_arr_ = *$2;
704 | GROUPING intastint_list {
705 $$ = get_grouping_req(*$2); delete $2;
708 $$ = new Group_change_req;
709 $$ -> command()->groupchange()->newgroup_str_ = *$2;
716 assert(THIS->post_reqs.empty());
718 | post_requests post_request {
719 $2->set_spot( THIS->here_input());
720 THIS->post_reqs.push($2);
726 | POST_REQUEST_IDENTIFIER {
727 $$ = $1->request(false)->clone();
732 pure_post_request_choice {
734 $$->set_spot( THIS->here_input());
738 pure_post_request_choice:
739 close_request_parens {
740 $$ = THIS->get_parens_request($1);
754 $$ = $1->clone()->musical()->melodic();
755 $$->octave_i_ += THIS->default_octave_i_;
757 | steno_melodic_req POST_QUOTES {
758 $$-> octave_i_ += $2;
760 | PRE_QUOTES steno_melodic_req {
762 $2-> octave_i_ -= $1;
769 * (Melodic_req *) $$ = *$1;
772 | steno_note_req '!' {
773 $$->forceacc_b_ = ! $$->forceacc_b_;
775 /* have to duration here. */
779 MELODIC_REQUEST '{' int int int '}' {/* ugh */
780 $$ = new Melodic_req;
782 $$->notename_i_ = $4;
783 $$->accidental_i_ = $5;
788 ABSDYNAMIC '{' int '}' {
789 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
790 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
793 | SPANDYNAMIC '{' int int '}' {
794 Span_dynamic_req * sp_p = new Span_dynamic_req;
796 sp_p-> dynamic_dir_i_ = $3;
804 THIS->default_duration_.set_plet($2,$4);
808 close_request_parens:
818 | close_plet_parens {
831 THIS->default_duration_.set_plet($2,$4);
852 SCRIPT '{' script_body '}' { $$ = $3; }
856 STRING int int int int {
858 $$->set_from_input(*$1,$2, $3,$4,$5);
864 script_dir mudela_text { $$ = get_text_req($1,$2); }
872 $$->style_str_ = THIS->textstyle_str_;
877 script_dir mudela_script {
878 $$ = get_script_req($1, $2);
882 '^' { $$ = get_scriptdef('^'); }
883 | '+' { $$ = get_scriptdef('+'); }
884 | '-' { $$ = get_scriptdef('-'); }
885 | '|' { $$ = get_scriptdef('|'); }
886 | 'o' { $$ = get_scriptdef('o'); }
887 | '>' { $$ = get_scriptdef('>'); }
890 THIS->here_input().warning( "too many staccato dots" );
891 $$ = get_scriptdef('.');
896 SCRIPT_IDENTIFIER { $$ = $1->script(true); }
897 | script_definition { $$ = $1; }
898 | script_abbreviation {
899 $$ = THIS->lexer_p_->lookup_identifier(*$1)->script(true);
911 | pre_requests pre_request {
912 THIS->pre_reqs.push($2);
913 $2->set_spot( THIS->here_input());
918 open_request_parens {
919 $$ = THIS->get_parens_request($1);
925 THIS->default_duration_.set_plet($2,$4);
927 | DURATIONCOMMAND STRING {
928 THIS->set_duration_mode(*$2);
931 | DURATIONCOMMAND notemode_duration {
932 THIS->set_default_duration($2);
937 This is weird, but default_octave_i_
938 is used in steno_note_req too
940 c' -> default_octave_i_ == 1
942 /* why can't we have \oct{0} iso \oct{c'}*/
943 THIS->default_octave_i_ = 1; }
946 THIS->default_octave_i_ = $3->octave_i_;
950 THIS->textstyle_str_ = *$2;
957 $$ = new Moment(0,1);
959 | duration_length explicit_duration {
966 $$ = new Duration(THIS->default_duration_);
969 $$ = new Duration(THIS->default_duration_);
972 | explicit_duration {
973 THIS->set_last_duration($1);
981 if ( !Duration::duration_type_b($1) )
982 THIS->parser_error("Not a duration");
985 $$->set_plet(THIS->default_duration_);
988 | explicit_duration DOTS {
991 | explicit_duration '*' int {
992 $$->plet_.iso_i_ *= $3;
994 | explicit_duration '/' int {
995 $$->plet_.type_i_ *= $3;
1001 steno_note_req notemode_duration {
1002 if (!THIS->lexer_p_->note_state_b())
1003 THIS->parser_error("have to be in Note mode for notes");
1004 $1->set_duration (*$2);
1005 $$ = THIS->get_note_element($1, $2);
1007 | RESTNAME notemode_duration {
1008 $$ = THIS->get_rest_element(*$1, $2);
1014 mudela_text notemode_duration {
1015 if (!THIS->lexer_p_->lyric_state_b())
1016 THIS->parser_error("Have to be in Lyric mode for lyrics");
1017 $$ = THIS->get_word_element($1, $2);
1025 $$ = new Array<Melodic_req*>;
1027 | pitch_list NOTENAME_ID {
1028 $$->push($2->clone()->musical()->melodic());
1035 if ( distance($1,Real(int($$)) ) > 1e-8)
1036 yyerror( "integer expected" );
1055 real unit { $$ = $1*$2; }
1059 unit: CM_T { $$ = 1 CM; }
1060 |IN_T { $$ = 1 INCH; }
1061 |MM_T { $$ = 1 MM; }
1062 |PT_T { $$ = 1 PT; }
1069 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
1077 $$ = new Lookup(*$1->lookup(true));
1079 | symtables_body TEXID STRING {
1080 $$->texsetting = *$3;
1083 | symtables_body STRING '=' symtable {
1090 TABLE '{' symtable_body '}' { $$ = $3; }
1094 { $$ = new Symtable; }
1095 | symtable_body STRING symboldef {
1104 $$ = new Symbol(*$1, *$2);
1109 Box b(Interval(0,0), Interval(0,0));
1110 $$ = new Symbol(*$1, b);
1116 dinterval dinterval {
1117 $$ = new Box(*$1, *$2);
1123 dinterval: dim dim {
1124 $$ = new Interval($1, $2);
1131 My_lily_parser::set_yydebug(bool b )
1138 My_lily_parser::do_yyparse()
1140 yyparse((void*)this);
1144 My_lily_parser::default_paper()
1146 return new Paper_def(
1147 lexer_p_->lookup_identifier("default_table")->lookup(true));