]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
release: 1.3.111
[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 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 MUSICAL_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 <id>     SCORE_IDENTIFIER
218 %token <id>     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 <scope>   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_musical_pitch musical_pitch absolute_musical_pitch
249 %type <scm>   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                 delete header_global_p;
305                 header_global_p = $1;
306         }
307         | score_block {
308                 score_global_array.push ($1);
309         }
310         | output_def {
311                 Identifier * id = new
312                         Music_output_def_identifier ($1, MUSIC_OUTPUT_DEF_IDENTIFIER);
313                 if (dynamic_cast<Paper_def*> ($1))
314                         THIS->lexer_p_->set_identifier ("$defaultpaper", id->self_scm ());
315                 else if (dynamic_cast<Midi_def*> ($1))
316                         THIS->lexer_p_->set_identifier ("$defaultmidi", id->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 Scope;
360                 THIS->lexer_p_-> scope_l_arr_.push ($$);
361         }
362         | lilypond_header_body assignment semicolon { 
363
364         }
365         ;
366
367 lilypond_header:
368         HEADER '{' lilypond_header_body '}'     {
369                 $$ = $3;
370                 THIS->lexer_p_-> scope_l_arr_.pop ();           
371         }
372         ;
373
374
375 /*
376         DECLARATIONS
377 */
378 assignment:
379         STRING {
380                 THIS->remember_spot ();
381         }
382         /* cont */ '=' identifier_init  {
383                 THIS->lexer_p_->set_identifier (ly_scm2string ($1), $4);
384
385 /*
386  TODO: devise standard for protection in parser.
387
388   The parser stack lives on the C-stack, which means that
389 all objects can be unprotected as soon as they're here.
390
391 */
392                 Identifier * id =unsmob_identifier ($4);
393                 Input spot = THIS->pop_spot ();
394                 if (id) id->set_spot (spot);
395         }
396         ;
397
398
399
400 identifier_init:
401         score_block {
402                 $$ = (new Score_identifier ($1, SCORE_IDENTIFIER))->self_scm();
403         }
404         | output_def {
405                 $$ = (new Music_output_def_identifier ($1, MUSIC_OUTPUT_DEF_IDENTIFIER))->self_scm();
406         }
407         | translator_spec_block {
408                 $$ = $1;
409         }
410         | Music  {
411                 $$ = $1->self_scm ();
412                 scm_unprotect_object ($$);
413         }
414         | post_request {
415                 $$ = $1->self_scm ();
416                 scm_unprotect_object ($$);
417         }
418         | explicit_duration {
419                 $$ = $1;
420         }
421         | number_expression {
422                 $$ = $1;
423         }
424         | string {
425                 $$ = $1;
426         }
427         | embedded_scm  {
428                 $$ = $1;
429         }
430         ;
431
432 translator_spec_block:
433         TRANSLATOR '{' translator_spec_body '}'
434                 {
435                 $$ = $3;
436         }
437         ;
438
439 translator_spec_body:
440         TRANSLATOR_IDENTIFIER   {
441                 $$ = unsmob_translator_def ($1)->clone_scm ();
442                 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
443         }
444         | TYPE STRING semicolon {
445                 $$ = Translator_def::make_scm ();
446                 Translator_def*td =  unsmob_translator_def ($$);
447                 td->translator_group_type_ = $2;
448                 td->set_spot (THIS->here_input ());
449         }
450         | translator_spec_body STRING '=' embedded_scm                  {
451                 unsmob_translator_def ($$)->add_property_assign ($2, $4);
452         }
453         | translator_spec_body STRING OVERRIDE embedded_scm '=' embedded_scm {
454                 unsmob_translator_def ($$)
455                         ->add_push_property (scm_string_to_symbol ($2), $4, $6);
456         }
457         | translator_spec_body STRING REVERT embedded_scm  {
458           unsmob_translator_def($$)->add_pop_property (
459                 scm_string_to_symbol ($2), $4);
460         }
461         | translator_spec_body STRING '=' identifier_init semicolon     { 
462                 SCM v = gh_int2scm (0);
463                 if (gh_string_p ($4) || gh_number_p ($4) || gh_boolean_p ($4))
464                         v = $4;
465                 else 
466                         THIS->parser_error (_("Wrong type for property value"));
467
468                 /* ugh*/
469                 unsmob_translator_def($$)->add_property_assign ($2, v);
470         }
471         | translator_spec_body NAME STRING semicolon {
472                 unsmob_translator_def ($$)->type_name_ = $3;
473         }
474         | translator_spec_body CONSISTS STRING semicolon {
475                 unsmob_translator_def ($$)->add_element ($3);
476         }
477         | translator_spec_body ELEMENTDESCRIPTIONS embedded_scm {
478                 for (SCM p = $3; gh_pair_p (p); p = gh_cdr (p))
479                         unsmob_translator_def ($$)
480                         ->add_property_assign (scm_symbol_to_string (gh_caar (p)), gh_cdar (p));
481
482         }
483         | translator_spec_body CONSISTSEND STRING semicolon {
484                 unsmob_translator_def ($$)->add_last_element ( $3);
485         }
486         | translator_spec_body ACCEPTS STRING semicolon {
487                 unsmob_translator_def ($$)->set_acceptor ($3,true);
488         }
489         | translator_spec_body DENIES STRING semicolon {
490                 unsmob_translator_def ($$)->set_acceptor ($3,false);
491         }
492         | translator_spec_body REMOVE STRING semicolon {
493                 unsmob_translator_def ($$)->remove_element ($3);
494         }
495         ;
496
497 /*
498         SCORE
499 */
500 score_block:
501         SCORE { 
502                 THIS->remember_spot ();
503         }
504         /*cont*/ '{' score_body '}'     {
505                 THIS->pop_spot ();
506                 $$ = $4;
507                 if (!$$->def_p_arr_.size ())
508                 {
509                   Identifier *id =
510                         unsmob_identifier (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
511                   $$->add_output (id ? id->access_content_Music_output_def (true) : new Paper_def );
512                 }
513         }
514 /*
515         | SCORE '{' score_body error {
516                 $$ = $3
517                 $$->set_spot (THIS->here_input ());
518                 // THIS->here_input ().error ("SCORE INVALID");
519                 $$->error ("SCORE INVALID");
520                 THIS->parser_error (_f ("SCORE ERROR"));
521         }
522 */
523         ;
524
525 score_body:
526         Music   {
527                 $$ = new Score;
528
529                 $$->set_spot (THIS->here_input ());
530                 SCM m = $1->self_scm ();
531                 scm_unprotect_object (m);
532                 $$->music_ = m;
533         }
534         | SCORE_IDENTIFIER {
535                 $$ = $1->access_content_Score (true);
536         }
537         | score_body lilypond_header    {
538                 $$->header_p_ = $2;
539         }
540         | score_body output_def {
541                 $$->add_output ($2);
542         }
543         | score_body error {
544
545         }
546         ;
547
548
549 /*
550         MIDI
551 */
552 output_def:
553         music_output_def_body '}' {
554                 $$ = $1;
555                 THIS-> lexer_p_-> scope_l_arr_.pop();
556         }
557         ;
558
559 music_output_def_body:
560         MIDI '{'    {
561          Identifier *id = unsmob_identifier (THIS->lexer_p_->lookup_identifier ("$defaultmidi"));
562
563                 
564          Midi_def* p =0;
565         if (id)
566                 p = dynamic_cast<Midi_def*> (id->access_content_Music_output_def (true));
567         else
568                 p = new Midi_def;
569
570          $$ = p;
571          THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
572         }
573         | PAPER '{'     {
574                   Identifier *id = unsmob_identifier (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
575                   Paper_def *p = 0;
576                 if (id)
577                         p = dynamic_cast<Paper_def*> (id->access_content_Music_output_def (true));
578                 else
579                         p = new Paper_def;
580                 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
581                 $$ = p;
582         }
583         | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER         {
584                 Music_output_def *p = $3->access_content_Music_output_def (true);
585                 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
586                 $$ = p;
587         }
588         | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER  {
589                 Music_output_def *p = $3->access_content_Music_output_def (true);
590                 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
591                 $$ = p;
592         }
593         | music_output_def_body assignment semicolon {
594
595         }
596         | music_output_def_body translator_spec_block   {
597                 $$->assign_translator ($2);
598         }
599         | music_output_def_body STYLESHEET embedded_scm {
600                 dynamic_cast<Paper_def*> ($$)-> style_sheet_ = $3;
601         }
602         | music_output_def_body tempo_request semicolon {
603                 /*
604                         junk this ? there already is tempo stuff in
605                         music.
606                 */
607                 int m = gh_scm2int ( $2->get_mus_property ("metronome-count"));
608                 Duration *d = unsmob_duration ($2->get_mus_property ("duration"));
609                 dynamic_cast<Midi_def*> ($$)->set_tempo (d->length_mom (), m);
610         }
611         | music_output_def_body error {
612
613         }
614         ;
615
616 tempo_request:
617         TEMPO steno_duration '=' bare_unsigned  {
618                 $$ = new Tempo_req;
619                 $$->set_mus_property ("duration", $2);
620                 $$->set_mus_property ("metronome-count", gh_int2scm ( $4));
621         }
622         ;
623
624 Music_list: /* empty */ {
625                 $$ = gh_cons (SCM_EOL, SCM_EOL);
626         }
627         | Music_list Music {
628                 SCM s = $$;
629                 SCM c = gh_cons ($2->self_scm (), SCM_EOL);
630                 scm_unprotect_object ($2->self_scm ()); /* UGH */
631
632         
633                 if (gh_pair_p (gh_cdr (s)))
634                         gh_set_cdr_x (gh_cdr (s), c); /* append */
635                 else
636                         gh_set_car_x (s, c); /* set first cons */
637                 gh_set_cdr_x (s, c) ;  /* remember last cell */ 
638         }
639         | Music_list error {
640         }
641         ;
642
643
644 Music:
645         Simple_music
646         | Composite_music
647         ;
648
649 Alternative_music:
650         /* empty */ {
651                 $$ = 0;
652         }
653         | ALTERNATIVE Music_sequence {
654                 $$ = $2;
655                 $2->set_spot (THIS->here_input ());
656         }
657         ;
658
659
660
661
662 Repeated_music:
663         REPEAT STRING bare_unsigned Music Alternative_music
664         {
665                 Music_sequence* m = dynamic_cast <Music_sequence*> ($5);
666                 if (m && $3 < m->length_i ())
667                         $5->origin ()->warning (_ ("More alternatives than repeats.  Junking excess alternatives."));
668
669                 SCM func = scm_eval2 (ly_symbol2scm ("repeat-name-to-ctor"), SCM_EOL);
670                 SCM result = gh_call1 (func, $2);
671                 Repeated_music * r = new Repeated_music ($4, $3 >? 1, m);
672                 set_music_properties (r, result);
673
674                 r->set_spot (*$4->origin ());
675                 $$ = r;
676         }
677         ;
678
679 Music_sequence: '{' Music_list '}'      {
680                 $$ = new Music_sequence (gh_car ($2));
681         }
682         ;
683
684 Sequential_music:
685         SEQUENTIAL '{' Music_list '}'           {
686                 $$ = new Sequential_music (gh_car ($3));
687         }
688         | '{' Music_list '}'            {
689                 $$ = new Sequential_music (gh_car ($2));
690         }
691         ;
692
693 Simultaneous_music:
694         SIMULTANEOUS '{' Music_list '}'{
695                 $$ = new Simultaneous_music (gh_car ($3));
696         }
697         | '<' Music_list '>'    {
698                 $$ = new Simultaneous_music (gh_car ($2));
699         }
700         ;
701
702 Simple_music:
703         request_chord           { $$ = $1; }
704         | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm     {
705                 SCM pred = $2;
706                 if (!gh_symbol_p ($3))
707                 {
708                         THIS->parser_error (_("Second argument must be a symbol")); 
709                 }
710                 /*hould check # args */
711                 if (!gh_procedure_p (pred))
712                 {
713                         THIS->parser_error (_("First argument must be a procedure taking 1 argument"));
714                 }
715
716           Music *m = new Music;
717           m->set_mus_property ("predicate", pred);
718           m->set_mus_property ("symbol", $3);
719           m->set_mus_property ("value",  $5);
720           m->set_mus_property ("iterator-ctor",
721                         Output_property_music_iterator::constructor_cxx_function);
722
723                 $$ = m;
724         }
725         | MUSIC_IDENTIFIER {
726                 $$ = unsmob_music ($1)->clone ();
727         }
728         | property_def
729         | translator_change
730         | Simple_music '*' bare_unsigned '/' bare_unsigned      {
731                 $$ = $1;
732                 $$->compress (Moment($3, $5 ));
733         }
734         | Simple_music '*' bare_unsigned                 {
735                 $$ = $1;
736                 $$->compress (Moment ($3, 1));
737         }
738         ;
739
740
741 Composite_music:
742         CONTEXT STRING Music    {
743                 Context_specced_music *csm =  new Context_specced_music ($3);
744
745                 csm->set_mus_property ("context-type",$2);
746                 csm->set_mus_property ("context-id", ly_str02scm (""));
747
748                 $$ = csm;
749         }
750         | AUTOCHANGE STRING Music       {
751                 Auto_change_music * chm = new Auto_change_music ($3);
752                 chm->set_mus_property ("what", $2); 
753
754                 $$ = chm;
755                 chm->set_spot (*$3->origin ());
756         }
757         | GRACE Music {
758                 $$ = new Grace_music ($2);
759         }
760         | CONTEXT STRING '=' STRING Music {
761                 Context_specced_music *csm =  new Context_specced_music ($5);
762
763                 csm->set_mus_property ("context-type", $2);
764                 csm->set_mus_property ("context-id", $4);
765
766                 $$ = csm;
767         }
768         | TIMES {
769                 THIS->remember_spot ();
770         }
771         /* CONTINUED */ 
772                 bare_unsigned '/' bare_unsigned Music   
773
774         {
775                 $$ = new Time_scaled_music ($3, $5, $6);
776                 $$->set_spot (THIS->pop_spot ());
777         }
778         | Repeated_music                { $$ = $1; }
779         | Simultaneous_music            { $$ = $1; }
780         | Sequential_music              { $$ = $1; }
781         | TRANSPOSE musical_pitch Music {
782                 $$ = new Transposed_music ($3, *unsmob_pitch ($2));
783         }
784         | TRANSPOSE steno_tonic_pitch Music {
785                 $$ = new Transposed_music ($3, *unsmob_pitch ($2));
786         }
787         | APPLY embedded_scm Music  {
788                 SCM ret = gh_call1 ($2, $3->self_scm ());
789                 Music *m = unsmob_music (ret);
790                 if (!m) {
791                         THIS->parser_error ("\\apply must return a Music");
792                         m = new Music ();
793                         }
794                 $$ = m;
795         }
796         | NOTES
797                 { THIS->lexer_p_->push_note_state (); }
798         Music
799                 { $$ = $3;
800                   THIS->lexer_p_->pop_state ();
801                 }
802         | CHORDS
803                 { THIS->lexer_p_->push_chord_state (); }
804         Music
805                 {
806                   $$ = $3;
807                   THIS->lexer_p_->pop_state ();
808         }
809         | LYRICS
810                 { THIS->lexer_p_->push_lyric_state (); }
811         Music
812                 {
813                   $$ = $3;
814                   THIS->lexer_p_->pop_state ();
815         }
816         | relative_music        { $$ = $1; }
817         | re_rhythmed_music     { $$ = $1; } 
818         | part_combined_music   { $$ = $1; } 
819         ;
820
821 relative_music:
822         RELATIVE absolute_musical_pitch Music {
823                 $$ = new Relative_octave_music ($3, *unsmob_pitch ($2));
824         }
825         ;
826
827 re_rhythmed_music:
828         ADDLYRICS Music Music {
829                 Lyric_combine_music * l = new Lyric_combine_music ($2, $3);
830                 $$ = l;
831         }
832         ;
833
834 part_combined_music:
835         PARTCOMBINE STRING Music Music {
836                 Part_combine_music * p = new Part_combine_music ($2, $3, $4);
837                 $$ = p;
838         }
839         ;
840
841 translator_change:
842         TRANSLATOR STRING '=' STRING  {
843                 Music * t = new Music;
844                 t->set_mus_property ("iterator-ctor",
845                         Change_iterator::constructor_cxx_function);
846                 t-> set_mus_property ("change-to-type", $2);
847                 t-> set_mus_property ("change-to-id", $4);
848
849                 $$ = t;
850                 $$->set_spot (THIS->here_input ());
851         }
852         ;
853
854 property_def:
855         PROPERTY STRING '.' STRING '='  scalar {
856                 Music *t = new Music;
857
858                 t->set_mus_property ("iterator-ctor",
859                         Property_iterator::constructor_cxx_function);
860                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
861                 t->set_mus_property ("value", $6);
862
863                 Context_specced_music *csm = new Context_specced_music (t);
864                 $$ = csm;
865                 $$->set_spot (THIS->here_input ());
866
867                 csm-> set_mus_property ("context-type", $2);
868         }
869         | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
870                 Music *t = new Music;
871                 t->set_mus_property ("iterator-ctor",
872                         Push_property_iterator::constructor_cxx_function);
873                 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
874                 t->set_mus_property ("pop-first", SCM_BOOL_T);
875                 t->set_mus_property ("grob-property", $6);
876                 t->set_mus_property ("grob-value", $8);
877                 Context_specced_music *csm = new Context_specced_music (t);
878                 $$ = csm;
879                 $$->set_spot (THIS->here_input ());
880
881                 csm-> set_mus_property ("context-type", $2);
882         }
883         | PROPERTY STRING '.' STRING OVERRIDE embedded_scm '=' embedded_scm {
884                 Music *t = new Music;
885                 t->set_mus_property ("iterator-ctor",
886                         Push_property_iterator::constructor_cxx_function);
887                 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
888                 t->set_mus_property ("grob-property", $6);
889                 t->set_mus_property ("grob-value", $8);
890                 Context_specced_music *csm = new Context_specced_music (t);
891                 $$ = csm;
892                 $$->set_spot (THIS->here_input ());
893
894                 csm-> set_mus_property ("context-type", $2);
895         }
896         | PROPERTY STRING '.' STRING REVERT embedded_scm {
897                 Music *t = new Music;
898                 t->set_mus_property ("iterator-ctor",
899                         Pop_property_iterator::constructor_cxx_function);
900                 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
901                 t->set_mus_property ("grob-property", $6);
902
903                 Context_specced_music *csm = new Context_specced_music (t);
904                 $$ = csm;
905                 $$->set_spot (THIS->here_input ());
906
907                 csm-> set_mus_property ("context-type", $2);
908         }
909         ;
910
911 scalar:
912         string          { $$ = $1; }
913         | bare_int      { $$ = gh_int2scm ($1); }
914         | embedded_scm  { $$ = $1; }
915         ;
916
917
918 request_chord:
919         pre_requests simple_element post_requests       {
920                 Music_sequence *l = dynamic_cast<Music_sequence*>($2);
921                 if (l) {
922                         for (int i=0; i < $1->size(); i++)
923                                 l->append_music ($1->elem(i));
924                         for (int i=0; i < $3->size(); i++)
925                                 l->append_music ($3->elem(i));
926                         }
927                 else
928                         programming_error ("Need Sequence to add music to");
929                 $$ = $2;
930                 
931         }
932         | command_element
933         ;
934
935 command_element:
936         command_req {
937                 $$ = new Request_chord (gh_cons ($1->self_scm (), SCM_EOL));
938                 $$-> set_spot (THIS->here_input ());
939                 $1-> set_spot (THIS->here_input ());
940         }
941         | BAR STRING ';'                        {
942                 Music *t = new Music;
943
944                 t->set_mus_property ("iterator-ctor",
945                         Property_iterator::constructor_cxx_function);
946                 t->set_mus_property ("symbol", ly_symbol2scm ("whichBar"));
947                 t->set_mus_property ("value", $2);
948
949                 Context_specced_music *csm = new Context_specced_music (t);
950                 $$ = csm;
951                 $$->set_spot (THIS->here_input ());
952
953                 csm->set_mus_property ("context-type", ly_str02scm ("Score"));
954         }
955         | PARTIAL duration_length ';'   {
956                 Music * p = new Music;
957                 p->set_mus_property ("symbol", ly_symbol2scm ( "measurePosition"));
958                 p->set_mus_property ("iterator-ctor",
959                         Property_iterator::constructor_cxx_function);
960
961                 Moment m = - unsmob_duration($2)->length_mom ();
962                 p->set_mus_property ("value", m.smobbed_copy ());
963
964                 Context_specced_music * sp = new Context_specced_music (p);
965                 $$ =sp ;
966                 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
967         }
968         | CLEF STRING ';' {
969                 SCM func = scm_eval2 (ly_symbol2scm ("clef-name-to-properties"), SCM_EOL);
970                 SCM result = gh_call1 (func, $2);
971
972                 SCM l = SCM_EOL;
973                 for (SCM s = result ; gh_pair_p (s); s = gh_cdr (s)) {
974                         Music * p = new Music;
975                         set_music_properties(p, gh_car (s));
976                         l = gh_cons (p->self_scm (), l);
977                         scm_unprotect_object (p->self_scm ());
978                 }
979                 Sequential_music * seq = new Sequential_music (l);
980
981                 Context_specced_music * sp = new Context_specced_music (seq);
982                 $$ =sp ;
983                 sp-> set_mus_property("context-type", ly_str02scm("Staff"));
984         }
985         | TIME_T bare_unsigned '/' bare_unsigned ';' {
986                 Music * p = new Music;
987                 p->set_mus_property ("symbol",
988                         ly_symbol2scm ( "timeSignatureFraction"));
989                 p->set_mus_property ("iterator-ctor",
990                         Property_iterator::constructor_cxx_function);
991
992                 p->set_mus_property ("value", gh_cons (gh_int2scm ($2),
993                                                         gh_int2scm ($4)));
994
995                 Context_specced_music * sp = new Context_specced_music (p);
996                 $$ =sp ;
997                 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
998         }
999         ;
1000
1001 command_req:
1002         shorthand_command_req   { $$ = $1; }
1003         | verbose_command_req semicolon { $$ = $1; }
1004         ;
1005
1006 shorthand_command_req:
1007         extender_req {
1008                 $$ = $1;
1009         }
1010         | hyphen_req {
1011                 $$ = $1;
1012         }
1013         | '|'                           {
1014                 $$ = new Barcheck_req;
1015         }
1016         | '~'   {
1017                 $$ = new Tie_req;
1018         }
1019         | '['           {
1020                 Span_req*b= new Span_req;
1021                 b->set_span_dir(START);
1022                 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1023                 $$ =b;
1024         }
1025         | ']'           {
1026                 Span_req*b= new Span_req;
1027                 b->set_span_dir( STOP);
1028                 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1029                 $$ = b;
1030         }
1031         | BREATHE {
1032                 $$ = new Breathing_sign_req;
1033         }
1034         ;
1035
1036
1037 verbose_command_req:
1038         COMMANDSPANREQUEST bare_int STRING {
1039                 Span_req * sp_p = new Span_req;
1040                 sp_p-> set_span_dir ( Direction($2));
1041                 sp_p->set_mus_property ("span-type",$3);
1042                 sp_p->set_spot (THIS->here_input ());
1043                 $$ = sp_p;
1044         }
1045         | MARK  {
1046                 Mark_req * m = new Mark_req;
1047                 $$ = m;
1048         }
1049         | MARK STRING {
1050                 Mark_req *m = new Mark_req;
1051                 m->set_mus_property ("label", $2);
1052                 $$ = m;
1053
1054         }
1055         | MARK bare_unsigned {
1056                 Mark_req *m = new Mark_req;
1057                 m->set_mus_property ("label",  gh_int2scm ($2));
1058                 $$ = m;
1059         }
1060         | PENALTY bare_int      {
1061                 Break_req * b = new Break_req;
1062                 b->set_mus_property ("penalty", gh_double2scm ( $2 / 100.0));
1063                 b->set_spot (THIS->here_input ());
1064                 $$ = b;
1065         }
1066         | SKIP duration_length {
1067                 Skip_req * skip_p = new Skip_req;
1068                 skip_p->set_mus_property ("duration", $2);
1069
1070                 $$ = skip_p;
1071         }
1072         | tempo_request {
1073                 $$ = $1;
1074         }
1075         | KEY {
1076                 Key_change_req *key_p= new Key_change_req;
1077                 $$ = key_p;
1078         }
1079         | KEY NOTENAME_PITCH SCM_IDENTIFIER     {
1080                 Key_change_req *key_p= new Key_change_req;
1081                 
1082                 key_p->set_mus_property ("pitch-alist", $3);
1083                 ((Music* )key_p)->transpose (* unsmob_pitch ($2));
1084                 $$ = key_p; 
1085         }
1086         ;
1087
1088 post_requests:
1089         {
1090                 $$ = new Link_array<Request>;
1091         }
1092         | post_requests post_request {
1093                 $2->set_spot (THIS->here_input ());
1094                 $$->push ($2);
1095         }
1096         ;
1097
1098 post_request:
1099         verbose_request
1100         | request_with_dir
1101         | close_request
1102         ;
1103
1104
1105 request_that_take_dir:
1106         gen_text_def
1107         | verbose_request
1108         | script_abbreviation {
1109                 SCM s = THIS->lexer_p_->lookup_identifier ("dash-" + ly_scm2string ($1));
1110                 Articulation_req *a = new Articulation_req;
1111                 if (gh_string_p (s))
1112                         a->set_mus_property ("articulation-type", s);
1113                 else THIS->parser_error (_ ("Expecting string as script definition"));
1114                 $$ = a;
1115         }
1116         ;
1117
1118 request_with_dir:
1119         script_dir request_that_take_dir        {
1120                 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1121                         gs->set_direction (Direction ($1));
1122                 else if ($1)
1123                         $2->origin ()->warning (_ ("Can't specify direction for this request"));
1124                 $$ = $2;
1125         }
1126         ;
1127         
1128 verbose_request:
1129         REQUEST_IDENTIFIER      {
1130                 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1131                 $$->set_spot (THIS->here_input ());
1132         }
1133         | DYNAMICSCRIPT embedded_scm {
1134                 /*
1135                         TODO: junkme, use text-type == dynamic
1136                 */
1137                 Text_script_req *d = new Text_script_req;
1138                 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1139                 d->set_mus_property ("text", $2);
1140                 d->set_spot (THIS->here_input ());
1141                 $$ = d;
1142         }
1143         | TEXTSCRIPT embedded_scm {
1144                 Text_script_req *t = new Text_script_req;
1145                 t->set_mus_property ("text", $2);
1146                 t->set_spot (THIS->here_input ());
1147                 $$ = t;
1148         }
1149         | SPANREQUEST bare_int STRING {
1150                 Span_req * sp_p = new Span_req;
1151                 sp_p->set_span_dir( Direction($2));
1152                 sp_p->set_mus_property ("span-type", $3);
1153                 sp_p->set_spot (THIS->here_input ());
1154                 $$ = sp_p;
1155         }
1156         | tremolo_type  {
1157                 Tremolo_req* a = new Tremolo_req;
1158                 a->set_spot (THIS->here_input ());
1159                 a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1160                 $$ = a;
1161         }
1162         | SCRIPT STRING         { 
1163                 Articulation_req * a = new Articulation_req;
1164                 a->set_mus_property ("articulation-type", $2);
1165                 a->set_spot (THIS->here_input ());
1166                 $$ = a;
1167         }
1168         | ARPEGGIO {
1169                 Arpeggio_req *a = new Arpeggio_req;
1170                 a->set_spot (THIS->here_input ());
1171                 $$ = a;
1172         }
1173         ;
1174
1175 sup_quotes:
1176         '\'' {
1177                 $$ = 1;
1178         }
1179         | sup_quotes '\'' {
1180                 $$ ++;
1181         }
1182         ;
1183
1184 sub_quotes:
1185         ',' {
1186                 $$ = 1;
1187         }
1188         | sub_quotes ',' {
1189                 $$ ++ ;
1190         }
1191         ;
1192
1193 steno_musical_pitch:
1194         NOTENAME_PITCH  {
1195                 $$ = $1;
1196         }
1197         | NOTENAME_PITCH sup_quotes     {
1198                 Pitch p = *unsmob_pitch ($1);
1199                 p.octave_i_ +=  $2;
1200                 $$ = p.smobbed_copy ();
1201         }
1202         | NOTENAME_PITCH sub_quotes      {
1203                 Pitch p =* unsmob_pitch ($1);
1204
1205                 p.octave_i_ +=  -$2;
1206                 $$ = p.smobbed_copy ();
1207
1208         }
1209         ;
1210
1211 /*
1212 ugh. duplication
1213 */
1214
1215 steno_tonic_pitch:
1216         TONICNAME_PITCH {
1217                 $$ = $1;
1218         }
1219         | TONICNAME_PITCH sup_quotes    {
1220                 Pitch p = *unsmob_pitch ($1);
1221                 p.octave_i_ +=  $2;
1222                 $$ = p.smobbed_copy ();
1223         }
1224         | TONICNAME_PITCH sub_quotes     {
1225                 Pitch p =* unsmob_pitch ($1);
1226
1227                 p.octave_i_ +=  -$2;
1228                 $$ = p.smobbed_copy ();
1229
1230         }
1231         ;
1232
1233 musical_pitch:
1234         steno_musical_pitch {
1235                 $$ = $1;
1236         }
1237         | MUSICAL_PITCH embedded_scm {
1238                 if (!unsmob_pitch ($2))
1239                         THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1240                  Pitch m;
1241                 $$ = m.smobbed_copy ();
1242         }
1243         ;
1244
1245 explicit_duration:
1246         DURATION embedded_scm   {
1247                 $$ = $2;
1248                 if (!unsmob_duration ($2))
1249                 {
1250                         THIS->parser_error (_("Must have duration object"));
1251                         $$ = Duration ().smobbed_copy ();
1252                 }
1253         }
1254         ;
1255
1256 extender_req:
1257         EXTENDER {
1258                 if (!THIS->lexer_p_->lyric_state_b ())
1259                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1260                 $$ = new Extender_req;
1261         }
1262         ;
1263
1264 hyphen_req:
1265         HYPHEN {
1266                 if (!THIS->lexer_p_->lyric_state_b ())
1267                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1268                 $$ = new Hyphen_req;
1269         }
1270         ;
1271
1272 close_request:
1273         close_request_parens {
1274                 $$ = $1;
1275                 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1276         }
1277         
1278 close_request_parens:
1279         '('     {
1280                 Span_req* s= new Span_req;
1281                 $$ = s;
1282                 s->set_mus_property ("span-type", ly_str02scm( "slur"));
1283         }
1284         | E_SMALLER {
1285                 Span_req*s =new Span_req;
1286                 $$ = s;
1287                 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1288         }
1289         | E_BIGGER {
1290                 Span_req*s =new Span_req;
1291                 $$ = s;
1292                 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1293         }
1294         ;
1295
1296
1297 open_request:
1298         open_request_parens {
1299                 $$ = $1;
1300                 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1301         }
1302         ;
1303
1304 open_request_parens:
1305         E_EXCLAMATION   {
1306                 Span_req *s =  new Span_req;
1307                 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1308
1309                 $$ = s;
1310         }
1311         | ')'   {
1312                 Span_req* s= new Span_req;
1313                 $$ = s;
1314                 s->set_mus_property ("span-type", ly_str02scm( "slur"));
1315         }
1316         ;
1317
1318 gen_text_def:
1319         embedded_scm {
1320                 Text_script_req *t = new Text_script_req;
1321                 t->set_mus_property ("text", $1);
1322                 t->set_spot (THIS->here_input ());
1323                 $$ = t;
1324         }
1325         | string {
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         | DIGIT {
1332                 String ds = to_str ($1);
1333                 Text_script_req* t = new Text_script_req;
1334
1335                 t->set_mus_property ("text",  ly_str02scm (ds.ch_C()));
1336                 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1337                 t->set_spot (THIS->here_input ());
1338                 $$ = t;
1339         }
1340         ;
1341
1342 script_abbreviation:
1343         '^'             {
1344                 $$ = gh_str02scm  ("hat");
1345         }
1346         | '+'           {
1347                 $$ = gh_str02scm("plus");
1348         }
1349         | '-'           {
1350                 $$ = gh_str02scm ("dash");
1351         }
1352         | '|'           {
1353                 $$ = gh_str02scm ("bar");
1354         }
1355         | '>'           {
1356                 $$ = gh_str02scm ("larger");
1357         }
1358         | '.'           {
1359                 $$ = gh_str02scm ("dot");
1360         }
1361         ;
1362
1363
1364 script_dir:
1365         '_'     { $$ = DOWN; }
1366         | '^'   { $$ = UP; }
1367         | '-'   { $$ = CENTER; }
1368         ;
1369
1370 pre_requests:
1371         {
1372                 $$ = new Link_array<Request>;
1373         }
1374         | pre_requests open_request {
1375                 $$->push ($2);
1376         }
1377         ;
1378
1379 absolute_musical_pitch:
1380         steno_musical_pitch     {
1381                 $$ = $1;
1382         }
1383         ;
1384
1385 duration_length:
1386         steno_duration {
1387                 $$ = $1;
1388         }
1389         | duration_length '*' bare_unsigned {
1390                 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1391         }
1392         | duration_length '/' bare_unsigned {
1393                 $$ = unsmob_duration ($$)->compressed (Moment (1,$3)).smobbed_copy ();
1394         }
1395         ;
1396
1397 entered_notemode_duration:
1398         steno_duration  {
1399                 THIS->set_last_duration (unsmob_duration ($1));
1400         }
1401         ;
1402
1403 optional_notemode_duration:
1404         {
1405                 $$ = THIS->default_duration_.smobbed_copy ();
1406         }
1407         | entered_notemode_duration {
1408                 $$ = $1;
1409         }
1410         ;
1411
1412 steno_duration:
1413         bare_unsigned dots              {
1414                 int l = 0;
1415                 if (!is_duration_b ($1))
1416                         THIS->parser_error (_f ("not a duration: %d", $1));
1417                 else
1418                         l =  intlog2 ($1);
1419
1420                 $$ = Duration (l, $2).smobbed_copy ();
1421         }
1422         | DURATION_IDENTIFIER dots      {
1423                 Duration *d =unsmob_duration ($1);
1424                 Duration k (d->duration_log (),d->dot_count () + $2);
1425                 $$ = k.smobbed_copy ();         
1426         }
1427         ;
1428
1429 dots:
1430         /* empty */     {
1431                 $$ = 0;
1432         }
1433         | dots '.' {
1434                 $$ ++;
1435         }
1436         ;
1437
1438
1439 tremolo_type: 
1440         ':'     {
1441                 $$ =0;
1442         }
1443         | ':' bare_unsigned {
1444                 if (!is_duration_b ($2))
1445                         THIS->parser_error (_f ("not a duration: %d", $2));
1446                 $$ = $2;
1447         }
1448         ;
1449
1450
1451 simple_element:
1452         musical_pitch exclamations questions optional_notemode_duration {
1453                 if (!THIS->lexer_p_->note_state_b ())
1454                         THIS->parser_error (_ ("Have to be in Note mode for notes"));
1455
1456                 Note_req *n = new Note_req;
1457                 
1458                 n->set_mus_property ("pitch", $1);
1459                 n->set_mus_property ("duration", $4);
1460
1461                 if ($3 % 2)
1462                         n->set_mus_property ("cautionary", SCM_BOOL_T);
1463                 if ($2 % 2 || $3 % 2)
1464                         n->set_mus_property ("force-accidental", SCM_BOOL_T);
1465
1466                 Simultaneous_music*v = new Request_chord (gh_list (n->self_scm (), SCM_UNDEFINED));
1467                 
1468 /*
1469 FIXME
1470 */
1471                 v->set_spot (THIS->here_input ());
1472                 n->set_spot (THIS->here_input ());
1473
1474                 $$ = v;
1475         }
1476         | RESTNAME optional_notemode_duration           {
1477
1478                 SCM e = SCM_UNDEFINED;
1479                   if (ly_scm2string ($1) =="s")
1480                     { /* Space */
1481                       Skip_req * skip_p = new Skip_req;
1482                       skip_p->set_mus_property ("duration" ,$2);
1483
1484                       skip_p->set_spot (THIS->here_input());
1485                         e = skip_p->self_scm ();
1486                     }
1487                   else
1488                     {
1489                       Rest_req * rest_req_p = new Rest_req;
1490                       rest_req_p->set_mus_property ("duration", $2);
1491                       rest_req_p->set_spot (THIS->here_input());
1492                         e = rest_req_p->self_scm ();
1493                     }
1494                   Simultaneous_music* velt_p = new Request_chord (gh_list (e,SCM_UNDEFINED));
1495                   velt_p->set_spot (THIS->here_input());
1496
1497
1498                   $$ = velt_p;
1499         }
1500         | MEASURES optional_notemode_duration   {
1501                 Skip_req * sk = new Skip_req;
1502                 sk->set_mus_property ("duration", $2);
1503                 Span_req *sp1 = new Span_req;
1504                 Span_req *sp2 = new Span_req;
1505                 sp1-> set_span_dir ( START);
1506                 sp2-> set_span_dir ( STOP);
1507                 SCM r = ly_str02scm ("rest");
1508                 sp1->set_mus_property ("span-type", r);
1509                 sp2->set_mus_property ("span-type", r);
1510
1511                 Request_chord * rqc1 = new Request_chord (gh_list (sp1->self_scm (), SCM_UNDEFINED));
1512                 Request_chord * rqc2 = new Request_chord (gh_list (sk->self_scm (), SCM_UNDEFINED));;
1513                 Request_chord * rqc3 = new Request_chord(gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1514
1515                 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1516
1517                 $$ = new Sequential_music (ms);
1518         }
1519         | STRING { 
1520                 THIS->remember_spot ();
1521         } 
1522         /* cont */
1523         optional_notemode_duration      {
1524                 if (!THIS->lexer_p_->lyric_state_b ()) {
1525                         THIS->pop_spot ().error (_ ("Have to be in Lyric mode for lyrics"));
1526                         THIS->error_level_i_  = 1;
1527                         THIS->parser_error (_ ("Giving up"));
1528                 } 
1529                 else
1530                         THIS->pop_spot ();
1531                 Lyric_req* lreq_p = new Lyric_req;
1532                 lreq_p->set_mus_property ("text", $1);
1533                 lreq_p->set_mus_property ("duration",$3);
1534                 lreq_p->set_spot (THIS->here_input());
1535                 Simultaneous_music* velt_p = new Request_chord (gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1536
1537
1538                 $$= velt_p;
1539
1540         }
1541         | chord {
1542                 if (!THIS->lexer_p_->chord_state_b ())
1543                         THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1544                 $$ = $1;
1545         }
1546         ;
1547
1548
1549 chord:
1550         steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1551                 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1552                 $$->set_spot (THIS->here_input ());
1553         };
1554
1555 chord_additions: 
1556         {
1557                 $$ = SCM_EOL;
1558         } 
1559         | CHORD_COLON chord_notes {
1560                 $$ = $2;
1561         }
1562         ;
1563
1564 chord_notes:
1565         chord_step {
1566                 $$ = $1
1567         }
1568         | chord_notes '.' chord_step {
1569                 $$ = gh_append2 ($$, $3);
1570         }
1571         ;
1572
1573 chord_subtractions: 
1574         {
1575                 $$ = SCM_EOL;
1576         } 
1577         | CHORD_CARET chord_notes {
1578                 $$ = $2;
1579         }
1580         ;
1581
1582
1583 chord_inversion:
1584         {
1585                 $$ = SCM_EOL;
1586         }
1587         | '/' steno_tonic_pitch {
1588                 $$ = $2;
1589         }
1590         ;
1591
1592 chord_bass:
1593         {
1594                 $$ = SCM_EOL;
1595         }
1596         | CHORD_BASS steno_tonic_pitch {
1597                 $$ = $2;
1598         }
1599         ;
1600
1601 chord_step:
1602         chord_note {
1603                 $$ = gh_cons ($1, SCM_EOL);
1604         }
1605         | CHORDMODIFIER_PITCH {
1606                 $$ = gh_cons ($1, SCM_EOL);
1607         }
1608         | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1609                 $$ = gh_list ($1, $2, SCM_UNDEFINED);
1610         }
1611         ;
1612
1613 chord_note:
1614         bare_unsigned {
1615                  Pitch m;
1616                 m.notename_i_ = ($1 - 1) % 7;
1617                 m.octave_i_ = $1 > 7 ? 1 : 0;
1618                 m.alteration_i_ = 0;
1619
1620                 $$ = m.smobbed_copy ();
1621         } 
1622         | bare_unsigned '+' {
1623                 Pitch m;
1624                 m.notename_i_ = ($1 - 1) % 7;
1625                 m.octave_i_ = $1 > 7 ? 1 : 0;
1626                 m.alteration_i_ = 1;
1627
1628
1629                 $$ = m.smobbed_copy ();
1630         }
1631         | bare_unsigned CHORD_MINUS {
1632                 Pitch m;
1633                 m.notename_i_ = ($1 - 1) % 7;
1634                 m.octave_i_ = $1 > 7 ? 1 : 0;
1635                 m.alteration_i_ = -1;
1636
1637                 $$ = m.smobbed_copy ();
1638         }
1639         ;
1640
1641 /*
1642         UTILITIES
1643  */
1644 number_expression:
1645         bare_number {
1646                 $$ = $1;
1647         }
1648         | '-'  number_expression %prec UNARY_MINUS {
1649                 $$ = scm_difference ($2, SCM_UNDEFINED);
1650         }
1651         | number_expression '*' number_expression {
1652                 $$ = scm_product ($1, $3);
1653         }
1654         | number_expression '/' number_expression {
1655                 $$ = scm_divide ($1, $3);
1656         }
1657         | number_expression '+' number_expression {
1658                 $$ = scm_sum ($1, $3);
1659         }
1660         | number_expression '-' number_expression {
1661                 $$ = scm_difference ($1, $3);
1662         }
1663         | '(' number_expression ')'     {
1664                 $$ = $2;
1665         }
1666         ;
1667
1668 bare_number:
1669         UNSIGNED        {
1670                 $$ = gh_int2scm ($1);
1671         }
1672         | DIGIT         {
1673                 $$ = gh_int2scm ($1);
1674         }
1675         | REAL          {
1676                 $$ = gh_double2scm ($1);
1677         }
1678         | NUMBER_IDENTIFIER             {
1679                 $$ = $1;
1680         }
1681         | REAL CM_T     {
1682                 $$ = gh_double2scm ($1 CM);
1683         }
1684         | REAL PT_T     {
1685                 $$ = gh_double2scm ($1 PT);
1686         }
1687         | REAL IN_T     {
1688                 $$ = gh_double2scm ($1 INCH);
1689         }
1690         | REAL MM_T     {
1691                 $$ = gh_double2scm ($1 MM);
1692         }
1693         | REAL CHAR_T   {
1694                 $$ = gh_double2scm ($1 CHAR);
1695         }
1696         ;
1697
1698
1699 bare_unsigned:
1700         bare_number {
1701                 if (scm_integer_p ($1) == SCM_BOOL_T) {
1702                         $$ = gh_scm2int ($1);
1703
1704                 } else {
1705                         THIS->parser_error (_("need integer number arg"));
1706                         $$ = 0;
1707                 }
1708                 if ($$ < 0) {
1709                         THIS->parser_error (_("Must be positive integer"));
1710                         $$ = -$$;
1711                         }
1712
1713         }
1714         ;
1715 bare_int:
1716         bare_number {
1717                 if (scm_integer_p ($1) == SCM_BOOL_T)
1718                 {
1719                         int k = gh_scm2int ($1);
1720                         $$ = k;
1721                 } else
1722                 {
1723                         THIS->parser_error (_("need integer number arg"));
1724                         $$ = 0;
1725                 }
1726         }
1727         | '-' bare_int {
1728                 $$ = -$2;
1729         }
1730         ;
1731
1732
1733 string:
1734         STRING          {
1735                 $$ = $1;
1736         }
1737         | STRING_IDENTIFIER     {
1738                 $$ = $1;
1739         }
1740         | string '+' string {
1741                 $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
1742         }
1743         ;
1744
1745
1746 exclamations:
1747                 { $$ = 0; }
1748         | exclamations '!'      { $$ ++; }
1749         ;
1750
1751 questions:
1752                 { $$ = 0; }
1753         | questions '?' { $$ ++; }
1754         ;
1755
1756
1757 semicolon:
1758         ';'
1759         ;
1760
1761 %%
1762
1763 void
1764 My_lily_parser::set_yydebug (bool b)
1765 {
1766 #ifdef YYDEBUG
1767         yydebug = b;
1768 #endif
1769 }
1770
1771 extern My_lily_parser * current_parser;
1772
1773 void
1774 My_lily_parser::do_yyparse ()
1775 {
1776
1777         current_parser = this;;
1778         yyparse ((void*)this);
1779 }
1780
1781