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