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