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.6"
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 <string> FIELDNAME RECORDLINE
187 %token <i> POST_QUOTES
188 %token <i> PRE_QUOTES
190 %type <outputdef> output_def
191 %type <header> mudela_header mudela_header_body
193 %type <c> open_request_parens close_request_parens
194 %type <c> open_abbrev_parens
195 %type <c> open_plet_parens close_plet_parens
196 %type <music> simple_element music_elt full_element lyrics_elt command_elt
197 %type <i> abbrev_type
200 %type <id> identifier_init
201 %type <duration> explicit_steno_duration notemode_duration
202 %type <duration> entered_notemode_duration explicit_duration
203 %type <interval> dinterval
204 %type <intvec> intastint_list
205 %type <lookup> symtables symtables_body
206 %type <melreq> melodic_request steno_melodic_req
207 %type <notereq> steno_note_req
208 %type <melreqvec> pitch_list
209 %type <midi> midi_block midi_body
210 %type <moment> duration_length
212 %type <scalar> scalar
213 %type <music> Music transposed_music
214 %type <music> property_def translator_change
215 %type <musiclist> Voice Voice_body
216 %type <chord> Chord Chord_body
217 %type <paper> paper_block paper_body
218 %type <real> dim real
220 %type <request> abbrev_command_req
221 %type <request> post_request pre_request command_req verbose_command_req
222 %type <request> script_req dynamic_req
223 %type <score> score_block score_body
224 %type <script> script_definition script_body mudela_script gen_script_def
225 %type <textdef> text_def
226 %type <string> script_abbreviation
227 %type <symbol> symboldef
228 %type <symtable> symtable symtable_body
229 %type <trans> translator_spec translator_spec_body
230 %type <tempo> tempo_request
231 %type <string> header_record
239 | mudela mudela_header {
240 delete THIS->default_header_p_ ;
241 THIS->default_header_p_ = $2;
243 | mudela score_block {
246 | mudela add_declaration { }
248 | mudela check_version { }
249 | mudela add_notenames { }
254 if (String (*$2) != MUDELA_VERSION) {
255 if (THIS->ignore_version_b_) {
256 THIS->here_input ().error ("Incorrect mudela version");
258 THIS->fatal_error_i_ = 1;
259 THIS->parser_error ("Incorrect mudela version");
266 NOTENAMES '{' notenames_body '}'
271 | notenames_body CLEAR {
272 THIS->clear_notenames ();
274 | notenames_body STRING '=' melodic_request {
275 THIS->add_notename (*$2, $4);
284 | mudela_header_body FIELDNAME header_record {
293 THIS->lexer_p_->push_header_state ();
296 '{' mudela_header_body '}' {
298 THIS->lexer_p_->pop_state ();
307 | header_record RECORDLINE {
319 THIS->remember_spot ();
321 /* cont */ '=' identifier_init {
322 THIS->lexer_p_->set_identifier (*$1, $4);
323 $4->init_b_ = THIS->init_parse_b_;
324 $4->set_spot (THIS->pop_spot ());
329 $$ = new Score_id ($1, SCORE_IDENTIFIER);
333 $$ = new Paper_def_id ($1, PAPER_IDENTIFIER);
337 $$ = new Midi_def_id ($1, MIDI_IDENTIFIER);
340 | script_definition {
341 $$ = new Script_id ($1, SCRIPT_IDENTIFIER);
345 $$ = new Music_id ($1, MUSIC_IDENTIFIER);
349 $$ = new Lookup_id ($1, IDENTIFIER);
353 $$ = new Real_id (new Real ($1), REAL_IDENTIFIER);
357 $$ = new Int_id (new int ($1), INT_IDENTIFIER);
361 $$ = new Request_id ($1, POST_REQUEST_IDENTIFIER);
365 $$ = new Request_id ($1, MELODIC_REQUEST_IDENTIFIER);
369 $$ = new Translator_id ($1, TRANS_IDENTIFIER);
371 | explicit_duration {
372 $$ = new Duration_id ($1, DURATION_IDENTIFIER);
379 TRANSLATOR '{' translator_spec_body '}'
383 translator_spec_body:
385 $$ = $1->translator ();
386 $$-> set_spot (THIS->here_input ());
389 $$ = get_translator_l (*$2)->clone ();
390 $$->set_spot (THIS->here_input ());
393 | translator_spec_body STRING '=' scalar ';' {
394 $$-> set_property (*$2, *$4);
398 | translator_spec_body CONSISTS STRING ';' {
399 $$->group_l ()->consists_str_arr_.push (*$3);
402 | translator_spec_body ACCEPTS STRING ';' {
403 $$->group_l ()->accepts_str_arr_.push (*$3);
412 SCORE { THIS->remember_spot ();
413 THIS->error_level_i_ =0;
415 /*cont*/ '{' score_body '}' {
417 $$->set_spot (THIS->pop_spot ());
418 if (!$$->def_p_arr_.size ())
419 $$->add (THIS->default_paper ());
421 /* handle error levels. */
422 $$->errorlevel_i_ = THIS->error_level_i_;
423 THIS->error_level_i_ = 0;
424 if (!$$->header_p_ && THIS->default_header_p_)
425 $$->header_p_ = new Header (*THIS->default_header_p_);
435 | score_body mudela_header {
441 | score_body output_def {
459 /* */ { $$ =new Array<int>; }
460 | intastint_list int '*' int {
461 $$->push ($2); $$->push ($4);
471 '{' paper_body '}' { $$ = $3; }
476 $$ = THIS->default_paper ();
479 $$ = $1->paperdef ();
481 | paper_body OUTPUT STRING ';' {
482 $$->outfile_str_ = *$3;
485 | paper_body symtables { $$->set ($2); }
486 | paper_body STRING '=' dim ';' {
487 $$->set_var (*$2, $4);
489 | paper_body STRING '=' real ';' {
490 $$->set_var (*$2, $4);
492 | paper_body STRING '=' translator_spec {
493 $$-> assign_translator (*$2, $4);
507 '{' midi_body '}' { $$ = $3; }
510 midi_body: /* empty */ {
511 $$ = THIS->default_midi ();
513 | midi_body STRING '=' translator_spec {
514 $$-> assign_translator (*$2, $4);
517 | midi_body OUTPUT STRING ';' {
518 $$->outfile_str_ = *$3;
521 | midi_body tempo_request ';' {
522 $$->set_tempo ($2->dur_.length (), $2->metronome_i_);
531 TEMPO entered_notemode_duration '=' int {
535 $$-> metronome_i_ = $4;
559 full_element { $$ = $1; }
560 | TYPE STRING Music {
562 $$->translator_type_str_ = *$2;
565 | TYPE STRING '=' STRING Music {
567 $$->translator_type_str_ = *$2;
568 $$->translator_id_str_ = *$4;
574 | transposed_music { $$ = $1; }
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;
602 PROPERTY STRING '.' STRING '=' scalar {
603 Translation_property *t = new Translation_property;
604 t-> translator_type_str_ = *$2;
615 STRING { $$ = new Scalar (*$1); delete $1; }
616 | int { $$ = new Scalar ($1); }
621 '<' Chord_body '>' { $$ = $2; }
624 $$->multi_level_i_=$2;
631 $$-> multi_level_i_ = 1;
639 TRANSPOSE steno_melodic_req Music {
641 $$ -> transpose ($2);
651 pre_requests simple_element post_requests {
652 THIS->add_requests ((Chord*)$2);//ugh
656 | voice_command ';' { $$ = 0; }
666 $$ = new Request_chord;
667 $$-> set_spot (THIS->here_input ());
668 $1-> set_spot (THIS->here_input ());
669 ((Chord*)$$) ->add ($1);//ugh
676 | verbose_command_req ';' { $$ = $1; }
681 $$ = new Barcheck_req;
683 | COMMAND_IDENTIFIER {
690 $$ = new Bar_req (*$2);
693 | METER int '/' int {
694 Meter_change_req *m = new Meter_change_req;
698 | SKIP duration_length {
699 Skip_req * skip_p = new Skip_req;
700 skip_p->duration_.set_plet ($2->numerator ().as_long (),
701 $2->denominator ().as_long ());
710 $$ = new Cadenza_req ($2);
712 | PARTIAL duration_length {
713 $$ = new Partial_measure_req (*$2);
717 $$ = new Clef_change_req (*$2);
721 Key_change_req *key_p= new Key_change_req;
722 key_p->melodic_p_arr_ = *$2;
726 | GROUPING intastint_list {
727 $$ = get_grouping_req (*$2); delete $2;
733 assert (THIS->post_reqs.empty ());
735 | post_requests post_request {
736 $2->set_spot (THIS->here_input ());
737 THIS->post_reqs.push ($2);
743 POST_REQUEST_IDENTIFIER {
744 $$ = (Request*)$1->request ();
746 |close_request_parens {
747 $$ = THIS->get_parens_request ($1);
752 Abbreviation_req* a = new Abbreviation_req;
765 $$ = $1->clone ()->musical ()->melodic ();
766 $$->octave_i_ += THIS->default_octave_i_;
768 | steno_melodic_req POST_QUOTES {
769 $$-> octave_i_ += $2;
771 | PRE_QUOTES steno_melodic_req {
773 $2-> octave_i_ -= $1;
780 * (Melodic_req *) $$ = *$1;
783 | steno_note_req '!' {
784 $$->forceacc_b_ = ! $$->forceacc_b_;
786 /* have to duration here. */
790 MELODIC_REQUEST '{' int int int '}' {/* ugh */
791 $$ = new Melodic_req;
793 $$->notename_i_ = $4;
794 $$->accidental_i_ = $5;
799 DURATION '{' int int '}' {
807 ABSDYNAMIC '{' int '}' {
808 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
809 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
812 | SPANDYNAMIC '{' int int '}' {
813 Span_dynamic_req * sp_p = new Span_dynamic_req;
815 sp_p-> dynamic_dir_ = $3;
823 THIS->plet_.type_i_ = $4;
824 THIS->plet_.iso_i_ = $2;
828 close_request_parens:
838 | close_plet_parens {
852 if (!Duration::duration_type_b ($3))
853 THIS->parser_error ("Not a duration");
855 THIS->parser_error ("Can't abbreviate");
857 THIS->set_abbrev_beam ($3);
864 THIS->plet_.type_i_ = $4;
865 THIS->plet_.iso_i_ = $2;
879 | open_abbrev_parens {
888 SCRIPT '{' script_body '}' { $$ = $3; }
892 STRING int int int int int {
893 Script_def *s = new Script_def;
894 s->set_from_input (*$1,$2, $3,$4,$5, $6);
901 script_dir gen_script_def {
902 Musical_script_req *m = new Musical_script_req;
904 m-> scriptdef_p_ = $2;
905 m-> set_spot (THIS->here_input ());
911 text_def { $$ = $1; }
912 | mudela_script { $$ = $1;
913 $$-> set_spot (THIS->here_input ());
919 Text_def *t = new Text_def;
923 t->style_str_ = THIS->textstyle_str_;
924 $$->set_spot (THIS->here_input ());
929 '^' { $$ = get_scriptdef ('^'); }
930 | '+' { $$ = get_scriptdef ('+'); }
931 | '-' { $$ = get_scriptdef ('-'); }
932 | '|' { $$ = get_scriptdef ('|'); }
933 | 'o' { $$ = get_scriptdef ('o'); }
934 | '>' { $$ = get_scriptdef ('>'); }
936 $$ = get_scriptdef ('.');
941 SCRIPT_IDENTIFIER { $$ = $1->script (); }
942 | script_definition { $$ = $1; }
943 | script_abbreviation {
944 $$ = THIS->lexer_p_->lookup_identifier (*$1)->script ();
956 | pre_requests pre_request {
957 THIS->pre_reqs.push ($2);
958 $2->set_spot (THIS->here_input ());
963 open_request_parens {
964 $$ = THIS->get_parens_request ($1);
970 THIS->default_duration_.set_plet ($2,$4);
973 THIS->set_duration_mode (*$2);
976 | DURATION entered_notemode_duration {
977 THIS->set_default_duration ($2);
982 This is weird, but default_octave_i_
983 is used in steno_note_req too
985 c' -> default_octave_i_ == 1
987 /* why can't we have \oct 0 iso \oct{c'}*/
988 THIS->default_octave_i_ = 1; }
991 THIS->default_octave_i_ = $3->octave_i_;
995 THIS->textstyle_str_ = *$2;
1002 $$ = new Moment (0,1);
1004 | duration_length explicit_steno_duration {
1005 *$$ += $2->length ();
1011 | dots '.' { $$ ++; }
1014 entered_notemode_duration:
1016 $$ = new Duration (THIS->default_duration_);
1019 $$ = new Duration (THIS->default_duration_);
1022 | explicit_steno_duration {
1023 THIS->set_last_duration ($1);
1029 entered_notemode_duration {
1031 $$->plet_.type_i_ *= THIS->plet_.type_i_;
1032 $$->plet_.iso_i_ *= THIS->plet_.iso_i_;
1036 explicit_steno_duration:
1039 if (!Duration::duration_type_b ($1))
1040 THIS->parser_error ("Not a duration");
1042 $$->durlog_i_ = Duration_convert::i2_type ($1);
1045 | DURATION_IDENTIFIER {
1046 $$ = $1->duration ();
1048 | explicit_steno_duration '.' {
1051 | explicit_steno_duration '*' int {
1052 $$->plet_.iso_i_ *= $3;
1054 | explicit_steno_duration '/' int {
1055 $$->plet_.type_i_ *= $3;
1065 if (!Duration::duration_type_b ($2))
1066 THIS->parser_error ("Not a duration");
1068 THIS->parser_error ("Can't abbreviate");
1075 steno_note_req notemode_duration {
1076 if (!THIS->lexer_p_->note_state_b ())
1077 THIS->parser_error ("have to be in Note mode for notes");
1078 $1->set_duration (*$2);
1079 int durlog_i = $2->durlog_i_;
1080 $$ = THIS->get_note_element ($1, $2);
1082 | RESTNAME notemode_duration {
1083 $$ = THIS->get_rest_element (*$1, $2);
1089 text_def notemode_duration {
1090 /* this sux! text-def should be feature of lyric-engraver. */
1091 if (!THIS->lexer_p_->lyric_state_b ())
1092 THIS->parser_error ("Have to be in Lyric mode for lyrics");
1093 $$ = THIS->get_word_element ($1, $2);
1101 $$ = new Array<Melodic_req*>;
1103 | pitch_list NOTENAME_ID {
1104 $$->push ($2->clone ()->musical ()->melodic ());
1113 int *i_p = $1->intid ();
1125 Real *r_p = $1->real ();
1134 real unit { $$ = $1*$2; }
1138 unit: CM_T { $$ = 1 CM; }
1139 |IN_T { $$ = 1 INCH; }
1140 |MM_T { $$ = 1 MM; }
1141 |PT_T { $$ = 1 PT; }
1148 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
1158 | symtables_body TEXID STRING {
1159 $$->texsetting = *$3;
1162 | symtables_body STRING '=' symtable {
1169 TABLE '{' symtable_body '}' { $$ = $3; }
1173 { $$ = new Symtable; }
1174 | symtable_body STRING symboldef {
1183 $$ = new Atom (*$1, *$2);
1188 Box b (Interval (0,0), Interval (0,0));
1189 $$ = new Atom (*$1, b);
1195 dinterval dinterval {
1196 $$ = new Box (*$1, *$2);
1202 dinterval: dim dim {
1203 $$ = new Interval ($1, $2);
1210 My_lily_parser::set_yydebug (bool b)
1217 My_lily_parser::do_yyparse ()
1219 yyparse ((void*)this);
1223 My_lily_parser::default_paper ()
1225 Identifier *id = lexer_p_->lookup_identifier ("default_paper");
1226 return id ? id->paperdef () : new Paper_def ;
1230 My_lily_parser::default_midi ()
1232 Identifier *id = lexer_p_->lookup_identifier ("default_midi");
1233 return id ? id->mididef () : new Midi_def ;