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.2"
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"
38 #include "duration-convert.hh"
44 #define YYERROR_VERBOSE 1
46 #define YYPARSE_PARAM my_lily_parser_l
47 #define YYLEX_PARAM my_lily_parser_l
48 #define THIS ((My_lily_parser *) my_lily_parser_l)
50 #define yyerror THIS->parser_error
56 Array<Melodic_req*> *melreqvec;/* should clean up naming */
57 Array<String> * strvec;
63 Input_translator* itrans;
65 Music_list *musiclist;
72 Music_output_def * outputdef;
79 General_script_def * script;
83 Symtables * symtables;
94 yylex(YYSTYPE *s, void * v_l)
96 My_lily_parser *pars_l = (My_lily_parser*) v_l;
97 My_lily_lexer * lex_l = pars_l->lexer_p_;
99 lex_l->lexval_l = (void*) s;
100 return lex_l->yylex();
108 /* tokens which are not keywords */
124 %token REQUESTTRANSLATOR
133 %token MELODIC_REQUEST
161 %token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
165 %token <melreq> NOTENAME_ID
166 %token <id> DURATION_IDENTIFIER
167 %token <id> IDENTIFIER
168 %token <id> MELODIC_REQUEST_IDENTIFIER
169 %token <id> MUSIC_IDENTIFIER
170 %token <id> VOICE_IDENTIFIER
171 %token <id> POST_REQUEST_IDENTIFIER
172 %token <id> SCRIPT_IDENTIFIER
173 %token <id> COMMAND_IDENTIFIER
174 %token <id> REAL_IDENTIFIER
175 %token <id> INPUT_TRANS_IDENTIFIER
176 %token <id> INT_IDENTIFIER
177 %token <id> SCORE_IDENTIFIER
178 %token <id> MIDI_IDENTIFIER
179 %token <id> PAPER_IDENTIFIER
180 %token <id> REQUEST_IDENTIFIER
182 %token <string> DURATION RESTNAME
183 %token <string> STRING
184 %token <string> FIELDNAME RECORDLINE
185 %token <i> POST_QUOTES
186 %token <i> PRE_QUOTES
188 %type <outputdef> output_def
189 %type <header> mudela_header mudela_header_body
191 %type <c> open_request_parens close_request_parens
192 %type <c> open_abbrev_parens
193 %type <c> open_plet_parens close_plet_parens
194 %type <music> simple_element music_elt full_element lyrics_elt command_elt
195 %type <i> abbrev_type
198 %type <id> identifier_init
199 %type <duration> explicit_steno_duration notemode_duration
200 %type <duration> entered_notemode_duration explicit_duration
201 %type <interval> dinterval
202 %type <intvec> intastint_list
203 %type <lookup> symtables symtables_body
204 %type <melreq> melodic_request steno_melodic_req
205 %type <notereq> steno_note_req
206 %type <melreqvec> pitch_list
207 %type <midi> midi_block midi_body
208 %type <moment> duration_length
210 %type <music> Music transposed_music
211 %type <musiclist> Voice Voice_body
212 %type <chord> Chord Chord_body
213 %type <paper> paper_block paper_body
214 %type <real> dim real
216 %type <request> abbrev_command_req
217 %type <request> post_request pre_request command_req verbose_command_req
218 %type <request> script_req dynamic_req
219 %type <score> score_block score_body
220 %type <script> script_definition script_body mudela_script gen_script_def
221 %type <textdef> text_def
222 %type <string> script_abbreviation
223 %type <symbol> symboldef
224 %type <symtable> symtable symtable_body
225 %type <itrans> input_translator_spec input_translator_spec_body
226 %type <tempo> tempo_request
227 %type <string> header_record
234 | mudela mudela_header {
235 delete THIS->default_header_p_ ;
236 THIS->default_header_p_ = $2;
238 | mudela score_block {
241 | mudela add_declaration { }
243 | mudela check_version { }
244 | mudela add_notenames { }
249 if ( String( *$2 ) != MUDELA_VERSION) {
250 if (THIS->ignore_version_b_) {
251 THIS->here_input().error("Incorrect mudela version");
253 THIS->fatal_error_i_ = 1;
254 THIS->parser_error("Incorrect mudela version");
261 NOTENAMES '{' notenames_body '}'
266 | notenames_body CLEAR {
267 THIS->clear_notenames();
269 | notenames_body STRING '=' melodic_request {
270 THIS->add_notename(*$2, $4);
279 | mudela_header_body FIELDNAME header_record {
288 THIS->lexer_p_->push_header_state();
291 '{' mudela_header_body '}' {
293 THIS->lexer_p_->pop_state();
302 | header_record RECORDLINE {
314 THIS->remember_spot();
316 /* cont */ '=' identifier_init {
317 THIS->lexer_p_->set_identifier(*$1, $4);
318 $4->init_b_ = THIS->init_parse_b_;
319 $4->set_spot(THIS->pop_spot());
324 $$ = new Score_id($1, SCORE_IDENTIFIER);
328 $$ = new Paper_def_id($1, PAPER_IDENTIFIER);
332 $$ = new Midi_def_id($1, MIDI_IDENTIFIER);
335 | script_definition {
336 $$ = new Script_id($1, SCRIPT_IDENTIFIER);
340 $$ = new Music_id($1, MUSIC_IDENTIFIER);
344 $$ = new Lookup_id($1, IDENTIFIER);
348 $$ = new Real_id(new Real($1), REAL_IDENTIFIER);
352 $$ = new Int_id(new int($1), INT_IDENTIFIER);
356 $$ = new Request_id($1, POST_REQUEST_IDENTIFIER);
360 $$ = new Request_id($1, MELODIC_REQUEST_IDENTIFIER);
363 | input_translator_spec {
364 $$ = new Input_translator_id ( $1, INPUT_TRANS_IDENTIFIER);
366 | explicit_duration {
367 $$ = new Duration_id( $1, DURATION_IDENTIFIER);
373 input_translator_spec:
374 REQUESTTRANSLATOR '{' input_translator_spec_body '}'
378 input_translator_spec_body:
379 INPUT_TRANS_IDENTIFIER {
380 $$ = $1->input_translator();
381 $$-> set_spot( THIS->here_input() );
384 $$ = new Input_translator;
387 $$->set_spot ( THIS->here_input() );
391 | input_translator_spec_body ID STRING ';' {
392 $$-> default_id_str_ = *$3;
395 | input_translator_spec_body ALIAS STRING ';' {
396 $$-> alias_str_arr_.push(*$3);
399 | input_translator_spec_body CONSISTS STRING ';' {
400 $$-> consists_str_arr_.push(*$3);
403 | input_translator_spec_body CONTAINS input_translator_spec {
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(); // paper / video / engrave
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 input_translator_spec {
506 '{' midi_body '}' { $$ = $3; }
509 midi_body: /* empty */ {
510 $$ = THIS->default_midi();
512 | midi_body OUTPUT STRING ';' {
513 $$->outfile_str_ = *$3;
516 | midi_body tempo_request ';' {
517 $$->set_tempo( $2->dur_.length(), $2->metronome_i_ );
520 | midi_body input_translator_spec {
529 TEMPO entered_notemode_duration '=' int {
533 $$-> metronome_i_ = $4;
551 | Voice_body ID STRING STRING ';' {
564 full_element { $$ = $1; }
567 | transposed_music { $$ = $1; }
568 | MUSIC_IDENTIFIER { $$ = $1->music(); }
570 { THIS->lexer_p_->push_note_state(); }
572 { $$=$3; THIS->lexer_p_->pop_state(); }
575 { THIS->lexer_p_->push_lyric_state(); }
577 { $$ = $3; THIS->lexer_p_->pop_state(); }
581 '<' Chord_body '>' { $$ = $2; }
587 $$-> multi_level_i_ = 1;
589 | Chord_body MULTI INT ';' {
590 $$->multi_level_i_=$3;
592 | Chord_body ID STRING STRING ';' {
604 TRANSPOSE steno_melodic_req Music {
616 pre_requests simple_element post_requests {
617 THIS->add_requests((Chord*)$2);//ugh
621 | voice_command ';' { $$ = 0; }
631 $$ = new Request_chord;
632 $$-> set_spot( THIS->here_input());
633 $1-> set_spot( THIS->here_input());
634 ((Chord*)$$) ->add($1);//ugh
641 | verbose_command_req ';' { $$ = $1; }
646 $$ = new Barcheck_req;
648 | COMMAND_IDENTIFIER {
655 $$ = new Bar_req(*$2);
658 | METER int '/' int {
659 Meter_change_req *m = new Meter_change_req;
661 // sorry hw, i need meter at output of track,
662 // but don-t know where to get it... statics should go.
663 // HW : default: 4/4, meterchange reqs may change it.
665 Midi_def::num_i_s = $2;
666 Midi_def::den_i_s = $4;
669 | SKIP duration_length {
670 Skip_req * skip_p = new Skip_req;
671 skip_p->duration_.set_plet($2->numerator().as_long(),
672 $2->denominator().as_long());
681 $$ = new Cadenza_req($2);
683 | PARTIAL duration_length {
684 $$ = new Partial_measure_req(*$2);
688 $$ = get_stemdir_req($2);
691 $$ = get_hshift_req($2);
694 $$ = new Clef_change_req(*$2);
698 Key_change_req *key_p= new Key_change_req;
699 key_p->melodic_p_arr_ = *$2;
703 | GROUPING intastint_list {
704 $$ = get_grouping_req(*$2); delete $2;
710 assert(THIS->post_reqs.empty());
712 | post_requests post_request {
713 $2->set_spot( THIS->here_input());
714 THIS->post_reqs.push($2);
720 POST_REQUEST_IDENTIFIER {
721 $$ = (Request*)$1->request();
723 |close_request_parens {
724 $$ = THIS->get_parens_request($1);
737 $$ = $1->clone()->musical()->melodic();
738 $$->octave_i_ += THIS->default_octave_i_;
740 | steno_melodic_req POST_QUOTES {
741 $$-> octave_i_ += $2;
743 | PRE_QUOTES steno_melodic_req {
745 $2-> octave_i_ -= $1;
752 * (Melodic_req *) $$ = *$1;
755 | steno_note_req '!' {
756 $$->forceacc_b_ = ! $$->forceacc_b_;
758 /* have to duration here. */
762 MELODIC_REQUEST '{' int int int '}' {/* ugh */
763 $$ = new Melodic_req;
765 $$->notename_i_ = $4;
766 $$->accidental_i_ = $5;
771 DURATION '{' int int '}' {
779 ABSDYNAMIC '{' int '}' {
780 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
781 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
784 | SPANDYNAMIC '{' int int '}' {
785 Span_dynamic_req * sp_p = new Span_dynamic_req;
787 sp_p-> dynamic_dir_ = $3;
795 THIS->plet_.type_i_ = $4;
796 THIS->plet_.iso_i_ = $2;
800 close_request_parens:
810 | close_plet_parens {
824 if (!Duration::duration_type_b ($3))
825 THIS->parser_error ("Not a duration");
827 THIS->parser_error ("Can't abbreviate");
829 THIS->set_abbrev_beam ($3);
836 THIS->plet_.type_i_ = $4;
837 THIS->plet_.iso_i_ = $2;
851 | open_abbrev_parens {
860 SCRIPT '{' script_body '}' { $$ = $3; }
864 STRING int int int int int {
865 Script_def *s = new Script_def;
866 s->set_from_input(*$1,$2, $3,$4,$5, $6);
873 script_dir gen_script_def {
874 Musical_script_req *m = new Musical_script_req;
876 m-> scriptdef_p_ = $2;
877 m-> set_spot ( THIS->here_input() );
883 text_def { $$ = $1; }
884 | mudela_script { $$ = $1;
885 $$-> set_spot( THIS->here_input() );
891 Text_def *t = new Text_def;
895 t->style_str_ = THIS->textstyle_str_;
896 $$->set_spot( THIS->here_input() );
901 '^' { $$ = get_scriptdef('^'); }
902 | '+' { $$ = get_scriptdef('+'); }
903 | '-' { $$ = get_scriptdef('-'); }
904 | '|' { $$ = get_scriptdef('|'); }
905 | 'o' { $$ = get_scriptdef('o'); }
906 | '>' { $$ = get_scriptdef('>'); }
908 $$ = get_scriptdef('.');
913 SCRIPT_IDENTIFIER { $$ = $1->script(); }
914 | script_definition { $$ = $1; }
915 | script_abbreviation {
916 $$ = THIS->lexer_p_->lookup_identifier(*$1)->script();
928 | pre_requests pre_request {
929 THIS->pre_reqs.push($2);
930 $2->set_spot( THIS->here_input());
935 open_request_parens {
936 $$ = THIS->get_parens_request($1);
942 THIS->default_duration_.set_plet($2,$4);
945 THIS->set_duration_mode(*$2);
948 | DURATION entered_notemode_duration {
949 THIS->set_default_duration($2);
954 This is weird, but default_octave_i_
955 is used in steno_note_req too
957 c' -> default_octave_i_ == 1
959 /* why can't we have \oct{0} iso \oct{c'}*/
960 THIS->default_octave_i_ = 1; }
963 THIS->default_octave_i_ = $3->octave_i_;
967 THIS->textstyle_str_ = *$2;
974 $$ = new Moment(0,1);
976 | duration_length explicit_steno_duration {
983 | dots '.' { $$ ++; }
986 entered_notemode_duration:
988 $$ = new Duration(THIS->default_duration_);
991 $$ = new Duration(THIS->default_duration_);
994 | explicit_steno_duration {
995 THIS->set_last_duration($1);
1001 entered_notemode_duration {
1003 $$->plet_.type_i_ *= THIS->plet_.type_i_;
1004 $$->plet_.iso_i_ *= THIS->plet_.iso_i_;
1008 explicit_steno_duration:
1011 if ( !Duration::duration_type_b($1) )
1012 THIS->parser_error("Not a duration");
1014 $$->durlog_i_ = Duration_convert::i2_type($1);
1017 | DURATION_IDENTIFIER {
1018 $$ = $1->duration();
1020 | explicit_steno_duration '.' {
1023 | explicit_steno_duration '*' int {
1024 $$->plet_.iso_i_ *= $3;
1026 | explicit_steno_duration '/' int {
1027 $$->plet_.type_i_ *= $3;
1035 $$ = THIS->default_abbrev_type_i_;
1038 if (!Duration::duration_type_b ($2))
1039 THIS->parser_error ("Not a duration");
1041 THIS->parser_error ("Can't abbreviate");
1043 THIS->set_last_abbrev ($2);
1044 $$ = THIS->default_abbrev_type_i_;
1049 steno_note_req notemode_duration abbrev_type {
1050 if (!THIS->lexer_p_->note_state_b ())
1051 THIS->parser_error ("have to be in Note mode for notes");
1052 $1->set_duration (*$2);
1053 int durlog_i = $2->durlog_i_;
1054 Chord* c = THIS->get_note_element ($1, $2);
1057 Abbreviation_req* a = new Abbreviation_req;
1062 | RESTNAME notemode_duration {
1063 $$ = THIS->get_rest_element(*$1, $2);
1069 text_def notemode_duration {
1070 /* this sux! text-def should be feature of lyric-engraver. */
1071 if (!THIS->lexer_p_->lyric_state_b())
1072 THIS->parser_error("Have to be in Lyric mode for lyrics");
1073 $$ = THIS->get_word_element($1, $2);
1081 $$ = new Array<Melodic_req*>;
1083 | pitch_list NOTENAME_ID {
1084 $$->push($2->clone()->musical()->melodic());
1093 int *i_p = $1->intid();
1105 Real *r_p = $1->real();
1114 real unit { $$ = $1*$2; }
1118 unit: CM_T { $$ = 1 CM; }
1119 |IN_T { $$ = 1 INCH; }
1120 |MM_T { $$ = 1 MM; }
1121 |PT_T { $$ = 1 PT; }
1128 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
1138 | symtables_body TEXID STRING {
1139 $$->texsetting = *$3;
1142 | symtables_body STRING '=' symtable {
1149 TABLE '{' symtable_body '}' { $$ = $3; }
1153 { $$ = new Symtable; }
1154 | symtable_body STRING symboldef {
1163 $$ = new Symbol(*$1, *$2);
1168 Box b(Interval(0,0), Interval(0,0));
1169 $$ = new Symbol(*$1, b);
1175 dinterval dinterval {
1176 $$ = new Box(*$1, *$2);
1182 dinterval: dim dim {
1183 $$ = new Interval($1, $2);
1190 My_lily_parser::set_yydebug(bool b )
1197 My_lily_parser::do_yyparse()
1199 yyparse((void*)this);
1203 My_lily_parser::default_paper()
1205 Identifier *id = lexer_p_->lookup_identifier( "default_paper" );
1206 return id ? id->paperdef() : new Paper_def ;
1210 My_lily_parser::default_midi()
1212 Identifier *id = lexer_p_->lookup_identifier( "default_midi" );
1213 return id ? id->mididef() : new Midi_def ;