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;
71 Music_output_def * outputdef;
78 General_script_def * script;
82 Symtables * symtables;
93 yylex(YYSTYPE *s, void * v_l)
95 My_lily_parser *pars_l = (My_lily_parser*) v_l;
96 My_lily_lexer * lex_l = pars_l->lexer_p_;
98 lex_l->lexval_l = (void*) s;
99 return lex_l->yylex();
107 /* tokens which are not keywords */
123 %token REQUESTTRANSLATOR
132 %token MELODIC_REQUEST
160 %token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
164 %token <melreq> NOTENAME_ID
165 %token <id> DURATION_IDENTIFIER
166 %token <id> IDENTIFIER
167 %token <id> MELODIC_REQUEST_IDENTIFIER
168 %token <id> MUSIC_IDENTIFIER
169 %token <id> VOICE_IDENTIFIER
170 %token <id> POST_REQUEST_IDENTIFIER
171 %token <id> SCRIPT_IDENTIFIER
172 %token <id> COMMAND_IDENTIFIER
173 %token <id> REAL_IDENTIFIER
174 %token <id> INPUT_TRANS_IDENTIFIER
175 %token <id> INT_IDENTIFIER
176 %token <id> SCORE_IDENTIFIER
177 %token <id> MIDI_IDENTIFIER
178 %token <id> PAPER_IDENTIFIER
179 %token <id> REQUEST_IDENTIFIER
181 %token <string> DURATION RESTNAME
182 %token <string> STRING
183 %token <string> FIELDNAME RECORDLINE
184 %token <i> POST_QUOTES
185 %token <i> PRE_QUOTES
187 %type <outputdef> output_def
188 %type <header> mudela_header mudela_header_body
190 %type <c> open_request_parens close_request_parens
191 %type <c> open_plet_parens close_plet_parens
192 %type <music> simple_element music_elt full_element lyrics_elt command_elt
195 %type <id> identifier_init
196 %type <duration> explicit_steno_duration notemode_duration
197 %type <duration> entered_notemode_duration explicit_duration
198 %type <interval> dinterval
199 %type <intvec> intastint_list
200 %type <lookup> symtables symtables_body
201 %type <melreq> melodic_request steno_melodic_req
202 %type <notereq> steno_note_req
203 %type <melreqvec> pitch_list
204 %type <midi> midi_block midi_body
205 %type <moment> duration_length
207 %type <music> Music transposed_music
208 %type <musiclist> Voice Voice_body
209 %type <chord> Chord Chord_body
210 %type <paper> paper_block paper_body
211 %type <real> dim real
213 %type <request> post_request pre_request command_req verbose_command_req
214 %type <request> abbrev_command_req
215 %type <request> script_req dynamic_req
216 %type <score> score_block score_body
217 %type <script> script_definition script_body mudela_script gen_script_def
218 %type <textdef> text_def
219 %type <string> script_abbreviation
220 %type <symbol> symboldef
221 %type <symtable> symtable symtable_body
222 %type <itrans> input_translator_spec input_translator_spec_body
223 %type <tempo> tempo_request
224 %type <string> header_record
231 | mudela mudela_header {
232 delete THIS->default_header_p_ ;
233 THIS->default_header_p_ = $2;
235 | mudela score_block {
238 | mudela add_declaration { }
240 | mudela check_version { }
241 | mudela add_notenames { }
246 if ( String( *$2 ) != MUDELA_VERSION) {
247 if (THIS->ignore_version_b_) {
248 THIS->here_input().error("Incorrect mudela version");
250 THIS->fatal_error_i_ = 1;
251 THIS->parser_error("Incorrect mudela version");
258 NOTENAMES '{' notenames_body '}'
263 | notenames_body CLEAR {
264 THIS->clear_notenames();
266 | notenames_body STRING '=' melodic_request {
267 THIS->add_notename(*$2, $4);
276 | mudela_header_body FIELDNAME header_record {
285 THIS->lexer_p_->push_header_state();
288 '{' mudela_header_body '}' {
290 THIS->lexer_p_->pop_state();
299 | header_record RECORDLINE {
311 THIS->remember_spot();
313 /* cont */ '=' identifier_init {
314 THIS->lexer_p_->set_identifier(*$1, $4);
315 $4->init_b_ = THIS->init_parse_b_;
316 $4->set_spot(THIS->pop_spot());
321 $$ = new Score_id($1, SCORE_IDENTIFIER);
325 $$ = new Paper_def_id($1, PAPER_IDENTIFIER);
329 $$ = new Midi_def_id($1, MIDI_IDENTIFIER);
332 | script_definition {
333 $$ = new Script_id($1, SCRIPT_IDENTIFIER);
337 $$ = new Music_id($1, MUSIC_IDENTIFIER);
341 $$ = new Lookup_id($1, IDENTIFIER);
345 $$ = new Real_id(new Real($1), REAL_IDENTIFIER);
349 $$ = new Int_id(new int($1), INT_IDENTIFIER);
353 $$ = new Request_id($1, POST_REQUEST_IDENTIFIER);
357 $$ = new Request_id($1, MELODIC_REQUEST_IDENTIFIER);
360 | input_translator_spec {
361 $$ = new Input_translator_id ( $1, INPUT_TRANS_IDENTIFIER);
363 | explicit_duration {
364 $$ = new Duration_id( $1, DURATION_IDENTIFIER);
370 input_translator_spec:
371 REQUESTTRANSLATOR '{' input_translator_spec_body '}'
375 input_translator_spec_body:
376 INPUT_TRANS_IDENTIFIER {
377 $$ = $1->input_translator();
378 $$-> set_spot( THIS->here_input() );
381 $$ = new Input_translator;
384 $$->set_spot ( THIS->here_input() );
388 | input_translator_spec_body ID STRING ';' {
389 $$-> default_id_str_ = *$3;
392 | input_translator_spec_body ALIAS STRING ';' {
393 $$-> alias_str_arr_.push(*$3);
396 | input_translator_spec_body CONSISTS STRING ';' {
397 $$-> consists_str_arr_.push(*$3);
400 | input_translator_spec_body CONTAINS input_translator_spec {
409 SCORE { THIS->remember_spot();
410 THIS->error_level_i_ =0;
412 /*cont*/ '{' score_body '}' {
414 $$->set_spot(THIS->pop_spot());
415 if (!$$->def_p_arr_.size ())
416 $$->add ( THIS->default_paper());
418 /* handle error levels. */
419 $$->errorlevel_i_ = THIS->error_level_i_;
420 THIS->error_level_i_ = 0;
421 if (!$$->header_p_ && THIS->default_header_p_)
422 $$->header_p_ = new Header(*THIS->default_header_p_);
432 | score_body mudela_header {
438 | score_body output_def {
456 /* */ { $$ =new Array<int>; }
457 | intastint_list int '*' int {
458 $$->push($2); $$->push($4);
468 '{' paper_body '}' { $$ = $3; }
473 $$ = THIS->default_paper(); // paper / video / engrave
478 | paper_body OUTPUT STRING ';' {
479 $$->outfile_str_ = *$3;
482 | paper_body symtables { $$->set($2); }
483 | paper_body STRING '=' dim ';' {
484 $$->set_var(*$2, $4);
486 | paper_body STRING '=' real ';' {
487 $$->set_var(*$2, $4);
489 | paper_body input_translator_spec {
503 '{' midi_body '}' { $$ = $3; }
506 midi_body: /* empty */ {
507 $$ = THIS->default_midi();
509 | midi_body OUTPUT STRING ';' {
510 $$->outfile_str_ = *$3;
513 | midi_body tempo_request ';' {
514 $$->set_tempo( $2->dur_.length(), $2->metronome_i_ );
517 | midi_body input_translator_spec {
526 TEMPO entered_notemode_duration '=' int {
530 $$-> metronome_i_ = $4;
548 | Voice_body ID STRING STRING ';' {
561 full_element { $$ = $1; }
564 | transposed_music { $$ = $1; }
565 | MUSIC_IDENTIFIER { $$ = $1->music(); }
567 { THIS->lexer_p_->push_note_state(); }
569 { $$=$3; THIS->lexer_p_->pop_state(); }
572 { THIS->lexer_p_->push_lyric_state(); }
574 { $$ = $3; THIS->lexer_p_->pop_state(); }
578 '<' Chord_body '>' { $$ = $2; }
584 $$-> multi_level_i_ = 1;
586 | Chord_body MULTI INT ';' {
587 $$->multi_level_i_=$3;
589 | Chord_body ID STRING STRING ';' {
601 TRANSPOSE steno_melodic_req Music {
613 pre_requests simple_element post_requests {
614 THIS->add_requests((Chord*)$2);//ugh
618 | voice_command ';' { $$ = 0; }
628 $$ = new Request_chord;
629 $$-> set_spot( THIS->here_input());
630 $1-> set_spot( THIS->here_input());
631 ((Chord*)$$) ->add($1);//ugh
638 | verbose_command_req ';' { $$ = $1; }
643 $$ = new Barcheck_req;
645 | COMMAND_IDENTIFIER {
652 $$ = new Bar_req(*$2);
655 | METER int '/' int {
656 Meter_change_req *m = new Meter_change_req;
658 // sorry hw, i need meter at output of track,
659 // but don-t know where to get it... statics should go.
660 // HW : default: 4/4, meterchange reqs may change it.
662 Midi_def::num_i_s = $2;
663 Midi_def::den_i_s = $4;
666 | SKIP duration_length {
667 Skip_req * skip_p = new Skip_req;
668 skip_p->duration_.set_plet($2->numerator().as_long(),
669 $2->denominator().as_long());
678 $$ = new Cadenza_req($2);
680 | PARTIAL duration_length {
681 $$ = new Partial_measure_req(*$2);
685 $$ = get_stemdir_req($2);
688 $$ = get_hshift_req($2);
691 $$ = new Clef_change_req(*$2);
695 Key_change_req *key_p= new Key_change_req;
696 key_p->melodic_p_arr_ = *$2;
700 | GROUPING intastint_list {
701 $$ = get_grouping_req(*$2); delete $2;
707 assert(THIS->post_reqs.empty());
709 | post_requests post_request {
710 $2->set_spot( THIS->here_input());
711 THIS->post_reqs.push($2);
717 POST_REQUEST_IDENTIFIER {
718 $$ = (Request*)$1->request();
720 |close_request_parens {
721 $$ = THIS->get_parens_request($1);
734 $$ = $1->clone()->musical()->melodic();
735 $$->octave_i_ += THIS->default_octave_i_;
737 | steno_melodic_req POST_QUOTES {
738 $$-> octave_i_ += $2;
740 | PRE_QUOTES steno_melodic_req {
742 $2-> octave_i_ -= $1;
749 * (Melodic_req *) $$ = *$1;
752 | steno_note_req '!' {
753 $$->forceacc_b_ = ! $$->forceacc_b_;
755 /* have to duration here. */
759 MELODIC_REQUEST '{' int int int '}' {/* ugh */
760 $$ = new Melodic_req;
762 $$->notename_i_ = $4;
763 $$->accidental_i_ = $5;
768 DURATION '{' int int '}' {
776 ABSDYNAMIC '{' int '}' {
777 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
778 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
781 | SPANDYNAMIC '{' int int '}' {
782 Span_dynamic_req * sp_p = new Span_dynamic_req;
784 sp_p-> dynamic_dir_ = $3;
792 THIS->plet_.type_i_ = $4;
793 THIS->plet_.iso_i_ = $2;
797 close_request_parens:
807 | close_plet_parens {
821 THIS->plet_.type_i_ = $4;
822 THIS->plet_.iso_i_ = $2;
843 SCRIPT '{' script_body '}' { $$ = $3; }
847 STRING int int int int int {
848 Script_def *s = new Script_def;
849 s->set_from_input(*$1,$2, $3,$4,$5, $6);
856 script_dir gen_script_def {
857 Musical_script_req *m = new Musical_script_req;
859 m-> scriptdef_p_ = $2;
860 m-> set_spot ( THIS->here_input() );
866 text_def { $$ = $1; }
867 | mudela_script { $$ = $1;
868 $$-> set_spot( THIS->here_input() );
874 Text_def *t = new Text_def;
878 t->style_str_ = THIS->textstyle_str_;
879 $$->set_spot( THIS->here_input() );
884 '^' { $$ = get_scriptdef('^'); }
885 | '+' { $$ = get_scriptdef('+'); }
886 | '-' { $$ = get_scriptdef('-'); }
887 | '|' { $$ = get_scriptdef('|'); }
888 | 'o' { $$ = get_scriptdef('o'); }
889 | '>' { $$ = get_scriptdef('>'); }
891 $$ = get_scriptdef('.');
896 SCRIPT_IDENTIFIER { $$ = $1->script(); }
897 | script_definition { $$ = $1; }
898 | script_abbreviation {
899 $$ = THIS->lexer_p_->lookup_identifier(*$1)->script();
911 | pre_requests pre_request {
912 THIS->pre_reqs.push($2);
913 $2->set_spot( THIS->here_input());
918 open_request_parens {
919 $$ = THIS->get_parens_request($1);
925 THIS->default_duration_.set_plet($2,$4);
928 THIS->set_duration_mode(*$2);
931 | DURATION entered_notemode_duration {
932 THIS->set_default_duration($2);
937 This is weird, but default_octave_i_
938 is used in steno_note_req too
940 c' -> default_octave_i_ == 1
942 /* why can't we have \oct{0} iso \oct{c'}*/
943 THIS->default_octave_i_ = 1; }
946 THIS->default_octave_i_ = $3->octave_i_;
950 THIS->textstyle_str_ = *$2;
957 $$ = new Moment(0,1);
959 | duration_length explicit_steno_duration {
966 | dots '.' { $$ ++; }
969 entered_notemode_duration:
971 $$ = new Duration(THIS->default_duration_);
974 $$ = new Duration(THIS->default_duration_);
977 | explicit_steno_duration {
978 THIS->set_last_duration($1);
984 entered_notemode_duration {
986 $$->plet_.type_i_ *= THIS->plet_.type_i_;
987 $$->plet_.iso_i_ *= THIS->plet_.iso_i_;
991 explicit_steno_duration:
994 if ( !Duration::duration_type_b($1) )
995 THIS->parser_error("Not a duration");
997 $$->durlog_i_ = Duration_convert::i2_type($1);
1000 | DURATION_IDENTIFIER {
1001 $$ = $1->duration();
1003 | explicit_steno_duration '.' {
1006 | explicit_steno_duration '*' int {
1007 $$->plet_.iso_i_ *= $3;
1009 | explicit_steno_duration '/' int {
1010 $$->plet_.type_i_ *= $3;
1016 steno_note_req notemode_duration {
1017 if (!THIS->lexer_p_->note_state_b())
1018 THIS->parser_error("have to be in Note mode for notes");
1019 $1->set_duration (*$2);
1020 $$ = THIS->get_note_element($1, $2);
1022 | RESTNAME notemode_duration {
1023 $$ = THIS->get_rest_element(*$1, $2);
1029 text_def notemode_duration {
1030 /* this sux! text-def should be feature of lyric-engraver. */
1031 if (!THIS->lexer_p_->lyric_state_b())
1032 THIS->parser_error("Have to be in Lyric mode for lyrics");
1033 $$ = THIS->get_word_element($1, $2);
1041 $$ = new Array<Melodic_req*>;
1043 | pitch_list NOTENAME_ID {
1044 $$->push($2->clone()->musical()->melodic());
1053 int *i_p = $1->intid();
1065 Real *r_p = $1->real();
1074 real unit { $$ = $1*$2; }
1078 unit: CM_T { $$ = 1 CM; }
1079 |IN_T { $$ = 1 INCH; }
1080 |MM_T { $$ = 1 MM; }
1081 |PT_T { $$ = 1 PT; }
1088 SYMBOLTABLES '{' symtables_body '}' { $$ = $3; }
1098 | symtables_body TEXID STRING {
1099 $$->texsetting = *$3;
1102 | symtables_body STRING '=' symtable {
1109 TABLE '{' symtable_body '}' { $$ = $3; }
1113 { $$ = new Symtable; }
1114 | symtable_body STRING symboldef {
1123 $$ = new Symbol(*$1, *$2);
1128 Box b(Interval(0,0), Interval(0,0));
1129 $$ = new Symbol(*$1, b);
1135 dinterval dinterval {
1136 $$ = new Box(*$1, *$2);
1142 dinterval: dim dim {
1143 $$ = new Interval($1, $2);
1150 My_lily_parser::set_yydebug(bool b )
1157 My_lily_parser::do_yyparse()
1159 yyparse((void*)this);
1163 My_lily_parser::default_paper()
1165 Identifier *id = lexer_p_->lookup_identifier( "default_paper" );
1166 return id ? id->paperdef() : new Paper_def ;
1170 My_lily_parser::default_midi()
1172 Identifier *id = lexer_p_->lookup_identifier( "default_midi" );
1173 return id ? id->mididef() : new Midi_def ;