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.1"
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;
77 General_script_def * script;
81 Symtables * symtables;
92 yylex(YYSTYPE *s, void * v_l)
94 My_lily_parser *pars_l = (My_lily_parser*) v_l;
95 My_lily_lexer * lex_l = pars_l->lexer_p_;
97 lex_l->lexval_l = (void*) s;
98 return lex_l->yylex();
106 /* tokens which are not keywords */
122 %token REQUESTTRANSLATOR
131 %token MELODIC_REQUEST
159 %token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
163 %token <melreq> NOTENAME_ID
164 %token <id> DURATION_IDENTIFIER
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> COMMAND_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 <string> FIELDNAME RECORDLINE
183 %token <i> POST_QUOTES
184 %token <i> PRE_QUOTES
187 %type <header> mudela_header mudela_header_body
189 %type <c> open_request_parens close_request_parens
190 %type <c> open_plet_parens close_plet_parens
191 %type <music> simple_element music_elt full_element lyrics_elt command_elt
194 %type <id> identifier_init
195 %type <duration> explicit_steno_duration notemode_duration
196 %type <duration> entered_notemode_duration explicit_duration
197 %type <interval> dinterval
198 %type <intvec> intastint_list
199 %type <lookup> symtables symtables_body
200 %type <melreq> melodic_request steno_melodic_req
201 %type <notereq> steno_note_req
202 %type <melreqvec> pitch_list
203 %type <midi> midi_block midi_body
204 %type <moment> duration_length
206 %type <music> Music transposed_music
207 %type <musiclist> Voice Voice_body
208 %type <chord> Chord Chord_body
209 %type <paper> paper_block paper_body
210 %type <real> dim real
212 %type <request> post_request pre_request command_req verbose_command_req
213 %type <request> abbrev_command_req
214 %type <request> script_req dynamic_req
215 %type <score> score_block score_body
216 %type <script> script_definition script_body mudela_script gen_script_def
217 %type <textdef> text_def
218 %type <string> script_abbreviation
219 %type <symbol> symboldef
220 %type <symtable> symtable symtable_body
221 %type <itrans> input_translator_spec input_translator_spec_body
222 %type <tempo> tempo_request
223 %type <string> header_record
230 | mudela mudela_header {
231 delete THIS->default_header_p_ ;
232 THIS->default_header_p_ = $2;
234 | mudela score_block {
237 | mudela add_declaration { }
239 | mudela check_version { }
240 | mudela add_notenames { }
245 if ( String( *$2 ) != MUDELA_VERSION) {
246 if (THIS->ignore_version_b_) {
247 THIS->here_input().error("Incorrect mudela version");
249 THIS->fatal_error_i_ = 1;
250 THIS->parser_error("Incorrect mudela version");
257 NOTENAMES '{' notenames_body '}'
262 | notenames_body CLEAR {
263 THIS->clear_notenames();
265 | notenames_body STRING '=' melodic_request {
266 THIS->add_notename(*$2, $4);
275 | mudela_header_body FIELDNAME header_record {
284 THIS->lexer_p_->push_header_state();
287 '{' mudela_header_body '}' {
289 THIS->lexer_p_->pop_state();
298 | header_record RECORDLINE {
310 THIS->remember_spot();
312 /* cont */ '=' identifier_init {
313 THIS->lexer_p_->set_identifier(*$1, $4);
314 $4->init_b_ = THIS->init_parse_b_;
315 $4->set_spot(THIS->pop_spot());
320 $$ = new Score_id($1, SCORE_IDENTIFIER);
324 $$ = new Paper_def_id($1, PAPER_IDENTIFIER);
328 $$ = new Midi_def_id($1, MIDI_IDENTIFIER);
331 | script_definition {
332 $$ = new Script_id($1, SCRIPT_IDENTIFIER);
336 $$ = new Music_id($1, MUSIC_IDENTIFIER);
340 $$ = new Lookup_id($1, IDENTIFIER);
344 $$ = new Real_id(new Real($1), REAL_IDENTIFIER);
348 $$ = new Int_id(new int($1), INT_IDENTIFIER);
352 $$ = new Request_id($1, POST_REQUEST_IDENTIFIER);
356 $$ = new Request_id($1, MELODIC_REQUEST_IDENTIFIER);
359 | input_translator_spec {
360 $$ = new Input_translator_id ( $1, INPUT_TRANS_IDENTIFIER);
362 | explicit_duration {
363 $$ = new Duration_id( $1, DURATION_IDENTIFIER);
369 input_translator_spec:
370 REQUESTTRANSLATOR '{' input_translator_spec_body '}'
374 input_translator_spec_body:
375 INPUT_TRANS_IDENTIFIER {
376 $$ = $1->input_translator();
377 $$-> set_spot( THIS->here_input() );
380 $$ = new Input_translator;
383 $$->set_spot ( THIS->here_input() );
387 | input_translator_spec_body ID STRING ';' {
388 $$-> default_id_str_ = *$3;
391 | input_translator_spec_body ALIAS STRING ';' {
392 $$-> alias_str_arr_.push(*$3);
395 | input_translator_spec_body CONSISTS STRING ';' {
396 $$-> consists_str_arr_.push(*$3);
399 | input_translator_spec_body CONTAINS input_translator_spec {
408 SCORE { THIS->remember_spot();
409 THIS->error_level_i_ =0;
411 /*cont*/ '{' score_body '}' {
413 $$->set_spot(THIS->pop_spot());
414 if (!$$->paper_p_ && ! $$->midi_p_)
415 $$->paper_p_ = THIS->default_paper();
417 /* handle error levels. */
418 $$->errorlevel_i_ = THIS->error_level_i_;
419 THIS->error_level_i_ = 0;
420 if (!$$->header_p_ && THIS->default_header_p_)
421 $$->header_p_ = new Header(*THIS->default_header_p_);
431 | score_body mudela_header {
437 | score_body paper_block {
440 | score_body midi_block {
449 /* */ { $$ =new Array<int>; }
450 | intastint_list int '*' int {
451 $$->push($2); $$->push($4);
461 '{' paper_body '}' { $$ = $3; }
466 $$ = THIS->default_paper(); // paper / video / engrave
471 | paper_body OUTPUT STRING ';' { $$->outfile_str_ = *$3;
474 | paper_body symtables { $$->set($2); }
475 | paper_body STRING '=' dim ';' {
476 $$->set_var(*$2, $4);
478 | paper_body STRING '=' real ';' {
479 $$->set_var(*$2, $4);
481 | paper_body input_translator_spec {
495 '{' midi_body '}' { $$ = $3; }
498 midi_body: /* empty */ {
499 $$ = THIS->default_midi();
501 | midi_body OUTPUT STRING ';' {
502 $$->outfile_str_ = *$3;
505 | midi_body tempo_request ';' {
506 $$->set_tempo( $2->dur_.length(), $2->metronome_i_ );
509 | midi_body input_translator_spec {
518 TEMPO entered_notemode_duration '=' int {
522 $$-> metronome_i_ = $4;
540 | Voice_body ID STRING STRING ';' {
553 full_element { $$ = $1; }
556 | transposed_music { $$ = $1; }
557 | MUSIC_IDENTIFIER { $$ = $1->music(); }
559 { THIS->lexer_p_->push_note_state(); }
561 { $$=$3; THIS->lexer_p_->pop_state(); }
564 { THIS->lexer_p_->push_lyric_state(); }
566 { $$ = $3; THIS->lexer_p_->pop_state(); }
570 '<' Chord_body '>' { $$ = $2; }
576 $$-> multi_level_i_ = 1;
578 | Chord_body MULTI INT ';' {
579 $$->multi_level_i_=$3;
581 | Chord_body ID STRING STRING ';' {
593 TRANSPOSE steno_melodic_req Music {
605 pre_requests simple_element post_requests {
606 THIS->add_requests((Chord*)$2);//ugh
610 | voice_command ';' { $$ = 0; }
620 $$ = new Request_chord;
621 $$-> set_spot( THIS->here_input());
622 $1-> set_spot( THIS->here_input());
623 ((Chord*)$$) ->add($1);//ugh
630 | verbose_command_req ';' { $$ = $1; }
635 $$ = new Barcheck_req;
637 | COMMAND_IDENTIFIER {
644 $$ = new Bar_req(*$2);
647 | METER int '/' int {
648 Meter_change_req *m = new Meter_change_req;
650 // sorry hw, i need meter at output of track,
651 // but don-t know where to get it... statics should go.
652 // HW : default: 4/4, meterchange reqs may change it.
654 Midi_def::num_i_s = $2;
655 Midi_def::den_i_s = $4;
658 | SKIP duration_length {
659 Skip_req * skip_p = new Skip_req;
660 skip_p->duration_.set_plet($2->numerator().as_long(),
661 $2->denominator().as_long());
670 $$ = new Cadenza_req($2);
672 | PARTIAL duration_length {
673 $$ = new Partial_measure_req(*$2);
677 $$ = get_stemdir_req($2);
680 $$ = get_hshift_req($2);
683 $$ = new Clef_change_req(*$2);
687 Key_change_req *key_p= new Key_change_req;
688 key_p->melodic_p_arr_ = *$2;
692 | GROUPING intastint_list {
693 $$ = get_grouping_req(*$2); delete $2;
699 assert(THIS->post_reqs.empty());
701 | post_requests post_request {
702 $2->set_spot( THIS->here_input());
703 THIS->post_reqs.push($2);
709 POST_REQUEST_IDENTIFIER {
710 $$ = (Request*)$1->request();
712 |close_request_parens {
713 $$ = THIS->get_parens_request($1);
726 $$ = $1->clone()->musical()->melodic();
727 $$->octave_i_ += THIS->default_octave_i_;
729 | steno_melodic_req POST_QUOTES {
730 $$-> octave_i_ += $2;
732 | PRE_QUOTES steno_melodic_req {
734 $2-> octave_i_ -= $1;
741 * (Melodic_req *) $$ = *$1;
744 | steno_note_req '!' {
745 $$->forceacc_b_ = ! $$->forceacc_b_;
747 /* have to duration here. */
751 MELODIC_REQUEST '{' int int int '}' {/* ugh */
752 $$ = new Melodic_req;
754 $$->notename_i_ = $4;
755 $$->accidental_i_ = $5;
760 DURATION '{' int int '}' {
768 ABSDYNAMIC '{' int '}' {
769 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
770 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
773 | SPANDYNAMIC '{' int int '}' {
774 Span_dynamic_req * sp_p = new Span_dynamic_req;
776 sp_p-> dynamic_dir_i_ = $3;
784 THIS->plet_.type_i_ = $4;
785 THIS->plet_.iso_i_ = $2;
789 close_request_parens:
799 | close_plet_parens {
813 THIS->plet_.type_i_ = $4;
814 THIS->plet_.iso_i_ = $2;
835 SCRIPT '{' script_body '}' { $$ = $3; }
839 STRING int int int int int {
840 Script_def *s = new Script_def;
841 s->set_from_input(*$1,$2, $3,$4,$5, $6);
848 script_dir gen_script_def {
849 Musical_script_req *m = new Musical_script_req;
851 m-> scriptdef_p_ = $2;
852 m-> set_spot ( THIS->here_input() );
858 text_def { $$ = $1; }
859 | mudela_script { $$ = $1;
860 $$-> set_spot( THIS->here_input() );
866 Text_def *t = new Text_def;
870 t->style_str_ = THIS->textstyle_str_;
871 $$->set_spot( THIS->here_input() );
876 '^' { $$ = get_scriptdef('^'); }
877 | '+' { $$ = get_scriptdef('+'); }
878 | '-' { $$ = get_scriptdef('-'); }
879 | '|' { $$ = get_scriptdef('|'); }
880 | 'o' { $$ = get_scriptdef('o'); }
881 | '>' { $$ = get_scriptdef('>'); }
883 $$ = get_scriptdef('.');
888 SCRIPT_IDENTIFIER { $$ = $1->script(); }
889 | script_definition { $$ = $1; }
890 | script_abbreviation {
891 $$ = THIS->lexer_p_->lookup_identifier(*$1)->script();
903 | pre_requests pre_request {
904 THIS->pre_reqs.push($2);
905 $2->set_spot( THIS->here_input());
910 open_request_parens {
911 $$ = THIS->get_parens_request($1);
917 THIS->default_duration_.set_plet($2,$4);
920 THIS->set_duration_mode(*$2);
923 | DURATION entered_notemode_duration {
924 THIS->set_default_duration($2);
929 This is weird, but default_octave_i_
930 is used in steno_note_req too
932 c' -> default_octave_i_ == 1
934 /* why can't we have \oct{0} iso \oct{c'}*/
935 THIS->default_octave_i_ = 1; }
938 THIS->default_octave_i_ = $3->octave_i_;
942 THIS->textstyle_str_ = *$2;
949 $$ = new Moment(0,1);
951 | duration_length explicit_steno_duration {
958 | dots '.' { $$ ++; }
961 entered_notemode_duration:
963 $$ = new Duration(THIS->default_duration_);
966 $$ = new Duration(THIS->default_duration_);
969 | explicit_steno_duration {
970 THIS->set_last_duration($1);
976 entered_notemode_duration {
978 $$->plet_.type_i_ *= THIS->plet_.type_i_;
979 $$->plet_.iso_i_ *= THIS->plet_.iso_i_;
983 explicit_steno_duration:
986 if ( !Duration::duration_type_b($1) )
987 THIS->parser_error("Not a duration");
989 $$->durlog_i_ = Duration_convert::i2_type($1);
992 | DURATION_IDENTIFIER {
995 | explicit_steno_duration '.' {
998 | explicit_steno_duration '*' int {
999 $$->plet_.iso_i_ *= $3;
1001 | explicit_steno_duration '/' int {
1002 $$->plet_.type_i_ *= $3;
1008 steno_note_req notemode_duration {
1009 if (!THIS->lexer_p_->note_state_b())
1010 THIS->parser_error("have to be in Note mode for notes");
1011 $1->set_duration (*$2);
1012 $$ = THIS->get_note_element($1, $2);
1014 | RESTNAME notemode_duration {
1015 $$ = THIS->get_rest_element(*$1, $2);
1021 text_def notemode_duration {
1022 /* this sux! text-def should be feature of lyric-engraver. */
1023 if (!THIS->lexer_p_->lyric_state_b())
1024 THIS->parser_error("Have to be in Lyric mode for lyrics");
1025 $$ = THIS->get_word_element($1, $2);
1033 $$ = new Array<Melodic_req*>;
1035 | pitch_list NOTENAME_ID {
1036 $$->push($2->clone()->musical()->melodic());
1045 int *i_p = $1->intid();
1057 Real *r_p = $1->real();
1066 real unit { $$ = $1*$2; }
1070 unit: CM_T { $$ = 1 CM; }
1071 |IN_T { $$ = 1 INCH; }
1072 |MM_T { $$ = 1 MM; }
1073 |PT_T { $$ = 1 PT; }
1080 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
1090 | symtables_body TEXID STRING {
1091 $$->texsetting = *$3;
1094 | symtables_body STRING '=' symtable {
1101 TABLE '{' symtable_body '}' { $$ = $3; }
1105 { $$ = new Symtable; }
1106 | symtable_body STRING symboldef {
1115 $$ = new Symbol(*$1, *$2);
1120 Box b(Interval(0,0), Interval(0,0));
1121 $$ = new Symbol(*$1, b);
1127 dinterval dinterval {
1128 $$ = new Box(*$1, *$2);
1134 dinterval: dim dim {
1135 $$ = new Interval($1, $2);
1142 My_lily_parser::set_yydebug(bool b )
1149 My_lily_parser::do_yyparse()
1151 yyparse((void*)this);
1155 My_lily_parser::default_paper()
1157 Identifier *id = lexer_p_->lookup_identifier( "default_paper" );
1158 return id ? id->paperdef() : new Paper_def ;
1162 My_lily_parser::default_midi()
1164 Identifier *id = lexer_p_->lookup_identifier( "default_midi" );
1165 return id ? id->mididef() : new Midi_def ;