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.7"
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 */
134 %token MELODIC_REQUEST
163 %token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
167 %token <melreq> NOTENAME_ID
168 %token <id> DURATION_IDENTIFIER
169 %token <id> IDENTIFIER
170 %token <id> MELODIC_REQUEST_IDENTIFIER
171 %token <id> MUSIC_IDENTIFIER
172 %token <id> VOICE_IDENTIFIER
173 %token <id> POST_REQUEST_IDENTIFIER
174 %token <id> SCRIPT_IDENTIFIER
175 %token <id> COMMAND_IDENTIFIER
176 %token <id> REAL_IDENTIFIER
177 %token <id> TRANS_IDENTIFIER
178 %token <id> INT_IDENTIFIER
179 %token <id> SCORE_IDENTIFIER
180 %token <id> MIDI_IDENTIFIER
181 %token <id> PAPER_IDENTIFIER
182 %token <id> REQUEST_IDENTIFIER
184 %token <string> DURATION RESTNAME
185 %token <string> STRING
186 %token <i> POST_QUOTES
187 %token <i> PRE_QUOTES
189 %type <outputdef> output_def
190 %type <header> mudela_header mudela_header_body
192 %type <c> open_request_parens close_request_parens
193 %type <c> open_abbrev_parens
194 %type <c> open_plet_parens close_plet_parens
195 %type <music> simple_element music_elt full_element lyrics_elt command_elt
196 %type <i> abbrev_type
199 %type <id> identifier_init
200 %type <duration> explicit_steno_duration notemode_duration
201 %type <duration> entered_notemode_duration explicit_duration
202 %type <interval> dinterval
203 %type <intvec> intastint_list
204 %type <lookup> symtables symtables_body
205 %type <melreq> melodic_request steno_melodic_req
206 %type <notereq> steno_note_req
207 %type <melreqvec> pitch_list
208 %type <midi> midi_block midi_body
209 %type <moment> duration_length
211 %type <scalar> scalar
212 %type <music> Music transposed_music
213 %type <music> property_def translator_change
214 %type <musiclist> Voice Voice_body
215 %type <chord> Chord Chord_body
216 %type <paper> paper_block paper_body
217 %type <real> dim real
219 %type <request> abbrev_command_req
220 %type <request> post_request pre_request command_req verbose_command_req
221 %type <request> script_req dynamic_req
222 %type <score> score_block score_body
223 %type <script> script_definition script_body mudela_script gen_script_def
224 %type <textdef> text_def
225 %type <string> script_abbreviation
226 %type <symbol> symboldef
227 %type <symtable> symtable symtable_body
228 %type <trans> translator_spec translator_spec_body
229 %type <tempo> tempo_request
230 %type <string> concat_strings
238 | mudela mudela_header {
239 delete THIS->default_header_p_ ;
240 THIS->default_header_p_ = $2;
242 | mudela score_block {
245 | mudela add_declaration { }
247 | mudela check_version { }
248 | mudela add_notenames { }
253 if (String (*$2) != MUDELA_VERSION) {
254 if (THIS->ignore_version_b_) {
255 THIS->here_input ().error ("Incorrect mudela version");
257 THIS->fatal_error_i_ = 1;
258 THIS->parser_error ("Incorrect mudela version");
265 NOTENAMES '{' notenames_body '}'
270 | notenames_body CLEAR {
271 THIS->clear_notenames ();
273 | notenames_body STRING '=' melodic_request {
274 THIS->add_notename (*$2, $4);
283 | mudela_header_body STRING '=' concat_strings ';' {
291 HEADER '{' mudela_header_body '}' {
301 | concat_strings STRING {
312 THIS->remember_spot ();
314 /* cont */ '=' identifier_init {
315 THIS->lexer_p_->set_identifier (*$1, $4);
316 $4->init_b_ = THIS->init_parse_b_;
317 $4->set_spot (THIS->pop_spot ());
322 $$ = new Score_id ($1, SCORE_IDENTIFIER);
326 $$ = new Paper_def_id ($1, PAPER_IDENTIFIER);
330 $$ = new Midi_def_id ($1, MIDI_IDENTIFIER);
333 | script_definition {
334 $$ = new Script_id ($1, SCRIPT_IDENTIFIER);
338 $$ = new Music_id ($1, MUSIC_IDENTIFIER);
342 $$ = new Lookup_id ($1, IDENTIFIER);
346 $$ = new Real_id (new Real ($1), REAL_IDENTIFIER);
350 $$ = new Int_id (new int ($1), INT_IDENTIFIER);
354 $$ = new Request_id ($1, POST_REQUEST_IDENTIFIER);
358 $$ = new Request_id ($1, MELODIC_REQUEST_IDENTIFIER);
362 $$ = new Translator_id ($1, TRANS_IDENTIFIER);
364 | explicit_duration {
365 $$ = new Duration_id ($1, DURATION_IDENTIFIER);
372 TRANSLATOR '{' translator_spec_body '}'
376 translator_spec_body:
378 $$ = $1->translator ();
379 $$-> set_spot (THIS->here_input ());
382 $$ = get_translator_l (*$2)->clone ();
383 $$->set_spot (THIS->here_input ());
386 | translator_spec_body STRING '=' scalar ';' {
387 $$-> set_property (*$2, *$4);
391 | translator_spec_body CONSISTS STRING ';' {
392 $$->group_l ()->consists_str_arr_.push (*$3);
395 | translator_spec_body ACCEPTS STRING ';' {
396 $$->group_l ()->accepts_str_arr_.push (*$3);
405 SCORE { THIS->remember_spot ();
406 THIS->error_level_i_ =0;
408 /*cont*/ '{' score_body '}' {
410 $$->set_spot (THIS->pop_spot ());
411 if (!$$->def_p_arr_.size ())
412 $$->add (THIS->default_paper ());
414 /* handle error levels. */
415 $$->errorlevel_i_ = THIS->error_level_i_;
416 THIS->error_level_i_ = 0;
417 if (!$$->header_p_ && THIS->default_header_p_)
418 $$->header_p_ = new Header (*THIS->default_header_p_);
428 | score_body mudela_header {
433 $2->warning ("More than one music block");
436 | score_body output_def {
454 /* */ { $$ =new Array<int>; }
455 | intastint_list int '*' int {
456 $$->push ($2); $$->push ($4);
466 '{' paper_body '}' { $$ = $3; }
471 $$ = THIS->default_paper ();
474 $$ = $1->paperdef ();
476 | paper_body OUTPUT STRING ';' {
477 $$->outfile_str_ = *$3;
480 | paper_body symtables { $$->set ($2); }
481 | paper_body STRING '=' dim ';' {
482 $$->set_var (*$2, $4);
484 | paper_body STRING '=' real ';' {
485 $$->set_var (*$2, $4);
487 | paper_body STRING '=' translator_spec {
488 $$-> assign_translator (*$2, $4);
502 '{' midi_body '}' { $$ = $3; }
505 midi_body: /* empty */ {
506 $$ = THIS->default_midi ();
508 | midi_body STRING '=' translator_spec {
509 $$-> assign_translator (*$2, $4);
512 | midi_body OUTPUT STRING ';' {
513 $$->outfile_str_ = *$3;
516 | midi_body tempo_request ';' {
517 $$->set_tempo ($2->dur_.length (), $2->metronome_i_);
526 TEMPO entered_notemode_duration '=' int {
530 $$-> metronome_i_ = $4;
547 $$->set_spot (THIS->here_input ());
555 full_element { $$ = $1; }
556 | TYPE STRING Music {
558 $$->translator_type_str_ = *$2;
561 | TYPE STRING '=' STRING Music {
563 $$->translator_type_str_ = *$2;
564 $$->translator_id_str_ = *$4;
570 | transposed_music { $$ = $1; }
571 | MUSIC_IDENTIFIER { $$ = $1->music (); }
572 | MUSIC_IDENTIFIER ';' { $$ = $1->music (); }
574 { THIS->lexer_p_->push_note_state (); }
576 { $$=$3; THIS->lexer_p_->pop_state (); }
579 { THIS->lexer_p_->push_lyric_state (); }
581 { $$ = $3; THIS->lexer_p_->pop_state (); }
587 TRANSLATOR STRING '=' STRING {
588 Change_translator * t = new Change_translator;
589 t-> change_to_type_str_ = *$2;
590 t-> change_to_id_str_ = *$4;
593 $$->set_spot (THIS->here_input ());
600 PROPERTY STRING '.' STRING '=' scalar {
601 Translation_property *t = new Translation_property;
602 t-> translator_type_str_ = *$2;
606 $$->set_spot (THIS->here_input ());
614 STRING { $$ = new Scalar (*$1); delete $1; }
615 | int { $$ = new Scalar ($1); }
620 '<' Chord_body '>' { $$ = $2; }
623 $$->multi_level_i_=$2;
630 $$-> multi_level_i_ = 1;
631 $$->set_spot (THIS->here_input ());
639 TRANSPOSE steno_melodic_req Music {
641 $$ -> transpose ($2);
652 pre_requests simple_element post_requests {
653 THIS->add_requests ((Chord*)$2);//ugh
657 | voice_command ';' { $$ = 0; }
667 $$ = new Request_chord;
668 $$-> set_spot (THIS->here_input ());
669 $1-> set_spot (THIS->here_input ());
670 ((Chord*)$$) ->add ($1);//ugh
677 | verbose_command_req ';' { $$ = $1; }
682 $$ = new Barcheck_req;
684 | COMMAND_IDENTIFIER {
691 $$ = new Bar_req (*$2);
694 | METER int '/' int {
695 Meter_change_req *m = new Meter_change_req;
699 | SKIP duration_length {
700 Skip_req * skip_p = new Skip_req;
701 skip_p->duration_.set_plet ($2->numerator ().as_long (),
702 $2->denominator ().as_long ());
711 $$ = new Cadenza_req ($2);
713 | PARTIAL duration_length {
714 $$ = new Partial_measure_req (*$2);
718 $$ = new Clef_change_req (*$2);
722 Key_change_req *key_p= new Key_change_req;
723 key_p->melodic_p_arr_ = *$2;
727 | GROUPING intastint_list {
728 $$ = get_grouping_req (*$2); delete $2;
734 assert (THIS->post_reqs.empty ());
736 | post_requests post_request {
737 $2->set_spot (THIS->here_input ());
738 THIS->post_reqs.push ($2);
744 POST_REQUEST_IDENTIFIER {
745 $$ = (Request*)$1->request ();
747 |close_request_parens {
748 $$ = THIS->get_parens_request ($1);
753 Abbreviation_req* a = new Abbreviation_req;
766 $$ = $1->clone ()->musical ()->melodic ();
767 $$->octave_i_ += THIS->default_octave_i_;
769 | steno_melodic_req POST_QUOTES {
770 $$-> octave_i_ += $2;
772 | PRE_QUOTES steno_melodic_req {
774 $2-> octave_i_ -= $1;
781 * (Melodic_req *) $$ = *$1;
784 | steno_note_req '!' {
785 $$->forceacc_b_ = ! $$->forceacc_b_;
787 /* have to duration here. */
791 MELODIC_REQUEST '{' int int int '}' {/* ugh */
792 $$ = new Melodic_req;
794 $$->notename_i_ = $4;
795 $$->accidental_i_ = $5;
800 DURATION '{' int int '}' {
808 ABSDYNAMIC '{' int '}' {
809 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
810 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
813 | SPANDYNAMIC '{' int int '}' {
814 Span_dynamic_req * sp_p = new Span_dynamic_req;
816 sp_p-> dynamic_dir_ = $3;
824 THIS->plet_.type_i_ = $4;
825 THIS->plet_.iso_i_ = $2;
829 close_request_parens:
839 | close_plet_parens {
853 if (!Duration::duration_type_b ($3))
854 THIS->parser_error ("Not a duration");
856 THIS->parser_error ("Can't abbreviate");
858 THIS->set_abbrev_beam ($3);
865 THIS->plet_.type_i_ = $4;
866 THIS->plet_.iso_i_ = $2;
880 | open_abbrev_parens {
889 SCRIPT '{' script_body '}' { $$ = $3; }
893 STRING int int int int int {
894 Script_def *s = new Script_def;
895 s->set_from_input (*$1,$2, $3,$4,$5, $6);
902 script_dir gen_script_def {
903 Musical_script_req *m = new Musical_script_req;
905 m-> scriptdef_p_ = $2;
906 m-> set_spot (THIS->here_input ());
913 ((Text_def*) $$)->align_i_ = CENTER; /* UGH */
915 | mudela_script { $$ = $1;
916 $$-> set_spot (THIS->here_input ());
922 Text_def *t = new Text_def;
926 t->style_str_ = THIS->textstyle_str_;
927 $$->set_spot (THIS->here_input ());
932 '^' { $$ = get_scriptdef ('^'); }
933 | '+' { $$ = get_scriptdef ('+'); }
934 | '-' { $$ = get_scriptdef ('-'); }
935 | '|' { $$ = get_scriptdef ('|'); }
936 | 'o' { $$ = get_scriptdef ('o'); }
937 | '>' { $$ = get_scriptdef ('>'); }
939 $$ = get_scriptdef ('.');
944 SCRIPT_IDENTIFIER { $$ = $1->script (); }
945 | script_definition { $$ = $1; }
946 | script_abbreviation {
947 $$ = THIS->lexer_p_->lookup_identifier (*$1)->script ();
959 | pre_requests pre_request {
960 THIS->pre_reqs.push ($2);
961 $2->set_spot (THIS->here_input ());
966 open_request_parens {
967 $$ = THIS->get_parens_request ($1);
973 THIS->plet_.type_i_ = $4;
974 THIS->plet_.iso_i_ = $2;
977 THIS->set_duration_mode (*$2);
980 | DURATION entered_notemode_duration {
981 THIS->set_default_duration ($2);
986 This is weird, but default_octave_i_
987 is used in steno_note_req too
989 c' -> default_octave_i_ == 1
991 /* why can't we have \oct 0 iso \oct{c'}*/
992 THIS->default_octave_i_ = 1; }
995 THIS->default_octave_i_ = $3->octave_i_;
999 THIS->textstyle_str_ = *$2;
1006 $$ = new Moment (0,1);
1008 | duration_length explicit_steno_duration {
1009 *$$ += $2->length ();
1015 | dots '.' { $$ ++; }
1018 entered_notemode_duration:
1020 $$ = new Duration (THIS->default_duration_);
1023 $$ = new Duration (THIS->default_duration_);
1026 | explicit_steno_duration {
1027 THIS->set_last_duration ($1);
1033 entered_notemode_duration {
1035 $$->plet_.type_i_ *= THIS->plet_.type_i_;
1036 $$->plet_.iso_i_ *= THIS->plet_.iso_i_;
1040 explicit_steno_duration:
1043 if (!Duration::duration_type_b ($1))
1044 THIS->parser_error ("Not a duration");
1046 $$->durlog_i_ = Duration_convert::i2_type ($1);
1049 | DURATION_IDENTIFIER {
1050 $$ = $1->duration ();
1052 | explicit_steno_duration '.' {
1055 | explicit_steno_duration '*' int {
1056 $$->plet_.iso_i_ *= $3;
1058 | explicit_steno_duration '/' int {
1059 $$->plet_.type_i_ *= $3;
1069 if (!Duration::duration_type_b ($2))
1070 THIS->parser_error ("Not a duration");
1072 THIS->parser_error ("Can't abbreviate");
1079 steno_note_req notemode_duration {
1080 if (!THIS->lexer_p_->note_state_b ())
1081 THIS->parser_error ("have to be in Note mode for notes");
1082 $1->set_duration (*$2);
1083 int durlog_i = $2->durlog_i_;
1084 $$ = THIS->get_note_element ($1, $2);
1086 | RESTNAME notemode_duration {
1087 $$ = THIS->get_rest_element (*$1, $2);
1093 text_def notemode_duration {
1094 /* this sux! text-def should be feature of lyric-engraver. */
1095 if (!THIS->lexer_p_->lyric_state_b ())
1096 THIS->parser_error ("Have to be in Lyric mode for lyrics");
1097 $$ = THIS->get_word_element ($1, $2);
1105 $$ = new Array<Melodic_req*>;
1107 | pitch_list NOTENAME_ID {
1108 $$->push ($2->clone ()->musical ()->melodic ());
1117 int *i_p = $1->intid ();
1129 Real *r_p = $1->real ();
1138 real unit { $$ = $1*$2; }
1142 unit: CM_T { $$ = 1 CM; }
1143 |IN_T { $$ = 1 INCH; }
1144 |MM_T { $$ = 1 MM; }
1145 |PT_T { $$ = 1 PT; }
1152 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
1162 | symtables_body TEXID STRING {
1163 $$->texsetting = *$3;
1166 | symtables_body STRING '=' symtable {
1173 TABLE '{' symtable_body '}' { $$ = $3; }
1177 { $$ = new Symtable; }
1178 | symtable_body STRING symboldef {
1187 $$ = new Atom (*$1, *$2);
1192 Box b (Interval (0,0), Interval (0,0));
1193 $$ = new Atom (*$1, b);
1199 dinterval dinterval {
1200 $$ = new Box (*$1, *$2);
1206 dinterval: dim dim {
1207 $$ = new Interval ($1, $2);
1214 My_lily_parser::set_yydebug (bool b)
1221 My_lily_parser::do_yyparse ()
1223 yyparse ((void*)this);
1227 My_lily_parser::default_paper ()
1229 Identifier *id = lexer_p_->lookup_identifier ("default_paper");
1230 return id ? id->paperdef () : new Paper_def ;
1234 My_lily_parser::default_midi ()
1236 Identifier *id = lexer_p_->lookup_identifier ("default_midi");
1237 return id ? id->mididef () : new Midi_def ;