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