]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
release: 1.1.33
[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                 { $$ = $3; }
448         ;
449
450 translator_spec_body:
451         TRANS_IDENTIFIER        {
452                 $$ = $1->access_content_Translator (true);
453                 $$-> set_spot (THIS->here_input ());
454         }
455         | TYPE STRING ';'       {
456                 Translator* t = get_translator_l (*$2);
457                 Translator_group * tg = dynamic_cast<Translator_group*> (t);
458
459                 if (!tg)
460                         THIS->parser_error (_("Need a translator group for a context"));
461                 
462                 t = t->clone ();
463                 t->set_spot (THIS->here_input ());
464                 $$ = t;
465                 delete $2;
466         }
467         | translator_spec_body STRING '=' identifier_init ';'   { 
468                 Identifier* id = $4;
469                 String_identifier *s = dynamic_cast<String_identifier*> (id);
470                 Real_identifier *r= dynamic_cast<Real_identifier*>(id);
471                 int_identifier *i = dynamic_cast<int_identifier*> (id);
472         
473                 String str;
474                 if (s) str = *s->access_content_String (false); 
475                 if (i) str = to_str (*i->access_content_int (false));
476                 if (r) str = to_str (*r->access_content_Real (false));
477                 if (!s && !i && !r)
478                         THIS->parser_error (_("Wrong type for property value"));
479
480                 delete $4;
481                 /* ugh*/
482                 Translator_group * tr = dynamic_cast<Translator_group*>($$);
483                 tr->set_property (*$2, str);
484         }
485         | translator_spec_body NAME STRING ';' {
486                 $$->type_str_ = *$3;
487                 delete $3;
488         }
489         | translator_spec_body CONSISTS STRING ';' {
490                 dynamic_cast<Translator_group*> ($$)-> set_element (*$3, true);
491                 delete $3;
492         }
493         | translator_spec_body ACCEPTS STRING ';' {
494                 dynamic_cast<Translator_group*> ($$)-> set_acceptor (*$3, true);
495                 delete $3;
496         }
497         | translator_spec_body REMOVE STRING ';' {
498                 dynamic_cast<Translator_group*> ($$)-> set_element (*$3, false);
499                 delete $3;
500         }
501         ;
502
503 /*
504         SCORE
505 */
506 score_block:
507         SCORE { THIS->remember_spot ();
508         }
509         /*cont*/ '{' score_body '}'     {
510                 $$ = $4;
511                 $$->set_spot (THIS->pop_spot ());
512                 if (!$$->def_p_arr_.size ())
513                         $$->add_output (THIS->default_paper_p ());
514
515         }
516         ;
517
518 score_body:             {
519                 $$ = new Score;
520         }
521         | SCORE_IDENTIFIER {
522                 $$ = $1->access_content_Score (true);
523         }
524         | score_body mudela_header      {
525                 $$->header_p_ = $2;
526         }
527         | score_body Music      {
528                 if ($$->music_p_)
529                         $2->warning (_ ("More than one music block"));  
530                 $$->music_p_ = $2;
531         }
532         | score_body output_def {
533                 $$->add_output ($2);
534         }
535         | score_body error {
536
537         }
538         ;
539
540 output_def:
541         paper_block {
542                 $$ = $1;
543         }
544         |  midi_block           {
545                 $$= $1;
546         }
547         ;
548
549 intastint_list:
550         /* */   { $$ =new Array<int>; }
551         | intastint_list int '*' int    {
552                 $$->push ($2); $$->push ($4);
553         }
554         | intastint_list int    {
555                 $$->push ($2); $$->push (1);
556         }
557         ;       
558
559
560 /*
561         PAPER
562 */
563 paper_block:
564         PAPER '{' paper_def_body '}'    { 
565                 $$ = $3;
566                 THIS-> lexer_p_->scope_l_arr_.pop ();
567         }
568         ;
569
570 optional_dot:
571         /* empty */
572         | '.'
573         ;
574
575 paper_def_body:
576         /* empty */                     {
577                 Paper_def *p = THIS->default_paper_p ();
578                 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
579                 $$ = p;
580         }
581         | PAPER_IDENTIFIER      {
582                 Paper_def *p = $1->access_content_Paper_def (true);
583                 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
584                 $$ = p;
585         }
586         | paper_def_body int '=' FONT STRING            { // ugh, what a syntax
587                 Lookup * l = new Lookup;
588                 l->font_name_ = *$5;
589                 delete $5;
590                 $$->set_lookup ($2, l);
591         }
592         | paper_def_body assignment ';' {
593
594         }
595         | paper_def_body translator_spec_block {
596                 $$->assign_translator ($2);
597         }
598         | paper_def_body SHAPE '=' shape_array ';' {
599                 $$->shape_int_a_ = *$4;
600                 delete $4;
601         }
602         | paper_def_body error {
603
604         }
605         ;
606
607
608 real:
609         real_expression         { $$ = $1; }
610         ;
611
612
613 real_with_dimension:
614         REAL CM_T       {
615                 $$ = $1 CM;
616         }
617         | REAL PT_T     {
618                 $$ = $1 PT;
619         }
620         | REAL IN_T     {
621                 $$ = $1 INCH;
622         }
623         | REAL MM_T     {
624                 $$ = $1 MM;
625         }
626         ;
627
628 real_expression:
629         REAL            {
630                 $$ = $1;
631         }
632         | real_with_dimension
633         | REAL_IDENTIFIER               {
634                 $$= *$1->access_content_Real (false);
635         }
636         | '-'  real_expression %prec UNARY_MINUS {
637                 $$ = -$2;
638         }
639         | real_expression '*' real_expression {
640                 $$ = $1 * $3;
641         }
642         | real_expression '/' real_expression {
643                 $$ = $1 / $3;
644         }
645         | real_expression '+' real_expression {
646                 $$ = $1  + $3;
647         }
648         | real_expression '-' real_expression {
649                 $$ = $1 - $3;
650         }
651         | '(' real_expression ')'       {
652                 $$ = $2;
653         }
654         ;
655                 
656
657 shape_array:
658         /* empty */ {
659                 $$ = new Array<Interval>;
660         }
661         | shape_array real real {
662                 $$->push(Interval($2, $2 + $3));
663         };
664
665 /*
666         MIDI
667 */
668 midi_block:
669         MIDI
670
671         '{' midi_body '}'       { $$ = $3; }
672         ;
673
674 midi_body: /* empty */          {
675                 $$ = THIS->default_midi_p ();
676         }
677         | MIDI_IDENTIFIER       {
678                 $$ = $1-> access_content_Midi_def (true);
679         }
680         | midi_body translator_spec_block       {
681                 $$-> assign_translator ($2);
682         }
683         | midi_body tempo_request ';' {
684                 $$->set_tempo ($2->dur_.length_mom (), $2->metronome_i_);
685                 delete $2;
686         }
687         | midi_body error {
688
689         }
690         ;
691
692 tempo_request:
693         TEMPO steno_duration '=' unsigned       {
694                 $$ = new Tempo_req;
695                 $$->dur_ = *$2;
696                 delete $2;
697                 $$-> metronome_i_ = $4;
698         }
699         ;
700
701 Music_list: /* empty */ {
702                 $$ = new Music_list;
703         }
704         | Music_list Music {
705                 $$->add_music ($2);
706         }
707         | Music_list error {
708         }
709         ;
710
711
712 Music:
713         Simple_music
714         | Composite_music
715         ;
716
717 Alternative_music: {
718                 Music_list* m = new Music_list;
719                 $$ = new Sequential_music (m);
720         }
721         | ALTERNATIVE Simultaneous_music {
722                 $$ = $2;
723         }
724         | ALTERNATIVE Sequential_music {
725                 $$ = $2;
726         }
727         ;
728
729 Repeated_music: REPEAT unsigned Music Alternative_music {
730                 Music_sequence* m = dynamic_cast <Music_sequence*> ($4);
731                 assert (m);
732                 $$ = new Repeated_music ($3, $2 >? 1, m);
733         }
734         ;
735
736 Sequential_music: '{' Music_list '}'            {
737                 $$ = new Sequential_music ($2);
738         }
739         ;
740
741 Simultaneous_music: '<' Music_list '>'  {
742                 $$ = new Simultaneous_music ($2);
743         }
744         ;
745
746 Simple_music:
747         request_chord           { $$ = $1; }
748         | MUSIC_IDENTIFIER { $$ = $1->access_content_Music (true); }
749         | property_def
750         | translator_change
751         | Simple_music '*' unsigned '/' unsigned        {
752                 /* urg */
753                 $$ = new Compressed_music ($3, $5, $1);
754         }
755         | Simple_music '*' unsigned              {
756                 $$ = new Compressed_music ($3, 1, $1);
757         }
758         ;
759
760
761 Composite_music:
762         TYPE STRING Music       {
763                 $$ = $3;
764                 $$->translator_type_str_ = *$2;
765                 delete $2;
766         }
767         | TYPE STRING '=' STRING Music {
768                 $$ = $5;
769                 $$->translator_type_str_ = *$2;
770                 $$->translator_id_str_ = *$4;
771                 delete $2;
772                 delete $4;
773         }
774         | TIMES {
775                 THIS->remember_spot ();
776         }
777         /* CONTINUED */ 
778                 unsigned '/' unsigned Music     
779
780         {
781                 $$ = new Compressed_music ($3, $5, $6);
782                 $$->set_spot (THIS->pop_spot ());
783         }
784         | Repeated_music                { $$ = $1; }
785         | Simultaneous_music            { $$ = $1; }
786         | Sequential_music              { $$ = $1; }
787         | TRANSPOSE musical_pitch Music {
788                 $$ = new Transposed_music ($3, *$2);
789                 delete $2;
790         }
791         | TRANSPOSE steno_tonic_pitch Music {
792                 $$ = new Transposed_music ($3, *$2);
793                 delete $2;
794         }
795         | NOTES
796                 { THIS->lexer_p_->push_note_state (); }
797         Music
798                 { $$ = $3;
799                   THIS->lexer_p_->pop_state ();
800                 }
801         | CHORDS
802                 { THIS->lexer_p_->push_chord_state (); }
803         Music
804                 {
805                   $$ = $3;
806                   THIS->lexer_p_->pop_state ();
807         }
808         | LYRICS
809                 { THIS->lexer_p_->push_lyric_state (); }
810         Music
811                 {
812                   $$ = $3;
813                   THIS->lexer_p_->pop_state ();
814         }
815         | relative_music        { $$ = $1; }
816         ;
817
818 relative_music:
819         RELATIVE absolute_musical_pitch Music {
820                 $$ = new Relative_octave_music ($3, *$2);
821                 delete $2;
822         }
823         ;
824
825 translator_change:
826         TRANSLATOR STRING '=' STRING  {
827                 Change_translator * t = new Change_translator;
828                 t-> change_to_type_str_ = *$2;
829                 t-> change_to_id_str_ = *$4;
830
831                 $$ = t;
832                 $$->set_spot (THIS->here_input ());
833                 delete $2;
834                 delete $4;
835         }
836         ;
837
838 property_def:
839         PROPERTY STRING '.' STRING '=' scalar   {
840                 Translation_property *t = new Translation_property;
841                 t-> translator_type_str_ = *$2;
842                 t-> var_str_ = *$4;
843                 t-> value_ = *$6;
844                 $$ = t;
845                 $$->set_spot (THIS->here_input ());
846                 delete $2;
847                 delete $4;
848                 delete $6;
849         }
850         ;
851
852 scalar:
853         STRING          { $$ = new Scalar (*$1); delete $1; }
854         | int           { $$ = new Scalar ($1); }
855         ;
856
857
858 request_chord:
859         pre_requests simple_element post_requests       {
860                 Music_sequence *l = dynamic_cast<Music_sequence*>($2);
861                 for (int i=0; i < $1->size(); i++)
862                         l->add_music ($1->elem(i));
863                 for (int i=0; i < $3->size(); i++)
864                         l->add_music ($3->elem(i));
865                 $$ = $2;
866                 
867         }
868         | command_element
869         ;
870
871 command_element:
872         command_req {
873                 $$ = new Request_chord;
874                 $$-> set_spot (THIS->here_input ());
875                 $1-> set_spot (THIS->here_input ());
876                 ((Simultaneous_music*)$$) ->add_music ($1);//ugh
877         }
878         ;
879
880 command_req:
881         abbrev_command_req
882         | verbose_command_req ';'       { $$ = $1; }
883         ;
884
885 abbrev_command_req:
886         extender_req {
887                 $$ = $1;
888         }
889         | '|'                           {
890                 $$ = new Barcheck_req;
891         }
892         | COMMAND_IDENTIFIER    {
893                 $$ = $1->access_content_Request (true);
894         }
895         | '~'   {
896                 $$ = new Tie_req;
897         }
898         | '['           {
899                 Beam_req*b= new Beam_req;
900                 b->spantype_ = START;
901                 $$ =b;
902         }
903         | ']'           {
904                 Beam_req*b= new Beam_req;
905                 b->spantype_ = STOP;
906                 $$ = b;
907         }
908         ;
909
910
911 verbose_command_req:
912         BAR STRING                      {
913                 $$ = new Bar_req (*$2);
914                 delete $2;
915         }
916         | MARK STRING {
917                 $$ = new Mark_req (*$2);
918                 delete $2;
919         }
920         | MARK unsigned {
921                 $$ = new Mark_req (to_str ($2));
922         }
923         | TIME_T unsigned '/' unsigned  {
924                 Time_signature_change_req *m = new Time_signature_change_req;
925                 m->beats_i_ = $2;
926                 m->one_beat_i_=$4;
927                 $$ = m;
928         }
929         | PENALTY '=' int       {
930                 Break_req * b = new Break_req;
931                 b->penalty_i_ = $3;
932                 b-> set_spot (THIS->here_input ());
933                 $$ = b;
934         }
935         | SKIP duration_length {
936                 Skip_req * skip_p = new Skip_req;
937                 skip_p->duration_ = *$2;
938                 delete $2;
939                 $$ = skip_p;
940         }
941         | tempo_request {
942                 $$ = $1;
943         }
944         | CADENZA unsigned      {
945                 $$ = new Cadenza_req ($2);
946         }
947         | PARTIAL duration_length       {
948                 $$ = new Partial_measure_req ($2->length_mom ());
949                 delete $2;
950         }
951         | CLEF STRING {
952                 $$ = new Clef_change_req (*$2);
953                 delete $2;
954         }
955         | KEY NOTENAME_PITCH optional_modality  {
956                 Key_change_req *key_p= new Key_change_req;
957                 key_p->pitch_arr_.push(*$2);
958                 key_p->ordinary_key_b_ = true;
959                 key_p->modality_i_ = $3;
960                 $$ = key_p;
961                 delete $2;
962         }
963         | KEYSIGNATURE pitch_list       {
964                 Key_change_req *key_p= new Key_change_req;
965                 key_p->pitch_arr_ = *$2;
966                 key_p->ordinary_key_b_ = false;
967                 $$ = key_p;
968                 delete $2;
969         }
970         | GROUPING intastint_list {
971                   Measure_grouping_req * mr_p = new Measure_grouping_req;
972                   for (int i=0; i < $2->size();) 
973                     {
974                       mr_p->elt_length_arr_.push (Moment (1, $2->elem(i++)));
975                       mr_p->beat_i_arr_.push ($2->elem(i++));
976                     }
977
978
979                 $$ = mr_p;
980                 delete $2;
981         }
982         ;
983
984 post_requests:
985         {
986                 $$ = new Link_array<Request>;
987         }
988         | post_requests structured_post_request {
989                 $2->set_spot (THIS->here_input ());
990                 $$->push ($2);
991         }
992         | post_requests close_request   {
993                 $$->push ($2);
994         }
995         ;
996
997 structured_post_request:
998         script_req
999         | post_request
1000         ;
1001
1002 post_request:
1003         POST_REQUEST_IDENTIFIER {
1004                 $$ = (Request*)$1->access_content_Request (true);
1005         }
1006         | dynamic_req {
1007                 $$ = $1;
1008         }
1009         | abbrev_type   {
1010                 Abbreviation_req* a = new Abbreviation_req;
1011                 a->type_i_ = $1;
1012                 $$ = a;
1013         }
1014
1015         ;
1016
1017 optional_modality:
1018         /* empty */     {
1019                 $$ = 0;
1020         }
1021         | int   {
1022                 $$ = $1;
1023         }
1024         ;
1025
1026 sup_quotes:
1027         '\'' {
1028                 $$ = 1;
1029         }
1030         | sup_quotes '\'' {
1031                 $$ ++;
1032         }
1033         ;
1034
1035 sub_quotes:
1036         ',' {
1037                 $$ = 1;
1038         }
1039         | sub_quotes ',' {
1040                 $$ ++ ;
1041         }
1042         ;
1043
1044 steno_musical_pitch:
1045         NOTENAME_PITCH  {
1046                 $$ = $1;
1047         }
1048         | NOTENAME_PITCH sup_quotes     {
1049                 $$ = $1;
1050                 $$->octave_i_ +=  $2;
1051         }
1052         | NOTENAME_PITCH sub_quotes      {
1053                 $$ = $1;
1054                 $$->octave_i_ += - $2;
1055         }
1056         ;
1057
1058 steno_tonic_pitch:
1059         TONICNAME_PITCH {
1060                 $$ = $1;
1061         }
1062         | TONICNAME_PITCH sup_quotes    {
1063                 $$ = $1;
1064                 $$->octave_i_ +=  $2;
1065         }
1066         | TONICNAME_PITCH sub_quotes     {
1067                 $$ = $1;
1068                 $$->octave_i_ += - $2;
1069         }
1070         ;
1071
1072 explicit_musical_pitch:
1073         MUSICAL_PITCH '{' int_list '}'  {/* ugh */
1074                 Array<int> &a = *$3;
1075                 ARRAY_SIZE(a,3);
1076                 $$ = new Musical_pitch;
1077                 $$->octave_i_ = a[0];
1078                 $$->notename_i_ = a[1];
1079                 $$->accidental_i_ = a[2];
1080                 delete &a;
1081         }
1082         ;
1083
1084 musical_pitch:
1085         steno_musical_pitch
1086         | explicit_musical_pitch
1087         ;
1088
1089 steno_notepitch:
1090         musical_pitch   {
1091                 $$ = new Note_req;
1092                 
1093                 $$->pitch_ = *$1;
1094                 delete $1;
1095         }
1096         | steno_notepitch  '!'          {
1097                 $$->forceacc_b_ = ! $$->forceacc_b_;
1098         }
1099         | steno_notepitch  '?'          {
1100                 $$->forceacc_b_ = ! $$->forceacc_b_;
1101                 $$->cautionary_b_ = ! $$->cautionary_b_;
1102         }
1103         ;
1104
1105
1106 explicit_duration:
1107         DURATION '{' int_list '}'       {
1108                 $$ = new Duration;
1109                 Array<int> &a = *$3;
1110                 ARRAY_SIZE(a,2);
1111                         
1112                 $$-> durlog_i_ = a[0];
1113                 $$-> dots_i_ = a[1];
1114
1115                 delete &a;              
1116         }
1117         ;
1118
1119 extender_req:
1120         EXTENDER {
1121                 if (!THIS->lexer_p_->lyric_state_b ())
1122                         THIS->parser_error (_ ("have to be in Lyric mode for lyrics"));
1123                 $$ = new Extender_req;
1124         }
1125         ;
1126
1127 dynamic_req:
1128         ABSDYNAMIC '{' STRING '}'       {
1129                 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
1130                 ad_p ->loudness_str_ = *$3;
1131                 delete $3;
1132                 $$ =ad_p;
1133         }
1134         | SPANDYNAMIC '{' int int '}' {
1135                 Span_dynamic_req * sp_p = new Span_dynamic_req;
1136                 sp_p-> dynamic_dir_  = Direction($3);
1137                 sp_p->spantype_ = Direction($4);
1138                 $$ = sp_p;
1139         }
1140         ;
1141
1142
1143 close_request:
1144         close_request_parens {
1145                 $$ = $1;
1146                 dynamic_cast<Span_req*> ($$)->spantype_ = START;
1147         }
1148         
1149 close_request_parens:
1150         '('     {
1151                 $$= new Slur_req;
1152         }
1153         | E_SMALLER {
1154                 Span_dynamic_req*s =new Span_dynamic_req;
1155                 $$ = s;
1156                 s->dynamic_dir_ = UP;
1157         }
1158         | E_BIGGER {
1159                 Span_dynamic_req*s =new Span_dynamic_req;
1160                 $$ = s;
1161                 s->dynamic_dir_ = DOWN;
1162         }
1163         ;
1164
1165
1166 open_request:
1167         open_request_parens {
1168                 $$ = $1;
1169                 dynamic_cast<Span_req*> ($$)->spantype_ = STOP;
1170         }
1171         ;
1172
1173 open_request_parens:
1174         E_EXCLAMATION   {
1175                 Span_dynamic_req *s =  new Span_dynamic_req;
1176                 s->dynamic_dir_ = SMALLER;
1177                 $$ = s;
1178                 
1179         }
1180         | ')'   {
1181                 $$= new Slur_req
1182         }
1183         ;
1184
1185
1186
1187 script_definition:
1188         SCRIPT '{' script_body '}'      { $$ = $3; }
1189         ;
1190
1191 script_body:
1192         STRING int int int int int              {
1193                 Script_def *s = new Script_def;
1194                 s->set_from_input (*$1,$2, $3,$4,$5, $6);
1195                 $$  = s;
1196                 delete $1;
1197         }
1198         ;
1199
1200 script_req:
1201         script_dir gen_script_def       {
1202                 Musical_script_req *m = new Musical_script_req;
1203                 $$ = m;
1204                 m->scriptdef_p_ = $2;
1205                 m->set_spot (THIS->here_input ());
1206                 if (!m->dir_)
1207                   m->dir_  = (Direction)$1;
1208         }
1209         ;
1210
1211 gen_script_def:
1212         text_def        { 
1213                 $$ = $1;
1214                 ((Text_def*) $$)->align_dir_ = LEFT; /* UGH */
1215         }
1216         | mudela_script { 
1217                 $$ = $1;
1218                 $$-> set_spot (THIS->here_input ());
1219         }
1220         | finger {
1221                 $$ = $1;
1222                 ((Text_def*)$$)->align_dir_ = RIGHT; /* UGH */
1223         }
1224         ;
1225
1226 text_def:
1227         string {
1228                 Text_def *t  = new Text_def;
1229                 $$ = t;
1230                 t->text_str_ = *$1;
1231                 delete $1;
1232                 $$->set_spot (THIS->here_input ());
1233         }
1234         ;
1235
1236 finger:
1237          DIGIT {
1238                 Text_def* t  = new Text_def;
1239                 $$ = t;
1240                 t->text_str_ = to_str ($1);
1241                 t->style_str_ = "finger";
1242                 $$->set_spot (THIS->here_input ());
1243         }
1244         ;
1245
1246 script_abbreviation:
1247         '^'             {
1248                 $$ = THIS->lexer_p_
1249                 ->lookup_identifier ("dash-hat")->access_content_String (true)
1250
1251         }
1252         | '+'           {
1253                 $$ = THIS->lexer_p_
1254                 ->lookup_identifier ("dash-plus")->access_content_String (true)
1255  }
1256         | '-'           {
1257                 $$ = THIS->lexer_p_
1258                 ->lookup_identifier ("dash-dash")->access_content_String (true)
1259  }
1260         | '|'           {
1261                 $$ = THIS->lexer_p_
1262                 ->lookup_identifier ("dash-bar")->access_content_String (true)
1263  }
1264         | '>'           {
1265                 $$ = THIS->lexer_p_
1266                 ->lookup_identifier ("dash-larger")->access_content_String (true)
1267  }
1268         | '.'           {
1269                 $$ = THIS->lexer_p_
1270                 ->lookup_identifier ("dash-dot")->access_content_String (true);
1271         }
1272         ;
1273
1274 mudela_script:
1275         SCRIPT_IDENTIFIER               { $$ = $1->access_content_General_script_def (true); }
1276         | script_definition             { $$ = $1; }
1277         | script_abbreviation           {
1278                 $$ = THIS->lexer_p_->lookup_identifier (*$1)->access_content_General_script_def (true);
1279                 delete $1;
1280         }
1281         ;
1282
1283 script_dir:
1284         '_'     { $$ = DOWN; }
1285         | '^'   { $$ = CENTER; }
1286         | '-'   { $$ = UP; }
1287         ;
1288
1289 pre_requests:
1290         {
1291                 $$ = new Link_array<Request>;
1292         }
1293         | pre_requests open_request {
1294                 $$->push ($2);
1295         }
1296         ;
1297
1298 absolute_musical_pitch:
1299         steno_musical_pitch     {
1300                 $$ = $1;
1301         }
1302         ;
1303
1304 duration_length:
1305         steno_duration {
1306                 $$ = $1;
1307         }
1308         | duration_length '*' unsigned {
1309                 $$->plet_.iso_i_ *= $3;
1310         }
1311         | duration_length '/' unsigned {
1312                 $$->plet_.type_i_ *= $3;
1313         }
1314         ;
1315
1316 dots:
1317         '.'             { $$ = 1; }
1318         | dots '.'      { $$ ++; }
1319         ;
1320
1321 entered_notemode_duration:
1322         /* */           {
1323                 $$ = new Duration (THIS->default_duration_);
1324         }
1325         | dots          {
1326                 $$ = new Duration (THIS->default_duration_);
1327                 $$->dots_i_  = $1;
1328         }
1329         | steno_duration        {
1330                 THIS->set_last_duration ($1);
1331         }
1332         ;
1333
1334 notemode_duration:
1335         entered_notemode_duration {
1336                 $$ = $1;
1337         }
1338         ;
1339
1340 steno_duration:
1341         unsigned                {
1342                 $$ = new Duration;
1343                 if (!Duration::duration_type_b ($1))
1344                         THIS->parser_error (_f ("not a duration: %d", $1));
1345                 else {
1346                         $$->durlog_i_ = Duration_convert::i2_type ($1);
1347                      }
1348         }
1349         | DURATION_IDENTIFIER   {
1350                 $$ = $1->access_content_Duration (true);
1351         }
1352         | steno_duration '.'    {
1353                 $$->dots_i_ ++;
1354         }
1355         ;
1356
1357
1358 abbrev_type: 
1359         ':'     {
1360                 $$ =0;
1361         }
1362         | ':' unsigned {
1363                 if (!Duration::duration_type_b ($2))
1364                         THIS->parser_error (_f ("not a duration: %d", $2));
1365                 else if ($2 < 8)
1366                         THIS->parser_error (_ ("can't abbreviate"));
1367                 $$ = $2;
1368         }
1369         ;
1370
1371
1372
1373 simple_element:
1374         steno_notepitch notemode_duration  {
1375                 if (!THIS->lexer_p_->note_state_b ())
1376                         THIS->parser_error (_ ("have to be in Note mode for notes"));
1377                 $1->duration_ = *$2;
1378                 $$ = THIS->get_note_element ($1, $2);
1379         }
1380         | RESTNAME notemode_duration            {
1381                 $$ = THIS->get_rest_element (*$1, $2);
1382                 delete $1;  // delete notename
1383         }
1384         | MEASURES notemode_duration    {
1385                 Multi_measure_rest_req* m = new Multi_measure_rest_req;
1386                 m->duration_ = *$2;
1387                 delete $2;
1388
1389                 Simultaneous_music*velt_p = new Request_chord;
1390                 velt_p->set_spot (THIS->here_input ());
1391                 velt_p->add_music (m);
1392                 $$ = velt_p;
1393         }
1394         | STRING notemode_duration                      {
1395                 if (!THIS->lexer_p_->lyric_state_b ())
1396                         THIS->parser_error (_ ("have to be in Lyric mode for lyrics"));
1397                 $$ = THIS->get_word_element (*$1, $2);
1398                 delete $1;
1399         }
1400         | chord {
1401                 if (!THIS->lexer_p_->chord_state_b ())
1402                         THIS->parser_error (_ ("have to be in Chord mode for chords"));
1403                 $$ = $1;
1404         }
1405         | '@' notemode_chord '@' {
1406                 if (!THIS->lexer_p_->note_state_b ())
1407                         THIS->parser_error (_ ("have to be in Note mode for @chords"));
1408                 $$ = $2;
1409         }
1410         ;
1411
1412 chord:
1413         steno_tonic_pitch notemode_duration chord_additions chord_subtractions chord_inversion {
1414                 $$ = THIS->get_chord (*$1, $3, $4, $5, *$2);
1415         };
1416
1417 notemode_chord:
1418         steno_musical_pitch notemode_duration chord_additions chord_subtractions notemode_chord_inversion {
1419                 $$ = THIS->get_chord (*$1, $3, $4, $5, *$2);
1420         };
1421
1422 chord_additions: 
1423         {
1424                 $$ = new Array<Musical_pitch>;
1425         } 
1426         | '-' chord_notes {
1427                 $$ = $2;
1428         }
1429         ;
1430
1431 chord_notes:
1432         {
1433                 $$ = new Array<Musical_pitch>;
1434         }
1435         | chord_notes chord_addsub {
1436                 $$ = $1;
1437                 $$->push (*$2);
1438         }
1439         ;
1440
1441 chord_addsub:
1442         chord_note optional_dot
1443         | CHORDMODIFIER_PITCH optional_dot
1444         ;
1445
1446 chord_inversion:
1447         {
1448                 $$ = 0;
1449         }
1450         | '/' steno_tonic_pitch {
1451                 $$ = $2
1452         }
1453         ;
1454
1455 notemode_chord_inversion:
1456         {
1457                 $$ = 0;
1458         }
1459         | '/' steno_musical_pitch {
1460                 $$ = $2
1461         }
1462         ;
1463
1464 chord_note:
1465         unsigned {
1466                 $$ = new Musical_pitch;
1467                 $$->notename_i_ = ($1 - 1) % 7;
1468                 $$->octave_i_ = $1 > 7 ? 1 : 0;
1469                 $$->accidental_i_ = 0;
1470         } 
1471         | unsigned '+' {
1472                 $$ = new Musical_pitch;
1473                 $$->notename_i_ = ($1 - 1) % 7;
1474                 $$->octave_i_ = $1 > 7 ? 1 : 0;
1475                 $$->accidental_i_ = 1;
1476         }
1477         | unsigned '-' {
1478                 $$ = new Musical_pitch;
1479                 $$->notename_i_ = ($1 - 1) % 7;
1480                 $$->octave_i_ = $1 > 7 ? 1 : 0;
1481                 $$->accidental_i_ = -1;
1482         }
1483         ;
1484
1485 chord_subtractions: 
1486         {
1487                 $$ = new Array<Musical_pitch>;
1488         } 
1489         | '^' chord_notes {
1490                 $$ = $2;
1491         }
1492         ;
1493
1494 /*
1495         UTILITIES
1496  */
1497 pitch_list:                     {
1498                 $$ = new Array<Musical_pitch>;
1499         }
1500         | pitch_list musical_pitch      {
1501                 $$->push (*$2);
1502                 delete $2;
1503         }
1504         ;
1505
1506
1507 int_list:
1508         /**/                    {
1509                 $$ = new Array<int>
1510         }
1511         | int_list int          {
1512                 $$->push ($2);          
1513         }
1514         ;
1515
1516 unsigned:
1517         UNSIGNED        {
1518                 $$ = $1;
1519         }
1520         | DIGIT {
1521                 $$ = $1;
1522         };
1523
1524 int:
1525         unsigned {
1526                 $$ = $1;
1527         }
1528         | '-' unsigned {
1529                 $$ = -$2;
1530         }
1531         | INT_IDENTIFIER        {
1532                 $$ = *$1->access_content_int (false);
1533         }
1534         ;
1535
1536
1537 string:
1538         STRING          {
1539                 $$ = $1;
1540         }
1541         | STRING_IDENTIFIER     {
1542                 $$ = $1->access_content_String (true);
1543         }
1544         | string '+' string {
1545                 *$$ += *$3;
1546                 delete $3;
1547         }
1548         ;
1549
1550
1551
1552
1553
1554
1555 %%
1556
1557 void
1558 My_lily_parser::set_yydebug (bool b)
1559 {
1560 #ifdef YYDEBUG
1561         yydebug = b;
1562 #endif
1563 }
1564 void
1565 My_lily_parser::do_yyparse ()
1566 {
1567         yyparse ((void*)this);
1568 }
1569
1570