1 %{ // -*-Fundamental-*-
4 #define MUDELA_VERSION "0.0.61"
6 #include "script-def.hh"
10 #include "my-lily-lexer.hh"
11 #include "paper-def.hh"
12 #include "midi-def.hh"
16 #include "parseconstruct.hh"
18 #include "identifier.hh"
19 #include "command-request.hh"
20 #include "musical-request.hh"
21 #include "my-lily-parser.hh"
22 #include "text-def.hh"
23 #include "input-engraver.hh"
25 #include "music-list.hh"
31 #define YYERROR_VERBOSE 1
33 #define YYPARSE_PARAM my_lily_parser_l
34 #define YYLEX_PARAM my_lily_parser_l
35 #define THIS ((My_lily_parser *) my_lily_parser_l)
37 #define yyerror THIS->parser_error
43 Array<Melodic_req*> *melreqvec;/* should clean up naming */
44 Array<String> * strvec;
50 Input_engraver * iregs;
52 Music_list *musiclist;
63 General_script_def * script;
67 Symtables * symtables;
77 yylex(YYSTYPE *s, void * v_l)
79 My_lily_parser *pars_l = (My_lily_parser*) v_l;
80 My_lily_lexer * lex_l = pars_l->lexer_p_;
82 lex_l->lexval_l = (void*) s;
83 return lex_l->yylex();
91 /* tokens which are not keywords */
103 %token DURATIONCOMMAND
109 %token REQUESTENGRAVER
117 %token MELODIC_REQUEST
149 %token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
153 %token <melreq> NOTENAME_ID
154 %token <id> IDENTIFIER
155 %token <id> MELODIC_REQUEST_IDENTIFIER
156 %token <id> MUSIC_IDENTIFIER
157 %token <id> VOICE_IDENTIFIER
158 %token <id> POST_REQUEST_IDENTIFIER
159 %token <id> SCRIPT_IDENTIFIER
160 %token <id> STAFF_IDENTIFIER
161 %token <id> REAL_IDENTIFIER
162 %token <id> INT_IDENTIFIER
163 %token <id> SCORE_IDENTIFIER
164 %token <id> PAPER_IDENTIFIER
165 %token <id> REQUEST_IDENTIFIER
167 %token <string> DURATION RESTNAME
168 %token <string> STRING
169 %token <i> POST_QUOTES
170 %token <i> PRE_QUOTES
174 %type <c> open_request_parens close_request_parens
175 %type <c> open_plet_parens close_plet_parens
176 %type <music> simple_element music_elt full_element lyrics_elt command_elt
179 %type <id> declaration
180 %type <duration> explicit_duration notemode_duration
181 %type <interval> dinterval
182 %type <intvec> intastint_list
183 %type <lookup> symtables symtables_body
184 %type <melreq> melodic_request steno_melodic_req
185 %type <notereq> steno_note_req
186 %type <melreqvec> pitch_list
187 %type <midi> midi_block midi_body
188 %type <moment> duration_length
190 %type <music> Music transposed_music
191 %type <musiclist> Voice Voice_body
192 %type <chord> Chord Chord_body
193 %type <paper> paper_block paper_body
194 %type <real> dim real
196 %type <request> post_request pre_request command_req verbose_command_req abbrev_command_req
197 %type <request> script_req dynamic_req
198 %type <score> score_block score_body
199 %type <script> script_definition script_body mudela_script gen_script_def
200 %type <textdef> text_def
201 %type <string> declarable_identifier
202 %type <string> script_abbreviation
203 %type <id> old_identifier
204 %type <symbol> symboldef
205 %type <symtable> symtable symtable_body
206 %type <iregs> input_engraver_spec input_engraver_spec_body
213 | mudela score_block {
216 | mudela add_declaration { }
218 | mudela check_version { }
219 | mudela add_notenames { }
224 if (*$2 != MUDELA_VERSION) {
225 if (THIS->ignore_version_b_) {
226 THIS->here_input().error("Incorrect mudela version");
228 THIS->fatal_error_i_ = 1;
229 THIS->parser_error("Incorrect mudela version");
236 NOTENAMES '{' notenames_body '}'
241 | notenames_body CLEAR {
242 THIS->clear_notenames();
244 | notenames_body STRING '=' melodic_request {
245 THIS->add_notename(*$2, $4);
252 add_declaration: declaration {
253 THIS->lexer_p_->add_identifier($1);
254 $1->init_b_ = THIS->init_parse_b_;
255 $1->set_spot(THIS->pop_spot());
259 declarable_identifier:
261 THIS->remember_spot();
265 THIS->remember_spot();
266 $$ = new String($1->name_str_);
267 THIS->here_input().warning("redeclaration of `" + *$$ + "'");
274 | MELODIC_REQUEST_IDENTIFIER
275 | POST_REQUEST_IDENTIFIER
283 declarable_identifier '=' score_block {
284 $$ = new Score_id(*$1, $3, SCORE_IDENTIFIER);
287 | declarable_identifier '=' paper_block {
288 $$ = new Paper_def_id(*$1, $3, PAPER_IDENTIFIER);
291 | declarable_identifier '=' script_definition {
292 $$ = new Script_id(*$1, $3, SCRIPT_IDENTIFIER);
295 | declarable_identifier '=' Music {
296 $$ = new Music_id(*$1, $3, MUSIC_IDENTIFIER);
299 | declarable_identifier '=' symtables {
300 $$ = new Lookup_id(*$1, $3, IDENTIFIER);
303 | declarable_identifier '=' real {
304 $$ = new Real_id(*$1, new Real($3), REAL_IDENTIFIER);
307 | declarable_identifier '=' int {
308 $$ = new Int_id(*$1, new int($3), INT_IDENTIFIER);
311 | declarable_identifier '=' post_request {
312 $$ = new Request_id(*$1, $3, POST_REQUEST_IDENTIFIER);
315 | declarable_identifier '=' melodic_request {
316 $$ = new Request_id(*$1, $3, MELODIC_REQUEST_IDENTIFIER);
324 REQUESTENGRAVER '{' input_engraver_spec_body '}'
328 input_engraver_spec_body:
330 $$ = new Input_engraver;
332 $$->set_spot ( THIS->here_input() );
335 | input_engraver_spec_body ALIAS STRING ';' {
336 $$-> alias_str_arr_.push(*$3);
339 | input_engraver_spec_body CONSISTS STRING ';' {
340 $$-> consists_str_arr_.push(*$3);
343 | input_engraver_spec_body CONTAINS input_engraver_spec {
351 SCORE { THIS->remember_spot(); }
352 /*cont*/ '{' score_body '}' {
354 $$->set_spot(THIS->pop_spot());
355 if (!$$->paper_p_ && ! $$->midi_p_)
356 $$->paper_p_ = THIS->default_paper();
358 /* handle error levels. */
359 $$->errorlevel_i_ = THIS->error_level_i_;
360 THIS->error_level_i_ = 0;
368 $$ = $1->score(true);
373 | score_body paper_block {
376 | score_body midi_block {
385 /* */ { $$ =new Array<int>; }
386 | intastint_list int '*' int {
387 $$->push($2); $$->push($4);
397 '{' paper_body '}' { $$ = $3; }
402 $$ = THIS->default_paper();
404 | paper_body OUTPUT STRING ';' { $$->outfile_str_ = *$3;
407 | paper_body symtables { $$->set($2); }
408 | paper_body STRING '=' dim ';' {
409 $$->set_var(*$2, $4);
411 | paper_body STRING '=' REAL ';' {
412 $$->set_var(*$2, $4);
414 | paper_body input_engraver_spec {
428 '{' midi_body '}' { $$ = $3; }
434 | midi_body OUTPUT STRING ';' {
435 $$->outfile_str_ = *$3;
438 | midi_body TEMPO notemode_duration ':' int ';' {
439 $$->set_tempo( $3->length(), $5 );
463 | Voice_body ID STRING STRING ';' {
476 full_element { $$ = $1; }
479 | transposed_music { $$ = $1; }
480 | MUSIC_IDENTIFIER { $$ = $1->music(true); }
482 { THIS->lexer_p_->push_note_state(); }
484 { $$=$3; THIS->lexer_p_->pop_state(); }
487 { THIS->lexer_p_->push_lyric_state(); }
489 { $$ = $3; THIS->lexer_p_->pop_state(); }
493 '<' Chord_body '>' { $$ = $2; }
499 $$-> multi_level_i_ = 1;
501 | Chord_body MULTI INT ';' {
502 $$->multi_level_i_=$3;
504 | Chord_body ID STRING STRING ';' {
516 TRANSPOSE steno_melodic_req Music {
528 pre_requests simple_element post_requests {
529 THIS->add_requests((Chord*)$2);//ugh
532 | voice_command ';' { $$ = 0; }
543 $$ = new Voice_element;
544 $$-> set_spot( THIS->here_input());
548 $2-> set_spot( THIS->here_input());
549 ((Chord*)$$) ->add($2);//ugh
552 | GROUP STRING ';' { // ugh ugh ugh
553 Change_reg *chr_p = new Change_reg;
555 chr_p-> type_str_ = "Voice_group_engravers"; //ugh
556 chr_p-> id_str_ = *$2;
563 | verbose_command_req ';' { $$ = $1; }
568 $$ = new Barcheck_req;
574 $$ = new Bar_req(*$2);
577 | METER int '/' int {
578 Meter_change_req *m = new Meter_change_req;
580 // sorry hw, i need meter at output of track,
581 // but don-t know where to get it... statics should go.
582 // HW : default: 4/4, meterchange reqs may change it.
584 Midi_def::num_i_s = $2;
585 Midi_def::den_i_s = $4;
588 | SKIP duration_length {
589 Skip_req * skip_p = new Skip_req;
590 skip_p->duration_ = Duration(1,0);
591 skip_p->duration_.set_plet($2->numerator().as_long(),
592 $2->denominator().as_long());
598 $$ = new Cadenza_req($2);
600 | PARTIAL duration_length {
601 $$ = new Partial_measure_req(*$2);
605 $$ = get_stemdir_req($2);
608 $$ = get_hshift_req($2);
611 $$ = new Clef_change_req(*$2);
615 Key_change_req *key_p= new Key_change_req;
616 key_p->melodic_p_arr_ = *$2;
620 | GROUPING intastint_list {
621 $$ = get_grouping_req(*$2); delete $2;
628 assert(THIS->post_reqs.empty());
630 | post_requests post_request {
631 $2->set_spot( THIS->here_input());
632 THIS->post_reqs.push($2);
638 POST_REQUEST_IDENTIFIER {
639 $$ = (Request*)$1->request(true);
641 |close_request_parens {
642 $$ = THIS->get_parens_request($1);
655 $$ = $1->clone()->musical()->melodic();
656 $$->octave_i_ += THIS->default_octave_i_;
658 | steno_melodic_req POST_QUOTES {
659 $$-> octave_i_ += $2;
661 | PRE_QUOTES steno_melodic_req {
663 $2-> octave_i_ -= $1;
670 * (Melodic_req *) $$ = *$1;
673 | steno_note_req '!' {
674 $$->forceacc_b_ = ! $$->forceacc_b_;
676 /* have to duration here. */
680 MELODIC_REQUEST '{' int int int '}' {/* ugh */
681 $$ = new Melodic_req;
683 $$->notename_i_ = $4;
684 $$->accidental_i_ = $5;
689 ABSDYNAMIC '{' int '}' {
690 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
691 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
694 | SPANDYNAMIC '{' int int '}' {
695 Span_dynamic_req * sp_p = new Span_dynamic_req;
697 sp_p-> dynamic_dir_i_ = $3;
705 THIS->default_duration_.set_plet($2,$4);
709 close_request_parens:
719 | close_plet_parens {
733 THIS->default_duration_.set_plet($2,$4);
754 SCRIPT '{' script_body '}' { $$ = $3; }
758 STRING int int int int int {
759 Script_def *s = new Script_def;
760 s->set_from_input(*$1,$2, $3,$4,$5, $6);
767 script_dir gen_script_def {
768 Musical_script_req *m = new Musical_script_req;
770 m-> scriptdef_p_ = $2;
771 m-> set_spot ( THIS->here_input() );
777 text_def { $$ = $1; }
778 | mudela_script { $$ = $1;
779 $$-> set_spot( THIS->here_input() );
785 Text_def *t = new Text_def;
789 t->style_str_ = THIS->textstyle_str_;
790 $$->set_spot( THIS->here_input() );
795 '^' { $$ = get_scriptdef('^'); }
796 | '+' { $$ = get_scriptdef('+'); }
797 | '-' { $$ = get_scriptdef('-'); }
798 | '|' { $$ = get_scriptdef('|'); }
799 | 'o' { $$ = get_scriptdef('o'); }
800 | '>' { $$ = get_scriptdef('>'); }
802 $$ = get_scriptdef('.');
807 SCRIPT_IDENTIFIER { $$ = $1->script(true); }
808 | script_definition { $$ = $1; }
809 | script_abbreviation {
810 $$ = THIS->lexer_p_->lookup_identifier(*$1)->script(true);
822 | pre_requests pre_request {
823 THIS->pre_reqs.push($2);
824 $2->set_spot( THIS->here_input());
829 open_request_parens {
830 $$ = THIS->get_parens_request($1);
836 THIS->default_duration_.set_plet($2,$4);
838 | DURATIONCOMMAND STRING {
839 THIS->set_duration_mode(*$2);
842 | DURATIONCOMMAND notemode_duration {
843 THIS->set_default_duration($2);
848 This is weird, but default_octave_i_
849 is used in steno_note_req too
851 c' -> default_octave_i_ == 1
853 /* why can't we have \oct{0} iso \oct{c'}*/
854 THIS->default_octave_i_ = 1; }
857 THIS->default_octave_i_ = $3->octave_i_;
861 THIS->textstyle_str_ = *$2;
868 $$ = new Moment(0,1);
870 | duration_length explicit_duration {
877 | dots '.' { $$ ++; }
882 $$ = new Duration(THIS->default_duration_);
885 $$ = new Duration(THIS->default_duration_);
888 | explicit_duration {
889 THIS->set_last_duration($1);
897 if ( !Duration::duration_type_b($1) )
898 THIS->parser_error("Not a duration");
901 $$->set_plet(THIS->default_duration_);
904 | explicit_duration '.' {
907 | explicit_duration '*' int {
908 $$->plet_.iso_i_ *= $3;
910 | explicit_duration '/' int {
911 $$->plet_.type_i_ *= $3;
917 steno_note_req notemode_duration {
918 if (!THIS->lexer_p_->note_state_b())
919 THIS->parser_error("have to be in Note mode for notes");
920 $1->set_duration (*$2);
921 $$ = THIS->get_note_element($1, $2);
923 | RESTNAME notemode_duration {
924 $$ = THIS->get_rest_element(*$1, $2);
930 text_def notemode_duration {
931 if (!THIS->lexer_p_->lyric_state_b())
932 THIS->parser_error("Have to be in Lyric mode for lyrics");
933 $$ = THIS->get_word_element($1, $2);
941 $$ = new Array<Melodic_req*>;
943 | pitch_list NOTENAME_ID {
944 $$->push($2->clone()->musical()->melodic());
970 real unit { $$ = $1*$2; }
974 unit: CM_T { $$ = 1 CM; }
975 |IN_T { $$ = 1 INCH; }
984 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
992 $$ = $1->lookup(true);
994 | symtables_body TEXID STRING {
995 $$->texsetting = *$3;
998 | symtables_body STRING '=' symtable {
1005 TABLE '{' symtable_body '}' { $$ = $3; }
1009 { $$ = new Symtable; }
1010 | symtable_body STRING symboldef {
1019 $$ = new Symbol(*$1, *$2);
1024 Box b(Interval(0,0), Interval(0,0));
1025 $$ = new Symbol(*$1, b);
1031 dinterval dinterval {
1032 $$ = new Box(*$1, *$2);
1038 dinterval: dim dim {
1039 $$ = new Interval($1, $2);
1046 My_lily_parser::set_yydebug(bool b )
1053 My_lily_parser::do_yyparse()
1055 yyparse((void*)this);
1059 My_lily_parser::default_paper()
1061 Identifier *id = lexer_p_->lookup_identifier( "default_paper" );
1062 return id ? id->paperdef(true) : new Paper_def ;