1 %{ // -*-Fundamental-*-
4 parser.y -- lily parser
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.0"
17 #include "script-def.hh"
18 #include "symtable.hh"
21 #include "my-lily-lexer.hh"
22 #include "paper-def.hh"
23 #include "midi-def.hh"
27 #include "parseconstruct.hh"
29 #include "identifier.hh"
30 #include "command-request.hh"
31 #include "musical-request.hh"
32 #include "my-lily-parser.hh"
33 #include "text-def.hh"
34 #include "input-translator.hh"
36 #include "music-list.hh"
42 #define YYERROR_VERBOSE 1
44 #define YYPARSE_PARAM my_lily_parser_l
45 #define YYLEX_PARAM my_lily_parser_l
46 #define THIS ((My_lily_parser *) my_lily_parser_l)
48 #define yyerror THIS->parser_error
54 Array<Melodic_req*> *melreqvec;/* should clean up naming */
55 Array<String> * strvec;
61 Input_translator* itrans;
63 Music_list *musiclist;
74 General_script_def * script;
78 Symtables * symtables;
88 yylex(YYSTYPE *s, void * v_l)
90 My_lily_parser *pars_l = (My_lily_parser*) v_l;
91 My_lily_lexer * lex_l = pars_l->lexer_p_;
93 lex_l->lexval_l = (void*) s;
94 return lex_l->yylex();
102 /* tokens which are not keywords */
114 %token DURATIONCOMMAND
120 %token REQUESTTRANSLATOR
129 %token MELODIC_REQUEST
160 %token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
164 %token <melreq> NOTENAME_ID
165 %token <id> IDENTIFIER
166 %token <id> MELODIC_REQUEST_IDENTIFIER
167 %token <id> MUSIC_IDENTIFIER
168 %token <id> VOICE_IDENTIFIER
169 %token <id> POST_REQUEST_IDENTIFIER
170 %token <id> SCRIPT_IDENTIFIER
171 %token <id> STAFF_IDENTIFIER
172 %token <id> REAL_IDENTIFIER
173 %token <id> INPUT_TRANS_IDENTIFIER
174 %token <id> INT_IDENTIFIER
175 %token <id> SCORE_IDENTIFIER
176 %token <id> MIDI_IDENTIFIER
177 %token <id> PAPER_IDENTIFIER
178 %token <id> REQUEST_IDENTIFIER
180 %token <string> DURATION RESTNAME
181 %token <string> STRING
182 %token <i> POST_QUOTES
183 %token <i> PRE_QUOTES
187 %type <c> open_request_parens close_request_parens
188 %type <c> open_plet_parens close_plet_parens
189 %type <music> simple_element music_elt full_element lyrics_elt command_elt
192 %type <id> declaration
193 %type <duration> explicit_duration notemode_duration
194 %type <interval> dinterval
195 %type <intvec> intastint_list
196 %type <lookup> symtables symtables_body
197 %type <melreq> melodic_request steno_melodic_req
198 %type <notereq> steno_note_req
199 %type <melreqvec> pitch_list
200 %type <midi> midi_block midi_body
201 %type <moment> duration_length
203 %type <music> Music transposed_music
204 %type <musiclist> Voice Voice_body
205 %type <chord> Chord Chord_body
206 %type <paper> paper_block paper_body
207 %type <real> dim real
209 %type <request> post_request pre_request command_req verbose_command_req abbrev_command_req
210 %type <request> script_req dynamic_req
211 %type <score> score_block score_body
212 %type <script> script_definition script_body mudela_script gen_script_def
213 %type <textdef> text_def
214 %type <string> declarable_identifier
215 %type <string> script_abbreviation
216 %type <id> old_identifier
217 %type <symbol> symboldef
218 %type <symtable> symtable symtable_body
219 %type <itrans> input_translator_spec input_translator_spec_body
226 | mudela score_block {
229 | mudela add_declaration { }
231 | mudela check_version { }
232 | mudela add_notenames { }
237 if (*$2 != MUDELA_VERSION) {
238 if (THIS->ignore_version_b_) {
239 THIS->here_input().error("Incorrect mudela version");
241 THIS->fatal_error_i_ = 1;
242 THIS->parser_error("Incorrect mudela version");
249 NOTENAMES '{' notenames_body '}'
254 | notenames_body CLEAR {
255 THIS->clear_notenames();
257 | notenames_body STRING '=' melodic_request {
258 THIS->add_notename(*$2, $4);
265 add_declaration: declaration {
266 THIS->lexer_p_->add_identifier($1);
267 $1->init_b_ = THIS->init_parse_b_;
268 $1->set_spot(THIS->pop_spot());
272 declarable_identifier:
274 THIS->remember_spot();
278 THIS->remember_spot();
279 $$ = new String($1->name_str_);
280 THIS->here_input().warning("redeclaration of `" + *$$ + "'");
287 | INPUT_TRANS_IDENTIFIER
288 | MELODIC_REQUEST_IDENTIFIER
289 | POST_REQUEST_IDENTIFIER
297 declarable_identifier '=' score_block {
298 $$ = new Score_id(*$1, $3, SCORE_IDENTIFIER);
301 | declarable_identifier '=' paper_block {
302 $$ = new Paper_def_id(*$1, $3, PAPER_IDENTIFIER);
305 | declarable_identifier '=' midi_block {
306 $$ = new Midi_def_id(*$1, $3, MIDI_IDENTIFIER);
309 | declarable_identifier '=' script_definition {
310 $$ = new Script_id(*$1, $3, SCRIPT_IDENTIFIER);
313 | declarable_identifier '=' Music {
314 $$ = new Music_id(*$1, $3, MUSIC_IDENTIFIER);
317 | declarable_identifier '=' symtables {
318 $$ = new Lookup_id(*$1, $3, IDENTIFIER);
321 | declarable_identifier '=' real {
322 $$ = new Real_id(*$1, new Real($3), REAL_IDENTIFIER);
325 | declarable_identifier '=' int {
326 $$ = new Int_id(*$1, new int($3), INT_IDENTIFIER);
329 | declarable_identifier '=' post_request {
330 $$ = new Request_id(*$1, $3, POST_REQUEST_IDENTIFIER);
333 | declarable_identifier '=' melodic_request {
334 $$ = new Request_id(*$1, $3, MELODIC_REQUEST_IDENTIFIER);
337 | declarable_identifier '=' input_translator_spec {
338 $$ = new Input_translator_id ( *$1, $3, INPUT_TRANS_IDENTIFIER);
345 input_translator_spec:
346 REQUESTTRANSLATOR '{' input_translator_spec_body '}'
350 input_translator_spec_body:
351 INPUT_TRANS_IDENTIFIER {
352 $$ = $1->input_translator(true);
353 $$-> set_spot( THIS->here_input() );
356 $$ = new Input_translator;
359 $$->set_spot ( THIS->here_input() );
363 | input_translator_spec_body ID STRING ';' {
364 $$-> default_id_str_ = *$3;
367 | input_translator_spec_body ALIAS STRING ';' {
368 $$-> alias_str_arr_.push(*$3);
371 | input_translator_spec_body CONSISTS STRING ';' {
372 $$-> consists_str_arr_.push(*$3);
375 | input_translator_spec_body CONTAINS input_translator_spec {
384 SCORE { THIS->remember_spot(); }
385 /*cont*/ '{' score_body '}' {
387 $$->set_spot(THIS->pop_spot());
388 if (!$$->paper_p_ && ! $$->midi_p_)
389 $$->paper_p_ = THIS->default_paper();
391 /* handle error levels. */
392 $$->errorlevel_i_ = THIS->error_level_i_;
393 THIS->error_level_i_ = 0;
401 $$ = $1->score(true);
406 | score_body paper_block {
409 | score_body midi_block {
418 /* */ { $$ =new Array<int>; }
419 | intastint_list int '*' int {
420 $$->push($2); $$->push($4);
430 '{' paper_body '}' { $$ = $3; }
435 $$ = THIS->default_paper(); // paper / video / engrave
437 | paper_body OUTPUT STRING ';' { $$->outfile_str_ = *$3;
440 | paper_body symtables { $$->set($2); }
441 | paper_body STRING '=' dim ';' {
442 $$->set_var(*$2, $4);
444 | paper_body STRING '=' REAL ';' {
445 $$->set_var(*$2, $4);
447 | paper_body input_translator_spec {
461 '{' midi_body '}' { $$ = $3; }
464 midi_body: /* empty */ {
465 $$ = THIS->default_midi(); // midi / audio / perform
467 | midi_body OUTPUT STRING ';' {
468 $$->outfile_str_ = *$3;
471 | midi_body TEMPO notemode_duration ':' int ';' {
472 $$->set_tempo( $3->length(), $5 );
474 | midi_body input_translator_spec {
496 | Voice_body ID STRING STRING ';' {
509 full_element { $$ = $1; }
512 | transposed_music { $$ = $1; }
513 | MUSIC_IDENTIFIER { $$ = $1->music(true); }
515 { THIS->lexer_p_->push_note_state(); }
517 { $$=$3; THIS->lexer_p_->pop_state(); }
520 { THIS->lexer_p_->push_lyric_state(); }
522 { $$ = $3; THIS->lexer_p_->pop_state(); }
526 '<' Chord_body '>' { $$ = $2; }
532 $$-> multi_level_i_ = 1;
534 | Chord_body MULTI INT ';' {
535 $$->multi_level_i_=$3;
537 | Chord_body ID STRING STRING ';' {
549 TRANSPOSE steno_melodic_req Music {
561 pre_requests simple_element post_requests {
562 THIS->add_requests((Chord*)$2);//ugh
565 | voice_command ';' { $$ = 0; }
576 $$ = new Request_chord;
577 $$-> set_spot( THIS->here_input());
581 $2-> set_spot( THIS->here_input());
582 ((Chord*)$$) ->add($2);//ugh
585 | GROUP STRING ';' { // ugh ugh ugh
586 Change_reg *chr_p = new Change_reg;
588 chr_p-> type_str_ = "Voice_group_engravers"; //ugh
589 chr_p-> id_str_ = *$2;
596 | verbose_command_req ';' { $$ = $1; }
601 $$ = new Barcheck_req;
607 $$ = new Bar_req(*$2);
610 | METER int '/' int {
611 Meter_change_req *m = new Meter_change_req;
613 // sorry hw, i need meter at output of track,
614 // but don-t know where to get it... statics should go.
615 // HW : default: 4/4, meterchange reqs may change it.
617 Midi_def::num_i_s = $2;
618 Midi_def::den_i_s = $4;
621 | SKIP duration_length {
622 Skip_req * skip_p = new Skip_req;
623 skip_p->duration_ = Duration(1,0);
624 skip_p->duration_.set_plet($2->numerator().as_long(),
625 $2->denominator().as_long());
631 $$ = new Cadenza_req($2);
633 | PARTIAL duration_length {
634 $$ = new Partial_measure_req(*$2);
638 $$ = get_stemdir_req($2);
641 $$ = get_hshift_req($2);
644 $$ = new Clef_change_req(*$2);
648 Key_change_req *key_p= new Key_change_req;
649 key_p->melodic_p_arr_ = *$2;
653 | GROUPING intastint_list {
654 $$ = get_grouping_req(*$2); delete $2;
661 assert(THIS->post_reqs.empty());
663 | post_requests post_request {
664 $2->set_spot( THIS->here_input());
665 THIS->post_reqs.push($2);
671 POST_REQUEST_IDENTIFIER {
672 $$ = (Request*)$1->request(true);
674 |close_request_parens {
675 $$ = THIS->get_parens_request($1);
688 $$ = $1->clone()->musical()->melodic();
689 $$->octave_i_ += THIS->default_octave_i_;
691 | steno_melodic_req POST_QUOTES {
692 $$-> octave_i_ += $2;
694 | PRE_QUOTES steno_melodic_req {
696 $2-> octave_i_ -= $1;
703 * (Melodic_req *) $$ = *$1;
706 | steno_note_req '!' {
707 $$->forceacc_b_ = ! $$->forceacc_b_;
709 /* have to duration here. */
713 MELODIC_REQUEST '{' int int int '}' {/* ugh */
714 $$ = new Melodic_req;
716 $$->notename_i_ = $4;
717 $$->accidental_i_ = $5;
722 ABSDYNAMIC '{' int '}' {
723 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
724 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
727 | SPANDYNAMIC '{' int int '}' {
728 Span_dynamic_req * sp_p = new Span_dynamic_req;
730 sp_p-> dynamic_dir_i_ = $3;
738 THIS->default_duration_.set_plet($2,$4);
742 close_request_parens:
752 | close_plet_parens {
766 THIS->default_duration_.set_plet($2,$4);
787 SCRIPT '{' script_body '}' { $$ = $3; }
791 STRING int int int int int {
792 Script_def *s = new Script_def;
793 s->set_from_input(*$1,$2, $3,$4,$5, $6);
800 script_dir gen_script_def {
801 Musical_script_req *m = new Musical_script_req;
803 m-> scriptdef_p_ = $2;
804 m-> set_spot ( THIS->here_input() );
810 text_def { $$ = $1; }
811 | mudela_script { $$ = $1;
812 $$-> set_spot( THIS->here_input() );
818 Text_def *t = new Text_def;
822 t->style_str_ = THIS->textstyle_str_;
823 $$->set_spot( THIS->here_input() );
828 '^' { $$ = get_scriptdef('^'); }
829 | '+' { $$ = get_scriptdef('+'); }
830 | '-' { $$ = get_scriptdef('-'); }
831 | '|' { $$ = get_scriptdef('|'); }
832 | 'o' { $$ = get_scriptdef('o'); }
833 | '>' { $$ = get_scriptdef('>'); }
835 $$ = get_scriptdef('.');
840 SCRIPT_IDENTIFIER { $$ = $1->script(true); }
841 | script_definition { $$ = $1; }
842 | script_abbreviation {
843 $$ = THIS->lexer_p_->lookup_identifier(*$1)->script(true);
855 | pre_requests pre_request {
856 THIS->pre_reqs.push($2);
857 $2->set_spot( THIS->here_input());
862 open_request_parens {
863 $$ = THIS->get_parens_request($1);
869 THIS->default_duration_.set_plet($2,$4);
871 | DURATIONCOMMAND STRING {
872 THIS->set_duration_mode(*$2);
875 | DURATIONCOMMAND notemode_duration {
876 THIS->set_default_duration($2);
881 This is weird, but default_octave_i_
882 is used in steno_note_req too
884 c' -> default_octave_i_ == 1
886 /* why can't we have \oct{0} iso \oct{c'}*/
887 THIS->default_octave_i_ = 1; }
890 THIS->default_octave_i_ = $3->octave_i_;
894 THIS->textstyle_str_ = *$2;
901 $$ = new Moment(0,1);
903 | duration_length explicit_duration {
910 | dots '.' { $$ ++; }
915 $$ = new Duration(THIS->default_duration_);
918 $$ = new Duration(THIS->default_duration_);
921 | explicit_duration {
922 THIS->set_last_duration($1);
930 if ( !Duration::duration_type_b($1) )
931 THIS->parser_error("Not a duration");
934 $$->set_plet(THIS->default_duration_);
937 | explicit_duration '.' {
940 | explicit_duration '*' int {
941 $$->plet_.iso_i_ *= $3;
943 | explicit_duration '/' int {
944 $$->plet_.type_i_ *= $3;
950 steno_note_req notemode_duration {
951 if (!THIS->lexer_p_->note_state_b())
952 THIS->parser_error("have to be in Note mode for notes");
953 $1->set_duration (*$2);
954 $$ = THIS->get_note_element($1, $2);
956 | RESTNAME notemode_duration {
957 $$ = THIS->get_rest_element(*$1, $2);
963 text_def notemode_duration {
964 if (!THIS->lexer_p_->lyric_state_b())
965 THIS->parser_error("Have to be in Lyric mode for lyrics");
966 $$ = THIS->get_word_element($1, $2);
974 $$ = new Array<Melodic_req*>;
976 | pitch_list NOTENAME_ID {
977 $$->push($2->clone()->musical()->melodic());
1003 real unit { $$ = $1*$2; }
1007 unit: CM_T { $$ = 1 CM; }
1008 |IN_T { $$ = 1 INCH; }
1009 |MM_T { $$ = 1 MM; }
1010 |PT_T { $$ = 1 PT; }
1017 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
1025 $$ = $1->lookup(true);
1027 | symtables_body TEXID STRING {
1028 $$->texsetting = *$3;
1031 | symtables_body STRING '=' symtable {
1038 TABLE '{' symtable_body '}' { $$ = $3; }
1042 { $$ = new Symtable; }
1043 | symtable_body STRING symboldef {
1052 $$ = new Symbol(*$1, *$2);
1057 Box b(Interval(0,0), Interval(0,0));
1058 $$ = new Symbol(*$1, b);
1064 dinterval dinterval {
1065 $$ = new Box(*$1, *$2);
1071 dinterval: dim dim {
1072 $$ = new Interval($1, $2);
1079 My_lily_parser::set_yydebug(bool b )
1086 My_lily_parser::do_yyparse()
1088 yyparse((void*)this);
1092 My_lily_parser::default_paper()
1094 Identifier *id = lexer_p_->lookup_identifier( "default_paper" );
1095 return id ? id->paperdef(true) : new Paper_def ;
1099 My_lily_parser::default_midi()
1101 Identifier *id = lexer_p_->lookup_identifier( "default_midi" );
1102 return id ? id->mididef(true) : new Midi_def ;