]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
release: 1.3.147
[lilypond.git] / lily / parser.yy
1 %{ // -*-Fundamental-*-
2
3 /*
4   parser.yy -- Bison/C++ parser for lilypond
5
6   source file of the GNU LilyPond music typesetter
7
8   (c)  1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9            Jan Nieuwenhuizen <janneke@gnu.org>
10 */
11 #include <ctype.h>
12 #include <iostream.h>
13
14 #include "translator-def.hh"
15 #include "lily-guile.hh"
16 #include "change-iterator.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 "debug.hh"
24 #include "dimensions.hh"
25 #include "command-request.hh"
26 #include "musical-request.hh"
27 #include "my-lily-parser.hh"
28 #include "context-specced-music.hh"
29 #include "score.hh"
30 #include "music-list.hh"
31 #include "output-property-music-iterator.hh"
32 #include "property-iterator.hh"
33 #include "file-results.hh"
34 #include "input.hh"
35 #include "scope.hh"
36 #include "relative-music.hh"
37 #include "lyric-combine-music.hh"
38 #include "transposed-music.hh"
39 #include "time-scaled-music.hh"
40 #include "repeated-music.hh"
41 #include "lilypond-input-version.hh"
42 #include "grace-music.hh"
43 #include "part-combine-music.hh"
44 #include "scm-hash.hh"
45 #include "auto-change-iterator.hh"
46 #include "un-relativable-music.hh"
47 #include "chord.hh"
48
49
50
51 bool
52 regular_identifier_b (SCM id)
53 {
54   String str = ly_scm2string (id);
55   char const *s = str.ch_C() ;
56
57   bool v = true;
58   while (*s && v)
59    {
60         v = v && isalpha (*s);
61         s++;
62    }
63   return v;
64 }
65
66
67 bool
68 is_duration_b (int t)
69 {
70   return t && t == 1 << intlog2 (t);
71 }
72
73
74 void
75 set_music_properties (Music *p, SCM a)
76 {
77   for (SCM k = a; gh_pair_p (k); k = gh_cdr (k))
78         {
79         p->set_mus_property (gh_caar (k), gh_cdar (k));
80         }
81 }
82
83
84 // mmm JUNKME ?
85 Lilypond_version oldest_version ("1.3.59");
86
87 void
88 print_lilypond_versions (ostream &os)
89 {
90   os << _f ("Oldest supported input version: %s", oldest_version.str ()) 
91     << endl;
92 }
93
94
95 // needed for bison.simple's malloc () and free ()
96 #include <malloc.h>
97
98 #ifndef NDEBUG
99 #define YYDEBUG 1
100 #endif
101
102 #define YYERROR_VERBOSE 1
103
104 #define YYPARSE_PARAM my_lily_parser_l
105 #define YYLEX_PARAM my_lily_parser_l
106 #define THIS\
107         ((My_lily_parser *) my_lily_parser_l)
108
109 #define yyerror THIS->parser_error
110 #define ARRAY_SIZE(a,s)   if (a.size () != s) THIS->parser_error (_f ("Expecting %d arguments", s))
111
112 %}
113
114
115 %union {
116
117     Link_array<Request> *reqvec;
118
119     String *string; // needed by the lexer as temporary scratch area.
120     Music *music;
121     Score *score;
122     Scope *scope;
123     Scheme_hash_table *scmhash;
124     Music_output_def * outputdef;
125
126     Request * request;
127
128     /* We use SCMs to do strings, because it saves us the trouble of
129 deleting them.  Let's hope that a stack overflow doesnt trigger a move
130 of the parse stack onto the heap. */
131
132     SCM scm;
133
134     Tempo_req *tempo;
135     int i;
136 }
137 %{
138
139 int
140 yylex (YYSTYPE *s,  void * v_l)
141 {
142         My_lily_parser   *pars_l = (My_lily_parser*) v_l;
143         My_lily_lexer * lex_l = pars_l->lexer_p_;
144
145         lex_l->lexval_l = (void*) s;
146         return lex_l->yylex ();
147 }
148
149
150 %}
151
152 %pure_parser
153
154 /* tokens which are not keywords */
155 %token AUTOCHANGE
156 %token ALIAS
157 %token APPLY
158 %token ARPEGGIO
159 %token DYNAMICSCRIPT
160 %token ACCEPTS
161 %token ALTERNATIVE
162 %token BAR
163 %token BREATHE
164 %token CHORDMODIFIERS
165 %token CHORDS
166 %token CHAR_T
167 %token CLEF
168 %token CM_T
169 %token CONSISTS
170 %token DURATION
171 %token SEQUENTIAL
172 %token ELEMENTDESCRIPTIONS
173 %token SIMULTANEOUS
174 %token CONSISTSEND
175 %token DENIES
176 %token DURATION
177 %token EXTENDER
178 %token FONT
179 %token GLISSANDO
180 %token GRACE
181 %token HEADER
182 %token HYPHEN
183 %token IN_T
184 %token INVALID
185 %token KEY
186 %token LYRICS
187 %token MARK
188 %token MULTI_MEASURE_REST
189 %token MIDI
190 %token MM_T
191 %token PITCH
192 %token DEFAULT
193 %token NAME
194 %token PITCHNAMES
195 %token NOTES
196 %token PAPER
197 %token PARTIAL
198 %token PENALTY
199 %token PROPERTY
200 %token OVERRIDE SET REVERT 
201 %token PT_T
202 %token RELATIVE
203 %token REMOVE
204 %token REPEAT
205 %token ADDLYRICS
206 %token PARTCOMBINE
207 %token SCM_T
208 %token SCORE
209 %token SCRIPT
210 %token SKIP
211 %token SPANREQUEST
212 %token STYLESHEET
213 %token COMMANDSPANREQUEST
214 %token TEMPO
215 %token OUTPUTPROPERTY
216 %token TIME_T
217 %token TIMES
218 %token TRANSLATOR
219 %token TRANSPOSE
220 %token TYPE
221 %token UNSET
222 %token CONTEXT
223
224 /* escaped */
225 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
226 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET 
227
228 %type <i>       exclamations questions dots
229 %token <i>      DIGIT
230 %token <scm>    NOTENAME_PITCH
231 %token <scm>    TONICNAME_PITCH
232 %token <scm>    CHORDMODIFIER_PITCH
233 %token <scm>    DURATION_IDENTIFIER
234 %token <id>     IDENTIFIER
235
236
237 %token <scm>    SCORE_IDENTIFIER
238 %token <scm>    MUSIC_OUTPUT_DEF_IDENTIFIER
239
240 %token <scm>    NUMBER_IDENTIFIER
241 %token <scm>    REQUEST_IDENTIFIER
242 %token <scm>    MUSIC_IDENTIFIER TRANSLATOR_IDENTIFIER
243 %token <scm>    STRING_IDENTIFIER SCM_IDENTIFIER 
244 %token <scm>    RESTNAME
245 %token <scm>    STRING   
246 %token <scm>    SCM_T
247 %token <i>      UNSIGNED
248 %token <scm>   REAL
249
250 %type <outputdef> output_def
251 %type <scmhash>         lilypond_header lilypond_header_body
252 %type <request> open_request_parens close_request_parens open_request close_request
253 %type <request> request_with_dir request_that_take_dir verbose_request
254 %type <i>       sub_quotes sup_quotes
255 %type <music>   simple_element  request_chord command_element Simple_music  Composite_music 
256 %type <music>   Alternative_music Repeated_music
257 %type <i>       tremolo_type
258 %type <i>       bare_int  bare_unsigned
259 %type <i>       script_dir
260
261 %type <scm>     identifier_init 
262
263 %type <scm> steno_duration optional_notemode_duration multiplied_duration
264 %type <scm>  explicit_duration
265         
266 %type <reqvec>  pre_requests post_requests
267 %type <request> gen_text_def
268 %type <scm>   steno_pitch pitch absolute_pitch
269 %type <scm>   explicit_pitch steno_tonic_pitch
270
271 %type <scm>     chord_additions chord_subtractions chord_notes chord_step
272 %type <music>   chord
273 %type <scm>     chord_note chord_inversion chord_bass
274 %type <scm>     duration_length
275
276 %type <scm>  embedded_scm scalar
277 %type <music>   Music Sequential_music Simultaneous_music Music_sequence
278 %type <music>   relative_music re_rhythmed_music part_combined_music
279 %type <music>   property_def translator_change
280 %type <scm> Music_list
281 %type <outputdef>  music_output_def_body
282 %type <request> shorthand_command_req
283 %type <request> post_request 
284 %type <music> command_req verbose_command_req
285 %type <request> extender_req
286 %type <request> hyphen_req
287 %type <scm>     string bare_number number_expression
288
289 %type <score>   score_block score_body
290
291 %type <scm>     translator_spec_block translator_spec_body
292 %type <tempo>   tempo_request
293 %type <scm> notenames_body notenames_block chordmodifiers_block
294 %type <scm>     script_abbreviation
295
296
297
298 %left '-' '+'
299 %left '*' '/'
300 %left UNARY_MINUS
301
302 %%
303
304 lilypond:       /* empty */
305         | lilypond toplevel_expression {}
306         | lilypond assignment  { }
307         | lilypond error {
308                 THIS->error_level_i_  = 1;
309                 //THIS->parser_error (_ ("ly invalid"));
310         }
311         | lilypond INVALID      {
312                 THIS->error_level_i_  = 1;
313                 //THIS->parser_error (_ ("ly invalid"));
314         }
315         ;
316
317 toplevel_expression:
318         notenames_block                 {
319                 THIS->lexer_p_->pitchname_tab_ =  $1;
320         }
321         | chordmodifiers_block                  {
322                 THIS->lexer_p_->chordmodifier_tab_  = $1;
323         }
324         | lilypond_header {
325                 if (global_header_p)
326                         scm_unprotect_object (global_header_p->self_scm ());
327                 global_header_p = $1;
328         }
329         | score_block {
330                 score_global_array.push ($1);
331                 
332         }
333         | output_def {
334                 if (dynamic_cast<Paper_def*> ($1))
335                         THIS->lexer_p_->set_identifier ("$defaultpaper", $1->self_scm ());
336                 else if (dynamic_cast<Midi_def*> ($1))
337                         THIS->lexer_p_->set_identifier ("$defaultmidi", $1->self_scm ());
338         }
339         | embedded_scm {
340                 // junk value
341         }       
342         ;
343
344 embedded_scm:
345         SCM_T
346         | SCM_IDENTIFIER 
347         ;
348
349
350 chordmodifiers_block:
351         CHORDMODIFIERS notenames_body   {  $$ = $2; }
352         ;
353
354
355 notenames_block:
356         PITCHNAMES notenames_body   {  $$ = $2; }
357         ;
358
359
360
361 notenames_body:
362         embedded_scm    {
363           int i = scm_ilength ($1);
364
365           SCM tab = scm_make_vector (gh_int2scm (i), SCM_EOL);
366           for (SCM s = $1; gh_pair_p (s); s = gh_cdr (s)) {
367                 SCM pt = gh_cdar (s);
368                 if (!unsmob_pitch (pt))
369                         THIS->parser_error ("Need pitch object.");
370                 else
371                         scm_hashq_set_x (tab, gh_caar (s), pt);
372           }
373
374           $$ = tab;
375         }
376         ;
377
378 lilypond_header_body:
379         {
380                 $$ = new Scheme_hash_table;
381                 
382                 Scope *sc = new Scope ($$);
383                 THIS->lexer_p_-> scope_l_arr_.push (sc);
384         }
385         | lilypond_header_body assignment  { 
386
387         }
388         ;
389
390 lilypond_header:
391         HEADER '{' lilypond_header_body '}'     {
392                 $$ = $3;
393                 delete THIS->lexer_p_-> scope_l_arr_.pop ();
394         }
395         ;
396
397
398 /*
399         DECLARATIONS
400 */
401 assignment:
402         STRING {
403                 THIS->remember_spot ();
404         }
405         /* cont */ '=' identifier_init  {
406                 if (! regular_identifier_b ($1))
407                         THIS->parser_error (_ ("Identifier should have  alphabetic characters only"));
408
409                 THIS->lexer_p_->set_identifier (ly_scm2string ($1), $4);
410
411 /*
412  TODO: devise standard for protection in parser.
413
414   The parser stack lives on the C-stack, which means that
415 all objects can be unprotected as soon as they're here.
416
417 */
418         /*
419                 Should find generic way of associating input with objects.
420         */
421                 THIS->pop_spot ();
422         }
423         ;
424
425
426
427 identifier_init:
428         score_block {
429                 $$ = $1->self_scm ();
430                 scm_unprotect_object ($$);
431         }
432         | output_def {
433                 $$ = $1->self_scm ();
434                 scm_unprotect_object ($$);
435         }
436         | translator_spec_block {
437                 $$ = $1;
438         }
439         | Music  {
440                 $$ = $1->self_scm ();
441                 scm_unprotect_object ($$);
442         }
443         | post_request {
444                 $$ = $1->self_scm ();
445                 scm_unprotect_object ($$);
446         }
447         | explicit_duration {
448                 $$ = $1;
449         }
450         | number_expression {
451                 $$ = $1;
452         }
453         | string {
454                 $$ = $1;
455         }
456         | embedded_scm  {
457                 $$ = $1;
458         }
459         ;
460
461 translator_spec_block:
462         TRANSLATOR '{' translator_spec_body '}'
463                 {
464                 $$ = $3;
465         }
466         ;
467
468 translator_spec_body:
469         TRANSLATOR_IDENTIFIER   {
470                 $$ = unsmob_translator_def ($1)->clone_scm ();
471                 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
472         }
473         | TYPE STRING   {
474                 $$ = Translator_def::make_scm ();
475                 Translator_def*td =  unsmob_translator_def ($$);
476                 td->translator_group_type_ = $2;
477                 td->set_spot (THIS->here_input ());
478         }
479         | translator_spec_body STRING '=' embedded_scm                  {
480                 unsmob_translator_def ($$)->add_property_assign ($2, $4);
481         }
482         | translator_spec_body STRING OVERRIDE embedded_scm '=' embedded_scm {
483                 unsmob_translator_def ($$)
484                         ->add_push_property (scm_string_to_symbol ($2), $4, $6);
485         }
486         | translator_spec_body STRING REVERT embedded_scm  {
487           unsmob_translator_def ($$)->add_pop_property (
488                 scm_string_to_symbol ($2), $4);
489         }
490         | translator_spec_body NAME STRING  {
491                 unsmob_translator_def ($$)->type_name_ = $3;
492         }
493         | translator_spec_body CONSISTS STRING  {
494                 unsmob_translator_def ($$)->add_element ($3);
495         }
496         | translator_spec_body ALIAS STRING  {
497                 Translator_def*td = unsmob_translator_def ($$);
498                 td->type_aliases_ = gh_cons ($3, td->type_aliases_);
499         }
500         | translator_spec_body ELEMENTDESCRIPTIONS embedded_scm {
501                 for (SCM p = $3; gh_pair_p (p); p = gh_cdr (p))
502                         unsmob_translator_def ($$)
503                         ->add_property_assign (scm_symbol_to_string (gh_caar (p)), gh_cdar (p));
504
505         }
506         | translator_spec_body CONSISTSEND STRING  {
507                 unsmob_translator_def ($$)->add_last_element ( $3);
508         }
509         | translator_spec_body ACCEPTS STRING  {
510                 unsmob_translator_def ($$)->set_acceptor ($3,true);
511         }
512         | translator_spec_body DENIES STRING  {
513                 unsmob_translator_def ($$)->set_acceptor ($3,false);
514         }
515         | translator_spec_body REMOVE STRING  {
516                 unsmob_translator_def ($$)->remove_element ($3);
517         }
518         ;
519
520 /*
521         SCORE
522 */
523 score_block:
524         SCORE { 
525                 THIS->remember_spot ();
526         }
527         /*cont*/ '{' score_body '}'     {
528                 THIS->pop_spot ();
529                 $$ = $4;
530                 if (!$$->def_p_arr_.size ())
531                 {
532                   Music_output_def *id =
533                         unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
534                   $$->add_output (id ? id->clone () :  new Paper_def );
535                 }
536         }
537         ;
538
539 score_body:
540         Music   {
541                 $$ = new Score;
542         
543                 $$->set_spot (THIS->here_input ());
544                 SCM m = $1->self_scm ();
545                 scm_unprotect_object (m);
546                 $$->music_ = m;
547         }
548         | SCORE_IDENTIFIER {
549                 $$ = new Score (*unsmob_score ($1));
550                 $$->set_spot (THIS->here_input ());
551         }
552         | score_body lilypond_header    {
553                 scm_unprotect_object ($2->self_scm ()); 
554                 $$->header_p_ = $2;
555         }
556         | score_body output_def {
557                 $$->add_output ($2);
558         }
559         | score_body error {
560
561         }
562         ;
563
564
565 /*
566         MIDI
567 */
568 output_def:
569         music_output_def_body '}' {
570                 $$ = $1;
571                 THIS-> lexer_p_-> scope_l_arr_.pop ();
572         }
573         ;
574
575 music_output_def_body:
576         MIDI '{'    {
577            Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultmidi"));
578
579                 
580          Midi_def* p =0;
581         if (id)
582                 p = dynamic_cast<Midi_def*> (id->clone ());
583         else
584                 p = new Midi_def;
585
586          $$ = p;
587          THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
588         }
589         | PAPER '{'     {
590                 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
591                   Paper_def *p = 0;
592                 if (id)
593                         p = dynamic_cast<Paper_def*> (id->clone ());
594                 else
595                         p = new Paper_def;
596                 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
597                 $$ = p;
598         }
599         | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER         {
600                 Music_output_def *p = unsmob_music_output_def ($3);
601                 p = p->clone ();
602                 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
603                 $$ = p;
604         }
605         | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER  {
606                 Music_output_def *p = unsmob_music_output_def ($3);
607                 p = p->clone ();
608
609                 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
610                 $$ = p;
611         }
612         | music_output_def_body assignment  {
613
614         }
615         | music_output_def_body translator_spec_block   {
616                 $$->assign_translator ($2);
617         }
618         | music_output_def_body STYLESHEET embedded_scm {
619                 dynamic_cast<Paper_def*> ($$)-> style_sheet_ = $3;
620         }
621         | music_output_def_body tempo_request  {
622                 /*
623                         junk this ? there already is tempo stuff in
624                         music.
625                 */
626                 int m = gh_scm2int ( $2->get_mus_property ("metronome-count"));
627                 Duration *d = unsmob_duration ($2->get_mus_property ("duration"));
628                 dynamic_cast<Midi_def*> ($$)->set_tempo (d->length_mom (), m);
629         }
630         | music_output_def_body error {
631
632         }
633         ;
634
635 tempo_request:
636         TEMPO steno_duration '=' bare_unsigned  {
637                 $$ = new Tempo_req;
638                 $$->set_mus_property ("duration", $2);
639                 $$->set_mus_property ("metronome-count", gh_int2scm ( $4));
640         }
641         ;
642
643 Music_list: /* empty */ {
644                 $$ = gh_cons (SCM_EOL, SCM_EOL);
645         }
646         | Music_list Music {
647                 SCM s = $$;
648                 SCM c = gh_cons ($2->self_scm (), SCM_EOL);
649                 scm_unprotect_object ($2->self_scm ()); /* UGH */
650                 if (gh_pair_p (gh_cdr (s)))
651                         gh_set_cdr_x (gh_cdr (s), c); /* append */
652                 else
653                         gh_set_car_x (s, c); /* set first cons */
654                 gh_set_cdr_x (s, c) ;  /* remember last cell */ 
655         }
656         | Music_list error {
657         }
658         ;
659
660
661 Music:
662         Simple_music
663         | Composite_music
664         ;
665
666 Alternative_music:
667         /* empty */ {
668                 $$ = 0;
669         }
670         | ALTERNATIVE Music_sequence {
671                 $$ = $2;
672                 $2->set_spot (THIS->here_input ());
673         }
674         ;
675
676
677
678
679 Repeated_music:
680         REPEAT string bare_unsigned Music Alternative_music
681         {
682                 Music_sequence* alts = dynamic_cast <Music_sequence*> ($5);
683                 if (alts && $3 < alts->length_i ())
684                         $5->origin ()->warning (_ ("More alternatives than repeats.  Junking excess alternatives."));
685                 Music *beg = $4;
686                 int times = $3;
687
688                 Repeated_music * r = new Repeated_music (SCM_EOL);
689
690                 if (beg)
691                         {
692                         r-> set_mus_property ("body", beg->self_scm ());
693                         scm_unprotect_object (beg->self_scm ());
694                         }
695                 r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
696
697                 if (alts)
698                         {
699                         alts->truncate (times);
700                         r-> set_mus_property ("alternatives", alts->self_scm ());
701                         scm_unprotect_object (alts->self_scm ());  
702                         }
703                 SCM func = scm_eval2 (ly_symbol2scm ("repeat-name-to-ctor"), SCM_EOL);
704                 SCM result = gh_call1 (func, $2);
705
706                 set_music_properties (r, result);
707
708                 r->set_spot (*$4->origin ());
709                 $$ = r;
710         }
711         ;
712
713 Music_sequence: '{' Music_list '}'      {
714                 $$ = new Music_sequence (SCM_EOL);
715                 $$->set_mus_property ("elements", gh_car ($2));
716         }
717         ;
718
719 Sequential_music:
720         SEQUENTIAL '{' Music_list '}'           {
721                 $$ = new Sequential_music (SCM_EOL);
722                 $$->set_mus_property ("elements", gh_car ($3));
723         }
724         | '{' Music_list '}'            {
725                 $$ = new Sequential_music (SCM_EOL);
726                 $$->set_mus_property ("elements", gh_car ($2));
727         }
728         ;
729
730 Simultaneous_music:
731         SIMULTANEOUS '{' Music_list '}'{
732                 $$ = new Simultaneous_music (SCM_EOL);
733                 $$->set_mus_property ("elements", gh_car ($3));
734
735         }
736         | '<' Music_list '>'    {
737                 $$ = new Simultaneous_music (SCM_EOL);
738                 $$->set_mus_property ("elements", gh_car ($2));
739         }
740         ;
741
742 Simple_music:
743         request_chord           { $$ = $1; }
744         | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm     {
745                 SCM pred = $2;
746                 if (!gh_symbol_p ($3))
747                 {
748                         THIS->parser_error (_ ("Second argument must be a symbol")); 
749                 }
750                 /*hould check # args */
751                 if (!gh_procedure_p (pred))
752                 {
753                         THIS->parser_error (_ ("First argument must be a procedure taking 1 argument"));
754                 }
755
756                 Music *m = new Music (SCM_EOL);
757                 m->set_mus_property ("predicate", pred);
758                 m->set_mus_property ("symbol", $3);
759                 m->set_mus_property ("value",  $5);
760                 m->set_mus_property ("iterator-ctor",
761                 Output_property_music_iterator::constructor_cxx_function);
762
763                 $$ = m;
764         }
765         | MUSIC_IDENTIFIER {
766                 $$ = unsmob_music ($1)->clone ();
767         }
768         | property_def
769         | translator_change
770         ;
771
772
773 Composite_music:
774         CONTEXT STRING Music    {
775                 Context_specced_music *csm =  new Context_specced_music (SCM_EOL);
776                 csm->set_mus_property ("element", $3->self_scm ());
777                 scm_unprotect_object ($3->self_scm ());
778
779                 csm->set_mus_property ("context-type",$2);
780                 csm->set_mus_property ("context-id", ly_str02scm (""));
781
782                 $$ = csm;
783         }
784         | AUTOCHANGE STRING Music       {
785                 Music * chm = new Music_wrapper (SCM_EOL);
786                 chm->set_mus_property ("element", $3->self_scm ());
787                 chm->set_mus_property ("iterator-ctor", Auto_change_iterator::constructor_cxx_function);
788
789                 scm_unprotect_object ($3->self_scm ());
790                 chm->set_mus_property ("what", $2); 
791
792                 $$ = chm;
793                 chm->set_spot (*$3->origin ());
794         }
795         | GRACE Music {
796                 $$ = new Grace_music (SCM_EOL);
797                 $$->set_mus_property ("element", $2->self_scm ());
798                 scm_unprotect_object ($2->self_scm ());
799
800         }
801         | CONTEXT string '=' string Music {
802                 Context_specced_music *csm =  new Context_specced_music (SCM_EOL);
803                 csm->set_mus_property ("element", $5->self_scm ());
804                 scm_unprotect_object ($5->self_scm ());
805
806                 csm->set_mus_property ("context-type", $2);
807                 csm->set_mus_property ("context-id", $4);
808
809                 $$ = csm;
810         }
811         | TIMES {
812                 THIS->remember_spot ();
813         }
814         /* CONTINUED */ 
815                 bare_unsigned '/' bare_unsigned Music   
816
817         {
818                 int n = $3; int d = $5;
819                 Music *mp = $6;
820                 $$ = new Time_scaled_music (SCM_EOL);
821                 $$->set_spot (THIS->pop_spot ());
822
823
824                 $$->set_mus_property ("element", mp->self_scm ());
825                 scm_unprotect_object (mp->self_scm ());
826                 $$->set_mus_property ("numerator", gh_int2scm (n));
827                 $$->set_mus_property ("denominator", gh_int2scm (d));
828                 $$->compress (Moment (n,d));
829
830         }
831         | Repeated_music                { $$ = $1; }
832         | Simultaneous_music            { $$ = $1; }
833         | Sequential_music              { $$ = $1; }
834         | TRANSPOSE pitch Music {
835                 $$ = new Transposed_music (SCM_EOL);
836                 Music *p = $3;
837                 Pitch pit = *unsmob_pitch ($2);
838
839                 p->transpose (pit);
840                 $$->set_mus_property ("element", p->self_scm ());
841                 scm_unprotect_object (p->self_scm ());
842         }
843         | TRANSPOSE steno_tonic_pitch Music {
844                 $$ = new Transposed_music (SCM_EOL);
845                 Music *p = $3;
846                 Pitch pit = *unsmob_pitch ($2);
847
848                 p->transpose (pit);
849                 $$->set_mus_property ("element", p->self_scm ());
850                 scm_unprotect_object (p->self_scm ());
851         
852         }
853         | APPLY embedded_scm Music  {
854                 SCM ret = gh_call1 ($2, $3->self_scm ());
855                 Music *m = unsmob_music (ret);
856                 if (!m) {
857                         THIS->parser_error ("\\apply must return a Music");
858                         m = new Music (SCM_EOL);
859                         }
860                 $$ = m;
861         }
862         | NOTES
863                 { THIS->lexer_p_->push_note_state (); }
864         Music
865                 { $$ = $3;
866                   THIS->lexer_p_->pop_state ();
867                 }
868         | CHORDS
869                 { THIS->lexer_p_->push_chord_state (); }
870         Music
871                 {
872                   Music * chm = new Un_relativable_music ;
873                   chm->set_mus_property ("element", $3->self_scm ());
874                   $$ = chm;
875
876                   THIS->lexer_p_->pop_state ();
877         }
878         | LYRICS
879                 { THIS->lexer_p_->push_lyric_state (); }
880         Music
881                 {
882                   $$ = $3;
883                   THIS->lexer_p_->pop_state ();
884         }
885         | relative_music        { $$ = $1; }
886         | re_rhythmed_music     { $$ = $1; } 
887         | part_combined_music   { $$ = $1; } 
888         ;
889
890 relative_music:
891         RELATIVE absolute_pitch Music {
892                 Music * p = $3;
893                 Pitch pit = *unsmob_pitch ($2);
894                 $$ = new Relative_octave_music (SCM_EOL);
895
896                 $$->set_mus_property ("element", p->self_scm ());
897                 scm_unprotect_object (p->self_scm ());
898
899                 $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
900
901         }
902         ;
903
904 re_rhythmed_music:
905         ADDLYRICS Music Music {
906           Lyric_combine_music * l = new Lyric_combine_music (SCM_EOL);
907           l->set_mus_property ("music", $2->self_scm ());
908           l->set_mus_property ("lyrics", $3->self_scm ());
909           scm_unprotect_object ($3->self_scm ());
910           scm_unprotect_object ($2->self_scm ());
911           $$ = l;
912         }
913         ;
914
915 part_combined_music:
916         PARTCOMBINE STRING Music Music {
917                 Part_combine_music * p = new Part_combine_music (SCM_EOL);
918
919                 p->set_mus_property ("what", $2);
920                 p->set_mus_property ("one", $3->self_scm ());
921                 p->set_mus_property ("two", $4->self_scm ());  
922
923                 scm_unprotect_object ($3->self_scm ());
924                 scm_unprotect_object ($4->self_scm ());  
925
926
927                 $$ = p;
928         }
929         ;
930
931 translator_change:
932         TRANSLATOR STRING '=' STRING  {
933                 Music * t = new Music (SCM_EOL);
934                 t->set_mus_property ("iterator-ctor",
935                         Change_iterator::constructor_cxx_function);
936                 t-> set_mus_property ("change-to-type", $2);
937                 t-> set_mus_property ("change-to-id", $4);
938
939                 $$ = t;
940                 $$->set_spot (THIS->here_input ());
941         }
942         ;
943
944 property_def:
945         PROPERTY STRING '.' STRING '='  scalar {
946                 Music *t = new Music (SCM_EOL);
947
948                 t->set_mus_property ("iterator-ctor",
949                         Property_iterator::constructor_cxx_function);
950                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
951                 t->set_mus_property ("value", $6);
952
953                 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
954
955                 csm->set_mus_property ("element", t->self_scm ());
956                 scm_unprotect_object (t->self_scm ());
957
958                 $$ = csm;
959                 $$->set_spot (THIS->here_input ());
960
961                 csm-> set_mus_property ("context-type", $2);
962         }
963         | PROPERTY STRING '.' STRING UNSET {
964                 Music *t = new Music (SCM_EOL);
965
966                 t->set_mus_property ("iterator-ctor",
967                         Property_unset_iterator::constructor_cxx_function);
968                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
969
970                 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
971                 csm->set_mus_property ("element", t->self_scm ());
972                 scm_unprotect_object (t->self_scm ());
973
974                 $$ = csm;
975                 $$->set_spot (THIS->here_input ());
976
977                 csm-> set_mus_property ("context-type", $2);
978         }
979         | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
980                 Music *t = new Music (SCM_EOL);
981                 t->set_mus_property ("iterator-ctor",
982                         Push_property_iterator::constructor_cxx_function);
983                 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
984                 t->set_mus_property ("pop-first", SCM_BOOL_T);
985                 t->set_mus_property ("grob-property", $6);
986                 t->set_mus_property ("grob-value", $8);
987                 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
988                 csm->set_mus_property ("element", t->self_scm ());
989                 scm_unprotect_object (t->self_scm ());
990                 $$ = csm;
991                 $$->set_spot (THIS->here_input ());
992
993                 csm-> set_mus_property ("context-type", $2);
994         }
995         | PROPERTY STRING '.' STRING OVERRIDE embedded_scm '=' embedded_scm {
996                 Music *t = new Music (SCM_EOL);
997                 t->set_mus_property ("iterator-ctor",
998                         Push_property_iterator::constructor_cxx_function);
999                 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1000                 t->set_mus_property ("grob-property", $6);
1001                 t->set_mus_property ("grob-value", $8);
1002                 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1003                 csm->set_mus_property ("element", t->self_scm ());
1004                 scm_unprotect_object (t->self_scm ());
1005
1006                 $$ = csm;
1007                 $$->set_spot (THIS->here_input ());
1008
1009                 csm-> set_mus_property ("context-type", $2);
1010         }
1011         | PROPERTY STRING '.' STRING REVERT embedded_scm {
1012                 Music *t = new Music (SCM_EOL);
1013                 t->set_mus_property ("iterator-ctor",
1014                         Pop_property_iterator::constructor_cxx_function);
1015                 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1016                 t->set_mus_property ("grob-property", $6);
1017
1018                 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1019                 csm->set_mus_property ("element", t->self_scm ());
1020                 scm_unprotect_object (t->self_scm ());
1021
1022                 $$ = csm;
1023                 $$->set_spot (THIS->here_input ());
1024
1025                 csm-> set_mus_property ("context-type", $2);
1026         }
1027         ;
1028
1029 scalar:
1030         string          { $$ = $1; }
1031         | bare_int      { $$ = gh_int2scm ($1); }
1032         | embedded_scm  { $$ = $1; }
1033         ;
1034
1035
1036 request_chord:
1037         pre_requests simple_element post_requests       {
1038                 Music_sequence *l = dynamic_cast<Music_sequence*> ($2);
1039                 if (l) {
1040                         for (int i=0; i < $1->size (); i++)
1041                                 l->append_music ($1->elem (i));
1042                         for (int i=0; i < $3->size (); i++)
1043                                 l->append_music ($3->elem (i));
1044                         }
1045                 else
1046                         programming_error ("Need Sequence to add music to");
1047                 $$ = $2;
1048                 
1049         }
1050         | command_element
1051         ;
1052
1053 command_element:
1054         command_req {
1055                 $$ = new Request_chord (SCM_EOL);
1056                 $$->set_mus_property ("elements", gh_cons ($1->self_scm (), SCM_EOL));
1057                 $$-> set_spot (THIS->here_input ());
1058                 $1-> set_spot (THIS->here_input ());
1059         }
1060         | BAR STRING                    {
1061                 Music *t = new Music (SCM_EOL);
1062
1063                 t->set_mus_property ("iterator-ctor",
1064                         Property_iterator::constructor_cxx_function);
1065                 t->set_mus_property ("symbol", ly_symbol2scm ("whichBar"));
1066                 t->set_mus_property ("value", $2);
1067
1068                 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1069                 csm->set_mus_property ("element", t->self_scm ());
1070                 scm_unprotect_object (t->self_scm ());
1071
1072                 $$ = csm;
1073                 $$->set_spot (THIS->here_input ());
1074
1075                 csm->set_mus_property ("context-type", ly_str02scm ("Score"));
1076         }
1077         | PARTIAL duration_length       {
1078                 Music * p = new Music (SCM_EOL);
1079                 p->set_mus_property ("symbol", ly_symbol2scm ( "measurePosition"));
1080                 p->set_mus_property ("iterator-ctor",
1081                         Property_iterator::constructor_cxx_function);
1082
1083                 Moment m = - unsmob_duration ($2)->length_mom ();
1084                 p->set_mus_property ("value", m.smobbed_copy ());
1085
1086                 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1087                 sp->set_mus_property ("element", p->self_scm ());
1088                 scm_unprotect_object (p->self_scm ());
1089
1090                 $$ =sp ;
1091                 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1092         }
1093         | CLEF STRING  {
1094                 SCM func = scm_eval2 (ly_symbol2scm ("clef-name-to-properties"), SCM_EOL);
1095                 SCM result = gh_call1 (func, $2);
1096
1097                 SCM l = SCM_EOL;
1098                 for (SCM s = result ; gh_pair_p (s); s = gh_cdr (s)) {
1099                         Music * p = new Music (SCM_EOL);
1100                         set_music_properties (p, gh_car (s));
1101                         l = gh_cons (p->self_scm (), l);
1102                         scm_unprotect_object (p->self_scm ());
1103                 }
1104                 Sequential_music * seq = new Sequential_music (SCM_EOL);
1105                 seq->set_mus_property ("elements", l);
1106
1107                 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1108                 sp->set_mus_property ("element", seq->self_scm ());
1109                 scm_unprotect_object (seq->self_scm ());
1110
1111                 $$ =sp ;
1112                 sp-> set_mus_property ("context-type", ly_str02scm ("Staff"));
1113         }
1114         | TIME_T bare_unsigned '/' bare_unsigned  {
1115                 Music * p = new Music (SCM_EOL);
1116                 p->set_mus_property ("symbol",
1117                         ly_symbol2scm ( "timeSignatureFraction"));
1118                 p->set_mus_property ("iterator-ctor",
1119                         Property_iterator::constructor_cxx_function);
1120
1121                 p->set_mus_property ("value", gh_cons (gh_int2scm ($2),
1122                                                         gh_int2scm ($4)));
1123
1124                 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1125                 sp->set_mus_property ("element", p->self_scm ());
1126                 scm_unprotect_object (p->self_scm ());
1127
1128                 $$ = sp;
1129
1130 /*
1131  TODO: should make alias TimingContext for Score
1132 */
1133
1134                 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1135         }
1136         ;
1137
1138 command_req:
1139         shorthand_command_req   { $$ = $1; }
1140         | verbose_command_req   { $$ = $1; }
1141         ;
1142
1143 shorthand_command_req:
1144         extender_req {
1145                 $$ = $1;
1146         }
1147         | hyphen_req {
1148                 $$ = $1;
1149         }
1150         | '|'                           {
1151                 $$ = new Barcheck_req;
1152         }
1153         | '~'   {
1154                 $$ = new Tie_req;
1155         }
1156         | '['           {
1157                 Span_req*b= new Span_req;
1158                 b->set_span_dir (START);
1159                 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1160                 $$ =b;
1161         }
1162         | ']'           {
1163                 Span_req*b= new Span_req;
1164                 b->set_span_dir ( STOP);
1165                 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1166                 $$ = b;
1167         }
1168         | BREATHE {
1169                 $$ = new Breathing_sign_req;
1170         }
1171         ;
1172
1173
1174 verbose_command_req:
1175         COMMANDSPANREQUEST bare_int STRING { /*TODO: junkme */
1176                 Span_req * sp_p = new Span_req;
1177                 sp_p-> set_span_dir ( Direction ($2));
1178                 sp_p->set_mus_property ("span-type",$3);
1179                 sp_p->set_spot (THIS->here_input ());
1180                 $$ = sp_p;
1181         }
1182         | MARK DEFAULT  {
1183                 Mark_req * m = new Mark_req;
1184                 $$ = m;
1185         }
1186         | MARK scalar {
1187                 Mark_req *m = new Mark_req;
1188                 m->set_mus_property ("label", $2);
1189                 $$ = m;
1190
1191         }
1192         | PENALTY SCM_T         {
1193
1194                 
1195                 Break_req * b = new Break_req;
1196                 SCM s = $2;
1197                 if (!gh_number_p (s))
1198                         s  =gh_int2scm (0);
1199
1200                 b->set_mus_property ("penalty", s);
1201                 b->set_spot (THIS->here_input ());
1202                 $$ = b;
1203         }
1204         | SKIP duration_length {
1205                 Skip_req * skip_p = new Skip_req;
1206                 skip_p->set_mus_property ("duration", $2);
1207
1208                 $$ = skip_p;
1209         }
1210         | tempo_request {
1211                 $$ = $1;
1212         }
1213         | KEY DEFAULT {
1214                 Key_change_req *key_p= new Key_change_req;
1215                 $$ = key_p;
1216         }
1217         | KEY NOTENAME_PITCH SCM_IDENTIFIER     {
1218                 Key_change_req *key_p= new Key_change_req;
1219                 
1220                 key_p->set_mus_property ("pitch-alist", $3);
1221  ((Music* )key_p)->transpose (* unsmob_pitch ($2));
1222                 $$ = key_p; 
1223         }
1224         ;
1225
1226 post_requests:
1227         {
1228                 $$ = new Link_array<Request>;
1229         }
1230         | post_requests post_request {
1231                 $2->set_spot (THIS->here_input ());
1232                 $$->push ($2);
1233         }
1234         ;
1235
1236 post_request:
1237         verbose_request
1238         | request_with_dir
1239         | close_request
1240         ;
1241
1242
1243 request_that_take_dir:
1244         gen_text_def
1245         | verbose_request
1246         | script_abbreviation {
1247                 SCM s = THIS->lexer_p_->lookup_identifier ("dash" + ly_scm2string ($1));
1248                 Articulation_req *a = new Articulation_req;
1249                 if (gh_string_p (s))
1250                         a->set_mus_property ("articulation-type", s);
1251                 else THIS->parser_error (_ ("Expecting string as script definition"));
1252                 $$ = a;
1253         }
1254         ;
1255
1256 request_with_dir:
1257         script_dir request_that_take_dir        {
1258                 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1259                         gs->set_direction (Direction ($1));
1260                 else if ($1)
1261                         $2->origin ()->warning (_ ("Can't specify direction for this request"));
1262                 $$ = $2;
1263         }
1264         ;
1265         
1266 verbose_request:
1267         REQUEST_IDENTIFIER      {
1268                 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1269                 $$->set_spot (THIS->here_input ());
1270         }
1271         | DYNAMICSCRIPT embedded_scm {
1272                 /*
1273                         TODO: junkme, use text-type == dynamic
1274                 */
1275                 Text_script_req *d = new Text_script_req;
1276                 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1277                 d->set_mus_property ("text", $2);
1278                 d->set_spot (THIS->here_input ());
1279                 $$ = d;
1280         }
1281         | SPANREQUEST bare_int STRING {
1282                 Span_req * sp_p = new Span_req;
1283                 sp_p->set_span_dir ( Direction ($2));
1284                 sp_p->set_mus_property ("span-type", $3);
1285                 sp_p->set_spot (THIS->here_input ());
1286                 $$ = sp_p;
1287         }
1288         | tremolo_type  {
1289                Tremolo_req* a = new Tremolo_req;
1290                a->set_spot (THIS->here_input ());
1291                a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1292                $$ = a;
1293         }
1294         | SCRIPT STRING         { 
1295                 Articulation_req * a = new Articulation_req;
1296                 a->set_mus_property ("articulation-type", $2);
1297                 a->set_spot (THIS->here_input ());
1298                 $$ = a;
1299         }
1300         /*
1301 duh, junk this syntax from the parser, if possible. 
1302         */
1303         | ARPEGGIO {
1304                 Arpeggio_req *a = new Arpeggio_req;
1305                 a->set_spot (THIS->here_input ());
1306                 $$ = a;
1307         }
1308         | GLISSANDO {
1309                 Glissando_req *g = new Glissando_req;
1310                 g->set_spot /* No pun intended */ (THIS->here_input ());
1311                 $$ = g;
1312         }       
1313         ;
1314
1315 sup_quotes:
1316         '\'' {
1317                 $$ = 1;
1318         }
1319         | sup_quotes '\'' {
1320                 $$ ++;
1321         }
1322         ;
1323
1324 sub_quotes:
1325         ',' {
1326                 $$ = 1;
1327         }
1328         | sub_quotes ',' {
1329                 $$ ++ ;
1330         }
1331         ;
1332
1333 steno_pitch:
1334         NOTENAME_PITCH  {
1335                 $$ = $1;
1336         }
1337         | NOTENAME_PITCH sup_quotes     {
1338                 Pitch p = *unsmob_pitch ($1);
1339                 p.octave_i_ +=  $2;
1340                 $$ = p.smobbed_copy ();
1341         }
1342         | NOTENAME_PITCH sub_quotes      {
1343                 Pitch p =* unsmob_pitch ($1);
1344
1345                 p.octave_i_ +=  -$2;
1346                 $$ = p.smobbed_copy ();
1347
1348         }
1349         ;
1350
1351 /*
1352 ugh. duplication
1353 */
1354
1355 steno_tonic_pitch:
1356         TONICNAME_PITCH {
1357                 $$ = $1;
1358         }
1359         | TONICNAME_PITCH sup_quotes    {
1360                 Pitch p = *unsmob_pitch ($1);
1361                 p.octave_i_ +=  $2;
1362                 $$ = p.smobbed_copy ();
1363         }
1364         | TONICNAME_PITCH sub_quotes     {
1365                 Pitch p =* unsmob_pitch ($1);
1366
1367                 p.octave_i_ +=  -$2;
1368                 $$ = p.smobbed_copy ();
1369
1370         }
1371         ;
1372
1373 pitch:
1374         steno_pitch {
1375                 $$ = $1;
1376         }
1377         | explicit_pitch {
1378                 $$ = $1;
1379         }
1380         ;
1381
1382 explicit_pitch:
1383         PITCH embedded_scm {
1384                 $$ = $2;
1385                 if (!unsmob_pitch ($2)) {
1386                         THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1387                          $$ = Pitch ().smobbed_copy ();
1388                 }
1389         }
1390         ;
1391
1392 explicit_duration:
1393         DURATION embedded_scm   {
1394                 $$ = $2;
1395                 if (!unsmob_duration ($2))
1396                 {
1397                         THIS->parser_error (_ ("Must have duration object"));
1398                         $$ = Duration ().smobbed_copy ();
1399                 }
1400         }
1401         ;
1402
1403 extender_req:
1404         EXTENDER {
1405                 if (!THIS->lexer_p_->lyric_state_b ())
1406                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1407                 $$ = new Extender_req;
1408         }
1409         ;
1410
1411 hyphen_req:
1412         HYPHEN {
1413                 if (!THIS->lexer_p_->lyric_state_b ())
1414                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1415                 $$ = new Hyphen_req;
1416         }
1417         ;
1418
1419 close_request:
1420         close_request_parens {
1421                 $$ = $1;
1422                 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1423         }
1424         
1425 close_request_parens:
1426         '('     {
1427                 Span_req* s= new Span_req;
1428                 $$ = s;
1429                 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1430         }
1431         | E_OPEN        {
1432                 Span_req* s= new Span_req;
1433                 $$ = s;
1434                 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1435         }
1436         | E_SMALLER {
1437                 Span_req*s =new Span_req;
1438                 $$ = s;
1439                 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1440         }
1441         | E_BIGGER {
1442                 Span_req*s =new Span_req;
1443                 $$ = s;
1444                 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1445         }
1446         ;
1447
1448
1449 open_request:
1450         open_request_parens {
1451                 $$ = $1;
1452                 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1453         }
1454         ;
1455
1456 open_request_parens:
1457         E_EXCLAMATION   {
1458                 Span_req *s =  new Span_req;
1459                 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1460
1461                 $$ = s;
1462         }
1463         | ')'   {
1464                 Span_req* s= new Span_req;
1465                 $$ = s;
1466                 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1467         }
1468         | E_CLOSE       {
1469                 Span_req* s= new Span_req;
1470                 $$ = s;
1471                 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1472         }
1473         ;
1474
1475 gen_text_def:
1476         embedded_scm {
1477                 Text_script_req *t = new Text_script_req;
1478                 t->set_mus_property ("text", $1);
1479                 t->set_spot (THIS->here_input ());
1480                 $$ = t;
1481         }
1482         | string {
1483                 Text_script_req *t = new Text_script_req;
1484                 t->set_mus_property ("text", $1);
1485                 t->set_spot (THIS->here_input ());
1486                 $$ = t;
1487         }
1488         | DIGIT {
1489                 String ds = to_str ($1);
1490                 Text_script_req* t = new Text_script_req;
1491
1492                 t->set_mus_property ("text",  ly_str02scm (ds.ch_C ()));
1493                 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1494                 t->set_spot (THIS->here_input ());
1495                 $$ = t;
1496         }
1497         ;
1498
1499 script_abbreviation:
1500         '^'             {
1501                 $$ = gh_str02scm ("Hat");
1502         }
1503         | '+'           {
1504                 $$ = gh_str02scm ("Plus");
1505         }
1506         | '-'           {
1507                 $$ = gh_str02scm ("Dash");
1508         }
1509         | '|'           {
1510                 $$ = gh_str02scm ("Bar");
1511         }
1512         | '>'           {
1513                 $$ = gh_str02scm ("Larger");
1514         }
1515         | '.'           {
1516                 $$ = gh_str02scm ("Dot");
1517         }
1518         ;
1519
1520
1521 script_dir:
1522         '_'     { $$ = DOWN; }
1523         | '^'   { $$ = UP; }
1524         | '-'   { $$ = CENTER; }
1525         ;
1526
1527 pre_requests:
1528         {
1529                 $$ = new Link_array<Request>;
1530         }
1531         | pre_requests open_request {
1532                 $$->push ($2);
1533         }
1534         ;
1535
1536 absolute_pitch:
1537         steno_pitch     {
1538                 $$ = $1;
1539         }
1540         ;
1541
1542 duration_length:
1543         multiplied_duration {
1544                 $$ = $1;
1545         }
1546         | explicit_duration {
1547                 $$ = $1;
1548         }       
1549         ;
1550
1551 optional_notemode_duration:
1552         {
1553                 $$ = THIS->default_duration_.smobbed_copy ();
1554         }
1555         | multiplied_duration   {
1556                 $$ = $1;
1557         }
1558         | explicit_duration {
1559                 $$ = $1;
1560         }       
1561         ;
1562
1563 steno_duration:
1564         bare_unsigned dots              {
1565                 int l = 0;
1566                 if (!is_duration_b ($1))
1567                         THIS->parser_error (_f ("not a duration: %d", $1));
1568                 else
1569                         l =  intlog2 ($1);
1570
1571                 $$ = Duration (l, $2).smobbed_copy ();
1572
1573                 THIS->set_last_duration (unsmob_duration ($$));
1574         }
1575         | DURATION_IDENTIFIER dots      {
1576                 Duration *d =unsmob_duration ($1);
1577                 Duration k (d->duration_log (),d->dot_count () + $2);
1578                 $$ = k.smobbed_copy ();
1579
1580                 THIS->set_last_duration (unsmob_duration ($$));
1581         }
1582         ;
1583
1584
1585
1586
1587 multiplied_duration:
1588         steno_duration {
1589                 $$ = $1;
1590         }
1591         | multiplied_duration '*' bare_unsigned {
1592                 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1593         }
1594         | multiplied_duration '/' bare_unsigned {
1595                 $$ = unsmob_duration ($$)->compressed (Moment (1,$3)).smobbed_copy ();
1596         }
1597         ;
1598
1599 dots:
1600         /* empty */     {
1601                 $$ = 0;
1602         }
1603         | dots '.' {
1604                 $$ ++;
1605         }
1606         ;
1607
1608
1609 tremolo_type: 
1610         ':'     {
1611                 $$ =0;
1612         }
1613         | ':' bare_unsigned {
1614                 if (!is_duration_b ($2))
1615                         THIS->parser_error (_f ("not a duration: %d", $2));
1616                 $$ = $2;
1617         }
1618         ;
1619
1620
1621 simple_element:
1622         pitch exclamations questions optional_notemode_duration {
1623                 if (!THIS->lexer_p_->note_state_b ())
1624                         THIS->parser_error (_ ("Have to be in Note mode for notes"));
1625
1626                 Note_req *n = new Note_req;
1627                 
1628                 n->set_mus_property ("pitch", $1);
1629                 n->set_mus_property ("duration", $4);
1630
1631                 if ($3 % 2)
1632                         n->set_mus_property ("cautionary", SCM_BOOL_T);
1633                 if ($2 % 2 || $3 % 2)
1634                         n->set_mus_property ("force-accidental", SCM_BOOL_T);
1635
1636                 Simultaneous_music*v = new Request_chord (SCM_EOL);
1637                 v->set_mus_property ("elements", gh_list (n->self_scm (), SCM_UNDEFINED));
1638                 
1639 /*
1640 FIXME: location is one off, since ptich & duration don't contain origin refs. 
1641 */
1642                 v->set_spot (THIS->here_input ());
1643                 n->set_spot (THIS->here_input ());
1644
1645                 $$ = v;
1646         }
1647         | RESTNAME optional_notemode_duration           {
1648
1649                 SCM e = SCM_UNDEFINED;
1650                   if (ly_scm2string ($1) =="s")
1651                     { /* Space */
1652                       Skip_req * skip_p = new Skip_req;
1653                       skip_p->set_mus_property ("duration" ,$2);
1654
1655                       skip_p->set_spot (THIS->here_input ());
1656                         e = skip_p->self_scm ();
1657                     }
1658                   else
1659                     {
1660                       Rest_req * rest_req_p = new Rest_req;
1661                       rest_req_p->set_mus_property ("duration", $2);
1662                       rest_req_p->set_spot (THIS->here_input ());
1663                         e = rest_req_p->self_scm ();
1664                     }
1665                   Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1666                 velt_p-> set_mus_property ("elements", gh_list (e,SCM_UNDEFINED));
1667                   velt_p->set_spot (THIS->here_input ());
1668
1669
1670                   $$ = velt_p;
1671         }
1672         | MULTI_MEASURE_REST optional_notemode_duration         {
1673                 Skip_req * sk = new Skip_req;
1674                 sk->set_mus_property ("duration", $2);
1675                 Span_req *sp1 = new Span_req;
1676                 Span_req *sp2 = new Span_req;
1677                 sp1-> set_span_dir ( START);
1678                 sp2-> set_span_dir ( STOP);
1679                 SCM r = ly_str02scm ("rest");
1680                 sp1->set_mus_property ("span-type", r);
1681                 sp2->set_mus_property ("span-type", r);
1682
1683                 Request_chord * rqc1 = new Request_chord (SCM_EOL);
1684                 rqc1->set_mus_property ("elements", gh_list (sp1->self_scm (), SCM_UNDEFINED));
1685                 Request_chord * rqc2 = new Request_chord (SCM_EOL);
1686                 rqc2->set_mus_property ("elements", gh_list (sk->self_scm (), SCM_UNDEFINED));;
1687                 Request_chord * rqc3 = new Request_chord (SCM_EOL);
1688                 rqc3->set_mus_property ("elements", gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1689
1690                 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1691
1692                 $$ = new Sequential_music (SCM_EOL);
1693                 $$->set_mus_property ("elements", ms);
1694         }
1695         | STRING optional_notemode_duration     {
1696
1697                 Lyric_req* lreq_p = new Lyric_req;
1698                 lreq_p->set_mus_property ("text", $1);
1699                 lreq_p->set_mus_property ("duration",$2);
1700                 lreq_p->set_spot (THIS->here_input ());
1701                 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1702                 velt_p->set_mus_property ("elements", gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1703
1704
1705                 $$= velt_p;
1706
1707         }
1708         | chord {
1709                 if (!THIS->lexer_p_->chord_state_b ())
1710                         THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1711                 $$ = $1;
1712         }
1713         ;
1714
1715
1716 chord:
1717         steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1718                 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1719                 $$->set_spot (THIS->here_input ());
1720         };
1721
1722 chord_additions: 
1723         {
1724                 $$ = SCM_EOL;
1725         } 
1726         | CHORD_COLON chord_notes {
1727                 $$ = $2;
1728         }
1729         ;
1730
1731 chord_notes:
1732         chord_step {
1733                 $$ = $1
1734         }
1735         | chord_notes '.' chord_step {
1736                 $$ = gh_append2 ($$, $3);
1737         }
1738         ;
1739
1740 chord_subtractions: 
1741         {
1742                 $$ = SCM_EOL;
1743         } 
1744         | CHORD_CARET chord_notes {
1745                 $$ = $2;
1746         }
1747         ;
1748
1749
1750 chord_inversion:
1751         {
1752                 $$ = SCM_EOL;
1753         }
1754         | '/' steno_tonic_pitch {
1755                 $$ = $2;
1756         }
1757         ;
1758
1759 chord_bass:
1760         {
1761                 $$ = SCM_EOL;
1762         }
1763         | CHORD_BASS steno_tonic_pitch {
1764                 $$ = $2;
1765         }
1766         ;
1767
1768 chord_step:
1769         chord_note {
1770                 $$ = gh_cons ($1, SCM_EOL);
1771         }
1772         | CHORDMODIFIER_PITCH {
1773                 $$ = gh_cons ($1, SCM_EOL);
1774         }
1775         | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1776                 $$ = gh_list ($1, $2, SCM_UNDEFINED);
1777         }
1778         ;
1779
1780 chord_note:
1781         bare_unsigned {
1782                  Pitch m;
1783                 m.notename_i_ = ($1 - 1) % 7;
1784                 m.octave_i_ = $1 > 7 ? 1 : 0;
1785                 m.alteration_i_ = 0;
1786
1787                 $$ = m.smobbed_copy ();
1788         } 
1789         | bare_unsigned '+' {
1790                 Pitch m;
1791                 m.notename_i_ = ($1 - 1) % 7;
1792                 m.octave_i_ = $1 > 7 ? 1 : 0;
1793                 m.alteration_i_ = 1;
1794
1795
1796                 $$ = m.smobbed_copy ();
1797         }
1798         | bare_unsigned CHORD_MINUS {
1799                 Pitch m;
1800                 m.notename_i_ = ($1 - 1) % 7;
1801                 m.octave_i_ = $1 > 7 ? 1 : 0;
1802                 m.alteration_i_ = -1;
1803
1804                 $$ = m.smobbed_copy ();
1805         }
1806         ;
1807
1808 /*
1809         UTILITIES
1810  */
1811 number_expression:
1812         bare_number {
1813                 $$ = $1;
1814         }
1815         | '-'  number_expression %prec UNARY_MINUS {
1816                 $$ = scm_difference ($2, SCM_UNDEFINED);
1817         }
1818         | number_expression '*' number_expression {
1819                 $$ = scm_product ($1, $3);
1820         }
1821         | number_expression '/' number_expression {
1822                 $$ = scm_divide ($1, $3);
1823         }
1824         | number_expression '+' number_expression {
1825                 $$ = scm_sum ($1, $3);
1826         }
1827         | number_expression '-' number_expression {
1828                 $$ = scm_difference ($1, $3);
1829         }
1830         | '(' number_expression ')'     {
1831                 $$ = $2;
1832         }
1833         ;
1834
1835 bare_number:
1836         UNSIGNED        {
1837                 $$ = gh_int2scm ($1);
1838         }
1839         | REAL          {
1840                 $$ = $1;
1841         }
1842         | NUMBER_IDENTIFIER             {
1843                 $$ = $1;
1844         }
1845         | REAL CM_T     {
1846                 $$ = gh_double2scm (gh_scm2double ($1) CM );
1847         }
1848         | REAL PT_T     {
1849                 $$ = gh_double2scm (gh_scm2double ($1) PT);
1850         }
1851         | REAL IN_T     {
1852                 $$ = gh_double2scm (gh_scm2double ($1) INCH);
1853         }
1854         | REAL MM_T     {
1855                 $$ = gh_double2scm (gh_scm2double ($1) MM);
1856         }
1857         | REAL CHAR_T   {
1858                 $$ = gh_double2scm (gh_scm2double ($1) CHAR);
1859         }
1860         ;
1861
1862
1863 bare_unsigned:
1864         UNSIGNED {
1865                         $$ = $1;
1866         }
1867         | DIGIT {
1868                 $$ = $1;
1869         }
1870         ;
1871
1872 bare_int:
1873         bare_number {
1874                 if (scm_integer_p ($1) == SCM_BOOL_T)
1875                 {
1876                         int k = gh_scm2int ($1);
1877                         $$ = k;
1878                 } else
1879                 {
1880                         THIS->parser_error (_ ("need integer number arg"));
1881                         $$ = 0;
1882                 }
1883         }
1884         | '-' bare_int {
1885                 $$ = -$2;
1886         }
1887         ;
1888
1889
1890 string:
1891         STRING          {
1892                 $$ = $1;
1893         }
1894         | STRING_IDENTIFIER     {
1895                 $$ = $1;
1896         }
1897         | string '+' string {
1898                 $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
1899         }
1900         ;
1901
1902
1903 exclamations:
1904                 { $$ = 0; }
1905         | exclamations '!'      { $$ ++; }
1906         ;
1907
1908 questions:
1909                 { $$ = 0; }
1910         | questions '?' { $$ ++; }
1911         ;
1912
1913
1914 %%
1915
1916 void
1917 My_lily_parser::set_yydebug (bool b)
1918 {
1919 #ifdef YYDEBUG
1920         yydebug = b;
1921 #endif
1922 }
1923
1924 extern My_lily_parser * current_parser;
1925
1926 void
1927 My_lily_parser::do_yyparse ()
1928 {
1929
1930         current_parser = this;;
1931         yyparse ((void*)this);
1932 }
1933
1934