]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
release: 1.1.24
[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     Array<String> * strvec;
95     Array<int> *intvec;
96     Notename_table *chordmodifiertab;
97     Duration *duration;
98     General_script_def * script;
99     Identifier *id;
100     Music *music;
101     Music_list *music_list;
102     Score *score;
103     Scope *scope;
104     Interval *interval;
105     Musical_req* musreq;
106     Music_output_def * outputdef;
107     Musical_pitch * pitch;
108     Midi_def* midi;
109     Moment *moment;
110     Note_req *notereq;
111     Notename_table *notenametab;
112     Paper_def *paper;
113     Real real;
114     Request * request;
115     Scalar *scalar;
116     Simultaneous_music *chord;
117     String *string;
118     Tempo_req *tempo;
119     Text_def * textdef;
120     Translator* trans;
121     char c;
122     const char *consstr;
123     int i;
124     int ii[10];
125 }
126 %{
127
128 int
129 yylex (YYSTYPE *s,  void * v_l)
130 {
131         My_lily_parser   *pars_l = (My_lily_parser*) v_l;
132         My_lily_lexer * lex_l = pars_l->lexer_p_;
133
134         lex_l->lexval_l = (void*) s;
135         return lex_l->yylex ();
136 }
137
138
139 %}
140
141 %pure_parser
142
143 /* tokens which are not keywords */
144
145 %token ABSDYNAMIC
146 %token ACCEPTS
147 %token ALTERNATIVE
148 %token BAR
149 %token CADENZA
150 %token CHORDMODIFIERS
151 %token CHORDS
152 %token CLEF
153 %token CM_T
154 %token CONSISTS
155 %token DURATION
156 %token EXTENDER
157 %token FONT
158 %token GROUPING
159 %token HEADER
160 %token IN_T
161 %token KEY
162 %token KEYSIGNATURE
163 %token LYRICS
164 %token MARK
165 %token MEASURES
166 %token MIDI
167 %token MM_T
168 %token MUSICAL_PITCH
169 %token NAME
170 %token NOTENAMES
171 %token NOTES
172 %token PAPER
173 %token PARTIAL
174 %token PENALTY
175 %token PROPERTY
176 %token PT_T
177 %token RELATIVE
178 %token REMOVE
179 %token REPEAT
180 %token SCM_T
181 %token SCMFILE
182 %token SCORE
183 %token SCRIPT
184 %token SHAPE
185 %token SKIP
186 %token SPANDYNAMIC
187 %token TEMPO
188 %token TIME_T
189 %token TIMES
190 %token TRANSLATOR
191 %token TRANSPOSE
192 %token TYPE
193 %token VERSION
194
195 /* escaped */
196 %token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
197
198 %type <i>       dots
199 %token <i>      DIGIT
200 %token <pitch>  NOTENAME_PITCH
201 %token <pitch>  TONICNAME_PITCH
202 %token <pitch>  CHORDMODIFIER_PITCH
203 %token <id>     DURATION_IDENTIFIER
204 %token <id>     IDENTIFIER
205 %token <id>     NOTENAME_TABLE_IDENTIFIER
206 %token <id>     MUSIC_IDENTIFIER
207 %token <id>     POST_REQUEST_IDENTIFIER
208 %token <id>     SCRIPT_IDENTIFIER
209 %token <id>     COMMAND_IDENTIFIER
210 %token <id>     REAL_IDENTIFIER
211 %token <id>     STRING_IDENTIFIER
212 %token <id>     TRANS_IDENTIFIER
213 %token <id>     INT_IDENTIFIER
214 %token <id>     SCORE_IDENTIFIER
215 %token <id>     MIDI_IDENTIFIER
216 %token <id>     PAPER_IDENTIFIER
217 %token <real>   REAL
218 %token <string> DURATION RESTNAME
219 %token <string> STRING
220 %token <i>      UNSIGNED
221
222
223 %type <outputdef> output_def
224 %type <scope>   mudela_header mudela_header_body
225 %type <i>       open_request_parens close_request_parens
226 %type <i>       sub_quotes sup_quotes
227 %type <music>   simple_element  request_chord command_element Simple_music  Composite_music 
228 %type <music>   Alternative_music Repeated_music
229 %type <i>       abbrev_type
230 %type <i>       int unsigned
231 %type <i>       script_dir
232 %type <i>       optional_modality
233 %type <id>      identifier_init simple_identifier_init block_identifier
234 %type <duration> steno_duration notemode_duration
235 %type <duration> entered_notemode_duration explicit_duration
236 %type <intvec>  intastint_list int_list
237
238 %type <pitch>   explicit_musical_pitch steno_musical_pitch musical_pitch absolute_musical_pitch
239 %type <pitch>   steno_tonic_pitch
240 %type <notereq> steno_notepitch
241 %type <pitch_arr>       pitch_list
242 %type <music>   chord notemode_chord
243 %type <pitch_arr>       chord_additions chord_subtractions
244 %type <pitch>   chord_addsub chord_note chord_inversion notemode_chord_inversion
245 %type <midi>    midi_block midi_body
246 %type <duration>        duration_length
247
248 %type <scalar>  scalar
249 %type <music>   Music  relative_music Sequential_music Simultaneous_music
250 %type <music>   property_def translator_change
251 %type <music_list> Music_list
252 %type <paper>   paper_block paper_def_body
253 %type <real>    real_expression real dimension
254 %type <request> abbrev_command_req
255 %type <request> post_request structured_post_request
256 %type <request> command_req verbose_command_req
257 %type <request> script_req  dynamic_req extender_req
258 %type <string>  string
259 %type <score>   score_block score_body
260 %type <intarr>  shape_array
261 %type <script>  script_definition script_body mudela_script gen_script_def
262 %type <textdef> text_def finger
263 %type <string>  script_abbreviation
264 %type <trans>   translator_spec translator_spec_body
265 %type <tempo>   tempo_request
266 %type <notenametab> notenames_body notenames_block chordmodifiers_block
267
268 %expect 7
269
270
271 %left '-' '+'
272 %left '*' '/'
273 %left UNARY_MINUS
274
275 %%
276
277 mudela: /* empty */
278         | mudela toplevel_expression {}
279         | mudela assignment { }
280         | mudela error
281         | mudela check_version { }
282         ;
283
284 toplevel_expression:
285         notenames_block                 {
286                 THIS->lexer_p_->set_notename_table ($1);
287         }
288         | chordmodifiers_block                  {
289                 THIS->lexer_p_->set_chordmodifier_table ($1);
290         }
291         | mudela_header {
292                 delete header_global_p;
293                 header_global_p = $1;
294         }
295         | score_block {
296                 score_global_array.push ($1);
297         }
298         | paper_block {
299                 Identifier * id = new
300                         Paper_def_identifier ($1, PAPER_IDENTIFIER);
301                 THIS->lexer_p_->set_identifier ("$defaultpaper", id)
302         }
303         | midi_block {
304                 Identifier * id = new
305                         Midi_def_identifier ($1, MIDI_IDENTIFIER);
306                 THIS->lexer_p_->set_identifier ("$defaultmidi", id)
307         }
308         | embedded_scm { 
309         }
310         ;
311
312 embedded_scm:
313         SCMFILE STRING ';' {
314                 read_lily_scm_file (*$2);
315                 delete $2;
316         }
317         | SCM_T STRING ';' {
318                 gh_eval_str ($2->ch_l ());
319                 delete $2;
320         };
321
322 check_version:
323         VERSION STRING ';'              {
324                 Mudela_version ver (*$2);
325                 if (!((ver >= oldest_version) && (ver <= version))) {
326                         if (THIS->ignore_version_b_) {
327                                 THIS->here_input ().error (_f ("incorrect mudela version: %s (%s, %s)", ver.str (), oldest_version.str (), version.str ()));
328                         } else {
329                                 THIS->fatal_error_i_ = 1;
330                                 THIS->parser_error (_f ("incorrect mudela version: %s (%s, %s)", ver.str (), oldest_version.str (), version.str ()));
331                         }
332                 }
333         }
334         ;
335
336
337 chordmodifiers_block:
338         CHORDMODIFIERS '{' notenames_body '}'  {  $$ = $3; }
339         ;
340
341
342 notenames_block:
343         NOTENAMES '{' notenames_body '}'  {  $$ = $3; }
344         ;
345
346
347
348 notenames_body:
349         /**/    {
350                 $$ = new Notename_table;
351         }
352         | NOTENAME_TABLE_IDENTIFIER     {
353                 $$ = $1-> access_content_Notename_table(true);
354         }
355         | notenames_body STRING '=' explicit_musical_pitch {
356                 (*$$)[*$2] = *$4;
357
358                 delete $4;
359                 delete $2;
360         }
361         ;
362
363 mudela_header_body:
364         {
365                 $$ = new Scope;
366                 THIS->lexer_p_-> scope_l_arr_.push ($$);
367         }
368         | mudela_header_body assignment ';' { 
369
370         }
371         ;
372
373 mudela_header:
374         HEADER '{' mudela_header_body '}'       {
375                 $$ = $3;
376                 THIS->lexer_p_-> scope_l_arr_.pop ();           
377         }
378         ;
379
380
381 /*
382         DECLARATIONS
383 */
384 assignment:
385         STRING {
386                 THIS->remember_spot ();
387         }
388         /* cont */ '=' identifier_init  {
389             THIS->lexer_p_->set_identifier (*$1, $4);
390             $4->init_b_ = THIS->init_parse_b_;
391             $4->set_spot (THIS->pop_spot ());
392         }
393         ;
394
395
396 simple_identifier_init: identifier_init
397         ;
398
399 identifier_init:
400         block_identifier
401         ;
402
403 block_identifier:
404         score_block {
405                 $$ = new Score_identifier ($1, SCORE_IDENTIFIER);
406
407         }
408         | chordmodifiers_block {
409                 $$ = new Notename_table_identifier ($1, NOTENAME_TABLE_IDENTIFIER);
410         }
411         | notenames_block {
412                 $$ = new Notename_table_identifier ($1, NOTENAME_TABLE_IDENTIFIER);
413         }
414         | paper_block {
415                 $$ = new Paper_def_identifier ($1, PAPER_IDENTIFIER);
416         }
417         | midi_block {
418                 $$ = new Midi_def_identifier ($1, MIDI_IDENTIFIER);
419
420         }
421         | translator_spec {
422                 $$ = new Translator_identifier ($1, TRANS_IDENTIFIER);
423         }
424         | Music  {
425                 $$ = new Music_identifier ($1, MUSIC_IDENTIFIER);
426         }
427
428         | post_request {
429                 $$ = new Request_identifier ($1, POST_REQUEST_IDENTIFIER);
430         }
431         | explicit_duration {
432                 $$ = new Duration_identifier ($1, DURATION_IDENTIFIER);
433         }
434         | real {
435                 $$ = new Real_identifier (new Real ($1), REAL_IDENTIFIER);
436         }
437         | string {
438                 $$ = new String_identifier ($1, STRING_IDENTIFIER);
439         }
440         | int   {
441                 $$ = new int_identifier (new int ($1), INT_IDENTIFIER);
442         }
443         | script_definition {
444                 $$ = new General_script_def_identifier ($1, SCRIPT_IDENTIFIER);
445
446         }
447         ;
448
449 translator_spec:
450         TRANSLATOR '{' translator_spec_body '}'
451                 { $$ = $3; }
452         ;
453
454 translator_spec_body:
455         TRANS_IDENTIFIER        {
456                 $$ = $1->access_content_Translator (true);
457                 $$-> set_spot (THIS->here_input ());
458         }
459         | TYPE STRING ';'       {
460                 Translator* t = get_translator_l (*$2);
461                 Translator_group * tg = dynamic_cast<Translator_group*> (t);
462
463                 if (!tg)
464                         THIS->parser_error (_("Need a translator group for a context"));
465                 
466                 t = t->clone ();
467                 t->set_spot (THIS->here_input ());
468                 $$ = t;
469                 delete $2;
470         }
471         | translator_spec_body STRING '=' simple_identifier_init ';'    { 
472                 Identifier* id = $4;
473                 String_identifier *s = dynamic_cast<String_identifier*> (id);
474                 Real_identifier *r= dynamic_cast<Real_identifier*>(id);
475                 int_identifier *i = dynamic_cast<int_identifier*> (id);
476         
477                 String str;
478                 if (s) str = *s->access_content_String (false); 
479                 if (i) str = to_str (*i->access_content_int (false));
480                 if (r) str = to_str (*r->access_content_Real (false));
481                 if (!s && !i && !r)
482                         THIS->parser_error (_("Wrong type for property value"));
483
484                 delete $4;
485                 $$->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_semicolon:
573         /* empty */
574         | ';'
575         ;
576
577 optional_dot:
578         /* empty */
579         | '.'
580         ;
581
582 paper_def_body:
583         /* empty */                     {
584                 Paper_def *p = THIS->default_paper_p ();
585                 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
586                 $$ = p;
587         }
588         | PAPER_IDENTIFIER optional_semicolon   {
589                 Paper_def *p = $1->access_content_Paper_def (true);
590                 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
591                 $$ = p;
592         }
593         | paper_def_body int '=' FONT STRING            { // ugh, what a syntax
594                 Lookup * l = new Lookup;
595                 l->font_name_ = *$5;
596                 delete $5;
597                 $$->set_lookup ($2, l);
598         }
599         | paper_def_body assignment ';' {
600
601         }
602         | paper_def_body translator_spec {
603                 $$->assign_translator ($2);
604         }
605         | paper_def_body SHAPE '=' shape_array ';' {
606                 $$->shape_int_a_ = *$4;
607                 delete $4;
608         }
609         | paper_def_body error {
610
611         }
612         ;
613
614
615 real:
616         real_expression         { $$ = $1; }
617         ;
618
619
620 dimension:
621         REAL CM_T       {
622                 $$ = $1 CM;
623         }
624         | REAL PT_T     {
625                 $$ = $1 PT;
626         }
627         | REAL IN_T     {
628                 $$ = $1 INCH;
629         }
630         | REAL MM_T     {
631                 $$ = $1 MM;
632         }
633         ;
634
635 real_expression:
636         REAL            {
637                 $$ = $1;
638         }
639         | dimension
640         | REAL_IDENTIFIER               {
641                 $$= *$1->access_content_Real (false);
642         }
643         | '-'  real_expression %prec UNARY_MINUS {
644                 $$ = -$2;
645         }
646         | real_expression '*' real_expression {
647                 $$ = $1 * $3;
648         }
649         | real_expression '/' real_expression {
650                 $$ = $1 / $3;
651         }
652         | real_expression '+' real_expression {
653                 $$ = $1  + $3;
654         }
655         | real_expression '-' real_expression {
656                 $$ = $1 - $3;
657         }
658         | '(' real_expression ')'       {
659                 $$ = $2;
660         }
661         ;
662                 
663
664 shape_array:
665         /* empty */ {
666                 $$ = new Array<Interval>;
667         }
668         | shape_array real real {
669                 $$->push(Interval($2, $2 + $3));
670         };
671
672 /*
673         MIDI
674 */
675 midi_block:
676         MIDI
677
678         '{' midi_body '}'       { $$ = $3; }
679         ;
680
681 midi_body: /* empty */          {
682                 $$ = THIS->default_midi_p ();
683         }
684         | MIDI_IDENTIFIER       {
685                 $$ = $1-> access_content_Midi_def (true);
686         }
687         | midi_body translator_spec     {
688                 $$-> assign_translator ($2);
689         }
690         | midi_body tempo_request ';' {
691                 $$->set_tempo ($2->dur_.length (), $2->metronome_i_);
692                 delete $2;
693         }
694         | midi_body error {
695
696         }
697         ;
698
699 tempo_request:
700         TEMPO steno_duration '=' unsigned       {
701                 $$ = new Tempo_req;
702                 $$->dur_ = *$2;
703                 delete $2;
704                 $$-> metronome_i_ = $4;
705         }
706         ;
707
708 Music_list: /* empty */ {
709                 $$ = new Music_list;
710         }
711         | Music_list Music {
712                 $$->add_music ($2);
713         }
714         | Music_list error {
715         }
716         ;
717
718
719 Music:
720         Simple_music
721         | Composite_music
722         ;
723
724 Alternative_music: {
725                 Music_list* m = new Music_list;
726                 $$ = new Sequential_music (m);
727         }
728         | ALTERNATIVE Simultaneous_music {
729                 $$ = $2;
730         }
731         | ALTERNATIVE Sequential_music {
732                 $$ = $2;
733         }
734         ;
735
736 Repeated_music: REPEAT unsigned Music Alternative_music {
737                 Music_sequence* m = dynamic_cast <Music_sequence*> ($4);
738                 assert (m);
739                 $$ = new Repeated_music ($3, $2 >? 1, m);
740         }
741         ;
742
743 Sequential_music: '{' Music_list '}'            {
744                 $$ = new Sequential_music ($2);
745         }
746         ;
747
748 Simultaneous_music: '<' Music_list '>'  {
749                 $$ = new Simultaneous_music ($2);
750         }
751         ;
752
753 Simple_music:
754         request_chord           { $$ = $1; }
755         | MUSIC_IDENTIFIER { $$ = $1->access_content_Music (true); }
756         | property_def
757         | translator_change
758         | Simple_music '*' unsigned '/' unsigned        {
759                 /* urg */
760                 $$ = new Compressed_music ($3, $5, $1);
761         }
762         | Simple_music '*' unsigned              {
763                 $$ = new Compressed_music ($3, 1, $1);
764         }
765         ;
766
767
768 Composite_music:
769         TYPE STRING Music       {
770                 $$ = $3;
771                 $$->translator_type_str_ = *$2;
772                 delete $2;
773         }
774         | TYPE STRING '=' STRING Music {
775                 $$ = $5;
776                 $$->translator_type_str_ = *$2;
777                 $$->translator_id_str_ = *$4;
778                 delete $2;
779                 delete $4;
780         }
781         | TIMES {
782                 THIS->remember_spot ();
783         }
784         /* CONTINUED */ 
785                 unsigned '/' unsigned Music     
786
787         {
788                 $$ = new Compressed_music ($3, $5, $6);
789                 $$->set_spot (THIS->pop_spot ());
790         }
791         | Repeated_music                { $$ = $1; }
792         | Simultaneous_music            { $$ = $1; }
793         | Sequential_music              { $$ = $1; }
794         | TRANSPOSE musical_pitch Music {
795                 $$ = new Transposed_music ($3, *$2);
796                 delete $2;
797         }
798         | TRANSPOSE steno_tonic_pitch Music {
799                 $$ = new Transposed_music ($3, *$2);
800                 delete $2;
801         }
802         | NOTES
803                 { THIS->lexer_p_->push_note_state (); }
804         Music
805                 { $$ = $3;
806                   THIS->lexer_p_->pop_state ();
807                 }
808         | CHORDS
809                 { THIS->lexer_p_->push_chord_state (); }
810         Music
811                 {
812                   $$ = $3;
813                   THIS->lexer_p_->pop_state ();
814         }
815         | LYRICS
816                 { THIS->lexer_p_->push_lyric_state (); }
817         Music
818                 {
819                   $$ = $3;
820                   THIS->lexer_p_->pop_state ();
821         }
822         | relative_music        { $$ = $1; }
823         ;
824
825 relative_music:
826         RELATIVE absolute_musical_pitch Music {
827                 $$ = new Relative_octave_music ($3, *$2);
828                 delete $2;
829         }
830         ;
831
832 translator_change:
833         TRANSLATOR STRING '=' STRING  {
834                 Change_translator * t = new Change_translator;
835                 t-> change_to_type_str_ = *$2;
836                 t-> change_to_id_str_ = *$4;
837
838                 $$ = t;
839                 $$->set_spot (THIS->here_input ());
840                 delete $2;
841                 delete $4;
842         }
843         ;
844
845 property_def:
846         PROPERTY STRING '.' STRING '=' scalar   {
847                 Translation_property *t = new Translation_property;
848                 t-> translator_type_str_ = *$2;
849                 t-> var_str_ = *$4;
850                 t-> value_ = *$6;
851                 $$ = t;
852                 $$->set_spot (THIS->here_input ());
853                 delete $2;
854                 delete $4;
855                 delete $6;
856         }
857         ;
858
859 scalar:
860         STRING          { $$ = new Scalar (*$1); delete $1; }
861         | int           { $$ = new Scalar ($1); }
862         ;
863
864
865 request_chord:
866         pre_requests simple_element post_requests       {
867                 THIS->add_requests ((Simultaneous_music*)$2);//ugh
868                 $$ = $2;
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         '|'                             {
889                 $$ = new Barcheck_req;
890         }
891         | COMMAND_IDENTIFIER    {
892                 $$ = $1->access_content_Request (true);
893         }
894         | '~'   {
895                 $$ = new Tie_req;
896         }
897         | '['           {
898                 Beam_req*b= new Beam_req;
899                 b->spantype_ = START;
900                 $$ =b;
901         }
902         | ']'           {
903                 Beam_req*b= new Beam_req;
904                 b->spantype_ = STOP;
905                 $$ = b;
906         }
907         ;
908
909
910 verbose_command_req:
911         BAR STRING                      {
912                 $$ = new Bar_req (*$2);
913                 delete $2;
914         }
915         | MARK STRING {
916                 $$ = new Mark_req (*$2);
917                 delete $2;
918         }
919         | MARK unsigned {
920                 $$ = new Mark_req (to_str ($2));
921         }
922         | TIME_T unsigned '/' unsigned  {
923                 Time_signature_change_req *m = new Time_signature_change_req;
924                 m->beats_i_ = $2;
925                 m->one_beat_i_=$4;
926                 $$ = m;
927         }
928         | PENALTY '=' int       {
929                 Break_req * b = new Break_req;
930                 b->penalty_i_ = $3;
931                 b-> set_spot (THIS->here_input ());
932                 $$ = b;
933         }
934         | SKIP duration_length {
935                 Skip_req * skip_p = new Skip_req;
936                 skip_p->duration_ = *$2;
937                 delete $2;
938                 $$ = skip_p;
939         }
940         | tempo_request {
941                 $$ = $1;
942         }
943         | CADENZA unsigned      {
944                 $$ = new Cadenza_req ($2);
945         }
946         | PARTIAL duration_length       {
947                 $$ = new Partial_measure_req ($2->length ());
948                 delete $2;
949         }
950         | CLEF STRING {
951                 $$ = new Clef_change_req (*$2);
952                 delete $2;
953         }
954         | KEY NOTENAME_PITCH optional_modality  {
955                 Key_change_req *key_p= new Key_change_req;
956                 key_p->pitch_arr_.push(*$2);
957                 key_p->ordinary_key_b_ = true;
958                 key_p->modality_i_ = $3;
959                 $$ = key_p;
960                 delete $2;
961         }
962         | KEYSIGNATURE pitch_list       {
963                 Key_change_req *key_p= new Key_change_req;
964                 key_p->pitch_arr_ = *$2;
965                 key_p->ordinary_key_b_ = false;
966                 $$ = key_p;
967                 delete $2;
968         }
969         | GROUPING intastint_list {
970                 $$ = get_grouping_req (*$2); delete $2;
971         }
972         ;
973
974 post_requests:
975         {
976                 /* something silly happened.  Junk this stuff*/
977                 if (!THIS->post_reqs.empty ())
978                 {
979                         warning ("Junking post-requests");
980                         THIS->post_reqs.clear ();
981                 }
982         }
983         | post_requests structured_post_request {
984                 $2->set_spot (THIS->here_input ());
985                 THIS->post_reqs.push ($2);
986         }
987         | post_requests close_request_parens    {
988                 Array<Request*>& r = *THIS->get_parens_request ($2);
989                 for (int i = 0; i < r.size (); i++ )
990                         r[i]->set_spot (THIS->here_input ());
991                 THIS->post_reqs.concat (r);
992                 delete &r;
993         }
994         ;
995
996 structured_post_request:
997         script_req
998         | post_request
999         ;
1000
1001 post_request:
1002         POST_REQUEST_IDENTIFIER {
1003                 $$ = (Request*)$1->access_content_Request (true);
1004         }
1005         | dynamic_req {
1006                 $$ = $1;
1007         }
1008         | abbrev_type   {
1009                 Abbreviation_req* a = new Abbreviation_req;
1010                 a->type_i_ = $1;
1011                 $$ = a;
1012         }
1013         | extender_req {
1014                 $$ = $1;
1015         }
1016         ;
1017
1018 optional_modality:
1019         /* empty */     {
1020                 $$ = 0;
1021         }
1022         | int   {
1023                 $$ = $1;
1024         }
1025         ;
1026
1027 sup_quotes:
1028         '\'' {
1029                 $$ = 1;
1030         }
1031         | sup_quotes '\'' {
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                 Extender_req * e_p = new Extender_req;
1124                 e_p->spantype_ = START;
1125                 $$ = e_p;
1126                 THIS->extender_req = e_p;
1127         };
1128
1129 dynamic_req:
1130         ABSDYNAMIC '{' unsigned '}'     {
1131                 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
1132                 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
1133                 $$ =ad_p;
1134         }
1135         | SPANDYNAMIC '{' int int '}' {
1136                 Span_dynamic_req * sp_p = new Span_dynamic_req;
1137                 sp_p->spantype_ = (Direction)$4;
1138                 sp_p-> dynamic_dir_  = (Direction)$3;
1139                 $$ = sp_p;
1140         }
1141         ;
1142
1143
1144
1145 close_request_parens:
1146         '('     {
1147                 $$='(';
1148         }
1149         | E_SMALLER {
1150                 $$ = '<';
1151         }
1152         | E_BIGGER {
1153                 $$ = '>';
1154         }
1155         ;
1156
1157
1158
1159 open_request_parens:
1160         E_EXCLAMATION   {
1161                 $$ = '!';
1162         }
1163         | ')'   {
1164                 $$=')';
1165         }
1166         ;
1167
1168
1169
1170 script_definition:
1171         SCRIPT '{' script_body '}'      { $$ = $3; }
1172         ;
1173
1174 script_body:
1175         STRING int int int int int              {
1176                 Script_def *s = new Script_def;
1177                 s->set_from_input (*$1,$2, $3,$4,$5, $6);
1178                 $$  = s;
1179                 delete $1;
1180         }
1181         ;
1182
1183 script_req:
1184         script_dir gen_script_def       {
1185                 Musical_script_req *m = new Musical_script_req;
1186                 $$ = m;
1187                 m->scriptdef_p_ = $2;
1188                 m->set_spot (THIS->here_input ());
1189                 if (!m->dir_)
1190                   m->dir_  = (Direction)$1;
1191         }
1192         ;
1193
1194 gen_script_def:
1195         text_def        { 
1196                 $$ = $1;
1197                 ((Text_def*) $$)->align_dir_ = LEFT; /* UGH */
1198         }
1199         | mudela_script { 
1200                 $$ = $1;
1201                 $$-> set_spot (THIS->here_input ());
1202         }
1203         | finger {
1204                 $$ = $1;
1205                 ((Text_def*)$$)->align_dir_ = RIGHT; /* UGH */
1206         }
1207         ;
1208
1209 text_def:
1210         string {
1211                 Text_def *t  = new Text_def;
1212                 $$ = t;
1213                 t->text_str_ = *$1;
1214                 delete $1;
1215                 $$->set_spot (THIS->here_input ());
1216         }
1217         ;
1218
1219 finger:
1220          DIGIT {
1221                 Text_def* t  = new Text_def;
1222                 $$ = t;
1223                 t->text_str_ = to_str ($1);
1224                 t->style_str_ = "finger";
1225                 $$->set_spot (THIS->here_input ());
1226         }
1227         ;
1228
1229 script_abbreviation:
1230         '^'             { $$ = get_scriptdef ('^'); }
1231         | '+'           { $$ = get_scriptdef ('+'); }
1232         | '-'           { $$ = get_scriptdef ('-'); }
1233         | '|'           { $$ = get_scriptdef ('|'); }
1234         | 'o'           { $$ = get_scriptdef ('o'); }
1235         | '>'           { $$ = get_scriptdef ('>'); }
1236         | '.'           {
1237                 $$ = get_scriptdef ('.');
1238         }
1239         ;
1240
1241 mudela_script:
1242         SCRIPT_IDENTIFIER               { $$ = $1->access_content_General_script_def (true); }
1243         | script_definition             { $$ = $1; }
1244         | script_abbreviation           {
1245                 $$ = THIS->lexer_p_->lookup_identifier (*$1)->access_content_General_script_def (true);
1246                 delete $1;
1247         }
1248         ;
1249
1250 script_dir:
1251         '_'     { $$ = -1; }
1252         | '^'   { $$ = 1; }
1253         | '-'   { $$ = 0; }
1254         ;
1255
1256 pre_requests:
1257         {
1258                 if (THIS->extender_req)
1259                   {
1260                     Extender_req * e_p = new Extender_req;
1261                     e_p->spantype_ = STOP;
1262                     THIS->pre_reqs.push (e_p);
1263                     THIS->extender_req = 0;
1264                   }
1265                         
1266         }
1267         | pre_requests open_request_parens {
1268
1269                 Array<Request*>& r = *THIS->get_parens_request ($2);
1270                 for (int i = 0; i < r.size (); i++ )
1271                         r[i]->set_spot (THIS->here_input ());
1272                 THIS->pre_reqs.concat (r);
1273                 delete &r;
1274         }
1275         ;
1276
1277 absolute_musical_pitch:
1278         steno_musical_pitch     {
1279                 $$ = $1;
1280         }
1281         ;
1282
1283 duration_length:
1284         steno_duration {
1285                 $$ = $1;
1286         }
1287         | duration_length '*' unsigned {
1288                 $$->plet_.iso_i_ *= $3;
1289         }
1290         | duration_length '/' unsigned {
1291                 $$->plet_.type_i_ *= $3;
1292         }
1293         ;
1294
1295 dots:
1296         '.'             { $$ = 1; }
1297         | dots '.'      { $$ ++; }
1298         ;
1299
1300 entered_notemode_duration:
1301         /* */           {
1302                 $$ = new Duration (THIS->default_duration_);
1303         }
1304         | dots          {
1305                 $$ = new Duration (THIS->default_duration_);
1306                 $$->dots_i_  = $1;
1307         }
1308         | steno_duration        {
1309                 THIS->set_last_duration ($1);
1310         }
1311         ;
1312
1313 notemode_duration:
1314         entered_notemode_duration {
1315                 $$ = $1;
1316         }
1317         ;
1318
1319 steno_duration:
1320         unsigned                {
1321                 $$ = new Duration;
1322                 if (!Duration::duration_type_b ($1))
1323                         THIS->parser_error (_f ("not a duration: %d", $1));
1324                 else {
1325                         $$->durlog_i_ = Duration_convert::i2_type ($1);
1326                      }
1327         }
1328         | DURATION_IDENTIFIER   {
1329                 $$ = $1->access_content_Duration (true);
1330         }
1331         | steno_duration '.'    {
1332                 $$->dots_i_ ++;
1333         }
1334         ;
1335
1336
1337 abbrev_type: 
1338         ':'     {
1339                 $$ =0;
1340         }
1341         | ':' unsigned {
1342                 if (!Duration::duration_type_b ($2))
1343                         THIS->parser_error (_f ("not a duration: %d", $2));
1344                 else if ($2 < 8)
1345                         THIS->parser_error (_ ("can't abbreviate"));
1346                 $$ = $2;
1347         }
1348         ;
1349
1350
1351
1352 simple_element:
1353         steno_notepitch notemode_duration  {
1354                 if (!THIS->lexer_p_->note_state_b ())
1355                         THIS->parser_error (_ ("have to be in Note mode for notes"));
1356                 $1->duration_ = *$2;
1357                 $$ = THIS->get_note_element ($1, $2);
1358         }
1359         | RESTNAME notemode_duration            {
1360                 $$ = THIS->get_rest_element (*$1, $2);
1361                 delete $1;  // delete notename
1362         }
1363         | MEASURES notemode_duration    {
1364                 Multi_measure_rest_req* m = new Multi_measure_rest_req;
1365                 m->duration_ = *$2;
1366                 delete $2;
1367
1368                 Simultaneous_music*velt_p = new Request_chord;
1369                 velt_p->set_spot (THIS->here_input ());
1370                 velt_p->add_music (m);
1371                 $$ = velt_p;
1372         }
1373         | STRING notemode_duration                      {
1374                 if (!THIS->lexer_p_->lyric_state_b ())
1375                         THIS->parser_error (_ ("have to be in Lyric mode for lyrics"));
1376                 $$ = THIS->get_word_element (*$1, $2);
1377                 delete $1;
1378         }
1379         | chord {
1380                 if (!THIS->lexer_p_->chord_state_b ())
1381                         THIS->parser_error (_ ("have to be in Chord mode for chords"));
1382                 $$ = $1;
1383         }
1384         | '@' notemode_chord '@' {
1385                 if (!THIS->lexer_p_->note_state_b ())
1386                         THIS->parser_error (_ ("have to be in Note mode for @chords"));
1387                 $$ = $2;
1388         }
1389         ;
1390
1391 chord:
1392         steno_tonic_pitch duration_length chord_additions chord_subtractions chord_inversion {
1393                 $$ = THIS->get_chord (*$1, $3, $4, $5, *$2);
1394         };
1395
1396 notemode_chord:
1397         steno_musical_pitch duration_length chord_additions chord_subtractions notemode_chord_inversion {
1398                 $$ = THIS->get_chord (*$1, $3, $4, $5, *$2);
1399         };
1400
1401 chord_additions: 
1402         {
1403                 $$ = new Array<Musical_pitch>;
1404         } 
1405         | chord_additions '-' chord_addsub {
1406                 $$ = $1;
1407                 $$->push (*$3);
1408         }
1409         ;
1410
1411 chord_addsub:
1412         chord_note optional_dot
1413         | CHORDMODIFIER_PITCH optional_dot
1414         ;
1415
1416 chord_inversion:
1417         {
1418                 $$ = 0;
1419         }
1420         | '/' steno_tonic_pitch {
1421                 $$ = $2
1422         }
1423         ;
1424
1425 notemode_chord_inversion:
1426         {
1427                 $$ = 0;
1428         }
1429         | '/' steno_musical_pitch {
1430                 $$ = $2
1431         }
1432         ;
1433
1434 chord_note:
1435         unsigned {
1436                 $$ = new Musical_pitch;
1437                 $$->notename_i_ = ($1 - 1) % 7;
1438                 $$->octave_i_ = $1 > 7 ? 1 : 0;
1439                 $$->accidental_i_ = 0;
1440         } 
1441         | unsigned '+' {
1442                 $$ = new Musical_pitch;
1443                 $$->notename_i_ = ($1 - 1) % 7;
1444                 $$->octave_i_ = $1 > 7 ? 1 : 0;
1445                 $$->accidental_i_ = 1;
1446         }
1447         | unsigned '-' {
1448                 $$ = new Musical_pitch;
1449                 $$->notename_i_ = ($1 - 1) % 7;
1450                 $$->octave_i_ = $1 > 7 ? 1 : 0;
1451                 $$->accidental_i_ = -1;
1452         }
1453         ;
1454
1455 chord_subtractions:
1456         {
1457                 $$ = new Array<Musical_pitch>;
1458         }
1459         | chord_subtractions '^' chord_addsub {
1460                 $$ = $1;
1461                 $$->push (*$3);
1462         }
1463         ;
1464
1465 /*
1466         UTILITIES
1467  */
1468 pitch_list:                     {
1469                 $$ = new Array<Musical_pitch>;
1470         }
1471         | pitch_list musical_pitch      {
1472                 $$->push (*$2);
1473                 delete $2;
1474         }
1475         ;
1476
1477
1478 int_list:
1479         /**/                    {
1480                 $$ = new Array<int>
1481         }
1482         | int_list int          {
1483                 $$->push ($2);          
1484         }
1485         ;
1486
1487 unsigned:
1488         UNSIGNED        {
1489                 $$ = $1;
1490         }
1491         | DIGIT {
1492                 $$ = $1;
1493         };
1494
1495 int:
1496         unsigned {
1497                 $$ = $1;
1498         }
1499         | '-' unsigned {
1500                 $$ = -$2;
1501         }
1502         | INT_IDENTIFIER        {
1503                 $$ = *$1->access_content_int (false);
1504         }
1505         ;
1506
1507
1508 string:
1509         STRING          {
1510                 $$ = $1;
1511         }
1512         | STRING_IDENTIFIER     {
1513                 $$ = $1->access_content_String (true);
1514         }
1515         | string '+' string {
1516                 *$$ += *$3;
1517                 delete $3;
1518         }
1519         ;
1520
1521
1522
1523
1524
1525
1526 %%
1527
1528 void
1529 My_lily_parser::set_yydebug (bool b)
1530 {
1531 #ifdef YYDEBUG
1532         yydebug = b;
1533 #endif
1534 }
1535 void
1536 My_lily_parser::do_yyparse ()
1537 {
1538         yyparse ((void*)this);
1539 }
1540
1541