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 #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"
43 int const GUESS_PLET = 5;
44 int guess_plet_a[GUESS_PLET] =
57 #define YYERROR_VERBOSE 1
59 #define YYPARSE_PARAM my_lily_parser_l
60 #define YYLEX_PARAM my_lily_parser_l
61 #define THIS ((My_lily_parser *) my_lily_parser_l)
63 #define yyerror THIS->parser_error
69 Array<Interval>* intarr;
70 Array<Melodic_req*> *melreqvec;/* should clean up naming */
71 Array<String> * strvec;
79 Music_list *musiclist;
86 Music_output_def * outputdef;
93 General_script_def * script;
98 Symtables * symtables;
110 yylex (YYSTYPE *s, void * v_l)
112 My_lily_parser *pars_l = (My_lily_parser*) v_l;
113 My_lily_lexer * lex_l = pars_l->lexer_p_;
115 lex_l->lexval_l = (void*) s;
116 return lex_l->yylex ();
124 /* tokens which are not keywords */
149 %token MELODIC_REQUEST
180 %token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
184 %token <melreq> NOTENAME_ID
185 %token <id> DURATION_IDENTIFIER
186 %token <id> IDENTIFIER
187 %token <id> MELODIC_REQUEST_IDENTIFIER
188 %token <id> MUSIC_IDENTIFIER
189 %token <id> VOICE_IDENTIFIER
190 %token <id> POST_REQUEST_IDENTIFIER
191 %token <id> SCRIPT_IDENTIFIER
192 %token <id> COMMAND_IDENTIFIER
193 %token <id> REAL_IDENTIFIER
194 %token <id> TRANS_IDENTIFIER
195 %token <id> INT_IDENTIFIER
196 %token <id> SCORE_IDENTIFIER
197 %token <id> MIDI_IDENTIFIER
198 %token <id> PAPER_IDENTIFIER
199 %token <id> REQUEST_IDENTIFIER
201 %token <string> DURATION RESTNAME
202 %token <string> STRING
204 %token <i> POST_QUOTES
205 %token <i> PRE_QUOTES
207 %type <outputdef> output_def
208 %type <header> mudela_header mudela_header_body
210 %type <i> open_request_parens close_request_parens
211 %type <c> open_abbrev_parens
212 %type <i> open_plet_parens close_plet_parens
213 %type <music> simple_element music_elt full_element lyrics_elt command_elt
214 %type <i> abbrev_type
215 %type <i> int unsigned
217 %type <id> identifier_init
218 %type <duration> explicit_steno_duration notemode_duration
219 %type <duration> entered_notemode_duration explicit_duration
220 %type <interval> dinterval
221 %type <intvec> intastint_list
222 %type <lookup> symtables symtables_body
223 %type <melreq> melodic_request steno_melodic_req
224 %type <notereq> steno_note_req
225 %type <melreqvec> pitch_list
226 %type <midi> midi_block midi_body
227 %type <moment> duration_length
229 %type <scalar> scalar
230 %type <music> Music transposed_music
231 %type <music> property_def translator_change
232 %type <musiclist> Voice Voice_body
233 %type <chord> Chord Chord_body
234 %type <paper> paper_block paper_body
235 %type <real> dim real
237 %type <request> abbrev_command_req
238 %type <request> post_request structured_post_request
239 %type <pair> plet_fraction
240 %type <request> command_req verbose_command_req
241 %type <request> script_req dynamic_req
242 %type <score> score_block score_body
243 %type <intarr> shape_array
244 %type <script> script_definition script_body mudela_script gen_script_def
245 %type <textdef> text_def finger
246 %type <string> script_abbreviation
247 %type <symbol> symboldef
248 %type <symtable> symtable symtable_body
249 %type <trans> translator_spec translator_spec_body
250 %type <tempo> tempo_request
251 %type <string> concat_strings
259 | mudela mudela_header {
260 delete THIS->default_header_p_ ;
261 THIS->default_header_p_ = $2;
263 | mudela score_block {
266 | mudela add_declaration { }
268 | mudela check_version { }
269 | mudela add_notenames { }
274 if (String (*$2) != MUDELA_VERSION) {
275 if (THIS->ignore_version_b_) {
276 THIS->here_input ().error ("Incorrect mudela version");
278 THIS->fatal_error_i_ = 1;
279 THIS->parser_error ("Incorrect mudela version");
286 NOTENAMES '{' notenames_body '}'
291 | notenames_body CLEAR {
292 THIS->clear_notenames ();
294 | notenames_body STRING '=' melodic_request {
295 THIS->add_notename (*$2, $4);
304 | mudela_header_body STRING '=' concat_strings ';' {
312 HEADER '{' mudela_header_body '}' {
322 | concat_strings STRING {
333 THIS->remember_spot ();
335 /* cont */ '=' identifier_init {
336 THIS->lexer_p_->set_identifier (*$1, $4);
337 $4->init_b_ = THIS->init_parse_b_;
338 $4->set_spot (THIS->pop_spot ());
344 $$ = new Score_id ($1, SCORE_IDENTIFIER);
348 $$ = new Paper_def_id ($1, PAPER_IDENTIFIER);
352 $$ = new Midi_def_id ($1, MIDI_IDENTIFIER);
355 | script_definition {
356 $$ = new Script_id ($1, SCRIPT_IDENTIFIER);
360 $$ = new Music_id ($1, MUSIC_IDENTIFIER);
364 $$ = new Lookup_id ($1, IDENTIFIER);
368 $$ = new Real_id (new Real ($1), REAL_IDENTIFIER);
372 $$ = new Int_id (new int ($1), INT_IDENTIFIER);
375 $$ = new Request_id ($1, POST_REQUEST_IDENTIFIER);
378 $$ = new Request_id ($1, MELODIC_REQUEST_IDENTIFIER);
382 $$ = new Translator_id ($1, TRANS_IDENTIFIER);
384 | explicit_duration {
385 $$ = new Duration_id ($1, DURATION_IDENTIFIER);
392 TRANSLATOR '{' translator_spec_body '}'
396 translator_spec_body:
398 $$ = $1->translator ();
399 $$-> set_spot (THIS->here_input ());
402 $$ = get_translator_l (*$2)->clone ();
403 $$->set_spot (THIS->here_input ());
406 | translator_spec_body STRING '=' scalar ';' {
407 $$-> set_property (*$2, *$4);
411 | translator_spec_body CONSISTS STRING ';' {
412 $$->group_l ()->consists_str_arr_.push (*$3);
415 | translator_spec_body ACCEPTS STRING ';' {
416 $$->group_l ()->accepts_str_arr_.push (*$3);
425 SCORE { THIS->remember_spot ();
426 THIS->error_level_i_ =0;
428 /*cont*/ '{' score_body '}' {
430 $$->set_spot (THIS->pop_spot ());
431 if (!$$->def_p_arr_.size ())
432 $$->add (THIS->default_paper ());
434 /* handle error levels. */
435 $$->errorlevel_i_ = THIS->error_level_i_;
436 THIS->error_level_i_ = 0;
437 if (!$$->header_p_ && THIS->default_header_p_)
438 $$->header_p_ = new Header (*THIS->default_header_p_);
448 | score_body mudela_header {
453 $2->warning ("More than one music block");
456 | score_body output_def {
474 /* */ { $$ =new Array<int>; }
475 | intastint_list int '*' int {
476 $$->push ($2); $$->push ($4);
486 '{' paper_body '}' { $$ = $3; }
491 $$ = THIS->default_paper ();
494 $$ = $1->paperdef ();
496 | paper_body OUTPUT STRING ';' {
497 $$->outfile_str_ = *$3;
500 | paper_body symtables { $$->set ($2); }
501 | paper_body STRING '=' dim ';' {
502 $$->set_var (*$2, $4);
504 | paper_body STRING '=' real ';' {
505 $$->set_var (*$2, $4);
507 | paper_body STRING '=' translator_spec {
508 $$-> assign_translator (*$2, $4);
511 | paper_body SHAPE '=' shape_array ';' {
512 $$->shape_int_a_ = *$4;
522 $$ = new Array<Interval>;
524 | shape_array dim dim {
525 $$->push(Interval($2, $2 + $3));
534 '{' midi_body '}' { $$ = $3; }
537 midi_body: /* empty */ {
538 $$ = THIS->default_midi ();
540 | midi_body STRING '=' translator_spec {
541 $$-> assign_translator (*$2, $4);
544 | midi_body OUTPUT STRING ';' {
545 $$->outfile_str_ = *$3;
548 | midi_body tempo_request ';' {
549 $$->set_tempo ($2->dur_.length (), $2->metronome_i_);
558 TEMPO entered_notemode_duration '=' unsigned {
562 $$-> metronome_i_ = $4;
579 $$->set_spot (THIS->here_input ());
587 full_element { $$ = $1; }
588 | TYPE STRING Music {
590 $$->translator_type_str_ = *$2;
593 | TYPE STRING '=' STRING Music {
595 $$->translator_type_str_ = *$2;
596 $$->translator_id_str_ = *$4;
602 | transposed_music { $$ = $1; }
603 | MUSIC_IDENTIFIER { $$ = $1->music (); }
604 | MUSIC_IDENTIFIER ';' { $$ = $1->music (); }
606 { THIS->lexer_p_->push_note_state (); }
608 { $$=$3; THIS->lexer_p_->pop_state (); }
611 { THIS->lexer_p_->push_lyric_state (); }
613 { $$ = $3; THIS->lexer_p_->pop_state (); }
619 TRANSLATOR STRING '=' STRING {
620 Change_translator * t = new Change_translator;
621 t-> change_to_type_str_ = *$2;
622 t-> change_to_id_str_ = *$4;
625 $$->set_spot (THIS->here_input ());
632 PROPERTY STRING '.' STRING '=' scalar {
633 Translation_property *t = new Translation_property;
634 t-> translator_type_str_ = *$2;
638 $$->set_spot (THIS->here_input ());
646 STRING { $$ = new Scalar (*$1); delete $1; }
647 | int { $$ = new Scalar ($1); }
652 '<' Chord_body '>' { $$ = $2; }
653 | MULTI unsigned Chord {
655 $$->multi_level_i_=$2;
662 $$-> multi_level_i_ = 1;
663 $$->set_spot (THIS->here_input ());
671 TRANSPOSE steno_melodic_req Music {
673 $$ -> transpose ($2);
684 pre_requests simple_element post_requests {
685 THIS->add_requests ((Chord*)$2);//ugh
689 | voice_command ';' { $$ = 0; }
699 $$ = new Request_chord;
700 $$-> set_spot (THIS->here_input ());
701 $1-> set_spot (THIS->here_input ());
702 ((Chord*)$$) ->add ($1);//ugh
709 | verbose_command_req ';' { $$ = $1; }
714 $$ = new Barcheck_req;
716 | COMMAND_IDENTIFIER {
723 $$ = new Bar_req (*$2);
727 Break_force_req * f = new Break_force_req;
728 f-> set_spot (THIS->here_input ());
731 | METER unsigned '/' unsigned {
732 Meter_change_req *m = new Meter_change_req;
736 | SKIP duration_length {
737 Skip_req * skip_p = new Skip_req;
738 skip_p->duration_.set_plet ($2->num (),
748 $$ = new Cadenza_req ($2);
750 | PARTIAL duration_length {
751 $$ = new Partial_measure_req (*$2);
755 $$ = new Clef_change_req (*$2);
759 Key_change_req *key_p= new Key_change_req;
760 key_p->melodic_p_arr_ = *$2;
764 | GROUPING intastint_list {
765 $$ = get_grouping_req (*$2); delete $2;
771 /* something silly happened. Junk this stuff*/
772 if (!THIS->post_reqs.empty ())
774 warning ("Junking post-requests");
775 THIS->post_reqs.clear ();
778 | post_requests structured_post_request {
779 $2->set_spot (THIS->here_input ());
780 THIS->post_reqs.push ($2);
782 | post_requests close_request_parens {
783 Array<Request*>& r = *THIS->get_parens_request ($2);
784 for (int i = 0; i < r.size (); i++ )
785 r[i]->set_spot (THIS->here_input ());
786 THIS->post_reqs.concat (r);
791 structured_post_request:
797 POST_REQUEST_IDENTIFIER {
798 $$ = (Request*)$1->request ();
804 Abbreviation_req* a = new Abbreviation_req;
817 $$ = $1->clone ()->musical ()->melodic ();
818 $$->octave_i_ += THIS->default_octave_i_;
820 | steno_melodic_req POST_QUOTES {
821 $$-> octave_i_ += $2;
823 | PRE_QUOTES steno_melodic_req {
825 $2-> octave_i_ -= $1;
832 * (Melodic_req *) $$ = *$1;
835 | steno_note_req '!' {
836 $$->forceacc_b_ = ! $$->forceacc_b_;
838 /* have to duration here. */
842 MELODIC_REQUEST '{' int int int '}' {/* ugh */
843 $$ = new Melodic_req;
845 $$->notename_i_ = $4;
846 $$->accidental_i_ = $5;
851 DURATION '{' int unsigned '}' {
859 ABSDYNAMIC '{' unsigned '}' {
860 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
861 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
864 | SPANDYNAMIC '{' int int '}' {
865 Span_dynamic_req * sp_p = new Span_dynamic_req;
867 sp_p-> dynamic_dir_ = $3;
873 unsigned '/' unsigned {
880 $$[0] = guess_plet_a[(num <? GUESS_PLET) - 1];
888 THIS->plet_.type_i_ = $2[1];
889 THIS->plet_.iso_i_ = $2[0];
890 THIS->default_duration_.plet_.type_i_ = $2[1];
891 THIS->default_duration_.plet_.iso_i_ = $2[0];
895 THIS->plet_.type_i_ = 1;
896 THIS->plet_.iso_i_ = 1;
897 THIS->default_duration_.plet_.iso_i_ = 1;
898 THIS->default_duration_.plet_.type_i_ = 1;
900 | TELP plet_fraction {
902 THIS->plet_.type_i_ = $2[1];
903 THIS->plet_.iso_i_ = $2[0];
904 THIS->default_duration_.plet_.type_i_ = $2[1];
905 THIS->default_duration_.plet_.iso_i_ = $2[0];
909 close_request_parens:
925 | close_plet_parens {
932 if (!Duration::duration_type_b ($3))
933 THIS->parser_error ("1:Not a duration");
935 THIS->parser_error ("Can't abbreviate");
937 THIS->set_abbrev_beam ($3);
944 THIS->plet_.type_i_ = $2[1];
945 THIS->plet_.iso_i_ = $2[0];
946 THIS->default_duration_.plet_.type_i_ = $2[1];
947 THIS->default_duration_.plet_.iso_i_ = $2[0];
949 | PLET plet_fraction {
951 THIS->plet_.type_i_ = $2[1];
952 THIS->plet_.iso_i_ = $2[0];
953 THIS->default_duration_.plet_.type_i_ = $2[1];
954 THIS->default_duration_.plet_.iso_i_ = $2[0];
968 | open_abbrev_parens {
977 SCRIPT '{' script_body '}' { $$ = $3; }
981 STRING int int int int int {
982 Script_def *s = new Script_def;
983 s->set_from_input (*$1,$2, $3,$4,$5, $6);
990 script_dir gen_script_def {
991 Musical_script_req *m = new Musical_script_req;
993 m->scriptdef_p_ = $2;
994 m->set_spot (THIS->here_input ());
1003 ((Text_def*) $$)->align_i_ = CENTER; /* UGH */
1007 $$-> set_spot (THIS->here_input ());
1011 ((Text_def*)$$)->align_i_ = CENTER;
1017 Text_def *t = new Text_def;
1021 t->style_str_ = THIS->textstyle_str_;
1022 $$->set_spot (THIS->here_input ());
1028 Text_def* t = new Text_def;
1030 t->text_str_ = String ($1);
1031 t->style_str_ = "finger";
1032 $$->set_spot (THIS->here_input ());
1036 script_abbreviation:
1037 '^' { $$ = get_scriptdef ('^'); }
1038 | '+' { $$ = get_scriptdef ('+'); }
1039 | '-' { $$ = get_scriptdef ('-'); }
1040 | '|' { $$ = get_scriptdef ('|'); }
1041 | 'o' { $$ = get_scriptdef ('o'); }
1042 | '>' { $$ = get_scriptdef ('>'); }
1044 $$ = get_scriptdef ('.');
1049 SCRIPT_IDENTIFIER { $$ = $1->script (); }
1050 | script_definition { $$ = $1; }
1051 | script_abbreviation {
1052 $$ = THIS->lexer_p_->lookup_identifier (*$1)->script ();
1066 | pre_requests open_request_parens {
1067 Array<Request*>& r = *THIS->get_parens_request ($2);
1068 for (int i = 0; i < r.size (); i++ )
1069 r[i]->set_spot (THIS->here_input ());
1070 THIS->pre_reqs.concat (r);
1077 THIS->set_duration_mode (*$2);
1080 | DURATION entered_notemode_duration {
1081 THIS->set_default_duration ($2);
1086 This is weird, but default_octave_i_
1087 is used in steno_note_req too
1089 c' -> default_octave_i_ == 1
1091 /* why can't we have \oct 0 iso \oct{c'}*/
1092 THIS->default_octave_i_ = 1; }
1095 THIS->default_octave_i_ = $3->octave_i_;
1098 | TEXTSTYLE STRING {
1099 THIS->textstyle_str_ = *$2;
1106 $$ = new Moment (0,1);
1108 | duration_length explicit_steno_duration {
1109 *$$ += $2->length ();
1115 | dots '.' { $$ ++; }
1118 entered_notemode_duration:
1120 $$ = new Duration (THIS->default_duration_);
1123 $$ = new Duration (THIS->default_duration_);
1126 | explicit_steno_duration {
1127 THIS->set_last_duration ($1);
1133 entered_notemode_duration {
1138 explicit_steno_duration:
1141 if (!Duration::duration_type_b ($1))
1142 THIS->parser_error ("2:Not a duration");
1144 $$->durlog_i_ = Duration_convert::i2_type ($1);
1145 $$->set_plet (THIS->default_duration_);
1148 | DURATION_IDENTIFIER {
1149 $$ = $1->duration ();
1151 | explicit_steno_duration '.' {
1154 | explicit_steno_duration '*' unsigned {
1155 $$->plet_.iso_i_ = $3;
1157 | explicit_steno_duration '/' unsigned {
1158 $$->plet_.type_i_ = $3;
1168 if (!Duration::duration_type_b ($2))
1169 THIS->parser_error ("3:Not a duration");
1171 THIS->parser_error ("Can't abbreviate");
1178 steno_note_req notemode_duration {
1179 if (!THIS->lexer_p_->note_state_b ())
1180 THIS->parser_error ("have to be in Note mode for notes");
1181 $1->set_duration (*$2);
1182 int durlog_i = $2->durlog_i_;
1183 $$ = THIS->get_note_element ($1, $2);
1185 | RESTNAME notemode_duration {
1186 $$ = THIS->get_rest_element (*$1, $2);
1192 text_def notemode_duration {
1193 /* this sux! text-def should be feature of lyric-engraver. */
1194 if (!THIS->lexer_p_->lyric_state_b ())
1195 THIS->parser_error ("Have to be in Lyric mode for lyrics");
1196 $$ = THIS->get_word_element ($1, $2);
1204 $$ = new Array<Melodic_req*>;
1206 | pitch_list NOTENAME_ID {
1207 $$->push ($2->clone ()->musical ()->melodic ());
1227 int *i_p = $1->intid ();
1238 Real *r_p = $1->real ();
1247 real unit { $$ = $1*$2; }
1251 unit: CM_T { $$ = 1 CM; }
1252 |IN_T { $$ = 1 INCH; }
1253 |MM_T { $$ = 1 MM; }
1254 |PT_T { $$ = 1 PT; }
1261 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
1271 | symtables_body TEXID STRING {
1272 $$->texsetting = *$3;
1275 | symtables_body STRING '=' symtable {
1282 TABLE '{' symtable_body '}' { $$ = $3; }
1286 { $$ = new Symtable; }
1287 | symtable_body STRING symboldef {
1296 $$ = new Atom (*$1, *$2);
1301 Box b (Interval (0,0), Interval (0,0));
1302 $$ = new Atom (*$1, b);
1308 dinterval dinterval {
1309 $$ = new Box (*$1, *$2);
1315 dinterval: dim dim {
1316 $$ = new Interval ($1, $2);
1323 My_lily_parser::set_yydebug (bool b)
1330 My_lily_parser::do_yyparse ()
1332 yyparse ((void*)this);
1336 My_lily_parser::default_paper ()
1338 Identifier *id = lexer_p_->lookup_identifier ("default_paper");
1339 return id ? id->paperdef () : new Paper_def ;
1343 My_lily_parser::default_midi ()
1345 Identifier *id = lexer_p_->lookup_identifier ("default_midi");
1346 return id ? id->mididef () : new Midi_def ;