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