]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
patch::: 1.3.111.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 "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* m = dynamic_cast <Music_sequence*> ($5);
667                 if (m && $3 < m->length_i ())
668                         $5->origin ()->warning (_ ("More alternatives than repeats.  Junking excess alternatives."));
669
670                 SCM func = scm_eval2 (ly_symbol2scm ("repeat-name-to-ctor"), SCM_EOL);
671                 SCM result = gh_call1 (func, $2);
672                 Repeated_music * r = new Repeated_music ($4, $3 >? 1, m);
673                 set_music_properties (r, result);
674
675                 r->set_spot (*$4->origin ());
676                 $$ = r;
677         }
678         ;
679
680 Music_sequence: '{' Music_list '}'      {
681                 $$ = new Music_sequence (gh_car ($2));
682         }
683         ;
684
685 Sequential_music:
686         SEQUENTIAL '{' Music_list '}'           {
687                 $$ = new Sequential_music (gh_car ($3));
688         }
689         | '{' Music_list '}'            {
690                 $$ = new Sequential_music (gh_car ($2));
691         }
692         ;
693
694 Simultaneous_music:
695         SIMULTANEOUS '{' Music_list '}'{
696                 $$ = new Simultaneous_music (gh_car ($3));
697         }
698         | '<' Music_list '>'    {
699                 $$ = new Simultaneous_music (gh_car ($2));
700         }
701         ;
702
703 Simple_music:
704         request_chord           { $$ = $1; }
705         | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm     {
706                 SCM pred = $2;
707                 if (!gh_symbol_p ($3))
708                 {
709                         THIS->parser_error (_("Second argument must be a symbol")); 
710                 }
711                 /*hould check # args */
712                 if (!gh_procedure_p (pred))
713                 {
714                         THIS->parser_error (_("First argument must be a procedure taking 1 argument"));
715                 }
716
717           Music *m = new Music;
718           m->set_mus_property ("predicate", pred);
719           m->set_mus_property ("symbol", $3);
720           m->set_mus_property ("value",  $5);
721           m->set_mus_property ("iterator-ctor",
722                         Output_property_music_iterator::constructor_cxx_function);
723
724                 $$ = m;
725         }
726         | MUSIC_IDENTIFIER {
727                 $$ = unsmob_music ($1)->clone ();
728         }
729         | property_def
730         | translator_change
731         | Simple_music '*' bare_unsigned '/' bare_unsigned      {
732                 $$ = $1;
733                 $$->compress (Moment($3, $5 ));
734         }
735         | Simple_music '*' bare_unsigned                 {
736                 $$ = $1;
737                 $$->compress (Moment ($3, 1));
738         }
739         ;
740
741
742 Composite_music:
743         CONTEXT STRING Music    {
744                 Context_specced_music *csm =  new Context_specced_music ($3);
745
746                 csm->set_mus_property ("context-type",$2);
747                 csm->set_mus_property ("context-id", ly_str02scm (""));
748
749                 $$ = csm;
750         }
751         | AUTOCHANGE STRING Music       {
752                 Auto_change_music * chm = new Auto_change_music ($3);
753                 chm->set_mus_property ("what", $2); 
754
755                 $$ = chm;
756                 chm->set_spot (*$3->origin ());
757         }
758         | GRACE Music {
759                 $$ = new Grace_music ($2);
760         }
761         | CONTEXT STRING '=' STRING Music {
762                 Context_specced_music *csm =  new Context_specced_music ($5);
763
764                 csm->set_mus_property ("context-type", $2);
765                 csm->set_mus_property ("context-id", $4);
766
767                 $$ = csm;
768         }
769         | TIMES {
770                 THIS->remember_spot ();
771         }
772         /* CONTINUED */ 
773                 bare_unsigned '/' bare_unsigned Music   
774
775         {
776                 $$ = new Time_scaled_music ($3, $5, $6);
777                 $$->set_spot (THIS->pop_spot ());
778         }
779         | Repeated_music                { $$ = $1; }
780         | Simultaneous_music            { $$ = $1; }
781         | Sequential_music              { $$ = $1; }
782         | TRANSPOSE musical_pitch Music {
783                 $$ = new Transposed_music ($3, *unsmob_pitch ($2));
784         }
785         | TRANSPOSE steno_tonic_pitch Music {
786                 $$ = new Transposed_music ($3, *unsmob_pitch ($2));
787         }
788         | APPLY embedded_scm Music  {
789                 SCM ret = gh_call1 ($2, $3->self_scm ());
790                 Music *m = unsmob_music (ret);
791                 if (!m) {
792                         THIS->parser_error ("\\apply must return a Music");
793                         m = new Music ();
794                         }
795                 $$ = m;
796         }
797         | NOTES
798                 { THIS->lexer_p_->push_note_state (); }
799         Music
800                 { $$ = $3;
801                   THIS->lexer_p_->pop_state ();
802                 }
803         | CHORDS
804                 { THIS->lexer_p_->push_chord_state (); }
805         Music
806                 {
807                   $$ = $3;
808                   THIS->lexer_p_->pop_state ();
809         }
810         | LYRICS
811                 { THIS->lexer_p_->push_lyric_state (); }
812         Music
813                 {
814                   $$ = $3;
815                   THIS->lexer_p_->pop_state ();
816         }
817         | relative_music        { $$ = $1; }
818         | re_rhythmed_music     { $$ = $1; } 
819         | part_combined_music   { $$ = $1; } 
820         ;
821
822 relative_music:
823         RELATIVE absolute_musical_pitch Music {
824                 $$ = new Relative_octave_music ($3, *unsmob_pitch ($2));
825         }
826         ;
827
828 re_rhythmed_music:
829         ADDLYRICS Music Music {
830                 Lyric_combine_music * l = new Lyric_combine_music ($2, $3);
831                 $$ = l;
832         }
833         ;
834
835 part_combined_music:
836         PARTCOMBINE STRING Music Music {
837                 Part_combine_music * p = new Part_combine_music ($2, $3, $4);
838                 $$ = p;
839         }
840         ;
841
842 translator_change:
843         TRANSLATOR STRING '=' STRING  {
844                 Music * t = new Music;
845                 t->set_mus_property ("iterator-ctor",
846                         Change_iterator::constructor_cxx_function);
847                 t-> set_mus_property ("change-to-type", $2);
848                 t-> set_mus_property ("change-to-id", $4);
849
850                 $$ = t;
851                 $$->set_spot (THIS->here_input ());
852         }
853         ;
854
855 property_def:
856         PROPERTY STRING '.' STRING '='  scalar {
857                 Music *t = new Music;
858
859                 t->set_mus_property ("iterator-ctor",
860                         Property_iterator::constructor_cxx_function);
861                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
862                 t->set_mus_property ("value", $6);
863
864                 Context_specced_music *csm = new Context_specced_music (t);
865                 $$ = csm;
866                 $$->set_spot (THIS->here_input ());
867
868                 csm-> set_mus_property ("context-type", $2);
869         }
870         | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
871                 Music *t = new Music;
872                 t->set_mus_property ("iterator-ctor",
873                         Push_property_iterator::constructor_cxx_function);
874                 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
875                 t->set_mus_property ("pop-first", SCM_BOOL_T);
876                 t->set_mus_property ("grob-property", $6);
877                 t->set_mus_property ("grob-value", $8);
878                 Context_specced_music *csm = new Context_specced_music (t);
879                 $$ = csm;
880                 $$->set_spot (THIS->here_input ());
881
882                 csm-> set_mus_property ("context-type", $2);
883         }
884         | PROPERTY STRING '.' STRING OVERRIDE embedded_scm '=' embedded_scm {
885                 Music *t = new Music;
886                 t->set_mus_property ("iterator-ctor",
887                         Push_property_iterator::constructor_cxx_function);
888                 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
889                 t->set_mus_property ("grob-property", $6);
890                 t->set_mus_property ("grob-value", $8);
891                 Context_specced_music *csm = new Context_specced_music (t);
892                 $$ = csm;
893                 $$->set_spot (THIS->here_input ());
894
895                 csm-> set_mus_property ("context-type", $2);
896         }
897         | PROPERTY STRING '.' STRING REVERT embedded_scm {
898                 Music *t = new Music;
899                 t->set_mus_property ("iterator-ctor",
900                         Pop_property_iterator::constructor_cxx_function);
901                 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
902                 t->set_mus_property ("grob-property", $6);
903
904                 Context_specced_music *csm = new Context_specced_music (t);
905                 $$ = csm;
906                 $$->set_spot (THIS->here_input ());
907
908                 csm-> set_mus_property ("context-type", $2);
909         }
910         ;
911
912 scalar:
913         string          { $$ = $1; }
914         | bare_int      { $$ = gh_int2scm ($1); }
915         | embedded_scm  { $$ = $1; }
916         ;
917
918
919 request_chord:
920         pre_requests simple_element post_requests       {
921                 Music_sequence *l = dynamic_cast<Music_sequence*>($2);
922                 if (l) {
923                         for (int i=0; i < $1->size(); i++)
924                                 l->append_music ($1->elem(i));
925                         for (int i=0; i < $3->size(); i++)
926                                 l->append_music ($3->elem(i));
927                         }
928                 else
929                         programming_error ("Need Sequence to add music to");
930                 $$ = $2;
931                 
932         }
933         | command_element
934         ;
935
936 command_element:
937         command_req {
938                 $$ = new Request_chord (gh_cons ($1->self_scm (), SCM_EOL));
939                 $$-> set_spot (THIS->here_input ());
940                 $1-> set_spot (THIS->here_input ());
941         }
942         | BAR STRING ';'                        {
943                 Music *t = new Music;
944
945                 t->set_mus_property ("iterator-ctor",
946                         Property_iterator::constructor_cxx_function);
947                 t->set_mus_property ("symbol", ly_symbol2scm ("whichBar"));
948                 t->set_mus_property ("value", $2);
949
950                 Context_specced_music *csm = new Context_specced_music (t);
951                 $$ = csm;
952                 $$->set_spot (THIS->here_input ());
953
954                 csm->set_mus_property ("context-type", ly_str02scm ("Score"));
955         }
956         | PARTIAL duration_length ';'   {
957                 Music * p = new Music;
958                 p->set_mus_property ("symbol", ly_symbol2scm ( "measurePosition"));
959                 p->set_mus_property ("iterator-ctor",
960                         Property_iterator::constructor_cxx_function);
961
962                 Moment m = - unsmob_duration($2)->length_mom ();
963                 p->set_mus_property ("value", m.smobbed_copy ());
964
965                 Context_specced_music * sp = new Context_specced_music (p);
966                 $$ =sp ;
967                 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
968         }
969         | CLEF STRING ';' {
970                 SCM func = scm_eval2 (ly_symbol2scm ("clef-name-to-properties"), SCM_EOL);
971                 SCM result = gh_call1 (func, $2);
972
973                 SCM l = SCM_EOL;
974                 for (SCM s = result ; gh_pair_p (s); s = gh_cdr (s)) {
975                         Music * p = new Music;
976                         set_music_properties(p, gh_car (s));
977                         l = gh_cons (p->self_scm (), l);
978                         scm_unprotect_object (p->self_scm ());
979                 }
980                 Sequential_music * seq = new Sequential_music (l);
981
982                 Context_specced_music * sp = new Context_specced_music (seq);
983                 $$ =sp ;
984                 sp-> set_mus_property("context-type", ly_str02scm("Staff"));
985         }
986         | TIME_T bare_unsigned '/' bare_unsigned ';' {
987                 Music * p = new Music;
988                 p->set_mus_property ("symbol",
989                         ly_symbol2scm ( "timeSignatureFraction"));
990                 p->set_mus_property ("iterator-ctor",
991                         Property_iterator::constructor_cxx_function);
992
993                 p->set_mus_property ("value", gh_cons (gh_int2scm ($2),
994                                                         gh_int2scm ($4)));
995
996                 Context_specced_music * sp = new Context_specced_music (p);
997                 $$ =sp ;
998                 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
999         }
1000         ;
1001
1002 command_req:
1003         shorthand_command_req   { $$ = $1; }
1004         | verbose_command_req semicolon { $$ = $1; }
1005         ;
1006
1007 shorthand_command_req:
1008         extender_req {
1009                 $$ = $1;
1010         }
1011         | hyphen_req {
1012                 $$ = $1;
1013         }
1014         | '|'                           {
1015                 $$ = new Barcheck_req;
1016         }
1017         | '~'   {
1018                 $$ = new Tie_req;
1019         }
1020         | '['           {
1021                 Span_req*b= new Span_req;
1022                 b->set_span_dir(START);
1023                 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1024                 $$ =b;
1025         }
1026         | ']'           {
1027                 Span_req*b= new Span_req;
1028                 b->set_span_dir( STOP);
1029                 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1030                 $$ = b;
1031         }
1032         | BREATHE {
1033                 $$ = new Breathing_sign_req;
1034         }
1035         ;
1036
1037
1038 verbose_command_req:
1039         COMMANDSPANREQUEST bare_int STRING {
1040                 Span_req * sp_p = new Span_req;
1041                 sp_p-> set_span_dir ( Direction($2));
1042                 sp_p->set_mus_property ("span-type",$3);
1043                 sp_p->set_spot (THIS->here_input ());
1044                 $$ = sp_p;
1045         }
1046         | MARK  {
1047                 Mark_req * m = new Mark_req;
1048                 $$ = m;
1049         }
1050         | MARK STRING {
1051                 Mark_req *m = new Mark_req;
1052                 m->set_mus_property ("label", $2);
1053                 $$ = m;
1054
1055         }
1056         | MARK bare_unsigned {
1057                 Mark_req *m = new Mark_req;
1058                 m->set_mus_property ("label",  gh_int2scm ($2));
1059                 $$ = m;
1060         }
1061         | PENALTY bare_int      {
1062                 Break_req * b = new Break_req;
1063                 b->set_mus_property ("penalty", gh_double2scm ( $2 / 100.0));
1064                 b->set_spot (THIS->here_input ());
1065                 $$ = b;
1066         }
1067         | SKIP duration_length {
1068                 Skip_req * skip_p = new Skip_req;
1069                 skip_p->set_mus_property ("duration", $2);
1070
1071                 $$ = skip_p;
1072         }
1073         | tempo_request {
1074                 $$ = $1;
1075         }
1076         | KEY {
1077                 Key_change_req *key_p= new Key_change_req;
1078                 $$ = key_p;
1079         }
1080         | KEY NOTENAME_PITCH SCM_IDENTIFIER     {
1081                 Key_change_req *key_p= new Key_change_req;
1082                 
1083                 key_p->set_mus_property ("pitch-alist", $3);
1084                 ((Music* )key_p)->transpose (* unsmob_pitch ($2));
1085                 $$ = key_p; 
1086         }
1087         ;
1088
1089 post_requests:
1090         {
1091                 $$ = new Link_array<Request>;
1092         }
1093         | post_requests post_request {
1094                 $2->set_spot (THIS->here_input ());
1095                 $$->push ($2);
1096         }
1097         ;
1098
1099 post_request:
1100         verbose_request
1101         | request_with_dir
1102         | close_request
1103         ;
1104
1105
1106 request_that_take_dir:
1107         gen_text_def
1108         | verbose_request
1109         | script_abbreviation {
1110                 SCM s = THIS->lexer_p_->lookup_identifier ("dash-" + ly_scm2string ($1));
1111                 Articulation_req *a = new Articulation_req;
1112                 if (gh_string_p (s))
1113                         a->set_mus_property ("articulation-type", s);
1114                 else THIS->parser_error (_ ("Expecting string as script definition"));
1115                 $$ = a;
1116         }
1117         ;
1118
1119 request_with_dir:
1120         script_dir request_that_take_dir        {
1121                 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1122                         gs->set_direction (Direction ($1));
1123                 else if ($1)
1124                         $2->origin ()->warning (_ ("Can't specify direction for this request"));
1125                 $$ = $2;
1126         }
1127         ;
1128         
1129 verbose_request:
1130         REQUEST_IDENTIFIER      {
1131                 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1132                 $$->set_spot (THIS->here_input ());
1133         }
1134         | DYNAMICSCRIPT embedded_scm {
1135                 /*
1136                         TODO: junkme, use text-type == dynamic
1137                 */
1138                 Text_script_req *d = new Text_script_req;
1139                 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1140                 d->set_mus_property ("text", $2);
1141                 d->set_spot (THIS->here_input ());
1142                 $$ = d;
1143         }
1144         | TEXTSCRIPT embedded_scm {
1145                 Text_script_req *t = new Text_script_req;
1146                 t->set_mus_property ("text", $2);
1147                 t->set_spot (THIS->here_input ());
1148                 $$ = t;
1149         }
1150         | SPANREQUEST bare_int STRING {
1151                 Span_req * sp_p = new Span_req;
1152                 sp_p->set_span_dir( Direction($2));
1153                 sp_p->set_mus_property ("span-type", $3);
1154                 sp_p->set_spot (THIS->here_input ());
1155                 $$ = sp_p;
1156         }
1157         | tremolo_type  {
1158                 Tremolo_req* a = new Tremolo_req;
1159                 a->set_spot (THIS->here_input ());
1160                 a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1161                 $$ = a;
1162         }
1163         | SCRIPT STRING         { 
1164                 Articulation_req * a = new Articulation_req;
1165                 a->set_mus_property ("articulation-type", $2);
1166                 a->set_spot (THIS->here_input ());
1167                 $$ = a;
1168         }
1169         | ARPEGGIO {
1170                 Arpeggio_req *a = new Arpeggio_req;
1171                 a->set_spot (THIS->here_input ());
1172                 $$ = a;
1173         }
1174         | GLISSANDO {
1175                 Glissando_req *g = new Glissando_req;
1176                 g->set_spot /* No pun intended */ (THIS->here_input ());
1177                 $$ = g;
1178         }       
1179         ;
1180
1181 sup_quotes:
1182         '\'' {
1183                 $$ = 1;
1184         }
1185         | sup_quotes '\'' {
1186                 $$ ++;
1187         }
1188         ;
1189
1190 sub_quotes:
1191         ',' {
1192                 $$ = 1;
1193         }
1194         | sub_quotes ',' {
1195                 $$ ++ ;
1196         }
1197         ;
1198
1199 steno_musical_pitch:
1200         NOTENAME_PITCH  {
1201                 $$ = $1;
1202         }
1203         | NOTENAME_PITCH sup_quotes     {
1204                 Pitch p = *unsmob_pitch ($1);
1205                 p.octave_i_ +=  $2;
1206                 $$ = p.smobbed_copy ();
1207         }
1208         | NOTENAME_PITCH sub_quotes      {
1209                 Pitch p =* unsmob_pitch ($1);
1210
1211                 p.octave_i_ +=  -$2;
1212                 $$ = p.smobbed_copy ();
1213
1214         }
1215         ;
1216
1217 /*
1218 ugh. duplication
1219 */
1220
1221 steno_tonic_pitch:
1222         TONICNAME_PITCH {
1223                 $$ = $1;
1224         }
1225         | TONICNAME_PITCH sup_quotes    {
1226                 Pitch p = *unsmob_pitch ($1);
1227                 p.octave_i_ +=  $2;
1228                 $$ = p.smobbed_copy ();
1229         }
1230         | TONICNAME_PITCH sub_quotes     {
1231                 Pitch p =* unsmob_pitch ($1);
1232
1233                 p.octave_i_ +=  -$2;
1234                 $$ = p.smobbed_copy ();
1235
1236         }
1237         ;
1238
1239 musical_pitch:
1240         steno_musical_pitch {
1241                 $$ = $1;
1242         }
1243         | MUSICAL_PITCH embedded_scm {
1244                 if (!unsmob_pitch ($2))
1245                         THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1246                  Pitch m;
1247                 $$ = m.smobbed_copy ();
1248         }
1249         ;
1250
1251 explicit_duration:
1252         DURATION embedded_scm   {
1253                 $$ = $2;
1254                 if (!unsmob_duration ($2))
1255                 {
1256                         THIS->parser_error (_("Must have duration object"));
1257                         $$ = Duration ().smobbed_copy ();
1258                 }
1259         }
1260         ;
1261
1262 extender_req:
1263         EXTENDER {
1264                 if (!THIS->lexer_p_->lyric_state_b ())
1265                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1266                 $$ = new Extender_req;
1267         }
1268         ;
1269
1270 hyphen_req:
1271         HYPHEN {
1272                 if (!THIS->lexer_p_->lyric_state_b ())
1273                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1274                 $$ = new Hyphen_req;
1275         }
1276         ;
1277
1278 close_request:
1279         close_request_parens {
1280                 $$ = $1;
1281                 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1282         }
1283         
1284 close_request_parens:
1285         '('     {
1286                 Span_req* s= new Span_req;
1287                 $$ = s;
1288                 s->set_mus_property ("span-type", ly_str02scm( "slur"));
1289         }
1290         | E_SMALLER {
1291                 Span_req*s =new Span_req;
1292                 $$ = s;
1293                 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1294         }
1295         | E_BIGGER {
1296                 Span_req*s =new Span_req;
1297                 $$ = s;
1298                 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1299         }
1300         ;
1301
1302
1303 open_request:
1304         open_request_parens {
1305                 $$ = $1;
1306                 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1307         }
1308         ;
1309
1310 open_request_parens:
1311         E_EXCLAMATION   {
1312                 Span_req *s =  new Span_req;
1313                 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1314
1315                 $$ = s;
1316         }
1317         | ')'   {
1318                 Span_req* s= new Span_req;
1319                 $$ = s;
1320                 s->set_mus_property ("span-type", ly_str02scm( "slur"));
1321         }
1322         ;
1323
1324 gen_text_def:
1325         embedded_scm {
1326                 Text_script_req *t = new Text_script_req;
1327                 t->set_mus_property ("text", $1);
1328                 t->set_spot (THIS->here_input ());
1329                 $$ = t;
1330         }
1331         | string {
1332                 Text_script_req *t = new Text_script_req;
1333                 t->set_mus_property ("text", $1);
1334                 t->set_spot (THIS->here_input ());
1335                 $$ = t;
1336         }
1337         | DIGIT {
1338                 String ds = to_str ($1);
1339                 Text_script_req* t = new Text_script_req;
1340
1341                 t->set_mus_property ("text",  ly_str02scm (ds.ch_C()));
1342                 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1343                 t->set_spot (THIS->here_input ());
1344                 $$ = t;
1345         }
1346         ;
1347
1348 script_abbreviation:
1349         '^'             {
1350                 $$ = gh_str02scm  ("hat");
1351         }
1352         | '+'           {
1353                 $$ = gh_str02scm("plus");
1354         }
1355         | '-'           {
1356                 $$ = gh_str02scm ("dash");
1357         }
1358         | '|'           {
1359                 $$ = gh_str02scm ("bar");
1360         }
1361         | '>'           {
1362                 $$ = gh_str02scm ("larger");
1363         }
1364         | '.'           {
1365                 $$ = gh_str02scm ("dot");
1366         }
1367         ;
1368
1369
1370 script_dir:
1371         '_'     { $$ = DOWN; }
1372         | '^'   { $$ = UP; }
1373         | '-'   { $$ = CENTER; }
1374         ;
1375
1376 pre_requests:
1377         {
1378                 $$ = new Link_array<Request>;
1379         }
1380         | pre_requests open_request {
1381                 $$->push ($2);
1382         }
1383         ;
1384
1385 absolute_musical_pitch:
1386         steno_musical_pitch     {
1387                 $$ = $1;
1388         }
1389         ;
1390
1391 duration_length:
1392         steno_duration {
1393                 $$ = $1;
1394         }
1395         | duration_length '*' bare_unsigned {
1396                 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1397         }
1398         | duration_length '/' bare_unsigned {
1399                 $$ = unsmob_duration ($$)->compressed (Moment (1,$3)).smobbed_copy ();
1400         }
1401         ;
1402
1403 entered_notemode_duration:
1404         steno_duration  {
1405                 THIS->set_last_duration (unsmob_duration ($1));
1406         }
1407         ;
1408
1409 optional_notemode_duration:
1410         {
1411                 $$ = THIS->default_duration_.smobbed_copy ();
1412         }
1413         | entered_notemode_duration {
1414                 $$ = $1;
1415         }
1416         ;
1417
1418 steno_duration:
1419         bare_unsigned dots              {
1420                 int l = 0;
1421                 if (!is_duration_b ($1))
1422                         THIS->parser_error (_f ("not a duration: %d", $1));
1423                 else
1424                         l =  intlog2 ($1);
1425
1426                 $$ = Duration (l, $2).smobbed_copy ();
1427         }
1428         | DURATION_IDENTIFIER dots      {
1429                 Duration *d =unsmob_duration ($1);
1430                 Duration k (d->duration_log (),d->dot_count () + $2);
1431                 $$ = k.smobbed_copy ();         
1432         }
1433         ;
1434
1435 dots:
1436         /* empty */     {
1437                 $$ = 0;
1438         }
1439         | dots '.' {
1440                 $$ ++;
1441         }
1442         ;
1443
1444
1445 tremolo_type: 
1446         ':'     {
1447                 $$ =0;
1448         }
1449         | ':' bare_unsigned {
1450                 if (!is_duration_b ($2))
1451                         THIS->parser_error (_f ("not a duration: %d", $2));
1452                 $$ = $2;
1453         }
1454         ;
1455
1456
1457 simple_element:
1458         musical_pitch exclamations questions optional_notemode_duration {
1459                 if (!THIS->lexer_p_->note_state_b ())
1460                         THIS->parser_error (_ ("Have to be in Note mode for notes"));
1461
1462                 Note_req *n = new Note_req;
1463                 
1464                 n->set_mus_property ("pitch", $1);
1465                 n->set_mus_property ("duration", $4);
1466
1467                 if ($3 % 2)
1468                         n->set_mus_property ("cautionary", SCM_BOOL_T);
1469                 if ($2 % 2 || $3 % 2)
1470                         n->set_mus_property ("force-accidental", SCM_BOOL_T);
1471
1472                 Simultaneous_music*v = new Request_chord (gh_list (n->self_scm (), SCM_UNDEFINED));
1473                 
1474 /*
1475 FIXME
1476 */
1477                 v->set_spot (THIS->here_input ());
1478                 n->set_spot (THIS->here_input ());
1479
1480                 $$ = v;
1481         }
1482         | RESTNAME optional_notemode_duration           {
1483
1484                 SCM e = SCM_UNDEFINED;
1485                   if (ly_scm2string ($1) =="s")
1486                     { /* Space */
1487                       Skip_req * skip_p = new Skip_req;
1488                       skip_p->set_mus_property ("duration" ,$2);
1489
1490                       skip_p->set_spot (THIS->here_input());
1491                         e = skip_p->self_scm ();
1492                     }
1493                   else
1494                     {
1495                       Rest_req * rest_req_p = new Rest_req;
1496                       rest_req_p->set_mus_property ("duration", $2);
1497                       rest_req_p->set_spot (THIS->here_input());
1498                         e = rest_req_p->self_scm ();
1499                     }
1500                   Simultaneous_music* velt_p = new Request_chord (gh_list (e,SCM_UNDEFINED));
1501                   velt_p->set_spot (THIS->here_input());
1502
1503
1504                   $$ = velt_p;
1505         }
1506         | MEASURES optional_notemode_duration   {
1507                 Skip_req * sk = new Skip_req;
1508                 sk->set_mus_property ("duration", $2);
1509                 Span_req *sp1 = new Span_req;
1510                 Span_req *sp2 = new Span_req;
1511                 sp1-> set_span_dir ( START);
1512                 sp2-> set_span_dir ( STOP);
1513                 SCM r = ly_str02scm ("rest");
1514                 sp1->set_mus_property ("span-type", r);
1515                 sp2->set_mus_property ("span-type", r);
1516
1517                 Request_chord * rqc1 = new Request_chord (gh_list (sp1->self_scm (), SCM_UNDEFINED));
1518                 Request_chord * rqc2 = new Request_chord (gh_list (sk->self_scm (), SCM_UNDEFINED));;
1519                 Request_chord * rqc3 = new Request_chord(gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1520
1521                 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1522
1523                 $$ = new Sequential_music (ms);
1524         }
1525         | STRING { 
1526                 THIS->remember_spot ();
1527         } 
1528         /* cont */
1529         optional_notemode_duration      {
1530                 if (!THIS->lexer_p_->lyric_state_b ()) {
1531                         THIS->pop_spot ().error (_ ("Have to be in Lyric mode for lyrics"));
1532                         THIS->error_level_i_  = 1;
1533                         THIS->parser_error (_ ("Giving up"));
1534                 } 
1535                 else
1536                         THIS->pop_spot ();
1537                 Lyric_req* lreq_p = new Lyric_req;
1538                 lreq_p->set_mus_property ("text", $1);
1539                 lreq_p->set_mus_property ("duration",$3);
1540                 lreq_p->set_spot (THIS->here_input());
1541                 Simultaneous_music* velt_p = new Request_chord (gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1542
1543
1544                 $$= velt_p;
1545
1546         }
1547         | chord {
1548                 if (!THIS->lexer_p_->chord_state_b ())
1549                         THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1550                 $$ = $1;
1551         }
1552         ;
1553
1554
1555 chord:
1556         steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1557                 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1558                 $$->set_spot (THIS->here_input ());
1559         };
1560
1561 chord_additions: 
1562         {
1563                 $$ = SCM_EOL;
1564         } 
1565         | CHORD_COLON chord_notes {
1566                 $$ = $2;
1567         }
1568         ;
1569
1570 chord_notes:
1571         chord_step {
1572                 $$ = $1
1573         }
1574         | chord_notes '.' chord_step {
1575                 $$ = gh_append2 ($$, $3);
1576         }
1577         ;
1578
1579 chord_subtractions: 
1580         {
1581                 $$ = SCM_EOL;
1582         } 
1583         | CHORD_CARET chord_notes {
1584                 $$ = $2;
1585         }
1586         ;
1587
1588
1589 chord_inversion:
1590         {
1591                 $$ = SCM_EOL;
1592         }
1593         | '/' steno_tonic_pitch {
1594                 $$ = $2;
1595         }
1596         ;
1597
1598 chord_bass:
1599         {
1600                 $$ = SCM_EOL;
1601         }
1602         | CHORD_BASS steno_tonic_pitch {
1603                 $$ = $2;
1604         }
1605         ;
1606
1607 chord_step:
1608         chord_note {
1609                 $$ = gh_cons ($1, SCM_EOL);
1610         }
1611         | CHORDMODIFIER_PITCH {
1612                 $$ = gh_cons ($1, SCM_EOL);
1613         }
1614         | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1615                 $$ = gh_list ($1, $2, SCM_UNDEFINED);
1616         }
1617         ;
1618
1619 chord_note:
1620         bare_unsigned {
1621                  Pitch m;
1622                 m.notename_i_ = ($1 - 1) % 7;
1623                 m.octave_i_ = $1 > 7 ? 1 : 0;
1624                 m.alteration_i_ = 0;
1625
1626                 $$ = m.smobbed_copy ();
1627         } 
1628         | bare_unsigned '+' {
1629                 Pitch m;
1630                 m.notename_i_ = ($1 - 1) % 7;
1631                 m.octave_i_ = $1 > 7 ? 1 : 0;
1632                 m.alteration_i_ = 1;
1633
1634
1635                 $$ = m.smobbed_copy ();
1636         }
1637         | bare_unsigned CHORD_MINUS {
1638                 Pitch m;
1639                 m.notename_i_ = ($1 - 1) % 7;
1640                 m.octave_i_ = $1 > 7 ? 1 : 0;
1641                 m.alteration_i_ = -1;
1642
1643                 $$ = m.smobbed_copy ();
1644         }
1645         ;
1646
1647 /*
1648         UTILITIES
1649  */
1650 number_expression:
1651         bare_number {
1652                 $$ = $1;
1653         }
1654         | '-'  number_expression %prec UNARY_MINUS {
1655                 $$ = scm_difference ($2, SCM_UNDEFINED);
1656         }
1657         | number_expression '*' number_expression {
1658                 $$ = scm_product ($1, $3);
1659         }
1660         | number_expression '/' number_expression {
1661                 $$ = scm_divide ($1, $3);
1662         }
1663         | number_expression '+' number_expression {
1664                 $$ = scm_sum ($1, $3);
1665         }
1666         | number_expression '-' number_expression {
1667                 $$ = scm_difference ($1, $3);
1668         }
1669         | '(' number_expression ')'     {
1670                 $$ = $2;
1671         }
1672         ;
1673
1674 bare_number:
1675         UNSIGNED        {
1676                 $$ = gh_int2scm ($1);
1677         }
1678         | DIGIT         {
1679                 $$ = gh_int2scm ($1);
1680         }
1681         | REAL          {
1682                 $$ = gh_double2scm ($1);
1683         }
1684         | NUMBER_IDENTIFIER             {
1685                 $$ = $1;
1686         }
1687         | REAL CM_T     {
1688                 $$ = gh_double2scm ($1 CM);
1689         }
1690         | REAL PT_T     {
1691                 $$ = gh_double2scm ($1 PT);
1692         }
1693         | REAL IN_T     {
1694                 $$ = gh_double2scm ($1 INCH);
1695         }
1696         | REAL MM_T     {
1697                 $$ = gh_double2scm ($1 MM);
1698         }
1699         | REAL CHAR_T   {
1700                 $$ = gh_double2scm ($1 CHAR);
1701         }
1702         ;
1703
1704
1705 bare_unsigned:
1706         bare_number {
1707                 if (scm_integer_p ($1) == SCM_BOOL_T) {
1708                         $$ = gh_scm2int ($1);
1709
1710                 } else {
1711                         THIS->parser_error (_("need integer number arg"));
1712                         $$ = 0;
1713                 }
1714                 if ($$ < 0) {
1715                         THIS->parser_error (_("Must be positive integer"));
1716                         $$ = -$$;
1717                         }
1718
1719         }
1720         ;
1721 bare_int:
1722         bare_number {
1723                 if (scm_integer_p ($1) == SCM_BOOL_T)
1724                 {
1725                         int k = gh_scm2int ($1);
1726                         $$ = k;
1727                 } else
1728                 {
1729                         THIS->parser_error (_("need integer number arg"));
1730                         $$ = 0;
1731                 }
1732         }
1733         | '-' bare_int {
1734                 $$ = -$2;
1735         }
1736         ;
1737
1738
1739 string:
1740         STRING          {
1741                 $$ = $1;
1742         }
1743         | STRING_IDENTIFIER     {
1744                 $$ = $1;
1745         }
1746         | string '+' string {
1747                 $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
1748         }
1749         ;
1750
1751
1752 exclamations:
1753                 { $$ = 0; }
1754         | exclamations '!'      { $$ ++; }
1755         ;
1756
1757 questions:
1758                 { $$ = 0; }
1759         | questions '?' { $$ ++; }
1760         ;
1761
1762
1763 semicolon:
1764         ';'
1765         ;
1766
1767 %%
1768
1769 void
1770 My_lily_parser::set_yydebug (bool b)
1771 {
1772 #ifdef YYDEBUG
1773         yydebug = b;
1774 #endif
1775 }
1776
1777 extern My_lily_parser * current_parser;
1778
1779 void
1780 My_lily_parser::do_yyparse ()
1781 {
1782
1783         current_parser = this;;
1784         yyparse ((void*)this);
1785 }
1786
1787