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