]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
release: 1.1.35
[lilypond.git] / lily / parser.yy
1 %{ // -*-Fundamental-*-
2
3 /*
4   parser.yy -- Bison/C++ parser for mudela
5
6   source file of the GNU LilyPond music typesetter
7
8   (c) 1997 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9            Jan Nieuwenhuizen <janneke@gnu.org>
10 */
11
12 #include <iostream.h>
13 #include "lily-guile.hh"
14 #include "notename-table.hh"
15 #include "scalar.hh"
16 #include "translation-property.hh"
17 #include "script-def.hh"
18 #include "lookup.hh"
19 #include "misc.hh"
20 #include "my-lily-lexer.hh"
21 #include "paper-def.hh"
22 #include "midi-def.hh"
23 #include "main.hh"
24 #include "file-path.hh"
25 #include "keyword.hh"
26 #include "debug.hh"
27 #include "parseconstruct.hh"
28 #include "dimensions.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 "translator-group.hh"
35 #include "score.hh"
36 #include "music-list.hh"
37 #include "duration-convert.hh"
38 #include "change-translator.hh"
39 #include "file-results.hh"
40 #include "mudela-version.hh"
41 #include "scope.hh"
42 #include "relative-music.hh"
43 #include "transposed-music.hh"
44 #include "compressed-music.hh"
45 #include "repeated-music.hh"
46
47 // mmm
48 Mudela_version oldest_version ("1.0.14");
49 Mudela_version version ("1.0.15");
50
51
52 // needed for bison.simple's malloc() and free()
53 #include <malloc.h>
54
55 struct Assignment {
56         String *name_p_;
57         Identifier *id_p_;
58         ~Assignment () {
59                 delete name_p_;
60                 delete id_p_;
61         }
62         Assignment () {
63                 name_p_ = 0;
64                 id_p_ =0;
65         }
66         Assignment (Assignment const&s)
67         {
68                 name_p_ = new String (*s.name_p_);
69                 id_p_ = s.id_p_->clone ();
70         }
71 };
72
73 Paper_def* current_paper = 0;
74
75 #ifndef NDEBUG
76 #define YYDEBUG 1
77 #endif
78
79 #define YYERROR_VERBOSE 1
80
81 #define YYPARSE_PARAM my_lily_parser_l
82 #define YYLEX_PARAM my_lily_parser_l
83 #define THIS ((My_lily_parser *) my_lily_parser_l)
84
85 #define yyerror THIS->parser_error
86 #define ARRAY_SIZE(a,s)   if (a.size () != s) THIS->parser_error (_f("expecting %d arguments", s))
87
88 %}
89
90
91 %union {
92     Array<Interval>* intarr;
93     Array<Musical_pitch> *pitch_arr;
94     Link_array<Request> *reqvec;
95     Array<String> * strvec;
96     Array<int> *intvec;
97     Notename_table *chordmodifiertab;
98     Duration *duration;
99     General_script_def * script;
100     Identifier *id;
101     Music *music;
102     Music_list *music_list;
103     Score *score;
104     Scope *scope;
105     Interval *interval;
106     Musical_req* musreq;
107     Music_output_def * outputdef;
108     Musical_pitch * pitch;
109     Midi_def* midi;
110     Moment *moment;
111     Note_req *notereq;
112     Notename_table *notenametab;
113     Paper_def *paper;
114     Real real;
115     Request * request;
116     Scalar *scalar;
117     Simultaneous_music *chord;
118     String *string;
119     Tempo_req *tempo;
120     Text_def * textdef;
121     Translator* trans;
122     char c;
123     const char *consstr;
124     int i;
125     int ii[10];
126 }
127 %{
128
129 int
130 yylex (YYSTYPE *s,  void * v_l)
131 {
132         My_lily_parser   *pars_l = (My_lily_parser*) v_l;
133         My_lily_lexer * lex_l = pars_l->lexer_p_;
134
135         lex_l->lexval_l = (void*) s;
136         return lex_l->yylex ();
137 }
138
139
140 %}
141
142 %pure_parser
143
144 /* tokens which are not keywords */
145
146 %token ABSDYNAMIC
147 %token ACCEPTS
148 %token ALTERNATIVE
149 %token BAR
150 %token CADENZA
151 %token CHORDMODIFIERS
152 %token CHORDS
153 %token CLEF
154 %token CM_T
155 %token CONSISTS
156 %token DURATION
157 %token EXTENDER
158 %token FONT
159 %token GROUPING
160 %token HEADER
161 %token IN_T
162 %token KEY
163 %token KEYSIGNATURE
164 %token LYRICS
165 %token MARK
166 %token MEASURES
167 %token MIDI
168 %token MM_T
169 %token MUSICAL_PITCH
170 %token NAME
171 %token NOTENAMES
172 %token NOTES
173 %token PAPER
174 %token PARTIAL
175 %token PENALTY
176 %token PROPERTY
177 %token PT_T
178 %token RELATIVE
179 %token REMOVE
180 %token REPEAT
181 %token SCM_T
182 %token SCMFILE
183 %token SCORE
184 %token SCRIPT
185 %token SHAPE
186 %token SKIP
187 %token SPANDYNAMIC
188 %token TEMPO
189 %token TIME_T
190 %token TIMES
191 %token TRANSLATOR
192 %token TRANSPOSE
193 %token TYPE
194 %token VERSION
195
196 /* escaped */
197 %token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
198
199 %type <i>       dots
200 %token <i>      DIGIT
201 %token <pitch>  NOTENAME_PITCH
202 %token <pitch>  TONICNAME_PITCH
203 %token <pitch>  CHORDMODIFIER_PITCH
204 %token <id>     DURATION_IDENTIFIER
205 %token <id>     IDENTIFIER
206 %token <id>     NOTENAME_TABLE_IDENTIFIER
207 %token <id>     MUSIC_IDENTIFIER
208 %token <id>     POST_REQUEST_IDENTIFIER
209 %token <id>     SCRIPT_IDENTIFIER
210 %token <id>     COMMAND_IDENTIFIER
211 %token <id>     REAL_IDENTIFIER
212 %token <id>     STRING_IDENTIFIER
213 %token <id>     TRANS_IDENTIFIER
214 %token <id>     INT_IDENTIFIER
215 %token <id>     SCORE_IDENTIFIER
216 %token <id>     MIDI_IDENTIFIER
217 %token <id>     PAPER_IDENTIFIER
218 %token <real>   REAL
219 %token <string> DURATION RESTNAME
220 %token <string> STRING
221 %token <i>      UNSIGNED
222
223
224 %type <outputdef> output_def
225 %type <scope>   mudela_header mudela_header_body
226 %type <request> open_request_parens close_request_parens open_request close_request
227 %type <i>       sub_quotes sup_quotes
228 %type <music>   simple_element  request_chord command_element Simple_music  Composite_music 
229 %type <music>   Alternative_music Repeated_music
230 %type <i>       abbrev_type
231 %type <i>       int unsigned
232 %type <i>       script_dir
233 %type <i>       optional_modality
234 %type <id>      identifier_init  
235 %type <duration> steno_duration notemode_duration
236 %type <duration> entered_notemode_duration explicit_duration
237 %type <intvec>  intastint_list int_list
238 %type <reqvec>  pre_requests post_requests
239
240 %type <pitch>   explicit_musical_pitch steno_musical_pitch musical_pitch absolute_musical_pitch
241 %type <pitch>   steno_tonic_pitch
242 %type <notereq> steno_notepitch
243 %type <pitch_arr>       pitch_list
244 %type <music>   chord notemode_chord
245 %type <pitch_arr>       chord_additions chord_subtractions chord_notes
246 %type <pitch>   chord_addsub chord_note chord_inversion notemode_chord_inversion
247 %type <midi>    midi_block midi_body
248 %type <duration>        duration_length
249
250 %type <scalar>  scalar
251 %type <music>   Music  relative_music Sequential_music Simultaneous_music
252 %type <music>   property_def translator_change
253 %type <music_list> Music_list
254 %type <paper>   paper_block paper_def_body
255 %type <real>    real_expression real real_with_dimension
256 %type <request> abbrev_command_req
257 %type <request> post_request structured_post_request
258 %type <request> command_req verbose_command_req
259 %type <request> script_req  dynamic_req extender_req
260 %type <string>  string
261 %type <score>   score_block score_body
262 %type <intarr>  shape_array
263 %type <script>  script_definition script_body mudela_script gen_script_def
264 %type <textdef> text_def finger
265 %type <string>  script_abbreviation
266 %type <trans>   translator_spec_block translator_spec_body
267 %type <tempo>   tempo_request
268 %type <notenametab> notenames_body notenames_block chordmodifiers_block
269
270 %expect 7
271
272
273 %left '-' '+'
274 %left '*' '/'
275 %left UNARY_MINUS
276
277 %%
278
279 mudela: /* empty */
280         | mudela toplevel_expression {}
281         | mudela assignment { }
282         | mudela error
283         | mudela check_version { }
284         ;
285
286 toplevel_expression:
287         notenames_block                 {
288                 THIS->lexer_p_->set_notename_table ($1);
289         }
290         | chordmodifiers_block                  {
291                 THIS->lexer_p_->set_chordmodifier_table ($1);
292         }
293         | mudela_header {
294                 delete header_global_p;
295                 header_global_p = $1;
296         }
297         | score_block {
298                 score_global_array.push ($1);
299         }
300         | paper_block {
301                 Identifier * id = new
302                         Paper_def_identifier ($1, PAPER_IDENTIFIER);
303                 THIS->lexer_p_->set_identifier ("$defaultpaper", id)
304         }
305         | midi_block {
306                 Identifier * id = new
307                         Midi_def_identifier ($1, MIDI_IDENTIFIER);
308                 THIS->lexer_p_->set_identifier ("$defaultmidi", id)
309         }
310         | embedded_scm { 
311         }
312         ;
313
314 embedded_scm:
315         SCMFILE STRING ';' {
316                 read_lily_scm_file (*$2);
317                 delete $2;
318         }
319         | SCM_T STRING ';' {
320                 gh_eval_str ($2->ch_l ());
321                 delete $2;
322         };
323
324 check_version:
325         VERSION STRING ';'              {
326                 Mudela_version ver (*$2);
327                 if (!((ver >= oldest_version) && (ver <= version))) {
328                         if (THIS->ignore_version_b_) {
329                                 THIS->here_input ().error (_f ("incorrect mudela version: %s (%s, %s)", ver.str (), oldest_version.str (), version.str ()));
330                         } else {
331                                 THIS->fatal_error_i_ = 1;
332                                 THIS->parser_error (_f ("incorrect mudela version: %s (%s, %s)", ver.str (), oldest_version.str (), version.str ()));
333                         }
334                 }
335         }
336         ;
337
338
339 chordmodifiers_block:
340         CHORDMODIFIERS '{' notenames_body '}'  {  $$ = $3; }
341         ;
342
343
344 notenames_block:
345         NOTENAMES '{' notenames_body '}'  {  $$ = $3; }
346         ;
347
348
349
350 notenames_body:
351         /**/    {
352                 $$ = new Notename_table;
353         }
354         | NOTENAME_TABLE_IDENTIFIER     {
355                 $$ = $1-> access_content_Notename_table(true);
356         }
357         | notenames_body STRING '=' explicit_musical_pitch {
358                 (*$$)[*$2] = *$4;
359
360                 delete $4;
361                 delete $2;
362         }
363         ;
364
365 mudela_header_body:
366         {
367                 $$ = new Scope;
368                 THIS->lexer_p_-> scope_l_arr_.push ($$);
369         }
370         | mudela_header_body assignment ';' { 
371
372         }
373         ;
374
375 mudela_header:
376         HEADER '{' mudela_header_body '}'       {
377                 $$ = $3;
378                 THIS->lexer_p_-> scope_l_arr_.pop ();           
379         }
380         ;
381
382
383 /*
384         DECLARATIONS
385 */
386 assignment:
387         STRING {
388                 THIS->remember_spot ();
389         }
390         /* cont */ '=' identifier_init  {
391             THIS->lexer_p_->set_identifier (*$1, $4);
392             $4->init_b_ = THIS->init_parse_b_;
393             $4->set_spot (THIS->pop_spot ());
394         }
395         ;
396
397
398
399 identifier_init:
400         score_block {
401                 $$ = new Score_identifier ($1, SCORE_IDENTIFIER);
402
403         }
404         | chordmodifiers_block {
405                 $$ = new Notename_table_identifier ($1, NOTENAME_TABLE_IDENTIFIER);
406         }
407         | notenames_block {
408                 $$ = new Notename_table_identifier ($1, NOTENAME_TABLE_IDENTIFIER);
409         }
410         | paper_block {
411                 $$ = new Paper_def_identifier ($1, PAPER_IDENTIFIER);
412         }
413         | midi_block {
414                 $$ = new Midi_def_identifier ($1, MIDI_IDENTIFIER);
415
416         }
417         | translator_spec_block {
418                 $$ = new Translator_identifier ($1, TRANS_IDENTIFIER);
419         }
420         | Music  {
421                 $$ = new Music_identifier ($1, MUSIC_IDENTIFIER);
422         }
423
424         | post_request {
425                 $$ = new Request_identifier ($1, POST_REQUEST_IDENTIFIER);
426         }
427         | explicit_duration {
428                 $$ = new Duration_identifier ($1, DURATION_IDENTIFIER);
429         }
430         | real {
431                 $$ = new Real_identifier (new Real ($1), REAL_IDENTIFIER);
432         }
433         | string {
434                 $$ = new String_identifier ($1, STRING_IDENTIFIER);
435         }
436         | int   {
437                 $$ = new int_identifier (new int ($1), INT_IDENTIFIER);
438         }
439         | script_definition {
440                 $$ = new General_script_def_identifier ($1, SCRIPT_IDENTIFIER);
441
442         }
443         ;
444
445 translator_spec_block:
446         TRANSLATOR '{' translator_spec_body '}'
447                 {
448                 $$ = $3;
449         }
450         ;
451
452 translator_spec_body:
453         TRANS_IDENTIFIER        {
454                 $$ = $1->access_content_Translator (true);
455                 $$-> set_spot (THIS->here_input ());
456         }
457         | TYPE STRING ';'       {
458                 Translator* t = get_translator_l (*$2);
459                 Translator_group * tg = dynamic_cast<Translator_group*> (t);
460
461                 if (!tg)
462                         THIS->parser_error (_("Need a translator group for a context"));
463                 
464                 t = t->clone ();
465                 t->set_spot (THIS->here_input ());
466                 $$ = t;
467                 delete $2;
468         }
469         | translator_spec_body STRING '=' identifier_init ';'   { 
470                 Identifier* id = $4;
471                 String_identifier *s = dynamic_cast<String_identifier*> (id);
472                 Real_identifier *r= dynamic_cast<Real_identifier*>(id);
473                 int_identifier *i = dynamic_cast<int_identifier*> (id);
474         
475                 String str;
476                 if (s) str = *s->access_content_String (false); 
477                 if (i) str = to_str (*i->access_content_int (false));
478                 if (r) str = to_str (*r->access_content_Real (false));
479                 if (!s && !i && !r)
480                         THIS->parser_error (_("Wrong type for property value"));
481
482                 delete $4;
483                 /* ugh*/
484                 Translator_group * tr = dynamic_cast<Translator_group*>($$);
485                 tr->set_property (*$2, str);
486         }
487         | translator_spec_body NAME STRING ';' {
488                 $$->type_str_ = *$3;
489                 delete $3;
490         }
491         | translator_spec_body CONSISTS STRING ';' {
492                 dynamic_cast<Translator_group*> ($$)-> set_element (*$3, true);
493                 delete $3;
494         }
495         | translator_spec_body ACCEPTS STRING ';' {
496                 dynamic_cast<Translator_group*> ($$)-> set_acceptor (*$3, true);
497                 delete $3;
498         }
499         | translator_spec_body REMOVE STRING ';' {
500                 dynamic_cast<Translator_group*> ($$)-> set_element (*$3, false);
501                 delete $3;
502         }
503         ;
504
505 /*
506         SCORE
507 */
508 score_block:
509         SCORE { THIS->remember_spot ();
510         }
511         /*cont*/ '{' score_body '}'     {
512                 $$ = $4;
513                 $$->set_spot (THIS->pop_spot ());
514                 if (!$$->def_p_arr_.size ())
515                         $$->add_output (THIS->default_paper_p ());
516
517         }
518         ;
519
520 score_body:             {
521                 $$ = new Score;
522         }
523         | SCORE_IDENTIFIER {
524                 $$ = $1->access_content_Score (true);
525         }
526         | score_body mudela_header      {
527                 $$->header_p_ = $2;
528         }
529         | score_body Music      {
530                 if ($$->music_p_)
531                         $2->warning (_ ("More than one music block"));  
532                 $$->music_p_ = $2;
533         }
534         | score_body output_def {
535                 $$->add_output ($2);
536         }
537         | score_body error {
538
539         }
540         ;
541
542 output_def:
543         paper_block {
544                 $$ = $1;
545         }
546         |  midi_block           {
547                 $$= $1;
548         }
549         ;
550
551 intastint_list:
552         /* */   { $$ =new Array<int>; }
553         | intastint_list int '*' int    {
554                 $$->push ($2); $$->push ($4);
555         }
556         | intastint_list int    {
557                 $$->push ($2); $$->push (1);
558         }
559         ;       
560
561
562 /*
563         PAPER
564 */
565 paper_block:
566         PAPER '{' paper_def_body '}'    { 
567                 $$ = $3;
568                 THIS-> lexer_p_->scope_l_arr_.pop ();
569         }
570         ;
571
572 optional_dot:
573         /* empty */
574         | '.'
575         ;
576
577 paper_def_body:
578         /* empty */                     {
579                 Paper_def *p = THIS->default_paper_p ();
580                 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
581                 $$ = p;
582         }
583         | PAPER_IDENTIFIER      {
584                 Paper_def *p = $1->access_content_Paper_def (true);
585                 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
586                 $$ = p;
587         }
588         | paper_def_body int '=' FONT STRING            { // ugh, what a syntax
589                 Lookup * l = new Lookup;
590                 l->font_name_ = *$5;
591                 delete $5;
592                 $$->set_lookup ($2, l);
593         }
594         | paper_def_body assignment ';' {
595
596         }
597         | paper_def_body translator_spec_block {
598                 $$->assign_translator ($2);
599         }
600         | paper_def_body SHAPE '=' shape_array ';' {
601                 $$->shape_int_a_ = *$4;
602                 delete $4;
603         }
604         | paper_def_body error {
605
606         }
607         ;
608
609
610 real:
611         real_expression         { $$ = $1; }
612         ;
613
614
615 real_with_dimension:
616         REAL CM_T       {
617                 $$ = $1 CM;
618         }
619         | REAL PT_T     {
620                 $$ = $1 PT;
621         }
622         | REAL IN_T     {
623                 $$ = $1 INCH;
624         }
625         | REAL MM_T     {
626                 $$ = $1 MM;
627         }
628         ;
629
630 real_expression:
631         REAL            {
632                 $$ = $1;
633         }
634         | real_with_dimension
635         | REAL_IDENTIFIER               {
636                 $$= *$1->access_content_Real (false);
637         }
638         | '-'  real_expression %prec UNARY_MINUS {
639                 $$ = -$2;
640         }
641         | real_expression '*' real_expression {
642                 $$ = $1 * $3;
643         }
644         | real_expression '/' real_expression {
645                 $$ = $1 / $3;
646         }
647         | real_expression '+' real_expression {
648                 $$ = $1  + $3;
649         }
650         | real_expression '-' real_expression {
651                 $$ = $1 - $3;
652         }
653         | '(' real_expression ')'       {
654                 $$ = $2;
655         }
656         ;
657                 
658
659 shape_array:
660         /* empty */ {
661                 $$ = new Array<Interval>;
662         }
663         | shape_array real real {
664                 $$->push(Interval($2, $2 + $3));
665         };
666
667 /*
668         MIDI
669 */
670 midi_block:
671         MIDI
672
673         '{' midi_body '}'       { $$ = $3; }
674         ;
675
676 midi_body: /* empty */          {
677                 $$ = THIS->default_midi_p ();
678         }
679         | MIDI_IDENTIFIER       {
680                 $$ = $1-> access_content_Midi_def (true);
681         }
682         | midi_body translator_spec_block       {
683                 $$-> assign_translator ($2);
684         }
685         | midi_body tempo_request ';' {
686                 $$->set_tempo ($2->dur_.length_mom (), $2->metronome_i_);
687                 delete $2;
688         }
689         | midi_body error {
690
691         }
692         ;
693
694 tempo_request:
695         TEMPO steno_duration '=' unsigned       {
696                 $$ = new Tempo_req;
697                 $$->dur_ = *$2;
698                 delete $2;
699                 $$-> metronome_i_ = $4;
700         }
701         ;
702
703 Music_list: /* empty */ {
704                 $$ = new Music_list;
705         }
706         | Music_list Music {
707                 $$->add_music ($2);
708         }
709         | Music_list error {
710         }
711         ;
712
713
714 Music:
715         Simple_music
716         | Composite_music
717         ;
718
719 Alternative_music: {
720                 Music_list* m = new Music_list;
721                 $$ = new Sequential_music (m);
722         }
723         | ALTERNATIVE Simultaneous_music {
724                 $$ = $2;
725         }
726         | ALTERNATIVE Sequential_music {
727                 $$ = $2;
728         }
729         ;
730
731 Repeated_music: REPEAT unsigned Music Alternative_music {
732                 Music_sequence* m = dynamic_cast <Music_sequence*> ($4);
733                 assert (m);
734                 $$ = new Repeated_music ($3, $2 >? 1, m);
735         }
736         ;
737
738 Sequential_music: '{' Music_list '}'            {
739                 $$ = new Sequential_music ($2);
740         }
741         ;
742
743 Simultaneous_music: '<' Music_list '>'  {
744                 $$ = new Simultaneous_music ($2);
745         }
746         ;
747
748 Simple_music:
749         request_chord           { $$ = $1; }
750         | MUSIC_IDENTIFIER { $$ = $1->access_content_Music (true); }
751         | property_def
752         | translator_change
753         | Simple_music '*' unsigned '/' unsigned        {
754                 /* urg */
755                 $$ = new Compressed_music ($3, $5, $1);
756         }
757         | Simple_music '*' unsigned              {
758                 $$ = new Compressed_music ($3, 1, $1);
759         }
760         ;
761
762
763 Composite_music:
764         TYPE STRING Music       {
765                 $$ = $3;
766                 $$->translator_type_str_ = *$2;
767                 delete $2;
768         }
769         | TYPE STRING '=' STRING Music {
770                 $$ = $5;
771                 $$->translator_type_str_ = *$2;
772                 $$->translator_id_str_ = *$4;
773                 delete $2;
774                 delete $4;
775         }
776         | TIMES {
777                 THIS->remember_spot ();
778         }
779         /* CONTINUED */ 
780                 unsigned '/' unsigned Music     
781
782         {
783                 $$ = new Compressed_music ($3, $5, $6);
784                 $$->set_spot (THIS->pop_spot ());
785         }
786         | Repeated_music                { $$ = $1; }
787         | Simultaneous_music            { $$ = $1; }
788         | Sequential_music              { $$ = $1; }
789         | TRANSPOSE musical_pitch Music {
790                 $$ = new Transposed_music ($3, *$2);
791                 delete $2;
792         }
793         | TRANSPOSE steno_tonic_pitch Music {
794                 $$ = new Transposed_music ($3, *$2);
795                 delete $2;
796         }
797         | NOTES
798                 { THIS->lexer_p_->push_note_state (); }
799         Music
800                 { $$ = $3;
801                   THIS->lexer_p_->pop_state ();
802                 }
803         | CHORDS
804                 { THIS->lexer_p_->push_chord_state (); }
805         Music
806                 {
807                   $$ = $3;
808                   THIS->lexer_p_->pop_state ();
809         }
810         | LYRICS
811                 { THIS->lexer_p_->push_lyric_state (); }
812         Music
813                 {
814                   $$ = $3;
815                   THIS->lexer_p_->pop_state ();
816         }
817         | relative_music        { $$ = $1; }
818         ;
819
820 relative_music:
821         RELATIVE absolute_musical_pitch Music {
822                 $$ = new Relative_octave_music ($3, *$2);
823                 delete $2;
824         }
825         ;
826
827 translator_change:
828         TRANSLATOR STRING '=' STRING  {
829                 Change_translator * t = new Change_translator;
830                 t-> change_to_type_str_ = *$2;
831                 t-> change_to_id_str_ = *$4;
832
833                 $$ = t;
834                 $$->set_spot (THIS->here_input ());
835                 delete $2;
836                 delete $4;
837         }
838         ;
839
840 property_def:
841         PROPERTY STRING '.' STRING '=' scalar   {
842                 Translation_property *t = new Translation_property;
843                 t-> translator_type_str_ = *$2;
844                 t-> var_str_ = *$4;
845                 t-> value_ = *$6;
846                 $$ = t;
847                 $$->set_spot (THIS->here_input ());
848                 delete $2;
849                 delete $4;
850                 delete $6;
851         }
852         ;
853
854 scalar:
855         STRING          { $$ = new Scalar (*$1); delete $1; }
856         | int           { $$ = new Scalar ($1); }
857         ;
858
859
860 request_chord:
861         pre_requests simple_element post_requests       {
862                 Music_sequence *l = dynamic_cast<Music_sequence*>($2);
863                 for (int i=0; i < $1->size(); i++)
864                         l->add_music ($1->elem(i));
865                 for (int i=0; i < $3->size(); i++)
866                         l->add_music ($3->elem(i));
867                 $$ = $2;
868                 
869         }
870         | command_element
871         ;
872
873 command_element:
874         command_req {
875                 $$ = new Request_chord;
876                 $$-> set_spot (THIS->here_input ());
877                 $1-> set_spot (THIS->here_input ());
878                 ((Simultaneous_music*)$$) ->add_music ($1);//ugh
879         }
880         ;
881
882 command_req:
883         abbrev_command_req
884         | verbose_command_req ';'       { $$ = $1; }
885         ;
886
887 abbrev_command_req:
888         extender_req {
889                 $$ = $1;
890         }
891         | '|'                           {
892                 $$ = new Barcheck_req;
893         }
894         | COMMAND_IDENTIFIER    {
895                 $$ = $1->access_content_Request (true);
896         }
897         | '~'   {
898                 $$ = new Tie_req;
899         }
900         | '['           {
901                 Beam_req*b= new Beam_req;
902                 b->spantype_ = START;
903                 $$ =b;
904         }
905         | ']'           {
906                 Beam_req*b= new Beam_req;
907                 b->spantype_ = STOP;
908                 $$ = b;
909         }
910         ;
911
912
913 verbose_command_req:
914         BAR STRING                      {
915                 $$ = new Bar_req (*$2);
916                 delete $2;
917         }
918         | MARK STRING {
919                 $$ = new Mark_req (*$2);
920                 delete $2;
921         }
922         | MARK unsigned {
923                 $$ = new Mark_req (to_str ($2));
924         }
925         | TIME_T unsigned '/' unsigned  {
926                 Time_signature_change_req *m = new Time_signature_change_req;
927                 m->beats_i_ = $2;
928                 m->one_beat_i_=$4;
929                 $$ = m;
930         }
931         | PENALTY '=' int       {
932                 Break_req * b = new Break_req;
933                 b->penalty_i_ = $3;
934                 b-> set_spot (THIS->here_input ());
935                 $$ = b;
936         }
937         | SKIP duration_length {
938                 Skip_req * skip_p = new Skip_req;
939                 skip_p->duration_ = *$2;
940                 delete $2;
941                 $$ = skip_p;
942         }
943         | tempo_request {
944                 $$ = $1;
945         }
946         | CADENZA unsigned      {
947                 $$ = new Cadenza_req ($2);
948         }
949         | PARTIAL duration_length       {
950                 $$ = new Partial_measure_req ($2->length_mom ());
951                 delete $2;
952         }
953         | CLEF STRING {
954                 $$ = new Clef_change_req (*$2);
955                 delete $2;
956         }
957         | KEY NOTENAME_PITCH optional_modality  {
958                 Key_change_req *key_p= new Key_change_req;
959                 key_p->pitch_arr_.push(*$2);
960                 key_p->ordinary_key_b_ = true;
961                 key_p->modality_i_ = $3;
962                 $$ = key_p;
963                 delete $2;
964         }
965         | KEYSIGNATURE pitch_list       {
966                 Key_change_req *key_p= new Key_change_req;
967                 key_p->pitch_arr_ = *$2;
968                 key_p->ordinary_key_b_ = false;
969                 $$ = key_p;
970                 delete $2;
971         }
972         | GROUPING intastint_list {
973                   Measure_grouping_req * mr_p = new Measure_grouping_req;
974                   for (int i=0; i < $2->size();) 
975                     {
976                       mr_p->elt_length_arr_.push (Moment (1, $2->elem(i++)));
977                       mr_p->beat_i_arr_.push ($2->elem(i++));
978                     }
979
980
981                 $$ = mr_p;
982                 delete $2;
983         }
984         ;
985
986 post_requests:
987         {
988                 $$ = new Link_array<Request>;
989         }
990         | post_requests structured_post_request {
991                 $2->set_spot (THIS->here_input ());
992                 $$->push ($2);
993         }
994         | post_requests close_request   {
995                 $$->push ($2);
996         }
997         ;
998
999 structured_post_request:
1000         script_req
1001         | post_request
1002         ;
1003
1004 post_request:
1005         POST_REQUEST_IDENTIFIER {
1006                 $$ = (Request*)$1->access_content_Request (true);
1007         }
1008         | dynamic_req {
1009                 $$ = $1;
1010         }
1011         | abbrev_type   {
1012                 Abbreviation_req* a = new Abbreviation_req;
1013                 a->type_i_ = $1;
1014                 $$ = a;
1015         }
1016
1017         ;
1018
1019 optional_modality:
1020         /* empty */     {
1021                 $$ = 0;
1022         }
1023         | int   {
1024                 $$ = $1;
1025         }
1026         ;
1027
1028 sup_quotes:
1029         '\'' {
1030                 $$ = 1;
1031         }
1032         | sup_quotes '\'' {
1033                 $$ ++;
1034         }
1035         ;
1036
1037 sub_quotes:
1038         ',' {
1039                 $$ = 1;
1040         }
1041         | sub_quotes ',' {
1042                 $$ ++ ;
1043         }
1044         ;
1045
1046 steno_musical_pitch:
1047         NOTENAME_PITCH  {
1048                 $$ = $1;
1049         }
1050         | NOTENAME_PITCH sup_quotes     {
1051                 $$ = $1;
1052                 $$->octave_i_ +=  $2;
1053         }
1054         | NOTENAME_PITCH sub_quotes      {
1055                 $$ = $1;
1056                 $$->octave_i_ += - $2;
1057         }
1058         ;
1059
1060 steno_tonic_pitch:
1061         TONICNAME_PITCH {
1062                 $$ = $1;
1063         }
1064         | TONICNAME_PITCH sup_quotes    {
1065                 $$ = $1;
1066                 $$->octave_i_ +=  $2;
1067         }
1068         | TONICNAME_PITCH sub_quotes     {
1069                 $$ = $1;
1070                 $$->octave_i_ += - $2;
1071         }
1072         ;
1073
1074 explicit_musical_pitch:
1075         MUSICAL_PITCH '{' int_list '}'  {/* ugh */
1076                 Array<int> &a = *$3;
1077                 ARRAY_SIZE(a,3);
1078                 $$ = new Musical_pitch;
1079                 $$->octave_i_ = a[0];
1080                 $$->notename_i_ = a[1];
1081                 $$->accidental_i_ = a[2];
1082                 delete &a;
1083         }
1084         ;
1085
1086 musical_pitch:
1087         steno_musical_pitch
1088         | explicit_musical_pitch
1089         ;
1090
1091 steno_notepitch:
1092         musical_pitch   {
1093                 $$ = new Note_req;
1094                 
1095                 $$->pitch_ = *$1;
1096                 delete $1;
1097         }
1098         | steno_notepitch  '!'          {
1099                 $$->forceacc_b_ = ! $$->forceacc_b_;
1100         }
1101         | steno_notepitch  '?'          {
1102                 $$->forceacc_b_ = ! $$->forceacc_b_;
1103                 $$->cautionary_b_ = ! $$->cautionary_b_;
1104         }
1105         ;
1106
1107
1108 explicit_duration:
1109         DURATION '{' int_list '}'       {
1110                 $$ = new Duration;
1111                 Array<int> &a = *$3;
1112                 ARRAY_SIZE(a,2);
1113                         
1114                 $$-> durlog_i_ = a[0];
1115                 $$-> dots_i_ = a[1];
1116
1117                 delete &a;              
1118         }
1119         ;
1120
1121 extender_req:
1122         EXTENDER {
1123                 if (!THIS->lexer_p_->lyric_state_b ())
1124                         THIS->parser_error (_ ("have to be in Lyric mode for lyrics"));
1125                 $$ = new Extender_req;
1126         }
1127         ;
1128
1129 dynamic_req:
1130         ABSDYNAMIC '{' STRING '}'       {
1131                 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
1132                 ad_p ->loudness_str_ = *$3;
1133                 delete $3;
1134                 $$ =ad_p;
1135         }
1136         | SPANDYNAMIC '{' int int '}' {
1137                 Span_dynamic_req * sp_p = new Span_dynamic_req;
1138                 sp_p-> dynamic_dir_  = Direction($3);
1139                 sp_p->spantype_ = Direction($4);
1140                 $$ = sp_p;
1141         }
1142         ;
1143
1144
1145 close_request:
1146         close_request_parens {
1147                 $$ = $1;
1148                 dynamic_cast<Span_req*> ($$)->spantype_ = START;
1149         }
1150         
1151 close_request_parens:
1152         '('     {
1153                 $$= new Slur_req;
1154         }
1155         | E_SMALLER {
1156                 Span_dynamic_req*s =new Span_dynamic_req;
1157                 $$ = s;
1158                 s->dynamic_dir_ = UP;
1159         }
1160         | E_BIGGER {
1161                 Span_dynamic_req*s =new Span_dynamic_req;
1162                 $$ = s;
1163                 s->dynamic_dir_ = DOWN;
1164         }
1165         ;
1166
1167
1168 open_request:
1169         open_request_parens {
1170                 $$ = $1;
1171                 dynamic_cast<Span_req*> ($$)->spantype_ = STOP;
1172         }
1173         ;
1174
1175 open_request_parens:
1176         E_EXCLAMATION   {
1177                 Span_dynamic_req *s =  new Span_dynamic_req;
1178                 s->dynamic_dir_ = SMALLER;
1179                 $$ = s;
1180                 
1181         }
1182         | ')'   {
1183                 $$= new Slur_req
1184         }
1185         ;
1186
1187
1188
1189 script_definition:
1190         SCRIPT '{' script_body '}'      { $$ = $3; }
1191         ;
1192
1193 script_body:
1194         STRING int int int int int              {
1195                 Script_def *s = new Script_def;
1196                 s->set_from_input (*$1,$2, $3,$4,$5, $6);
1197                 $$  = s;
1198                 delete $1;
1199         }
1200         ;
1201
1202 script_req:
1203         script_dir gen_script_def       {
1204                 Musical_script_req *m = new Musical_script_req;
1205                 $$ = m;
1206                 m->scriptdef_p_ = $2;
1207                 m->set_spot (THIS->here_input ());
1208                 if (!m->dir_)
1209                   m->dir_  = (Direction)$1;
1210         }
1211         ;
1212
1213 gen_script_def:
1214         text_def        { 
1215                 $$ = $1;
1216                 ((Text_def*) $$)->align_dir_ = LEFT; /* UGH */
1217         }
1218         | mudela_script { 
1219                 $$ = $1;
1220                 $$-> set_spot (THIS->here_input ());
1221         }
1222         | finger {
1223                 $$ = $1;
1224                 ((Text_def*)$$)->align_dir_ = RIGHT; /* UGH */
1225         }
1226         ;
1227
1228 text_def:
1229         string {
1230                 Text_def *t  = new Text_def;
1231                 $$ = t;
1232                 t->text_str_ = *$1;
1233                 delete $1;
1234                 $$->set_spot (THIS->here_input ());
1235         }
1236         ;
1237
1238 finger:
1239          DIGIT {
1240                 Text_def* t  = new Text_def;
1241                 $$ = t;
1242                 t->text_str_ = to_str ($1);
1243                 t->style_str_ = "finger";
1244                 $$->set_spot (THIS->here_input ());
1245         }
1246         ;
1247
1248 script_abbreviation:
1249         '^'             {
1250                 $$ = THIS->lexer_p_
1251                 ->lookup_identifier ("dash-hat")->access_content_String (true)
1252
1253         }
1254         | '+'           {
1255                 $$ = THIS->lexer_p_
1256                 ->lookup_identifier ("dash-plus")->access_content_String (true)
1257  }
1258         | '-'           {
1259                 $$ = THIS->lexer_p_
1260                 ->lookup_identifier ("dash-dash")->access_content_String (true)
1261  }
1262         | '|'           {
1263                 $$ = THIS->lexer_p_
1264                 ->lookup_identifier ("dash-bar")->access_content_String (true)
1265  }
1266         | '>'           {
1267                 $$ = THIS->lexer_p_
1268                 ->lookup_identifier ("dash-larger")->access_content_String (true)
1269  }
1270         | '.'           {
1271                 $$ = THIS->lexer_p_
1272                 ->lookup_identifier ("dash-dot")->access_content_String (true);
1273         }
1274         ;
1275
1276 mudela_script:
1277         SCRIPT_IDENTIFIER               { $$ = $1->access_content_General_script_def (true); }
1278         | script_definition             { $$ = $1; }
1279         | script_abbreviation           {
1280                 $$ = THIS->lexer_p_->lookup_identifier (*$1)->access_content_General_script_def (true);
1281                 delete $1;
1282         }
1283         ;
1284
1285 script_dir:
1286         '_'     { $$ = DOWN; }
1287         | '^'   { $$ = UP; }
1288         | '-'   { $$ = CENTER; }
1289         ;
1290
1291 pre_requests:
1292         {
1293                 $$ = new Link_array<Request>;
1294         }
1295         | pre_requests open_request {
1296                 $$->push ($2);
1297         }
1298         ;
1299
1300 absolute_musical_pitch:
1301         steno_musical_pitch     {
1302                 $$ = $1;
1303         }
1304         ;
1305
1306 duration_length:
1307         steno_duration {
1308                 $$ = $1;
1309         }
1310         | duration_length '*' unsigned {
1311                 $$->plet_.iso_i_ *= $3;
1312         }
1313         | duration_length '/' unsigned {
1314                 $$->plet_.type_i_ *= $3;
1315         }
1316         ;
1317
1318 dots:
1319         '.'             { $$ = 1; }
1320         | dots '.'      { $$ ++; }
1321         ;
1322
1323 entered_notemode_duration:
1324         /* */           {
1325                 $$ = new Duration (THIS->default_duration_);
1326         }
1327         | dots          {
1328                 $$ = new Duration (THIS->default_duration_);
1329                 $$->dots_i_  = $1;
1330         }
1331         | steno_duration        {
1332                 THIS->set_last_duration ($1);
1333         }
1334         ;
1335
1336 notemode_duration:
1337         entered_notemode_duration {
1338                 $$ = $1;
1339         }
1340         ;
1341
1342 steno_duration:
1343         unsigned                {
1344                 $$ = new Duration;
1345                 if (!Duration::duration_type_b ($1))
1346                         THIS->parser_error (_f ("not a duration: %d", $1));
1347                 else {
1348                         $$->durlog_i_ = Duration_convert::i2_type ($1);
1349                      }
1350         }
1351         | DURATION_IDENTIFIER   {
1352                 $$ = $1->access_content_Duration (true);
1353         }
1354         | steno_duration '.'    {
1355                 $$->dots_i_ ++;
1356         }
1357         ;
1358
1359
1360 abbrev_type: 
1361         ':'     {
1362                 $$ =0;
1363         }
1364         | ':' unsigned {
1365                 if (!Duration::duration_type_b ($2))
1366                         THIS->parser_error (_f ("not a duration: %d", $2));
1367                 else if ($2 < 8)
1368                         THIS->parser_error (_ ("can't abbreviate"));
1369                 $$ = $2;
1370         }
1371         ;
1372
1373
1374
1375 simple_element:
1376         steno_notepitch notemode_duration  {
1377                 if (!THIS->lexer_p_->note_state_b ())
1378                         THIS->parser_error (_ ("have to be in Note mode for notes"));
1379                 $1->duration_ = *$2;
1380                 $$ = THIS->get_note_element ($1, $2);
1381         }
1382         | RESTNAME notemode_duration            {
1383                 $$ = THIS->get_rest_element (*$1, $2);
1384                 delete $1;  // delete notename
1385         }
1386         | MEASURES notemode_duration    {
1387                 Multi_measure_rest_req* m = new Multi_measure_rest_req;
1388                 m->duration_ = *$2;
1389                 delete $2;
1390
1391                 Simultaneous_music*velt_p = new Request_chord;
1392                 velt_p->set_spot (THIS->here_input ());
1393                 velt_p->add_music (m);
1394                 $$ = velt_p;
1395         }
1396         | STRING notemode_duration                      {
1397                 if (!THIS->lexer_p_->lyric_state_b ())
1398                         THIS->parser_error (_ ("have to be in Lyric mode for lyrics"));
1399                 $$ = THIS->get_word_element (*$1, $2);
1400                 delete $1;
1401         }
1402         | chord {
1403                 if (!THIS->lexer_p_->chord_state_b ())
1404                         THIS->parser_error (_ ("have to be in Chord mode for chords"));
1405                 $$ = $1;
1406         }
1407         | '@' notemode_chord '@' {
1408                 if (!THIS->lexer_p_->note_state_b ())
1409                         THIS->parser_error (_ ("have to be in Note mode for @chords"));
1410                 $$ = $2;
1411         }
1412         ;
1413
1414 chord:
1415         steno_tonic_pitch notemode_duration chord_additions chord_subtractions chord_inversion {
1416                 $$ = THIS->get_chord (*$1, $3, $4, $5, *$2);
1417         };
1418
1419 notemode_chord:
1420         steno_musical_pitch notemode_duration chord_additions chord_subtractions notemode_chord_inversion {
1421                 $$ = THIS->get_chord (*$1, $3, $4, $5, *$2);
1422         };
1423
1424 chord_additions: 
1425         {
1426                 $$ = new Array<Musical_pitch>;
1427         } 
1428         | '-' chord_notes {
1429                 $$ = $2;
1430         }
1431         ;
1432
1433 chord_notes:
1434         {
1435                 $$ = new Array<Musical_pitch>;
1436         }
1437         | chord_notes chord_addsub {
1438                 $$ = $1;
1439                 $$->push (*$2);
1440         }
1441         ;
1442
1443 chord_addsub:
1444         chord_note optional_dot
1445         | CHORDMODIFIER_PITCH optional_dot
1446         ;
1447
1448 chord_inversion:
1449         {
1450                 $$ = 0;
1451         }
1452         | '/' steno_tonic_pitch {
1453                 $$ = $2
1454         }
1455         ;
1456
1457 notemode_chord_inversion:
1458         {
1459                 $$ = 0;
1460         }
1461         | '/' steno_musical_pitch {
1462                 $$ = $2
1463         }
1464         ;
1465
1466 chord_note:
1467         unsigned {
1468                 $$ = new Musical_pitch;
1469                 $$->notename_i_ = ($1 - 1) % 7;
1470                 $$->octave_i_ = $1 > 7 ? 1 : 0;
1471                 $$->accidental_i_ = 0;
1472         } 
1473         | unsigned '+' {
1474                 $$ = new Musical_pitch;
1475                 $$->notename_i_ = ($1 - 1) % 7;
1476                 $$->octave_i_ = $1 > 7 ? 1 : 0;
1477                 $$->accidental_i_ = 1;
1478         }
1479         | unsigned '-' {
1480                 $$ = new Musical_pitch;
1481                 $$->notename_i_ = ($1 - 1) % 7;
1482                 $$->octave_i_ = $1 > 7 ? 1 : 0;
1483                 $$->accidental_i_ = -1;
1484         }
1485         ;
1486
1487 chord_subtractions: 
1488         {
1489                 $$ = new Array<Musical_pitch>;
1490         } 
1491         | '^' chord_notes {
1492                 $$ = $2;
1493         }
1494         ;
1495
1496 /*
1497         UTILITIES
1498  */
1499 pitch_list:                     {
1500                 $$ = new Array<Musical_pitch>;
1501         }
1502         | pitch_list musical_pitch      {
1503                 $$->push (*$2);
1504                 delete $2;
1505         }
1506         ;
1507
1508
1509 int_list:
1510         /**/                    {
1511                 $$ = new Array<int>
1512         }
1513         | int_list int          {
1514                 $$->push ($2);          
1515         }
1516         ;
1517
1518 unsigned:
1519         UNSIGNED        {
1520                 $$ = $1;
1521         }
1522         | DIGIT {
1523                 $$ = $1;
1524         };
1525
1526 int:
1527         unsigned {
1528                 $$ = $1;
1529         }
1530         | '-' unsigned {
1531                 $$ = -$2;
1532         }
1533         | INT_IDENTIFIER        {
1534                 $$ = *$1->access_content_int (false);
1535         }
1536         ;
1537
1538
1539 string:
1540         STRING          {
1541                 $$ = $1;
1542         }
1543         | STRING_IDENTIFIER     {
1544                 $$ = $1->access_content_String (true);
1545         }
1546         | string '+' string {
1547                 *$$ += *$3;
1548                 delete $3;
1549         }
1550         ;
1551
1552
1553
1554
1555
1556
1557 %%
1558
1559 void
1560 My_lily_parser::set_yydebug (bool b)
1561 {
1562 #ifdef YYDEBUG
1563         yydebug = b;
1564 #endif
1565 }
1566 void
1567 My_lily_parser::do_yyparse ()
1568 {
1569         yyparse ((void*)this);
1570 }
1571
1572