1 %{ // -*-Fundamental-*-
4 parser.y -- YACC parser for mudela
6 source file of the GNU LilyPond music typesetter
8 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
9 Jan Nieuwenhuizen <jan@digicash.com>
15 #define MUDELA_VERSION "0.1.9"
18 #include "translation-property.hh"
19 #include "script-def.hh"
20 #include "symtable.hh"
23 #include "my-lily-lexer.hh"
24 #include "paper-def.hh"
25 #include "midi-def.hh"
29 #include "parseconstruct.hh"
31 #include "identifier.hh"
32 #include "command-request.hh"
33 #include "musical-request.hh"
34 #include "my-lily-parser.hh"
35 #include "text-def.hh"
36 #include "translator-group.hh"
38 #include "music-list.hh"
40 #include "duration-convert.hh"
41 #include "change-translator.hh"
47 #define YYERROR_VERBOSE 1
49 #define YYPARSE_PARAM my_lily_parser_l
50 #define YYLEX_PARAM my_lily_parser_l
51 #define THIS ((My_lily_parser *) my_lily_parser_l)
53 #define yyerror THIS->parser_error
59 Array<Interval>* intarr;
60 Array<Melodic_req*> *melreqvec;/* should clean up naming */
61 Array<String> * strvec;
69 Music_list *musiclist;
76 Music_output_def * outputdef;
83 General_script_def * script;
88 Symtables * symtables;
99 yylex (YYSTYPE *s, void * v_l)
101 My_lily_parser *pars_l = (My_lily_parser*) v_l;
102 My_lily_lexer * lex_l = pars_l->lexer_p_;
104 lex_l->lexval_l = (void*) s;
105 return lex_l->yylex ();
113 /* tokens which are not keywords */
137 %token MELODIC_REQUEST
168 %token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
172 %token <melreq> NOTENAME_ID
173 %token <id> DURATION_IDENTIFIER
174 %token <id> IDENTIFIER
175 %token <id> MELODIC_REQUEST_IDENTIFIER
176 %token <id> MUSIC_IDENTIFIER
177 %token <id> VOICE_IDENTIFIER
178 %token <id> POST_REQUEST_IDENTIFIER
179 %token <id> SCRIPT_IDENTIFIER
180 %token <id> COMMAND_IDENTIFIER
181 %token <id> REAL_IDENTIFIER
182 %token <id> TRANS_IDENTIFIER
183 %token <id> INT_IDENTIFIER
184 %token <id> SCORE_IDENTIFIER
185 %token <id> MIDI_IDENTIFIER
186 %token <id> PAPER_IDENTIFIER
187 %token <id> REQUEST_IDENTIFIER
189 %token <string> DURATION RESTNAME
190 %token <string> STRING
192 %token <i> POST_QUOTES
193 %token <i> PRE_QUOTES
195 %type <outputdef> output_def
196 %type <header> mudela_header mudela_header_body
198 %type <i> open_request_parens close_request_parens
199 %type <c> open_abbrev_parens
200 %type <i> open_plet_parens close_plet_parens
201 %type <music> simple_element music_elt full_element lyrics_elt command_elt
202 %type <i> abbrev_type
203 %type <i> int unsigned
205 %type <id> identifier_init
206 %type <duration> explicit_steno_duration notemode_duration
207 %type <duration> entered_notemode_duration explicit_duration
208 %type <interval> dinterval
209 %type <intvec> intastint_list
210 %type <lookup> symtables symtables_body
211 %type <melreq> melodic_request steno_melodic_req
212 %type <notereq> steno_note_req
213 %type <melreqvec> pitch_list
214 %type <midi> midi_block midi_body
215 %type <moment> duration_length
217 %type <scalar> scalar
218 %type <music> Music transposed_music
219 %type <music> property_def translator_change
220 %type <musiclist> Voice Voice_body
221 %type <chord> Chord Chord_body
222 %type <paper> paper_block paper_body
223 %type <real> dim real
225 %type <request> abbrev_command_req
226 %type <request> post_request structured_post_request
227 %type <request> command_req verbose_command_req
228 %type <request> script_req dynamic_req
229 %type <score> score_block score_body
230 %type <intarr> shape_array
231 %type <script> script_definition script_body mudela_script gen_script_def
232 %type <textdef> text_def finger
233 %type <string> script_abbreviation
234 %type <symbol> symboldef
235 %type <symtable> symtable symtable_body
236 %type <trans> translator_spec translator_spec_body
237 %type <tempo> tempo_request
238 %type <string> concat_strings
246 | mudela mudela_header {
247 delete THIS->default_header_p_ ;
248 THIS->default_header_p_ = $2;
250 | mudela score_block {
253 | mudela add_declaration { }
255 | mudela check_version { }
256 | mudela add_notenames { }
261 if (String (*$2) != MUDELA_VERSION) {
262 if (THIS->ignore_version_b_) {
263 THIS->here_input ().error ("Incorrect mudela version");
265 THIS->fatal_error_i_ = 1;
266 THIS->parser_error ("Incorrect mudela version");
273 NOTENAMES '{' notenames_body '}'
278 | notenames_body CLEAR {
279 THIS->clear_notenames ();
281 | notenames_body STRING '=' melodic_request {
282 THIS->add_notename (*$2, $4);
291 | mudela_header_body STRING '=' concat_strings ';' {
299 HEADER '{' mudela_header_body '}' {
309 | concat_strings STRING {
320 THIS->remember_spot ();
322 /* cont */ '=' identifier_init {
323 THIS->lexer_p_->set_identifier (*$1, $4);
324 $4->init_b_ = THIS->init_parse_b_;
325 $4->set_spot (THIS->pop_spot ());
331 $$ = new Score_id ($1, SCORE_IDENTIFIER);
335 $$ = new Paper_def_id ($1, PAPER_IDENTIFIER);
339 $$ = new Midi_def_id ($1, MIDI_IDENTIFIER);
342 | script_definition {
343 $$ = new Script_id ($1, SCRIPT_IDENTIFIER);
347 $$ = new Music_id ($1, MUSIC_IDENTIFIER);
351 $$ = new Lookup_id ($1, IDENTIFIER);
355 $$ = new Real_id (new Real ($1), REAL_IDENTIFIER);
359 $$ = new Int_id (new int ($1), INT_IDENTIFIER);
362 $$ = new Request_id ($1, POST_REQUEST_IDENTIFIER);
365 $$ = new Request_id ($1, MELODIC_REQUEST_IDENTIFIER);
369 $$ = new Translator_id ($1, TRANS_IDENTIFIER);
371 | explicit_duration {
372 $$ = new Duration_id ($1, DURATION_IDENTIFIER);
379 TRANSLATOR '{' translator_spec_body '}'
383 translator_spec_body:
385 $$ = $1->translator ();
386 $$-> set_spot (THIS->here_input ());
389 $$ = get_translator_l (*$2)->clone ();
390 $$->set_spot (THIS->here_input ());
393 | translator_spec_body STRING '=' scalar ';' {
394 $$-> set_property (*$2, *$4);
398 | translator_spec_body CONSISTS STRING ';' {
399 $$->group_l ()->consists_str_arr_.push (*$3);
402 | translator_spec_body ACCEPTS STRING ';' {
403 $$->group_l ()->accepts_str_arr_.push (*$3);
412 SCORE { THIS->remember_spot ();
413 THIS->error_level_i_ =0;
415 /*cont*/ '{' score_body '}' {
417 $$->set_spot (THIS->pop_spot ());
418 if (!$$->def_p_arr_.size ())
419 $$->add (THIS->default_paper ());
421 /* handle error levels. */
422 $$->errorlevel_i_ = THIS->error_level_i_;
423 THIS->error_level_i_ = 0;
424 if (!$$->header_p_ && THIS->default_header_p_)
425 $$->header_p_ = new Header (*THIS->default_header_p_);
435 | score_body mudela_header {
440 $2->warning ("More than one music block");
443 | score_body output_def {
461 /* */ { $$ =new Array<int>; }
462 | intastint_list int '*' int {
463 $$->push ($2); $$->push ($4);
473 '{' paper_body '}' { $$ = $3; }
478 $$ = THIS->default_paper ();
481 $$ = $1->paperdef ();
483 | paper_body OUTPUT STRING ';' {
484 $$->outfile_str_ = *$3;
487 | paper_body symtables { $$->set ($2); }
488 | paper_body STRING '=' dim ';' {
489 $$->set_var (*$2, $4);
491 | paper_body STRING '=' real ';' {
492 $$->set_var (*$2, $4);
494 | paper_body STRING '=' translator_spec {
495 $$-> assign_translator (*$2, $4);
498 | paper_body SHAPE '=' shape_array ';' {
499 $$->shape_int_a_ = *$4;
509 $$ = new Array<Interval>;
511 | shape_array dim dim {
512 $$->push(Interval($2, $2 + $3));
521 '{' midi_body '}' { $$ = $3; }
524 midi_body: /* empty */ {
525 $$ = THIS->default_midi ();
527 | midi_body STRING '=' translator_spec {
528 $$-> assign_translator (*$2, $4);
531 | midi_body OUTPUT STRING ';' {
532 $$->outfile_str_ = *$3;
535 | midi_body tempo_request ';' {
536 $$->set_tempo ($2->dur_.length (), $2->metronome_i_);
545 TEMPO entered_notemode_duration '=' unsigned {
549 $$-> metronome_i_ = $4;
566 $$->set_spot (THIS->here_input ());
574 full_element { $$ = $1; }
575 | TYPE STRING Music {
577 $$->translator_type_str_ = *$2;
580 | TYPE STRING '=' STRING Music {
582 $$->translator_type_str_ = *$2;
583 $$->translator_id_str_ = *$4;
589 | transposed_music { $$ = $1; }
590 | MUSIC_IDENTIFIER { $$ = $1->music (); }
591 | MUSIC_IDENTIFIER ';' { $$ = $1->music (); }
593 { THIS->lexer_p_->push_note_state (); }
595 { $$=$3; THIS->lexer_p_->pop_state (); }
598 { THIS->lexer_p_->push_lyric_state (); }
600 { $$ = $3; THIS->lexer_p_->pop_state (); }
606 TRANSLATOR STRING '=' STRING {
607 Change_translator * t = new Change_translator;
608 t-> change_to_type_str_ = *$2;
609 t-> change_to_id_str_ = *$4;
612 $$->set_spot (THIS->here_input ());
619 PROPERTY STRING '.' STRING '=' scalar {
620 Translation_property *t = new Translation_property;
621 t-> translator_type_str_ = *$2;
625 $$->set_spot (THIS->here_input ());
633 STRING { $$ = new Scalar (*$1); delete $1; }
634 | int { $$ = new Scalar ($1); }
639 '<' Chord_body '>' { $$ = $2; }
640 | MULTI unsigned Chord {
642 $$->multi_level_i_=$2;
649 $$-> multi_level_i_ = 1;
650 $$->set_spot (THIS->here_input ());
658 TRANSPOSE steno_melodic_req Music {
660 $$ -> transpose ($2);
671 pre_requests simple_element post_requests {
672 THIS->add_requests ((Chord*)$2);//ugh
676 | voice_command ';' { $$ = 0; }
686 $$ = new Request_chord;
687 $$-> set_spot (THIS->here_input ());
688 $1-> set_spot (THIS->here_input ());
689 ((Chord*)$$) ->add ($1);//ugh
696 | verbose_command_req ';' { $$ = $1; }
701 $$ = new Barcheck_req;
703 | COMMAND_IDENTIFIER {
710 $$ = new Bar_req (*$2);
713 | METER unsigned '/' unsigned {
714 Meter_change_req *m = new Meter_change_req;
718 | SKIP duration_length {
719 Skip_req * skip_p = new Skip_req;
720 skip_p->duration_.set_plet ($2->numerator ().as_long (),
721 $2->denominator ().as_long ());
730 $$ = new Cadenza_req ($2);
732 | PARTIAL duration_length {
733 $$ = new Partial_measure_req (*$2);
737 $$ = new Clef_change_req (*$2);
741 Key_change_req *key_p= new Key_change_req;
742 key_p->melodic_p_arr_ = *$2;
746 | GROUPING intastint_list {
747 $$ = get_grouping_req (*$2); delete $2;
753 assert (THIS->post_reqs.empty ());
755 | post_requests structured_post_request {
756 $2->set_spot (THIS->here_input ());
757 THIS->post_reqs.push ($2);
759 | post_requests close_request_parens {
760 Array<Request*>& r = *THIS->get_parens_request ($2);
761 for (int i = 0; i < r.size (); i++ )
762 r[i]->set_spot (THIS->here_input ());
763 THIS->post_reqs.concat (r);
768 structured_post_request:
774 POST_REQUEST_IDENTIFIER {
775 $$ = (Request*)$1->request ();
781 Abbreviation_req* a = new Abbreviation_req;
794 $$ = $1->clone ()->musical ()->melodic ();
795 $$->octave_i_ += THIS->default_octave_i_;
797 | steno_melodic_req POST_QUOTES {
798 $$-> octave_i_ += $2;
800 | PRE_QUOTES steno_melodic_req {
802 $2-> octave_i_ -= $1;
809 * (Melodic_req *) $$ = *$1;
812 | steno_note_req '!' {
813 $$->forceacc_b_ = ! $$->forceacc_b_;
815 /* have to duration here. */
819 MELODIC_REQUEST '{' int int int '}' {/* ugh */
820 $$ = new Melodic_req;
822 $$->notename_i_ = $4;
823 $$->accidental_i_ = $5;
828 DURATION '{' int unsigned '}' {
836 ABSDYNAMIC '{' unsigned '}' {
837 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
838 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
841 | SPANDYNAMIC '{' int int '}' {
842 Span_dynamic_req * sp_p = new Span_dynamic_req;
844 sp_p-> dynamic_dir_ = $3;
850 ']' unsigned '/' unsigned {
852 THIS->plet_.type_i_ = $4;
853 THIS->plet_.iso_i_ = $2;
854 THIS->default_duration_.plet_.type_i_ = $4;
855 THIS->default_duration_.plet_.iso_i_ = $2;
859 THIS->plet_.type_i_ = 1;
860 THIS->plet_.iso_i_ = 1;
861 THIS->default_duration_.plet_.iso_i_ = 1;
862 THIS->default_duration_.plet_.type_i_ = 1;
864 | TELP unsigned '/' unsigned {
866 THIS->plet_.type_i_ = $4;
867 THIS->plet_.iso_i_ = $2;
868 THIS->default_duration_.plet_.type_i_ = $4;
869 THIS->default_duration_.plet_.iso_i_ = $2;
873 close_request_parens:
889 | close_plet_parens {
896 if (!Duration::duration_type_b ($3))
897 THIS->parser_error ("1:Not a duration");
899 THIS->parser_error ("Can't abbreviate");
901 THIS->set_abbrev_beam ($3);
906 '[' unsigned '/' unsigned {
908 THIS->plet_.type_i_ = $4;
909 THIS->plet_.iso_i_ = $2;
910 THIS->default_duration_.plet_.type_i_ = $4;
911 THIS->default_duration_.plet_.iso_i_ = $2;
913 | PLET unsigned '/' unsigned {
915 THIS->plet_.type_i_ = $4;
916 THIS->plet_.iso_i_ = $2;
917 THIS->default_duration_.plet_.type_i_ = $4;
918 THIS->default_duration_.plet_.iso_i_ = $2;
932 | open_abbrev_parens {
941 SCRIPT '{' script_body '}' { $$ = $3; }
945 STRING int int int int int {
946 Script_def *s = new Script_def;
947 s->set_from_input (*$1,$2, $3,$4,$5, $6);
954 script_dir gen_script_def {
955 Musical_script_req *m = new Musical_script_req;
957 m->scriptdef_p_ = $2;
958 m->set_spot (THIS->here_input ());
967 ((Text_def*) $$)->align_i_ = CENTER; /* UGH */
971 $$-> set_spot (THIS->here_input ());
975 ((Text_def*)$$)->align_i_ = CENTER;
981 Text_def *t = new Text_def;
985 t->style_str_ = THIS->textstyle_str_;
986 $$->set_spot (THIS->here_input ());
992 Text_def* t = new Text_def;
994 t->text_str_ = String ($1);
995 t->style_str_ = "finger";
996 $$->set_spot (THIS->here_input ());
1000 script_abbreviation:
1001 '^' { $$ = get_scriptdef ('^'); }
1002 | '+' { $$ = get_scriptdef ('+'); }
1003 | '-' { $$ = get_scriptdef ('-'); }
1004 | '|' { $$ = get_scriptdef ('|'); }
1005 | 'o' { $$ = get_scriptdef ('o'); }
1006 | '>' { $$ = get_scriptdef ('>'); }
1008 $$ = get_scriptdef ('.');
1013 SCRIPT_IDENTIFIER { $$ = $1->script (); }
1014 | script_definition { $$ = $1; }
1015 | script_abbreviation {
1016 $$ = THIS->lexer_p_->lookup_identifier (*$1)->script ();
1030 | pre_requests open_request_parens {
1031 Array<Request*>& r = *THIS->get_parens_request ($2);
1032 for (int i = 0; i < r.size (); i++ )
1033 r[i]->set_spot (THIS->here_input ());
1034 THIS->pre_reqs.concat (r);
1041 THIS->set_duration_mode (*$2);
1044 | DURATION entered_notemode_duration {
1045 THIS->set_default_duration ($2);
1050 This is weird, but default_octave_i_
1051 is used in steno_note_req too
1053 c' -> default_octave_i_ == 1
1055 /* why can't we have \oct 0 iso \oct{c'}*/
1056 THIS->default_octave_i_ = 1; }
1059 THIS->default_octave_i_ = $3->octave_i_;
1062 | TEXTSTYLE STRING {
1063 THIS->textstyle_str_ = *$2;
1070 $$ = new Moment (0,1);
1072 | duration_length explicit_steno_duration {
1073 *$$ += $2->length ();
1079 | dots '.' { $$ ++; }
1082 entered_notemode_duration:
1084 $$ = new Duration (THIS->default_duration_);
1087 $$ = new Duration (THIS->default_duration_);
1090 | explicit_steno_duration {
1091 THIS->set_last_duration ($1);
1097 entered_notemode_duration {
1102 explicit_steno_duration:
1105 if (!Duration::duration_type_b ($1))
1106 THIS->parser_error ("2:Not a duration");
1108 $$->durlog_i_ = Duration_convert::i2_type ($1);
1109 $$->set_plet (THIS->default_duration_);
1112 | DURATION_IDENTIFIER {
1113 $$ = $1->duration ();
1115 | explicit_steno_duration '.' {
1118 | explicit_steno_duration '*' unsigned {
1119 $$->plet_.iso_i_ = $3;
1121 | explicit_steno_duration '/' unsigned {
1122 $$->plet_.type_i_ = $3;
1132 if (!Duration::duration_type_b ($2))
1133 THIS->parser_error ("3:Not a duration");
1135 THIS->parser_error ("Can't abbreviate");
1142 steno_note_req notemode_duration {
1143 if (!THIS->lexer_p_->note_state_b ())
1144 THIS->parser_error ("have to be in Note mode for notes");
1145 $1->set_duration (*$2);
1146 int durlog_i = $2->durlog_i_;
1147 $$ = THIS->get_note_element ($1, $2);
1149 | RESTNAME notemode_duration {
1150 $$ = THIS->get_rest_element (*$1, $2);
1156 text_def notemode_duration {
1157 /* this sux! text-def should be feature of lyric-engraver. */
1158 if (!THIS->lexer_p_->lyric_state_b ())
1159 THIS->parser_error ("Have to be in Lyric mode for lyrics");
1160 $$ = THIS->get_word_element ($1, $2);
1168 $$ = new Array<Melodic_req*>;
1170 | pitch_list NOTENAME_ID {
1171 $$->push ($2->clone ()->musical ()->melodic ());
1191 int *i_p = $1->intid ();
1202 Real *r_p = $1->real ();
1211 real unit { $$ = $1*$2; }
1215 unit: CM_T { $$ = 1 CM; }
1216 |IN_T { $$ = 1 INCH; }
1217 |MM_T { $$ = 1 MM; }
1218 |PT_T { $$ = 1 PT; }
1225 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
1235 | symtables_body TEXID STRING {
1236 $$->texsetting = *$3;
1239 | symtables_body STRING '=' symtable {
1246 TABLE '{' symtable_body '}' { $$ = $3; }
1250 { $$ = new Symtable; }
1251 | symtable_body STRING symboldef {
1260 $$ = new Atom (*$1, *$2);
1265 Box b (Interval (0,0), Interval (0,0));
1266 $$ = new Atom (*$1, b);
1272 dinterval dinterval {
1273 $$ = new Box (*$1, *$2);
1279 dinterval: dim dim {
1280 $$ = new Interval ($1, $2);
1287 My_lily_parser::set_yydebug (bool b)
1294 My_lily_parser::do_yyparse ()
1296 yyparse ((void*)this);
1300 My_lily_parser::default_paper ()
1302 Identifier *id = lexer_p_->lookup_identifier ("default_paper");
1303 return id ? id->paperdef () : new Paper_def ;
1307 My_lily_parser::default_midi ()
1309 Identifier *id = lexer_p_->lookup_identifier ("default_midi");
1310 return id ? id->mididef () : new Midi_def ;