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<Melodic_req*> *melreqvec;/* should clean up naming */
60 Array<String> * strvec;
68 Music_list *musiclist;
75 Music_output_def * outputdef;
82 General_script_def * script;
87 Symtables * symtables;
98 yylex (YYSTYPE *s, void * v_l)
100 My_lily_parser *pars_l = (My_lily_parser*) v_l;
101 My_lily_lexer * lex_l = pars_l->lexer_p_;
103 lex_l->lexval_l = (void*) s;
104 return lex_l->yylex ();
112 /* tokens which are not keywords */
136 %token MELODIC_REQUEST
166 %token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
170 %token <melreq> NOTENAME_ID
171 %token <id> DURATION_IDENTIFIER
172 %token <id> IDENTIFIER
173 %token <id> MELODIC_REQUEST_IDENTIFIER
174 %token <id> MUSIC_IDENTIFIER
175 %token <id> VOICE_IDENTIFIER
176 %token <id> POST_REQUEST_IDENTIFIER
177 %token <id> SCRIPT_IDENTIFIER
178 %token <id> COMMAND_IDENTIFIER
179 %token <id> REAL_IDENTIFIER
180 %token <id> TRANS_IDENTIFIER
181 %token <id> INT_IDENTIFIER
182 %token <id> SCORE_IDENTIFIER
183 %token <id> MIDI_IDENTIFIER
184 %token <id> PAPER_IDENTIFIER
185 %token <id> REQUEST_IDENTIFIER
187 %token <string> DURATION RESTNAME
188 %token <string> STRING
189 %token <i> POST_QUOTES
190 %token <i> PRE_QUOTES
192 %type <outputdef> output_def
193 %type <header> mudela_header mudela_header_body
195 %type <i> open_request_parens close_request_parens
196 %type <c> open_abbrev_parens
197 %type <i> open_plet_parens close_plet_parens
198 %type <music> simple_element music_elt full_element lyrics_elt command_elt
199 %type <i> abbrev_type
202 %type <id> identifier_init
203 %type <duration> explicit_steno_duration notemode_duration
204 %type <duration> entered_notemode_duration explicit_duration
205 %type <interval> dinterval
206 %type <intvec> intastint_list
207 %type <lookup> symtables symtables_body
208 %type <melreq> melodic_request steno_melodic_req
209 %type <notereq> steno_note_req
210 %type <melreqvec> pitch_list
211 %type <midi> midi_block midi_body
212 %type <moment> duration_length
214 %type <scalar> scalar
215 %type <music> Music transposed_music
216 %type <music> property_def translator_change
217 %type <musiclist> Voice Voice_body
218 %type <chord> Chord Chord_body
219 %type <paper> paper_block paper_body
220 %type <real> dim real
222 %type <request> abbrev_command_req
223 %type <request> post_request command_req verbose_command_req
224 %type <request> script_req dynamic_req
225 %type <score> score_block score_body
226 %type <script> script_definition script_body mudela_script gen_script_def
227 %type <textdef> text_def
228 %type <string> script_abbreviation
229 %type <symbol> symboldef
230 %type <symtable> symtable symtable_body
231 %type <trans> translator_spec translator_spec_body
232 %type <tempo> tempo_request
233 %type <string> concat_strings
241 | mudela mudela_header {
242 delete THIS->default_header_p_ ;
243 THIS->default_header_p_ = $2;
245 | mudela score_block {
248 | mudela add_declaration { }
250 | mudela check_version { }
251 | mudela add_notenames { }
256 if (String (*$2) != MUDELA_VERSION) {
257 if (THIS->ignore_version_b_) {
258 THIS->here_input ().error ("Incorrect mudela version");
260 THIS->fatal_error_i_ = 1;
261 THIS->parser_error ("Incorrect mudela version");
268 NOTENAMES '{' notenames_body '}'
273 | notenames_body CLEAR {
274 THIS->clear_notenames ();
276 | notenames_body STRING '=' melodic_request {
277 THIS->add_notename (*$2, $4);
286 | mudela_header_body STRING '=' concat_strings ';' {
294 HEADER '{' mudela_header_body '}' {
304 | concat_strings STRING {
315 THIS->remember_spot ();
317 /* cont */ '=' identifier_init {
318 THIS->lexer_p_->set_identifier (*$1, $4);
319 $4->init_b_ = THIS->init_parse_b_;
320 $4->set_spot (THIS->pop_spot ());
325 $$ = new Score_id ($1, SCORE_IDENTIFIER);
329 $$ = new Paper_def_id ($1, PAPER_IDENTIFIER);
333 $$ = new Midi_def_id ($1, MIDI_IDENTIFIER);
336 | script_definition {
337 $$ = new Script_id ($1, SCRIPT_IDENTIFIER);
341 $$ = new Music_id ($1, MUSIC_IDENTIFIER);
345 $$ = new Lookup_id ($1, IDENTIFIER);
349 $$ = new Real_id (new Real ($1), REAL_IDENTIFIER);
353 $$ = new Int_id (new int ($1), INT_IDENTIFIER);
357 $$ = new Request_id ($1, POST_REQUEST_IDENTIFIER);
361 $$ = new Request_id ($1, MELODIC_REQUEST_IDENTIFIER);
365 $$ = new Translator_id ($1, TRANS_IDENTIFIER);
367 | explicit_duration {
368 $$ = new Duration_id ($1, DURATION_IDENTIFIER);
375 TRANSLATOR '{' translator_spec_body '}'
379 translator_spec_body:
381 $$ = $1->translator ();
382 $$-> set_spot (THIS->here_input ());
385 $$ = get_translator_l (*$2)->clone ();
386 $$->set_spot (THIS->here_input ());
389 | translator_spec_body STRING '=' scalar ';' {
390 $$-> set_property (*$2, *$4);
394 | translator_spec_body CONSISTS STRING ';' {
395 $$->group_l ()->consists_str_arr_.push (*$3);
398 | translator_spec_body ACCEPTS STRING ';' {
399 $$->group_l ()->accepts_str_arr_.push (*$3);
408 SCORE { THIS->remember_spot ();
409 THIS->error_level_i_ =0;
411 /*cont*/ '{' score_body '}' {
413 $$->set_spot (THIS->pop_spot ());
414 if (!$$->def_p_arr_.size ())
415 $$->add (THIS->default_paper ());
417 /* handle error levels. */
418 $$->errorlevel_i_ = THIS->error_level_i_;
419 THIS->error_level_i_ = 0;
420 if (!$$->header_p_ && THIS->default_header_p_)
421 $$->header_p_ = new Header (*THIS->default_header_p_);
431 | score_body mudela_header {
436 $2->warning ("More than one music block");
439 | score_body output_def {
457 /* */ { $$ =new Array<int>; }
458 | intastint_list int '*' int {
459 $$->push ($2); $$->push ($4);
469 '{' paper_body '}' { $$ = $3; }
474 $$ = THIS->default_paper ();
477 $$ = $1->paperdef ();
479 | paper_body OUTPUT STRING ';' {
480 $$->outfile_str_ = *$3;
483 | paper_body symtables { $$->set ($2); }
484 | paper_body STRING '=' dim ';' {
485 $$->set_var (*$2, $4);
487 | paper_body STRING '=' real ';' {
488 $$->set_var (*$2, $4);
490 | paper_body STRING '=' translator_spec {
491 $$-> assign_translator (*$2, $4);
505 '{' midi_body '}' { $$ = $3; }
508 midi_body: /* empty */ {
509 $$ = THIS->default_midi ();
511 | midi_body STRING '=' translator_spec {
512 $$-> assign_translator (*$2, $4);
515 | midi_body OUTPUT STRING ';' {
516 $$->outfile_str_ = *$3;
519 | midi_body tempo_request ';' {
520 $$->set_tempo ($2->dur_.length (), $2->metronome_i_);
529 TEMPO entered_notemode_duration '=' int {
533 $$-> metronome_i_ = $4;
550 $$->set_spot (THIS->here_input ());
558 full_element { $$ = $1; }
559 | TYPE STRING Music {
561 $$->translator_type_str_ = *$2;
564 | TYPE STRING '=' STRING Music {
566 $$->translator_type_str_ = *$2;
567 $$->translator_id_str_ = *$4;
573 | transposed_music { $$ = $1; }
574 | MUSIC_IDENTIFIER { $$ = $1->music (); }
575 | MUSIC_IDENTIFIER ';' { $$ = $1->music (); }
577 { THIS->lexer_p_->push_note_state (); }
579 { $$=$3; THIS->lexer_p_->pop_state (); }
582 { THIS->lexer_p_->push_lyric_state (); }
584 { $$ = $3; THIS->lexer_p_->pop_state (); }
590 TRANSLATOR STRING '=' STRING {
591 Change_translator * t = new Change_translator;
592 t-> change_to_type_str_ = *$2;
593 t-> change_to_id_str_ = *$4;
596 $$->set_spot (THIS->here_input ());
603 PROPERTY STRING '.' STRING '=' scalar {
604 Translation_property *t = new Translation_property;
605 t-> translator_type_str_ = *$2;
609 $$->set_spot (THIS->here_input ());
617 STRING { $$ = new Scalar (*$1); delete $1; }
618 | int { $$ = new Scalar ($1); }
623 '<' Chord_body '>' { $$ = $2; }
626 $$->multi_level_i_=$2;
633 $$-> multi_level_i_ = 1;
634 $$->set_spot (THIS->here_input ());
642 TRANSPOSE steno_melodic_req Music {
644 $$ -> transpose ($2);
655 pre_requests simple_element post_requests {
656 THIS->add_requests ((Chord*)$2);//ugh
660 | voice_command ';' { $$ = 0; }
670 $$ = new Request_chord;
671 $$-> set_spot (THIS->here_input ());
672 $1-> set_spot (THIS->here_input ());
673 ((Chord*)$$) ->add ($1);//ugh
680 | verbose_command_req ';' { $$ = $1; }
685 $$ = new Barcheck_req;
687 | COMMAND_IDENTIFIER {
694 $$ = new Bar_req (*$2);
697 | METER int '/' int {
698 Meter_change_req *m = new Meter_change_req;
702 | SKIP duration_length {
703 Skip_req * skip_p = new Skip_req;
704 skip_p->duration_.set_plet ($2->numerator ().as_long (),
705 $2->denominator ().as_long ());
714 $$ = new Cadenza_req ($2);
716 | PARTIAL duration_length {
717 $$ = new Partial_measure_req (*$2);
721 $$ = new Clef_change_req (*$2);
725 Key_change_req *key_p= new Key_change_req;
726 key_p->melodic_p_arr_ = *$2;
730 | GROUPING intastint_list {
731 $$ = get_grouping_req (*$2); delete $2;
737 assert (THIS->post_reqs.empty ());
739 | post_requests post_request {
740 $2->set_spot (THIS->here_input ());
741 THIS->post_reqs.push ($2);
743 | post_requests close_request_parens {
744 Array<Request*>& r = *THIS->get_parens_request ($2);
745 for (int i = 0; i < r.size (); i++ )
746 r[i]->set_spot (THIS->here_input ());
747 THIS->post_reqs.concat (r);
754 POST_REQUEST_IDENTIFIER {
755 $$ = (Request*)$1->request ();
760 Abbreviation_req* a = new Abbreviation_req;
773 $$ = $1->clone ()->musical ()->melodic ();
774 $$->octave_i_ += THIS->default_octave_i_;
776 | steno_melodic_req POST_QUOTES {
777 $$-> octave_i_ += $2;
779 | PRE_QUOTES steno_melodic_req {
781 $2-> octave_i_ -= $1;
788 * (Melodic_req *) $$ = *$1;
791 | steno_note_req '!' {
792 $$->forceacc_b_ = ! $$->forceacc_b_;
794 /* have to duration here. */
798 MELODIC_REQUEST '{' int int int '}' {/* ugh */
799 $$ = new Melodic_req;
801 $$->notename_i_ = $4;
802 $$->accidental_i_ = $5;
807 DURATION '{' int int '}' {
815 ABSDYNAMIC '{' int '}' {
816 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
817 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
820 | SPANDYNAMIC '{' int int '}' {
821 Span_dynamic_req * sp_p = new Span_dynamic_req;
823 sp_p-> dynamic_dir_ = $3;
831 THIS->plet_.type_i_ = $4;
832 THIS->plet_.iso_i_ = $2;
836 THIS->plet_.type_i_ = 1;
837 THIS->plet_.iso_i_ = 1;
841 THIS->plet_.type_i_ = $4;
842 THIS->plet_.iso_i_ = $2;
846 close_request_parens:
862 | close_plet_parens {
869 if (!Duration::duration_type_b ($3))
870 THIS->parser_error ("Not a duration");
872 THIS->parser_error ("Can't abbreviate");
874 THIS->set_abbrev_beam ($3);
881 THIS->plet_.type_i_ = $4;
882 THIS->plet_.iso_i_ = $2;
886 THIS->plet_.type_i_ = $4;
887 THIS->plet_.iso_i_ = $2;
901 | open_abbrev_parens {
910 SCRIPT '{' script_body '}' { $$ = $3; }
914 STRING int int int int int {
915 Script_def *s = new Script_def;
916 s->set_from_input (*$1,$2, $3,$4,$5, $6);
923 script_dir gen_script_def {
924 Musical_script_req *m = new Musical_script_req;
926 m-> scriptdef_p_ = $2;
927 m-> set_spot (THIS->here_input ());
934 ((Text_def*) $$)->align_i_ = CENTER; /* UGH */
936 | mudela_script { $$ = $1;
937 $$-> set_spot (THIS->here_input ());
943 Text_def *t = new Text_def;
947 t->style_str_ = THIS->textstyle_str_;
948 $$->set_spot (THIS->here_input ());
953 '^' { $$ = get_scriptdef ('^'); }
954 | '+' { $$ = get_scriptdef ('+'); }
955 | '-' { $$ = get_scriptdef ('-'); }
956 | '|' { $$ = get_scriptdef ('|'); }
957 | 'o' { $$ = get_scriptdef ('o'); }
958 | '>' { $$ = get_scriptdef ('>'); }
960 $$ = get_scriptdef ('.');
965 SCRIPT_IDENTIFIER { $$ = $1->script (); }
966 | script_definition { $$ = $1; }
967 | script_abbreviation {
968 $$ = THIS->lexer_p_->lookup_identifier (*$1)->script ();
982 | pre_requests open_request_parens {
983 Array<Request*>& r = *THIS->get_parens_request ($2);
984 for (int i = 0; i < r.size (); i++ )
985 r[i]->set_spot (THIS->here_input ());
986 THIS->pre_reqs.concat (r);
993 THIS->set_duration_mode (*$2);
996 | DURATION entered_notemode_duration {
997 THIS->set_default_duration ($2);
1002 This is weird, but default_octave_i_
1003 is used in steno_note_req too
1005 c' -> default_octave_i_ == 1
1007 /* why can't we have \oct 0 iso \oct{c'}*/
1008 THIS->default_octave_i_ = 1; }
1011 THIS->default_octave_i_ = $3->octave_i_;
1014 | TEXTSTYLE STRING {
1015 THIS->textstyle_str_ = *$2;
1022 $$ = new Moment (0,1);
1024 | duration_length explicit_steno_duration {
1025 *$$ += $2->length ();
1031 | dots '.' { $$ ++; }
1034 entered_notemode_duration:
1036 $$ = new Duration (THIS->default_duration_);
1039 $$ = new Duration (THIS->default_duration_);
1042 | explicit_steno_duration {
1043 THIS->set_last_duration ($1);
1049 entered_notemode_duration {
1051 $$->plet_.type_i_ *= THIS->plet_.type_i_;
1052 $$->plet_.iso_i_ *= THIS->plet_.iso_i_;
1056 explicit_steno_duration:
1059 if (!Duration::duration_type_b ($1))
1060 THIS->parser_error ("Not a duration");
1062 $$->durlog_i_ = Duration_convert::i2_type ($1);
1065 | DURATION_IDENTIFIER {
1066 $$ = $1->duration ();
1068 | explicit_steno_duration '.' {
1071 | explicit_steno_duration '*' int {
1072 $$->plet_.iso_i_ *= $3;
1074 | explicit_steno_duration '/' int {
1075 $$->plet_.type_i_ *= $3;
1085 if (!Duration::duration_type_b ($2))
1086 THIS->parser_error ("Not a duration");
1088 THIS->parser_error ("Can't abbreviate");
1095 steno_note_req notemode_duration {
1096 if (!THIS->lexer_p_->note_state_b ())
1097 THIS->parser_error ("have to be in Note mode for notes");
1098 $1->set_duration (*$2);
1099 int durlog_i = $2->durlog_i_;
1100 $$ = THIS->get_note_element ($1, $2);
1102 | RESTNAME notemode_duration {
1103 $$ = THIS->get_rest_element (*$1, $2);
1109 text_def notemode_duration {
1110 /* this sux! text-def should be feature of lyric-engraver. */
1111 if (!THIS->lexer_p_->lyric_state_b ())
1112 THIS->parser_error ("Have to be in Lyric mode for lyrics");
1113 $$ = THIS->get_word_element ($1, $2);
1121 $$ = new Array<Melodic_req*>;
1123 | pitch_list NOTENAME_ID {
1124 $$->push ($2->clone ()->musical ()->melodic ());
1133 int *i_p = $1->intid ();
1145 Real *r_p = $1->real ();
1154 real unit { $$ = $1*$2; }
1158 unit: CM_T { $$ = 1 CM; }
1159 |IN_T { $$ = 1 INCH; }
1160 |MM_T { $$ = 1 MM; }
1161 |PT_T { $$ = 1 PT; }
1168 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
1178 | symtables_body TEXID STRING {
1179 $$->texsetting = *$3;
1182 | symtables_body STRING '=' symtable {
1189 TABLE '{' symtable_body '}' { $$ = $3; }
1193 { $$ = new Symtable; }
1194 | symtable_body STRING symboldef {
1203 $$ = new Atom (*$1, *$2);
1208 Box b (Interval (0,0), Interval (0,0));
1209 $$ = new Atom (*$1, b);
1215 dinterval dinterval {
1216 $$ = new Box (*$1, *$2);
1222 dinterval: dim dim {
1223 $$ = new Interval ($1, $2);
1230 My_lily_parser::set_yydebug (bool b)
1237 My_lily_parser::do_yyparse ()
1239 yyparse ((void*)this);
1243 My_lily_parser::default_paper ()
1245 Identifier *id = lexer_p_->lookup_identifier ("default_paper");
1246 return id ? id->paperdef () : new Paper_def ;
1250 My_lily_parser::default_midi ()
1252 Identifier *id = lexer_p_->lookup_identifier ("default_midi");
1253 return id ? id->mididef () : new Midi_def ;