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.8"
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
191 %token <i> POST_QUOTES
192 %token <i> PRE_QUOTES
194 %type <outputdef> output_def
195 %type <header> mudela_header mudela_header_body
197 %type <i> open_request_parens close_request_parens
198 %type <c> open_abbrev_parens
199 %type <i> open_plet_parens close_plet_parens
200 %type <music> simple_element music_elt full_element lyrics_elt command_elt
201 %type <i> abbrev_type
204 %type <id> identifier_init
205 %type <duration> explicit_steno_duration notemode_duration
206 %type <duration> entered_notemode_duration explicit_duration
207 %type <interval> dinterval
208 %type <intvec> intastint_list
209 %type <lookup> symtables symtables_body
210 %type <melreq> melodic_request steno_melodic_req
211 %type <notereq> steno_note_req
212 %type <melreqvec> pitch_list
213 %type <midi> midi_block midi_body
214 %type <moment> duration_length
216 %type <scalar> scalar
217 %type <music> Music transposed_music
218 %type <music> property_def translator_change
219 %type <musiclist> Voice Voice_body
220 %type <chord> Chord Chord_body
221 %type <paper> paper_block paper_body
222 %type <real> dim real
224 %type <request> abbrev_command_req
225 %type <request> post_request command_req verbose_command_req
226 %type <request> script_req dynamic_req
227 %type <score> score_block score_body
228 %type <intarr> shape_array
229 %type <script> script_definition script_body mudela_script gen_script_def
230 %type <textdef> text_def
231 %type <string> script_abbreviation
232 %type <symbol> symboldef
233 %type <symtable> symtable symtable_body
234 %type <trans> translator_spec translator_spec_body
235 %type <tempo> tempo_request
236 %type <string> concat_strings
244 | mudela mudela_header {
245 delete THIS->default_header_p_ ;
246 THIS->default_header_p_ = $2;
248 | mudela score_block {
251 | mudela add_declaration { }
253 | mudela check_version { }
254 | mudela add_notenames { }
259 if (String (*$2) != MUDELA_VERSION) {
260 if (THIS->ignore_version_b_) {
261 THIS->here_input ().error ("Incorrect mudela version");
263 THIS->fatal_error_i_ = 1;
264 THIS->parser_error ("Incorrect mudela version");
271 NOTENAMES '{' notenames_body '}'
276 | notenames_body CLEAR {
277 THIS->clear_notenames ();
279 | notenames_body STRING '=' melodic_request {
280 THIS->add_notename (*$2, $4);
289 | mudela_header_body STRING '=' concat_strings ';' {
297 HEADER '{' mudela_header_body '}' {
307 | concat_strings STRING {
318 THIS->remember_spot ();
320 /* cont */ '=' identifier_init {
321 THIS->lexer_p_->set_identifier (*$1, $4);
322 $4->init_b_ = THIS->init_parse_b_;
323 $4->set_spot (THIS->pop_spot ());
328 $$ = new Score_id ($1, SCORE_IDENTIFIER);
332 $$ = new Paper_def_id ($1, PAPER_IDENTIFIER);
336 $$ = new Midi_def_id ($1, MIDI_IDENTIFIER);
339 | script_definition {
340 $$ = new Script_id ($1, SCRIPT_IDENTIFIER);
344 $$ = new Music_id ($1, MUSIC_IDENTIFIER);
348 $$ = new Lookup_id ($1, IDENTIFIER);
352 $$ = new Real_id (new Real ($1), REAL_IDENTIFIER);
356 $$ = new Int_id (new int ($1), INT_IDENTIFIER);
360 $$ = new Request_id ($1, POST_REQUEST_IDENTIFIER);
364 $$ = new Request_id ($1, MELODIC_REQUEST_IDENTIFIER);
368 $$ = new Translator_id ($1, TRANS_IDENTIFIER);
370 | explicit_duration {
371 $$ = new Duration_id ($1, DURATION_IDENTIFIER);
378 TRANSLATOR '{' translator_spec_body '}'
382 translator_spec_body:
384 $$ = $1->translator ();
385 $$-> set_spot (THIS->here_input ());
388 $$ = get_translator_l (*$2)->clone ();
389 $$->set_spot (THIS->here_input ());
392 | translator_spec_body STRING '=' scalar ';' {
393 $$-> set_property (*$2, *$4);
397 | translator_spec_body CONSISTS STRING ';' {
398 $$->group_l ()->consists_str_arr_.push (*$3);
401 | translator_spec_body ACCEPTS STRING ';' {
402 $$->group_l ()->accepts_str_arr_.push (*$3);
411 SCORE { THIS->remember_spot ();
412 THIS->error_level_i_ =0;
414 /*cont*/ '{' score_body '}' {
416 $$->set_spot (THIS->pop_spot ());
417 if (!$$->def_p_arr_.size ())
418 $$->add (THIS->default_paper ());
420 /* handle error levels. */
421 $$->errorlevel_i_ = THIS->error_level_i_;
422 THIS->error_level_i_ = 0;
423 if (!$$->header_p_ && THIS->default_header_p_)
424 $$->header_p_ = new Header (*THIS->default_header_p_);
434 | score_body mudela_header {
439 $2->warning ("More than one music block");
442 | score_body output_def {
460 /* */ { $$ =new Array<int>; }
461 | intastint_list int '*' int {
462 $$->push ($2); $$->push ($4);
472 '{' paper_body '}' { $$ = $3; }
477 $$ = THIS->default_paper ();
480 $$ = $1->paperdef ();
482 | paper_body OUTPUT STRING ';' {
483 $$->outfile_str_ = *$3;
486 | paper_body symtables { $$->set ($2); }
487 | paper_body STRING '=' dim ';' {
488 $$->set_var (*$2, $4);
490 | paper_body STRING '=' real ';' {
491 $$->set_var (*$2, $4);
493 | paper_body STRING '=' translator_spec {
494 $$-> assign_translator (*$2, $4);
497 | paper_body SHAPE '=' shape_array ';' {
498 $$->shape_int_a_ = *$4;
508 $$ = new Array<Interval>;
510 | shape_array dim dim {
511 $$->push(Interval($2, $2 + $3));
520 '{' midi_body '}' { $$ = $3; }
523 midi_body: /* empty */ {
524 $$ = THIS->default_midi ();
526 | midi_body STRING '=' translator_spec {
527 $$-> assign_translator (*$2, $4);
530 | midi_body OUTPUT STRING ';' {
531 $$->outfile_str_ = *$3;
534 | midi_body tempo_request ';' {
535 $$->set_tempo ($2->dur_.length (), $2->metronome_i_);
544 TEMPO entered_notemode_duration '=' int {
548 $$-> metronome_i_ = $4;
565 $$->set_spot (THIS->here_input ());
573 full_element { $$ = $1; }
574 | TYPE STRING Music {
576 $$->translator_type_str_ = *$2;
579 | TYPE STRING '=' STRING Music {
581 $$->translator_type_str_ = *$2;
582 $$->translator_id_str_ = *$4;
588 | transposed_music { $$ = $1; }
589 | MUSIC_IDENTIFIER { $$ = $1->music (); }
590 | MUSIC_IDENTIFIER ';' { $$ = $1->music (); }
592 { THIS->lexer_p_->push_note_state (); }
594 { $$=$3; THIS->lexer_p_->pop_state (); }
597 { THIS->lexer_p_->push_lyric_state (); }
599 { $$ = $3; THIS->lexer_p_->pop_state (); }
605 TRANSLATOR STRING '=' STRING {
606 Change_translator * t = new Change_translator;
607 t-> change_to_type_str_ = *$2;
608 t-> change_to_id_str_ = *$4;
611 $$->set_spot (THIS->here_input ());
618 PROPERTY STRING '.' STRING '=' scalar {
619 Translation_property *t = new Translation_property;
620 t-> translator_type_str_ = *$2;
624 $$->set_spot (THIS->here_input ());
632 STRING { $$ = new Scalar (*$1); delete $1; }
633 | int { $$ = new Scalar ($1); }
638 '<' Chord_body '>' { $$ = $2; }
641 $$->multi_level_i_=$2;
648 $$-> multi_level_i_ = 1;
649 $$->set_spot (THIS->here_input ());
657 TRANSPOSE steno_melodic_req Music {
659 $$ -> transpose ($2);
670 pre_requests simple_element post_requests {
671 THIS->add_requests ((Chord*)$2);//ugh
675 | voice_command ';' { $$ = 0; }
685 $$ = new Request_chord;
686 $$-> set_spot (THIS->here_input ());
687 $1-> set_spot (THIS->here_input ());
688 ((Chord*)$$) ->add ($1);//ugh
695 | verbose_command_req ';' { $$ = $1; }
700 $$ = new Barcheck_req;
702 | COMMAND_IDENTIFIER {
709 $$ = new Bar_req (*$2);
712 | METER int '/' int {
713 Meter_change_req *m = new Meter_change_req;
717 | SKIP duration_length {
718 Skip_req * skip_p = new Skip_req;
719 skip_p->duration_.set_plet ($2->numerator ().as_long (),
720 $2->denominator ().as_long ());
729 $$ = new Cadenza_req ($2);
731 | PARTIAL duration_length {
732 $$ = new Partial_measure_req (*$2);
736 $$ = new Clef_change_req (*$2);
740 Key_change_req *key_p= new Key_change_req;
741 key_p->melodic_p_arr_ = *$2;
745 | GROUPING intastint_list {
746 $$ = get_grouping_req (*$2); delete $2;
752 assert (THIS->post_reqs.empty ());
754 | post_requests post_request {
755 $2->set_spot (THIS->here_input ());
756 THIS->post_reqs.push ($2);
758 | post_requests close_request_parens {
759 Array<Request*>& r = *THIS->get_parens_request ($2);
760 for (int i = 0; i < r.size (); i++ )
761 r[i]->set_spot (THIS->here_input ());
762 THIS->post_reqs.concat (r);
769 POST_REQUEST_IDENTIFIER {
770 $$ = (Request*)$1->request ();
775 Abbreviation_req* a = new Abbreviation_req;
788 $$ = $1->clone ()->musical ()->melodic ();
789 $$->octave_i_ += THIS->default_octave_i_;
791 | steno_melodic_req POST_QUOTES {
792 $$-> octave_i_ += $2;
794 | PRE_QUOTES steno_melodic_req {
796 $2-> octave_i_ -= $1;
803 * (Melodic_req *) $$ = *$1;
806 | steno_note_req '!' {
807 $$->forceacc_b_ = ! $$->forceacc_b_;
809 /* have to duration here. */
813 MELODIC_REQUEST '{' int int int '}' {/* ugh */
814 $$ = new Melodic_req;
816 $$->notename_i_ = $4;
817 $$->accidental_i_ = $5;
822 DURATION '{' int int '}' {
830 ABSDYNAMIC '{' int '}' {
831 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
832 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
835 | SPANDYNAMIC '{' int int '}' {
836 Span_dynamic_req * sp_p = new Span_dynamic_req;
838 sp_p-> dynamic_dir_ = $3;
846 THIS->plet_.type_i_ = $4;
847 THIS->plet_.iso_i_ = $2;
848 THIS->default_duration_.plet_.type_i_ = $4;
849 THIS->default_duration_.plet_.iso_i_ = $2;
853 THIS->plet_.type_i_ = 1;
854 THIS->plet_.iso_i_ = 1;
855 THIS->default_duration_.plet_.iso_i_ = 1;
856 THIS->default_duration_.plet_.type_i_ = 1;
860 THIS->plet_.type_i_ = $4;
861 THIS->plet_.iso_i_ = $2;
862 THIS->default_duration_.plet_.type_i_ = $4;
863 THIS->default_duration_.plet_.iso_i_ = $2;
867 close_request_parens:
883 | close_plet_parens {
890 if (!Duration::duration_type_b ($3))
891 THIS->parser_error ("Not a duration");
893 THIS->parser_error ("Can't abbreviate");
895 THIS->set_abbrev_beam ($3);
902 THIS->plet_.type_i_ = $4;
903 THIS->plet_.iso_i_ = $2;
904 THIS->default_duration_.plet_.type_i_ = $4;
905 THIS->default_duration_.plet_.iso_i_ = $2;
909 THIS->plet_.type_i_ = $4;
910 THIS->plet_.iso_i_ = $2;
911 THIS->default_duration_.plet_.type_i_ = $4;
912 THIS->default_duration_.plet_.iso_i_ = $2;
926 | open_abbrev_parens {
935 SCRIPT '{' script_body '}' { $$ = $3; }
939 STRING int int int int int {
940 Script_def *s = new Script_def;
941 s->set_from_input (*$1,$2, $3,$4,$5, $6);
948 script_dir gen_script_def {
949 Musical_script_req *m = new Musical_script_req;
951 m-> scriptdef_p_ = $2;
952 m-> set_spot (THIS->here_input ());
959 ((Text_def*) $$)->align_i_ = CENTER; /* UGH */
961 | mudela_script { $$ = $1;
962 $$-> set_spot (THIS->here_input ());
968 Text_def *t = new Text_def;
972 t->style_str_ = THIS->textstyle_str_;
973 $$->set_spot (THIS->here_input ());
978 '^' { $$ = get_scriptdef ('^'); }
979 | '+' { $$ = get_scriptdef ('+'); }
980 | '-' { $$ = get_scriptdef ('-'); }
981 | '|' { $$ = get_scriptdef ('|'); }
982 | 'o' { $$ = get_scriptdef ('o'); }
983 | '>' { $$ = get_scriptdef ('>'); }
985 $$ = get_scriptdef ('.');
990 SCRIPT_IDENTIFIER { $$ = $1->script (); }
991 | script_definition { $$ = $1; }
992 | script_abbreviation {
993 $$ = THIS->lexer_p_->lookup_identifier (*$1)->script ();
1007 | pre_requests open_request_parens {
1008 Array<Request*>& r = *THIS->get_parens_request ($2);
1009 for (int i = 0; i < r.size (); i++ )
1010 r[i]->set_spot (THIS->here_input ());
1011 THIS->pre_reqs.concat (r);
1018 THIS->set_duration_mode (*$2);
1021 | DURATION entered_notemode_duration {
1022 THIS->set_default_duration ($2);
1027 This is weird, but default_octave_i_
1028 is used in steno_note_req too
1030 c' -> default_octave_i_ == 1
1032 /* why can't we have \oct 0 iso \oct{c'}*/
1033 THIS->default_octave_i_ = 1; }
1036 THIS->default_octave_i_ = $3->octave_i_;
1039 | TEXTSTYLE STRING {
1040 THIS->textstyle_str_ = *$2;
1047 $$ = new Moment (0,1);
1049 | duration_length explicit_steno_duration {
1050 *$$ += $2->length ();
1056 | dots '.' { $$ ++; }
1059 entered_notemode_duration:
1061 $$ = new Duration (THIS->default_duration_);
1064 $$ = new Duration (THIS->default_duration_);
1067 | explicit_steno_duration {
1068 THIS->set_last_duration ($1);
1074 entered_notemode_duration {
1079 explicit_steno_duration:
1082 if (!Duration::duration_type_b ($1))
1083 THIS->parser_error ("Not a duration");
1085 $$->durlog_i_ = Duration_convert::i2_type ($1);
1086 $$->set_plet (THIS->default_duration_);
1089 | DURATION_IDENTIFIER {
1090 $$ = $1->duration ();
1092 | explicit_steno_duration '.' {
1095 | explicit_steno_duration '*' int {
1096 $$->plet_.iso_i_ = $3;
1098 | explicit_steno_duration '/' int {
1099 $$->plet_.type_i_ = $3;
1109 if (!Duration::duration_type_b ($2))
1110 THIS->parser_error ("Not a duration");
1112 THIS->parser_error ("Can't abbreviate");
1119 steno_note_req notemode_duration {
1120 if (!THIS->lexer_p_->note_state_b ())
1121 THIS->parser_error ("have to be in Note mode for notes");
1122 $1->set_duration (*$2);
1123 int durlog_i = $2->durlog_i_;
1124 $$ = THIS->get_note_element ($1, $2);
1126 | RESTNAME notemode_duration {
1127 $$ = THIS->get_rest_element (*$1, $2);
1133 text_def notemode_duration {
1134 /* this sux! text-def should be feature of lyric-engraver. */
1135 if (!THIS->lexer_p_->lyric_state_b ())
1136 THIS->parser_error ("Have to be in Lyric mode for lyrics");
1137 $$ = THIS->get_word_element ($1, $2);
1145 $$ = new Array<Melodic_req*>;
1147 | pitch_list NOTENAME_ID {
1148 $$->push ($2->clone ()->musical ()->melodic ());
1157 int *i_p = $1->intid ();
1169 Real *r_p = $1->real ();
1178 real unit { $$ = $1*$2; }
1182 unit: CM_T { $$ = 1 CM; }
1183 |IN_T { $$ = 1 INCH; }
1184 |MM_T { $$ = 1 MM; }
1185 |PT_T { $$ = 1 PT; }
1192 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
1202 | symtables_body TEXID STRING {
1203 $$->texsetting = *$3;
1206 | symtables_body STRING '=' symtable {
1213 TABLE '{' symtable_body '}' { $$ = $3; }
1217 { $$ = new Symtable; }
1218 | symtable_body STRING symboldef {
1227 $$ = new Atom (*$1, *$2);
1232 Box b (Interval (0,0), Interval (0,0));
1233 $$ = new Atom (*$1, b);
1239 dinterval dinterval {
1240 $$ = new Box (*$1, *$2);
1246 dinterval: dim dim {
1247 $$ = new Interval ($1, $2);
1254 My_lily_parser::set_yydebug (bool b)
1261 My_lily_parser::do_yyparse ()
1263 yyparse ((void*)this);
1267 My_lily_parser::default_paper ()
1269 Identifier *id = lexer_p_->lookup_identifier ("default_paper");
1270 return id ? id->paperdef () : new Paper_def ;
1274 My_lily_parser::default_midi ()
1276 Identifier *id = lexer_p_->lookup_identifier ("default_midi");
1277 return id ? id->mididef () : new Midi_def ;