1 %{ // -*-Fundamental-*-
4 #define MUDELA_VERSION "0.0.50"
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_;
86 lex_l->lexval_l = (void*) s;
87 return lex_l->yylex();
94 /* tokens which are not keywords */
102 %token DURATIONCOMMAND
113 %token MELODIC_REQUEST
145 %token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
149 %token <melreq> NOTENAME_ID
150 %token <id> REGS_IDENTIFIER
151 %token <id> IDENTIFIER
152 %token <id> MELODIC_REQUEST_IDENTIFIER
153 %token <id> CHORD_IDENTIFIER
154 %token <id> VOICE_IDENTIFIER
155 %token <id> POST_REQUEST_IDENTIFIER
156 %token <id> SCRIPT_IDENTIFIER
157 %token <id> STAFF_IDENTIFIER
158 %token <id> REAL_IDENTIFIER
159 %token <id> SCORE_IDENTIFIER
160 %token <id> REQUEST_IDENTIFIER
162 %token <string> DURATION RESTNAME
163 %token <string> STRING
164 %token <i> POST_QUOTES
165 %token <i> PRE_QUOTES
169 %type <c> open_request_parens close_request_parens close_plet_parens
170 %type <chord> music_chord music_chord_body init_music_chord
171 %type <el> voice_elt full_element lyrics_elt command_elt
174 %type <id> declaration
175 %type <duration> explicit_duration notemode_duration
176 %type <interval> dinterval
177 %type <intvec> intastint_list
178 %type <lookup> symtables symtables_body
179 %type <melreq> melodic_request steno_melodic_req
180 %type <notereq> steno_note_req
181 %type <melreqvec> pitch_list
182 %type <midi> midi_block midi_body
183 %type <moment> duration_length
184 %type <music> init_music
185 %type <mvoice> transposed_music_voice init_lyrics_voice
186 %type <mvoice> music_voice_body music_voice init_music_voice
187 %type <paper> paper_block paper_body
188 %type <real> dim real
190 %type <request> post_request pre_request command_req verbose_command_req abbrev_command_req
191 %type <request> pure_post_request pure_post_request_choice
192 %type <request> script_req textscript_req dynamic_req
193 %type <score> score_block score_body
194 %type <script> script_definition script_body mudela_script
195 %type <staff> staff_block staff_init staff_body
196 %type <string> declarable_identifier
197 %type <string> script_abbreviation
198 %type <id> old_identifier
199 %type <symbol> symboldef
200 %type <symtable> symtable symtable_body
201 %type <textdef> mudela_text
202 %type <iregs> input_regs input_regs_body
206 %expect 1 /* have to fix this. */
211 | mudela score_block {
214 | mudela add_declaration { }
216 | mudela check_version { }
217 | mudela add_notenames { }
222 if (*$2 != MUDELA_VERSION) {
223 if (THIS->ignore_version_b_) {
224 THIS->here_input().error("Incorrect mudela version");
226 THIS->fatal_error_i_ = 1;
227 THIS->parser_error("Incorrect mudela version");
234 NOTENAMES '{' notenames_body '}'
239 | notenames_body CLEAR {
240 THIS->clear_notenames();
242 | notenames_body STRING '=' melodic_request {
243 THIS->add_notename(*$2, $4);
250 add_declaration: declaration {
251 THIS->lexer_p_->add_identifier($1);
252 $1->init_b_ = THIS->init_parse_b_;
253 $1->set_spot(THIS->pop_spot());
257 declarable_identifier:
259 THIS->remember_spot();
263 THIS->remember_spot();
264 $$ = new String($1->name_str_);
265 THIS->here_input().warning("redeclaration of `" + *$$ + "'");
272 | MELODIC_REQUEST_IDENTIFIER
275 | POST_REQUEST_IDENTIFIER
285 declarable_identifier '=' score_block {
286 $$ = new Score_id(*$1, $3, SCORE_IDENTIFIER);
289 | declarable_identifier '=' staff_block {
290 $$ = new Staff_id(*$1, $3, STAFF_IDENTIFIER);
293 | declarable_identifier '=' init_music_voice {
294 $$ = new M_voice_id(*$1, $3, VOICE_IDENTIFIER);
297 | declarable_identifier '=' init_lyrics_voice {
298 $$ = new M_voice_id(*$1, $3, VOICE_IDENTIFIER);
301 | declarable_identifier '=' script_definition {
302 $$ = new Script_id(*$1, $3, SCRIPT_IDENTIFIER);
305 | declarable_identifier '=' init_music_chord {
306 $$ = new M_chord_id(*$1, $3, CHORD_IDENTIFIER);
309 | declarable_identifier '=' symtables {
310 $$ = new Lookup_id(*$1, $3, IDENTIFIER);
313 | declarable_identifier '=' real {
314 $$ = new Real_id(*$1, new Real($3), REAL_IDENTIFIER);
318 | declarable_identifier '=' pure_post_request {
319 $$ = new Request_id(*$1, $3, POST_REQUEST_IDENTIFIER);
322 | declarable_identifier '=' melodic_request {
323 $$ = new Request_id(*$1, $3, MELODIC_REQUEST_IDENTIFIER);
326 | declarable_identifier '=' input_regs {
327 $$ = new Input_regs_id(*$1, $3, REGS_IDENTIFIER);
335 { THIS->remember_spot(); }
336 '{' input_regs_body '}'
339 $$->set_spot(THIS->pop_spot());
345 $$ = $1->iregs(true);
348 $$ = new Input_register;
351 | input_regs_body input_regs {
360 SCORE { THIS->remember_spot(); }
361 /*cont*/ '{' score_body '}' {
363 $$->set_spot(THIS->pop_spot());
364 if (!$$->paper_p_ && ! $$->midi_p_)
365 $$->paper_p_ = THIS->default_paper();
367 /* handle error levels. */
368 $$->errorlevel_i_ = THIS->error_level_i_;
369 THIS->error_level_i_ = 0;
374 $$ = new Input_score;
377 $$ = $1->score(true);
379 | score_body staff_block { $$->add($2); }
380 | score_body paper_block { $$->set($2); }
381 | score_body midi_block { $$->set($2); }
388 /* */ { $$ =new Array<int>; }
389 | intastint_list int '*' int {
390 $$->push($2); $$->push($4);
400 '{' paper_body '}' { $$ = $3; }
405 $$ = THIS->default_paper();
408 | paper_body WIDTH dim { $$->linewidth = $3;}
409 | paper_body OUTPUT STRING { $$->outfile = *$3;
412 | paper_body symtables { $$->set($2); }
413 | paper_body UNITSPACE dim { $$->whole_width = $3; }
414 | paper_body GEOMETRIC REAL { $$->geometric_ = $3; }
426 '{' midi_body '}' { $$ = $3; }
432 | midi_body OUTPUT STRING {
433 $$->outfile_str_ = *$3;
436 | midi_body TEMPO notemode_duration ':' int {
437 $$->set_tempo( $3->length(), $5 );
448 STAFF { THIS->remember_spot(); }
449 /*cont*/ '{' staff_body '}' {
451 $$-> set_spot(THIS->pop_spot());
453 | { THIS->remember_spot(); }
454 /*cont*/ STAFF_IDENTIFIER {
455 $$ = $2->staff(true);
456 $$-> set_spot(THIS->pop_spot());
464 $$ = $1->staff(true);
467 $$ = new Input_staff;
468 $$->ireg_p_ = $1->iregs(true);
471 $$ = new Input_staff;
478 | staff_body init_music {
480 $2->set_default_group( "staff_music" + String($$->music_.size()));
488 let the lexer switch mode.
491 init_music_voice { $$ = $1; }
492 | init_music_chord { $$ = $1; }
493 | init_lyrics_voice { $$ = $1; }
495 $$ = $1->mvoice(true);
500 LYRIC { THIS->lexer_p_->push_lyric_state(); }
501 music_voice { $$ = $3; THIS->lexer_p_->pop_state(); }
505 MELODIC { THIS->lexer_p_->push_note_state(); }
506 /* cont*/ music_voice
507 { $$=$3; THIS->lexer_p_->pop_state(); }
510 { THIS->lexer_p_->push_note_state(); }
511 /* cont*/ music_chord
512 { $$=$2; THIS->lexer_p_->pop_state(); }
520 transposed_music_voice:
521 steno_melodic_req music_voice {
528 music_voice: '{' music_voice_body '}' { $$ = $2; }
529 | TRANSPOSE '{' transposed_music_voice '}' {
536 $$ = $1->mvoice(true);
539 $$ = new Music_voice;
541 | music_voice_body full_element {
544 | music_voice_body voice_command ';' {
546 | music_voice_body music_chord {
549 | music_voice_body CONCAT music_voice {
550 $$->add($3);/* niet echt */
552 | music_voice_body error {
554 | music_voice_body '>' {
555 THIS->fatal_error_i_ = 1;
556 THIS->parser_error("Confused by errors: bailing out");
560 music_chord: '<' music_chord_body '>' { $$ = $2; }
568 $$ = new Voice_group_chord;
571 $$ = new Multi_voice_chord;
573 | music_chord_body music_voice {
576 | music_chord_body full_element {
579 | music_chord_body '}' {
580 THIS->fatal_error_i_ = 1;
581 THIS->parser_error("Confused by errors: bailing out");
583 | music_chord_body error {
590 full_element: pre_requests voice_elt post_requests {
591 THIS->add_requests($2);
594 | pre_requests lyrics_elt post_requests {
595 THIS->add_requests($2);
603 $$ = new Voice_element;
604 $$-> set_spot( THIS->here_input());
608 $2-> set_spot( THIS->here_input());
616 | verbose_command_req ';' { $$ = $1; }
621 $$ = new Barcheck_req;
627 $$ = new Bar_req(*$2);
630 | METER int '/' int {
631 Meter_change_req *m = new Meter_change_req;
633 // sorry hw, i need meter at output of track,
634 // but don-t know where to get it... statics should go.
635 // HW : default: 4/4, meterchange reqs may change it.
637 Midi_def::num_i_s = $2;
638 Midi_def::den_i_s = $4;
641 | SKIP duration_length {
642 Skip_req * skip_p = new Skip_req;
643 skip_p->duration_ = *$2;
648 $$ = new Cadenza_req($2);
650 | PARTIAL duration_length {
651 $$ = new Partial_measure_req(*$2);
655 $$ = get_stemdir_req($2);
658 $$ = new Clef_change_req(*$2);
662 Key_change_req *key_p= new Key_change_req;
663 key_p->melodic_p_arr_ = *$2;
667 | GROUPING intastint_list {
668 $$ = get_grouping_req(*$2); delete $2;
671 $$ = new Group_change_req;
672 $$ -> command()->groupchange()->newgroup_str_ = *$2;
679 assert(THIS->post_reqs.empty());
681 | post_requests post_request {
682 $2->set_spot( THIS->here_input());
683 THIS->post_reqs.push($2);
685 | post_requests close_plet_parens INT '/' INT {
686 THIS->post_reqs.push( THIS->get_parens_request($2) );
687 THIS->post_reqs.push( get_plet_request( $2, $3, $5 ) );
693 | POST_REQUEST_IDENTIFIER {
694 $$ = $1->request(false)->clone();
699 pure_post_request_choice {
701 $$->set_spot( THIS->here_input());
704 pure_post_request_choice:
705 close_request_parens {
706 $$ = THIS->get_parens_request($1);
720 $$ = $1->clone()->melodic();
721 $$->octave_i_ += THIS->default_octave_i_;
723 | steno_melodic_req POST_QUOTES {
724 $$-> octave_i_ += $2;
726 | PRE_QUOTES steno_melodic_req {
728 $2-> octave_i_ -= $1;
735 * (Melodic_req *) $$ = *$1;
738 | steno_note_req '!' {
739 $$->forceacc_b_ = ! $$->forceacc_b_;
741 /* have to duration here. */
745 MELODIC_REQUEST '{' int int int '}' {/* ugh */
746 $$ = new Melodic_req;
748 $$->notename_i_ = $4;
749 $$->accidental_i_ = $5;
754 ABSDYNAMIC '{' int '}' {
755 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
756 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
759 |SPANDYNAMIC '{' int int '}' {
760 Span_dynamic_req * sp_p = new Span_dynamic_req;
762 sp_p-> dynamic_dir_i_ = $3;
773 close_request_parens:
803 SCRIPT '{' script_body '}' { $$ = $3; }
807 STRING int int int int {
808 $$ = new Script_def(*$1,$2, $3,$4,$5);
814 script_dir mudela_text { $$ = get_text_req($1,$2); }
822 $$->style_str_ = THIS->textstyle_str_;
827 script_dir mudela_script {
828 $$ = get_script_req($1, $2);
832 '^' { $$ = get_scriptdef('^'); }
833 | '+' { $$ = get_scriptdef('+'); }
834 | '-' { $$ = get_scriptdef('-'); }
835 | '|' { $$ = get_scriptdef('|'); }
836 | 'o' { $$ = get_scriptdef('o'); }
837 | '>' { $$ = get_scriptdef('>'); }
840 THIS->here_input().warning( "too many staccato dots" );
841 $$ = get_scriptdef('.');
846 SCRIPT_IDENTIFIER { $$ = $1->script(true); }
847 | script_definition { $$ = $1; }
848 | script_abbreviation {
849 $$ = THIS->lexer_p_->lookup_identifier(*$1)->script(true);
861 | pre_requests pre_request {
862 THIS->pre_reqs.push($2);
863 $2->set_spot( THIS->here_input());
868 open_request_parens {
869 $$ = THIS->get_parens_request($1);
875 THIS->default_duration_.set_plet($2,$4);
877 | DURATIONCOMMAND STRING {
878 THIS->set_duration_mode(*$2);
881 | DURATIONCOMMAND notemode_duration {
882 THIS->default_duration_ = *$2;
887 This is weird, but default_octave_i_
888 is used in steno_note_req too
890 c' -> default_octave_i_ == 1
892 /* why can't we have \oct{0} iso \oct{c'}*/
893 THIS->default_octave_i_ = 1; }
896 THIS->default_octave_i_ = $3->octave_i_;
900 THIS->textstyle_str_ = *$2;
907 $$ = new Moment(0,1);
909 | duration_length explicit_duration {
916 $$ = new Duration(THIS->default_duration_);
919 $$ = new Duration(THIS->default_duration_);
922 | explicit_duration {
923 THIS->set_last_duration($1);
931 if ( !Duration::duration_type_b($1) )
932 THIS->parser_error("Not a duration");
936 | explicit_duration DOTS {
939 | explicit_duration '*' int {
940 $$->plet_.iso_i_ *= $3;
942 | explicit_duration '/' int {
943 $$->plet_.type_i_ *= $3;
949 steno_note_req notemode_duration {
950 if (!THIS->lexer_p_->note_state_b())
951 THIS->parser_error("have to be in Note mode for notes");
952 $$ = THIS->get_note_element($1, $2);
954 | RESTNAME notemode_duration {
955 $$ = THIS->get_rest_element(*$1, $2);
961 mudela_text notemode_duration {
962 if (!THIS->lexer_p_->lyric_state_b())
963 THIS->parser_error("Have to be in Lyric mode for lyrics");
964 $$ = THIS->get_word_element($1, $2);
972 $$ = new Array<Melodic_req*>;
974 | pitch_list NOTENAME_ID {
975 $$->push($2->clone()->melodic());
982 if ( distance($1,Real(int($$)) ) > 1e-8)
983 yyerror( "integer expected" );
1002 real unit { $$ = $1*$2; }
1006 unit: CM_T { $$ = 1 CM; }
1007 |IN_T { $$ = 1 INCH; }
1008 |MM_T { $$ = 1 MM; }
1009 |PT_T { $$ = 1 PT; }
1016 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
1024 $$ = new Lookup(*$1->lookup(true));
1026 | symtables_body TEXID STRING {
1027 $$->texsetting = *$3;
1030 | symtables_body STRING '=' symtable {
1037 TABLE '{' symtable_body '}' { $$ = $3; }
1041 { $$ = new Symtable; }
1042 | symtable_body STRING symboldef {
1051 $$ = new Symbol(*$1, *$2);
1057 $$ = new Symbol(*$1, b);
1063 dinterval dinterval {
1064 $$ = new Box(*$1, *$2);
1070 dinterval: dim dim {
1071 $$ = new Interval($1, $2);
1078 My_lily_parser::set_yydebug(bool b )
1085 My_lily_parser::do_yyparse()
1087 yyparse((void*)this);
1091 My_lily_parser::default_paper()
1093 return new Paper_def(
1094 lexer_p_->lookup_identifier("default_table")->lookup(true));