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.0.61"
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> INT_IDENTIFIER
174 %token <id> SCORE_IDENTIFIER
175 %token <id> MIDI_IDENTIFIER
176 %token <id> PAPER_IDENTIFIER
177 %token <id> REQUEST_IDENTIFIER
179 %token <string> DURATION RESTNAME
180 %token <string> STRING
181 %token <i> POST_QUOTES
182 %token <i> PRE_QUOTES
186 %type <c> open_request_parens close_request_parens
187 %type <c> open_plet_parens close_plet_parens
188 %type <music> simple_element music_elt full_element lyrics_elt command_elt
191 %type <id> declaration
192 %type <duration> explicit_duration notemode_duration
193 %type <interval> dinterval
194 %type <intvec> intastint_list
195 %type <lookup> symtables symtables_body
196 %type <melreq> melodic_request steno_melodic_req
197 %type <notereq> steno_note_req
198 %type <melreqvec> pitch_list
199 %type <midi> midi_block midi_body
200 %type <moment> duration_length
202 %type <music> Music transposed_music
203 %type <musiclist> Voice Voice_body
204 %type <chord> Chord Chord_body
205 %type <paper> paper_block paper_body
206 %type <real> dim real
208 %type <request> post_request pre_request command_req verbose_command_req abbrev_command_req
209 %type <request> script_req dynamic_req
210 %type <score> score_block score_body
211 %type <script> script_definition script_body mudela_script gen_script_def
212 %type <textdef> text_def
213 %type <string> declarable_identifier
214 %type <string> script_abbreviation
215 %type <id> old_identifier
216 %type <symbol> symboldef
217 %type <symtable> symtable symtable_body
218 %type <itrans> input_translator_spec input_translator_spec_body
225 | mudela score_block {
228 | mudela add_declaration { }
230 | mudela check_version { }
231 | mudela add_notenames { }
236 if (*$2 != MUDELA_VERSION) {
237 if (THIS->ignore_version_b_) {
238 THIS->here_input().error("Incorrect mudela version");
240 THIS->fatal_error_i_ = 1;
241 THIS->parser_error("Incorrect mudela version");
248 NOTENAMES '{' notenames_body '}'
253 | notenames_body CLEAR {
254 THIS->clear_notenames();
256 | notenames_body STRING '=' melodic_request {
257 THIS->add_notename(*$2, $4);
264 add_declaration: declaration {
265 THIS->lexer_p_->add_identifier($1);
266 $1->init_b_ = THIS->init_parse_b_;
267 $1->set_spot(THIS->pop_spot());
271 declarable_identifier:
273 THIS->remember_spot();
277 THIS->remember_spot();
278 $$ = new String($1->name_str_);
279 THIS->here_input().warning("redeclaration of `" + *$$ + "'");
286 | MELODIC_REQUEST_IDENTIFIER
287 | POST_REQUEST_IDENTIFIER
295 declarable_identifier '=' score_block {
296 $$ = new Score_id(*$1, $3, SCORE_IDENTIFIER);
299 | declarable_identifier '=' paper_block {
300 $$ = new Paper_def_id(*$1, $3, PAPER_IDENTIFIER);
303 | declarable_identifier '=' midi_block {
304 $$ = new Midi_def_id(*$1, $3, MIDI_IDENTIFIER);
307 | declarable_identifier '=' script_definition {
308 $$ = new Script_id(*$1, $3, SCRIPT_IDENTIFIER);
311 | declarable_identifier '=' Music {
312 $$ = new Music_id(*$1, $3, MUSIC_IDENTIFIER);
315 | declarable_identifier '=' symtables {
316 $$ = new Lookup_id(*$1, $3, IDENTIFIER);
319 | declarable_identifier '=' real {
320 $$ = new Real_id(*$1, new Real($3), REAL_IDENTIFIER);
323 | declarable_identifier '=' int {
324 $$ = new Int_id(*$1, new int($3), INT_IDENTIFIER);
327 | declarable_identifier '=' post_request {
328 $$ = new Request_id(*$1, $3, POST_REQUEST_IDENTIFIER);
331 | declarable_identifier '=' melodic_request {
332 $$ = new Request_id(*$1, $3, MELODIC_REQUEST_IDENTIFIER);
339 input_translator_spec:
340 REQUESTTRANSLATOR '{' input_translator_spec_body '}'
344 input_translator_spec_body:
346 $$ = new Input_translator;
349 $$->set_spot ( THIS->here_input() );
353 | input_translator_spec_body ID STRING ';' {
354 $$-> default_id_str_ = *$3;
357 | input_translator_spec_body ALIAS STRING ';' {
358 $$-> alias_str_arr_.push(*$3);
361 | input_translator_spec_body CONSISTS STRING ';' {
362 $$-> consists_str_arr_.push(*$3);
365 | input_translator_spec_body CONTAINS input_translator_spec {
374 SCORE { THIS->remember_spot(); }
375 /*cont*/ '{' score_body '}' {
377 $$->set_spot(THIS->pop_spot());
378 if (!$$->paper_p_ && ! $$->midi_p_)
379 $$->paper_p_ = THIS->default_paper();
381 /* handle error levels. */
382 $$->errorlevel_i_ = THIS->error_level_i_;
383 THIS->error_level_i_ = 0;
391 $$ = $1->score(true);
396 | score_body paper_block {
399 | score_body midi_block {
408 /* */ { $$ =new Array<int>; }
409 | intastint_list int '*' int {
410 $$->push($2); $$->push($4);
420 '{' paper_body '}' { $$ = $3; }
425 $$ = THIS->default_paper(); // paper / video / engrave
427 | paper_body OUTPUT STRING ';' { $$->outfile_str_ = *$3;
430 | paper_body symtables { $$->set($2); }
431 | paper_body STRING '=' dim ';' {
432 $$->set_var(*$2, $4);
434 | paper_body STRING '=' REAL ';' {
435 $$->set_var(*$2, $4);
437 | paper_body input_translator_spec {
451 '{' midi_body '}' { $$ = $3; }
454 midi_body: /* empty */ {
455 $$ = THIS->default_midi(); // midi / audio / perform
457 | midi_body OUTPUT STRING ';' {
458 $$->outfile_str_ = *$3;
461 | midi_body TEMPO notemode_duration ':' int ';' {
462 $$->set_tempo( $3->length(), $5 );
464 | midi_body input_translator_spec {
486 | Voice_body ID STRING STRING ';' {
499 full_element { $$ = $1; }
502 | transposed_music { $$ = $1; }
503 | MUSIC_IDENTIFIER { $$ = $1->music(true); }
505 { THIS->lexer_p_->push_note_state(); }
507 { $$=$3; THIS->lexer_p_->pop_state(); }
510 { THIS->lexer_p_->push_lyric_state(); }
512 { $$ = $3; THIS->lexer_p_->pop_state(); }
516 '<' Chord_body '>' { $$ = $2; }
522 $$-> multi_level_i_ = 1;
524 | Chord_body MULTI INT ';' {
525 $$->multi_level_i_=$3;
527 | Chord_body ID STRING STRING ';' {
539 TRANSPOSE steno_melodic_req Music {
551 pre_requests simple_element post_requests {
552 THIS->add_requests((Chord*)$2);//ugh
555 | voice_command ';' { $$ = 0; }
566 $$ = new Voice_element;
567 $$-> set_spot( THIS->here_input());
571 $2-> set_spot( THIS->here_input());
572 ((Chord*)$$) ->add($2);//ugh
575 | GROUP STRING ';' { // ugh ugh ugh
576 Change_reg *chr_p = new Change_reg;
578 chr_p-> type_str_ = "Voice_group_engravers"; //ugh
579 chr_p-> id_str_ = *$2;
586 | verbose_command_req ';' { $$ = $1; }
591 $$ = new Barcheck_req;
597 $$ = new Bar_req(*$2);
600 | METER int '/' int {
601 Meter_change_req *m = new Meter_change_req;
603 // sorry hw, i need meter at output of track,
604 // but don-t know where to get it... statics should go.
605 // HW : default: 4/4, meterchange reqs may change it.
607 Midi_def::num_i_s = $2;
608 Midi_def::den_i_s = $4;
611 | SKIP duration_length {
612 Skip_req * skip_p = new Skip_req;
613 skip_p->duration_ = Duration(1,0);
614 skip_p->duration_.set_plet($2->numerator().as_long(),
615 $2->denominator().as_long());
621 $$ = new Cadenza_req($2);
623 | PARTIAL duration_length {
624 $$ = new Partial_measure_req(*$2);
628 $$ = get_stemdir_req($2);
631 $$ = get_hshift_req($2);
634 $$ = new Clef_change_req(*$2);
638 Key_change_req *key_p= new Key_change_req;
639 key_p->melodic_p_arr_ = *$2;
643 | GROUPING intastint_list {
644 $$ = get_grouping_req(*$2); delete $2;
651 assert(THIS->post_reqs.empty());
653 | post_requests post_request {
654 $2->set_spot( THIS->here_input());
655 THIS->post_reqs.push($2);
661 POST_REQUEST_IDENTIFIER {
662 $$ = (Request*)$1->request(true);
664 |close_request_parens {
665 $$ = THIS->get_parens_request($1);
678 $$ = $1->clone()->musical()->melodic();
679 $$->octave_i_ += THIS->default_octave_i_;
681 | steno_melodic_req POST_QUOTES {
682 $$-> octave_i_ += $2;
684 | PRE_QUOTES steno_melodic_req {
686 $2-> octave_i_ -= $1;
693 * (Melodic_req *) $$ = *$1;
696 | steno_note_req '!' {
697 $$->forceacc_b_ = ! $$->forceacc_b_;
699 /* have to duration here. */
703 MELODIC_REQUEST '{' int int int '}' {/* ugh */
704 $$ = new Melodic_req;
706 $$->notename_i_ = $4;
707 $$->accidental_i_ = $5;
712 ABSDYNAMIC '{' int '}' {
713 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
714 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
717 | SPANDYNAMIC '{' int int '}' {
718 Span_dynamic_req * sp_p = new Span_dynamic_req;
720 sp_p-> dynamic_dir_i_ = $3;
728 THIS->default_duration_.set_plet($2,$4);
732 close_request_parens:
742 | close_plet_parens {
756 THIS->default_duration_.set_plet($2,$4);
777 SCRIPT '{' script_body '}' { $$ = $3; }
781 STRING int int int int int {
782 Script_def *s = new Script_def;
783 s->set_from_input(*$1,$2, $3,$4,$5, $6);
790 script_dir gen_script_def {
791 Musical_script_req *m = new Musical_script_req;
793 m-> scriptdef_p_ = $2;
794 m-> set_spot ( THIS->here_input() );
800 text_def { $$ = $1; }
801 | mudela_script { $$ = $1;
802 $$-> set_spot( THIS->here_input() );
808 Text_def *t = new Text_def;
812 t->style_str_ = THIS->textstyle_str_;
813 $$->set_spot( THIS->here_input() );
818 '^' { $$ = get_scriptdef('^'); }
819 | '+' { $$ = get_scriptdef('+'); }
820 | '-' { $$ = get_scriptdef('-'); }
821 | '|' { $$ = get_scriptdef('|'); }
822 | 'o' { $$ = get_scriptdef('o'); }
823 | '>' { $$ = get_scriptdef('>'); }
825 $$ = get_scriptdef('.');
830 SCRIPT_IDENTIFIER { $$ = $1->script(true); }
831 | script_definition { $$ = $1; }
832 | script_abbreviation {
833 $$ = THIS->lexer_p_->lookup_identifier(*$1)->script(true);
845 | pre_requests pre_request {
846 THIS->pre_reqs.push($2);
847 $2->set_spot( THIS->here_input());
852 open_request_parens {
853 $$ = THIS->get_parens_request($1);
859 THIS->default_duration_.set_plet($2,$4);
861 | DURATIONCOMMAND STRING {
862 THIS->set_duration_mode(*$2);
865 | DURATIONCOMMAND notemode_duration {
866 THIS->set_default_duration($2);
871 This is weird, but default_octave_i_
872 is used in steno_note_req too
874 c' -> default_octave_i_ == 1
876 /* why can't we have \oct{0} iso \oct{c'}*/
877 THIS->default_octave_i_ = 1; }
880 THIS->default_octave_i_ = $3->octave_i_;
884 THIS->textstyle_str_ = *$2;
891 $$ = new Moment(0,1);
893 | duration_length explicit_duration {
900 | dots '.' { $$ ++; }
905 $$ = new Duration(THIS->default_duration_);
908 $$ = new Duration(THIS->default_duration_);
911 | explicit_duration {
912 THIS->set_last_duration($1);
920 if ( !Duration::duration_type_b($1) )
921 THIS->parser_error("Not a duration");
924 $$->set_plet(THIS->default_duration_);
927 | explicit_duration '.' {
930 | explicit_duration '*' int {
931 $$->plet_.iso_i_ *= $3;
933 | explicit_duration '/' int {
934 $$->plet_.type_i_ *= $3;
940 steno_note_req notemode_duration {
941 if (!THIS->lexer_p_->note_state_b())
942 THIS->parser_error("have to be in Note mode for notes");
943 $1->set_duration (*$2);
944 $$ = THIS->get_note_element($1, $2);
946 | RESTNAME notemode_duration {
947 $$ = THIS->get_rest_element(*$1, $2);
953 text_def notemode_duration {
954 if (!THIS->lexer_p_->lyric_state_b())
955 THIS->parser_error("Have to be in Lyric mode for lyrics");
956 $$ = THIS->get_word_element($1, $2);
964 $$ = new Array<Melodic_req*>;
966 | pitch_list NOTENAME_ID {
967 $$->push($2->clone()->musical()->melodic());
993 real unit { $$ = $1*$2; }
997 unit: CM_T { $$ = 1 CM; }
998 |IN_T { $$ = 1 INCH; }
1000 |PT_T { $$ = 1 PT; }
1007 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
1015 $$ = $1->lookup(true);
1017 | symtables_body TEXID STRING {
1018 $$->texsetting = *$3;
1021 | symtables_body STRING '=' symtable {
1028 TABLE '{' symtable_body '}' { $$ = $3; }
1032 { $$ = new Symtable; }
1033 | symtable_body STRING symboldef {
1042 $$ = new Symbol(*$1, *$2);
1047 Box b(Interval(0,0), Interval(0,0));
1048 $$ = new Symbol(*$1, b);
1054 dinterval dinterval {
1055 $$ = new Box(*$1, *$2);
1061 dinterval: dim dim {
1062 $$ = new Interval($1, $2);
1069 My_lily_parser::set_yydebug(bool b )
1076 My_lily_parser::do_yyparse()
1078 yyparse((void*)this);
1082 My_lily_parser::default_paper()
1084 Identifier *id = lexer_p_->lookup_identifier( "default_paper" );
1085 return id ? id->paperdef(true) : new Paper_def ;
1089 My_lily_parser::default_midi()
1091 Identifier *id = lexer_p_->lookup_identifier( "default_midi" );
1092 return id ? id->mididef(true) : new Midi_def ;