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