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