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