1 %{ // -*-Fundamental-*-
4 parser.yy -- YACC -> C++ 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 #include "translation-property.hh"
16 #include "script-def.hh"
17 #include "symtable.hh"
20 #include "my-lily-lexer.hh"
21 #include "paper-def.hh"
22 #include "midi-def.hh"
26 #include "parseconstruct.hh"
28 #include "identifier.hh"
29 #include "command-request.hh"
30 #include "musical-request.hh"
31 #include "my-lily-parser.hh"
32 #include "text-def.hh"
33 #include "translator-group.hh"
35 #include "music-list.hh"
37 #include "duration-convert.hh"
38 #include "change-translator.hh"
39 #include "file-results.hh"
40 #include "mudela-version.hh"
42 #include "relative-music.hh"
46 Mudela_version oldest_version ("0.1.15");
47 Mudela_version version ("0.1.15");
50 // needed for bison.simple's malloc() and free()
53 int const GUESS_PLET = 5;
54 int guess_plet_a[GUESS_PLET] =
63 Paper_def* current_paper = 0;
69 #define YYERROR_VERBOSE 1
71 #define YYPARSE_PARAM my_lily_parser_l
72 #define YYLEX_PARAM my_lily_parser_l
73 #define THIS ((My_lily_parser *) my_lily_parser_l)
75 #define yyerror THIS->parser_error
81 Array<Interval>* intarr;
82 Array<Musical_pitch> *pitch_arr;
83 Array<String> * strvec;
91 Music_list *musiclist;
98 Music_output_def * outputdef;
99 Musical_pitch * pitch;
106 General_script_def * script;
111 Symtables * symtables;
123 yylex (YYSTYPE *s, void * v_l)
125 My_lily_parser *pars_l = (My_lily_parser*) v_l;
126 My_lily_lexer * lex_l = pars_l->lexer_p_;
128 lex_l->lexval_l = (void*) s;
129 return lex_l->yylex ();
137 /* tokens which are not keywords */
196 %token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
200 %token <pitch> NOTENAME_PITCH
201 %token <id> DURATION_IDENTIFIER
202 %token <id> IDENTIFIER
204 %token <id> MUSIC_IDENTIFIER
205 %token <id> VOICE_IDENTIFIER
206 %token <id> POST_REQUEST_IDENTIFIER
207 %token <id> SCRIPT_IDENTIFIER
208 %token <id> COMMAND_IDENTIFIER
209 %token <id> REAL_IDENTIFIER
210 %token <id> STRING_IDENTIFIER
211 %token <id> TRANS_IDENTIFIER
212 %token <id> INT_IDENTIFIER
213 %token <id> SCORE_IDENTIFIER
214 %token <id> MIDI_IDENTIFIER
215 %token <id> PAPER_IDENTIFIER
216 %token <id> REQUEST_IDENTIFIER
218 %token <string> DURATION RESTNAME
219 %token <string> STRING
223 %type <outputdef> output_def
224 %type <header> mudela_header mudela_header_body
226 %type <i> open_request_parens close_request_parens
227 %type <i> open_abbrev_parens
228 %type <i> open_plet_parens close_plet_parens
229 %type <i> sub_quotes sup_quotes
230 %type <music> simple_element music_elt full_element lyrics_elt command_elt
231 %type <i> abbrev_type
232 %type <i> int unsigned
234 %type <id> identifier_init simple_identifier_init
235 %type <duration> steno_duration notemode_duration
236 %type <duration> entered_notemode_duration explicit_duration
237 %type <interval> dinterval
238 %type <intvec> intastint_list
239 %type <lookup> symtables symtables_body
241 %type <pitch> explicit_musical_pitch steno_musical_pitch musical_pitch absolute_musical_pitch
242 %type <notereq> steno_notepitch
243 %type <pitch_arr> pitch_list
244 %type <midi> midi_block midi_body
245 %type <moment> duration_length
247 %type <scalar> scalar
248 %type <music> Music transposed_music relative_music
249 %type <music> property_def translator_change
250 %type <musiclist> Voice Voice_body
251 %type <chord> Chord Chord_body
252 %type <paper> paper_block paper_body
253 %type <real> dim real
254 %type <real> real_mult_expression real_primary
256 %type <request> abbrev_command_req
257 %type <request> post_request structured_post_request
258 %type <pair> plet_fraction
259 %type <request> command_req verbose_command_req
260 %type <request> script_req dynamic_req
261 %type <string> string
262 %type <string> string_primary
263 %type <score> score_block score_body
264 %type <intarr> shape_array
265 %type <script> script_definition script_body mudela_script gen_script_def
266 %type <textdef> text_def finger
267 %type <string> script_abbreviation
268 %type <symbol> symboldef
269 %type <symtable> symtable symtable_body
270 %type <trans> translator_spec translator_spec_body
271 %type <tempo> tempo_request
272 %type <string> concat_strings
280 | mudela mudela_header {
281 delete THIS->default_header_p_ ;
282 THIS->default_header_p_ = $2;
284 | mudela score_block {
285 score_global_array.push ($2);
287 | mudela add_declaration { }
289 | mudela check_version { }
290 | mudela add_notenames { }
295 Mudela_version ver (*$2);
296 if (!((ver >= oldest_version) && (ver <= version))) {
297 if (THIS->ignore_version_b_) {
298 THIS->here_input ().error ("Incorrect mudela version");
300 THIS->fatal_error_i_ = 1;
301 THIS->parser_error ("Incorrect mudela version");
308 NOTENAMES '{' notenames_body '}'
313 | notenames_body CLEAR {
314 THIS->clear_notenames ();
316 | notenames_body STRING '=' explicit_musical_pitch {
317 THIS->add_notename (*$2, *$4);
327 | mudela_header_body STRING '=' concat_strings ';' {
335 HEADER '{' mudela_header_body '}' {
345 | concat_strings STRING {
356 THIS->remember_spot ();
358 /* cont */ '=' identifier_init optional_semicolon {
359 THIS->lexer_p_->set_identifier (*$1, $4);
360 $4->init_b_ = THIS->init_parse_b_;
361 $4->set_spot (THIS->pop_spot ());
367 $$ = new Score_identifier ($1, SCORE_IDENTIFIER);
371 $$ = new Paper_def_identifier ($1, PAPER_IDENTIFIER);
374 $$ = new Midi_def_identifier ($1, MIDI_IDENTIFIER);
377 | script_definition {
378 $$ = new General_script_def_identifier ($1, SCRIPT_IDENTIFIER);
382 $$ = new Music_identifier ($1, MUSIC_IDENTIFIER);
386 $$ = new Lookup_identifier ($1, IDENTIFIER);
390 $$ = new Request_identifier ($1, POST_REQUEST_IDENTIFIER);
392 /* | melodic_request {
393 $$ = new Request_identifier ($1, MELODIC_REQUEST_IDENTIFIER);
397 | explicit_duration {
398 $$ = new Duration_identifier ($1, DURATION_IDENTIFIER);
400 | simple_identifier_init
403 simple_identifier_init:
405 $$ = new Real_identifier (new Real ($1), REAL_IDENTIFIER);
408 $$ = new String_identifier ($1, STRING_IDENTIFIER);
411 $$ = new int_identifier (new int ($1), INT_IDENTIFIER);
414 $$ = new Translator_identifier ($1, TRANS_IDENTIFIER);
419 TRANSLATOR '{' translator_spec_body '}'
423 translator_spec_body:
425 $$ = $1->translator ();
426 $$-> set_spot (THIS->here_input ());
429 $$ = get_translator_l (*$2)->clone ();
430 $$->set_spot (THIS->here_input ());
433 | translator_spec_body STRING '=' scalar ';' {
434 $$-> set_property (*$2, *$4);
438 | translator_spec_body CONSISTS STRING ';' {
439 $$->group_l ()->consists_str_arr_.push (*$3);
442 | translator_spec_body ACCEPTS STRING ';' {
443 $$->group_l ()->accepts_str_arr_.push (*$3);
452 SCORE { THIS->remember_spot ();
453 THIS->error_level_i_ =0;
455 /*cont*/ '{' score_body '}' {
457 $$->set_spot (THIS->pop_spot ());
458 if (!$$->def_p_arr_.size ())
459 $$->add (THIS->default_paper_p ());
461 /* handle error levels. */
462 $$->errorlevel_i_ = THIS->error_level_i_;
463 THIS->error_level_i_ = 0;
464 if (!$$->header_p_ && THIS->default_header_p_)
465 $$->header_p_ = new Header (*THIS->default_header_p_);
475 | score_body mudela_header {
480 $2->warning ("More than one music block");
483 | score_body output_def {
501 /* */ { $$ =new Array<int>; }
502 | intastint_list int '*' int {
503 $$->push ($2); $$->push ($4);
512 PAPER '{' paper_body '}' {
514 THIS-> lexer_p_->scope_l_arr_.pop ();
525 Paper_def *p = THIS->default_paper_p ();
526 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
529 | PAPER_IDENTIFIER optional_semicolon {
530 Paper_def *p = $1->paperdef ();
531 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
534 | paper_body OUTPUT STRING ';' {
535 $$->outfile_str_ = *$3;
538 | paper_body symtables { $$->set ($2); }
539 | paper_body STRING '=' simple_identifier_init optional_semicolon {
541 id->init_b_ = THIS->init_parse_b_;
542 if (id->is_type_b (Translator_identifier::static_name ()))
544 $$->assign_translator (*$2, id->translator ());
548 THIS->lexer_p_->set_identifier (*$2, id);
551 | paper_body STRING '=' translator_spec {
552 $$-> assign_translator (*$2, $4);
556 | paper_body SHAPE '=' shape_array ';' {
557 $$->shape_int_a_ = *$4;
570 Real *r_p = $1->real ();
572 DOUT << "Lookup real: " << *r_p << "\n";
583 | real '+' real_mult_expression {
586 | real '-' real_mult_expression {
591 real_mult_expression:
593 | real_mult_expression '*' real_primary {
596 | real_mult_expression '/' real_primary {
603 $$ = new Array<Interval>;
605 | shape_array dim dim {
606 $$->push(Interval($2, $2 + $3));
615 '{' midi_body '}' { $$ = $3; }
618 midi_body: /* empty */ {
619 $$ = THIS->default_midi_p ();
621 | midi_body STRING '=' translator_spec {
622 $$-> assign_translator (*$2, $4);
625 | midi_body OUTPUT STRING ';' {
626 $$->outfile_str_ = *$3;
629 | midi_body tempo_request ';' {
630 $$->set_tempo ($2->dur_.length (), $2->metronome_i_);
639 TEMPO entered_notemode_duration '=' unsigned {
643 $$-> metronome_i_ = $4;
660 $$->set_spot (THIS->here_input ());
668 full_element { $$ = $1; }
669 | TYPE STRING Music {
671 $$->translator_type_str_ = *$2;
674 | TYPE STRING '=' STRING Music {
676 $$->translator_type_str_ = *$2;
677 $$->translator_id_str_ = *$4;
683 | transposed_music { $$ = $1; }
684 | MUSIC_IDENTIFIER { $$ = $1->music (); }
686 { THIS->lexer_p_->push_note_state (); }
688 { $$=$3; THIS->lexer_p_->pop_state (); }
691 { THIS->lexer_p_->push_lyric_state (); }
693 { $$ = $3; THIS->lexer_p_->pop_state (); }
696 | relative_music { $$ = $1; }
700 RELATIVE absolute_musical_pitch Music
702 $$ = new Relative_octave_music ($3, *$2);
708 TRANSLATOR STRING '=' STRING {
709 Change_translator * t = new Change_translator;
710 t-> change_to_type_str_ = *$2;
711 t-> change_to_id_str_ = *$4;
714 $$->set_spot (THIS->here_input ());
721 PROPERTY STRING '.' STRING '=' scalar {
722 Translation_property *t = new Translation_property;
723 t-> translator_type_str_ = *$2;
727 $$->set_spot (THIS->here_input ());
735 STRING { $$ = new Scalar (*$1); delete $1; }
736 | int { $$ = new Scalar ($1); }
741 '<' Chord_body '>' { $$ = $2; }
742 | MULTI unsigned Chord {
744 $$->multi_level_i_=$2;
751 $$-> multi_level_i_ = 1;
752 $$->set_spot (THIS->here_input ());
760 TRANSPOSE musical_pitch Music {
762 $$ -> transpose (*$2);
773 pre_requests simple_element post_requests {
774 THIS->add_requests ((Chord*)$2);//ugh
778 | voice_command ';' { $$ = 0; }
788 $$ = new Request_chord;
789 $$-> set_spot (THIS->here_input ());
790 $1-> set_spot (THIS->here_input ());
791 ((Chord*)$$) ->add ($1);//ugh
798 | verbose_command_req ';' { $$ = $1; }
803 $$ = new Barcheck_req;
805 | COMMAND_IDENTIFIER {
812 $$ = new Bar_req (*$2);
816 Break_req * b = new Break_req;
818 b-> set_spot (THIS->here_input ());
821 | METER unsigned '/' unsigned {
822 Meter_change_req *m = new Meter_change_req;
826 | SKIP duration_length {
827 Skip_req * skip_p = new Skip_req;
828 skip_p->duration_.set_plet ($2->num (),
838 $$ = new Cadenza_req ($2);
840 | PARTIAL duration_length {
841 $$ = new Partial_measure_req (*$2);
845 $$ = new Clef_change_req (*$2);
849 Key_change_req *key_p= new Key_change_req;
850 key_p->pitch_arr_ = *$2;
854 | GROUPING intastint_list {
855 $$ = get_grouping_req (*$2); delete $2;
861 /* something silly happened. Junk this stuff*/
862 if (!THIS->post_reqs.empty ())
864 warning ("Junking post-requests");
865 THIS->post_reqs.clear ();
868 | post_requests structured_post_request {
869 $2->set_spot (THIS->here_input ());
870 THIS->post_reqs.push ($2);
872 | post_requests close_request_parens {
873 Array<Request*>& r = *THIS->get_parens_request ($2);
874 for (int i = 0; i < r.size (); i++ )
875 r[i]->set_spot (THIS->here_input ());
876 THIS->post_reqs.concat (r);
881 structured_post_request:
887 POST_REQUEST_IDENTIFIER {
888 $$ = (Request*)$1->request ();
894 Abbreviation_req* a = new Abbreviation_req;
920 $$->octave_i_ += THIS->default_octave_i_;
922 | NOTENAME_PITCH sup_quotes {
924 $$->octave_i_ += $2 + THIS->default_octave_i_;
927 | NOTENAME_PITCH sub_quotes {
929 $$->octave_i_ += THIS->default_octave_i_ - $2 ;
933 explicit_musical_pitch:
934 MUSICAL_PITCH '{' int int int '}' {/* ugh */
935 $$ = new Musical_pitch;
937 $$->notename_i_ = $4;
938 $$->accidental_i_ = $5;
943 | explicit_musical_pitch
953 | steno_notepitch '!' {
954 $$->forceacc_b_ = ! $$->forceacc_b_;
960 DURATION '{' int unsigned '}' {
968 ABSDYNAMIC '{' unsigned '}' {
969 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
970 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
973 | SPANDYNAMIC '{' int int '}' {
974 Span_dynamic_req * sp_p = new Span_dynamic_req;
975 sp_p->spantype = (Span_req::Spantype)$4;
976 sp_p-> dynamic_dir_ = (Direction)$3;
982 unsigned '/' unsigned {
989 $$[0] = guess_plet_a[(num <? GUESS_PLET) - 1];
997 THIS->plet_.type_i_ = $2[1];
998 THIS->plet_.iso_i_ = $2[0];
999 THIS->default_duration_.plet_.type_i_ = $2[1];
1000 THIS->default_duration_.plet_.iso_i_ = $2[0];
1004 THIS->plet_.type_i_ = 1;
1005 THIS->plet_.iso_i_ = 1;
1006 THIS->default_duration_.plet_.iso_i_ = 1;
1007 THIS->default_duration_.plet_.type_i_ = 1;
1009 | TELP plet_fraction {
1011 THIS->plet_.type_i_ = $2[1];
1012 THIS->plet_.iso_i_ = $2[0];
1013 THIS->default_duration_.plet_.type_i_ = $2[1];
1014 THIS->default_duration_.plet_.iso_i_ = $2[0];
1018 close_request_parens:
1040 if (!Duration::duration_type_b ($3))
1041 THIS->parser_error (String ("Not a duration: ") + $3);
1043 THIS->parser_error ("Can't abbreviate");
1045 THIS->set_abbrev_beam ($3);
1052 THIS->plet_.type_i_ = $2[1];
1053 THIS->plet_.iso_i_ = $2[0];
1054 THIS->default_duration_.plet_.type_i_ = $2[1];
1055 THIS->default_duration_.plet_.iso_i_ = $2[0];
1057 | PLET plet_fraction {
1059 THIS->plet_.type_i_ = $2[1];
1060 THIS->plet_.iso_i_ = $2[0];
1061 THIS->default_duration_.plet_.type_i_ = $2[1];
1062 THIS->default_duration_.plet_.iso_i_ = $2[0];
1066 open_request_parens:
1076 | open_abbrev_parens
1083 SCRIPT '{' script_body '}' { $$ = $3; }
1087 STRING int int int int int {
1088 Script_def *s = new Script_def;
1089 s->set_from_input (*$1,$2, $3,$4,$5, $6);
1096 script_dir gen_script_def {
1097 Musical_script_req *m = new Musical_script_req;
1099 m->scriptdef_p_ = $2;
1100 m->set_spot (THIS->here_input ());
1102 m->dir_ = (Direction)$1;
1109 ((Text_def*) $$)->align_i_ = CENTER; /* UGH */
1113 $$-> set_spot (THIS->here_input ());
1117 ((Text_def*)$$)->align_i_ = CENTER;
1123 Text_def *t = new Text_def;
1127 t->style_str_ = THIS->textstyle_str_;
1128 $$->set_spot (THIS->here_input ());
1134 Text_def* t = new Text_def;
1136 t->text_str_ = String ($1);
1137 t->style_str_ = "finger";
1138 $$->set_spot (THIS->here_input ());
1142 script_abbreviation:
1143 '^' { $$ = get_scriptdef ('^'); }
1144 | '+' { $$ = get_scriptdef ('+'); }
1145 | '-' { $$ = get_scriptdef ('-'); }
1146 | '|' { $$ = get_scriptdef ('|'); }
1147 | 'o' { $$ = get_scriptdef ('o'); }
1148 | '>' { $$ = get_scriptdef ('>'); }
1150 $$ = get_scriptdef ('.');
1155 SCRIPT_IDENTIFIER { $$ = $1->script (); }
1156 | script_definition { $$ = $1; }
1157 | script_abbreviation {
1158 $$ = THIS->lexer_p_->lookup_identifier (*$1)->script ();
1172 | pre_requests open_request_parens {
1173 Array<Request*>& r = *THIS->get_parens_request ($2);
1174 for (int i = 0; i < r.size (); i++ )
1175 r[i]->set_spot (THIS->here_input ());
1176 THIS->pre_reqs.concat (r);
1181 absolute_musical_pitch:
1182 steno_musical_pitch {
1184 $$->octave_i_ -= THIS->default_octave_i_;
1188 OCTAVE absolute_musical_pitch {
1189 THIS->default_octave_i_ = $2->octave_i_;
1192 | TEXTSTYLE STRING {
1193 THIS->textstyle_str_ = *$2;
1200 $$ = new Moment (0,1);
1202 | duration_length steno_duration {
1203 *$$ += $2->length ();
1209 | dots '.' { $$ ++; }
1212 entered_notemode_duration:
1214 $$ = new Duration (THIS->default_duration_);
1215 // get sticky plet part too
1216 $$->set_plet (THIS->plet_.iso_i_, THIS->plet_.type_i_);
1219 $$ = new Duration (THIS->default_duration_);
1220 // get sticky plet part too
1221 $$->set_plet (THIS->plet_.iso_i_, THIS->plet_.type_i_);
1225 THIS->set_last_duration ($1);
1231 entered_notemode_duration {
1239 if (!Duration::duration_type_b ($1))
1240 THIS->parser_error ("Not a duration:" + String ($1));
1242 $$->durlog_i_ = Duration_convert::i2_type ($1);
1243 $$->set_plet (THIS->plet_.iso_i_, THIS->plet_.type_i_);
1246 | DURATION_IDENTIFIER {
1247 $$ = $1->duration ();
1249 | steno_duration '.' {
1252 | steno_duration '*' unsigned {
1253 $$->plet_.iso_i_ = $3; /* ugh. should do *= */
1255 | steno_duration '/' unsigned {
1256 $$->plet_.type_i_ = $3; /* ugh. should do *= iso = */
1266 if (!Duration::duration_type_b ($2))
1267 THIS->parser_error ("Not a duration:" + String ($2));
1269 THIS->parser_error ("Can't abbreviate");
1278 steno_notepitch notemode_duration {
1279 if (!THIS->lexer_p_->note_state_b ())
1280 THIS->parser_error ("have to be in Note mode for notes");
1281 $1->set_duration (*$2);
1282 int durlog_i = $2->durlog_i_;
1283 $$ = THIS->get_note_element ($1, $2);
1285 | RESTNAME notemode_duration {
1286 $$ = THIS->get_rest_element (*$1, $2);
1287 delete $1; // delete notename
1289 | MEASURES notemode_duration {
1290 Multi_measure_rest_req* m = new Multi_measure_rest_req;
1294 Chord*velt_p = new Request_chord;
1295 velt_p->set_spot (THIS->here_input ());
1303 text_def notemode_duration {
1304 /* this sux! text-def should be feature of lyric-engraver. */
1305 if (!THIS->lexer_p_->lyric_state_b ())
1306 THIS->parser_error ("Have to be in Lyric mode for lyrics");
1307 $$ = THIS->get_word_element ($1, $2);
1315 $$ = new Array<Musical_pitch>;
1317 | pitch_list NOTENAME_PITCH {
1339 int *i_p = $1->intid ();
1349 | STRING_IDENTIFIER {
1350 String *s_p = $1->string ();
1353 DOUT << "Lookup string: " << *s_p << "\n";
1361 | string '+' string_primary {
1368 real_primary unit { $$ = $1*$2; }
1372 unit: CM_T { $$ = 1 CM; }
1373 |IN_T { $$ = 1 INCH; }
1374 |MM_T { $$ = 1 MM; }
1375 |PT_T { $$ = 1 PT; }
1382 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
1392 | symtables_body TEXID STRING {
1393 $$->texsetting = *$3;
1396 | symtables_body STRING '=' symtable {
1403 TABLE '{' symtable_body '}' { $$ = $3; }
1407 { $$ = new Symtable; }
1408 | symtable_body STRING symboldef {
1417 $$ = new Atom (*$1, *$2);
1422 Box b (Interval (0,0), Interval (0,0));
1423 $$ = new Atom (*$1, b);
1429 dinterval dinterval {
1430 $$ = new Box (*$1, *$2);
1436 dinterval: dim dim {
1437 $$ = new Interval ($1, $2);
1444 My_lily_parser::set_yydebug (bool b)
1451 My_lily_parser::do_yyparse ()
1453 yyparse ((void*)this);