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