]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
* lily/parser.yy: remove TYPED_MAKE_MUSIC().
[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 /*
13   Two shift/reduce problems:
14     -
15     -
16  */
17
18 /*
19
20 the rules for who is protecting what are very shady. TODO: uniformise
21 this.
22
23
24 */
25
26 #include <iostream.h>
27 #include <ctype.h>
28
29 #include "translator-def.hh"
30 #include "lily-guile.hh"
31 #include "change-iterator.hh"
32 #include "misc.hh"
33 #include "my-lily-lexer.hh"
34 #include "paper-def.hh"
35 #include "midi-def.hh"
36 #include "main.hh"
37 #include "file-path.hh"
38 #include "warn.hh"
39 #include "dimensions.hh"
40 #include "command-request.hh"
41 #include "musical-request.hh"
42 #include "my-lily-parser.hh"
43 #include "context-specced-music.hh"
44 #include "score.hh"
45 #include "music-list.hh"
46 #include "output-property-music-iterator.hh"
47 #include "property-iterator.hh"
48 #include "input-file-results.hh"
49 #include "input.hh"
50 #include "relative-music.hh"
51 #include "lyric-combine-music.hh"
52 #include "transposed-music.hh"
53 #include "time-scaled-music.hh"
54 #include "repeated-music.hh"
55 #include "untransposable-music.hh"
56 #include "lilypond-input-version.hh"
57 #include "grace-music.hh"
58 #include "part-combine-music.hh"
59 #include "scm-hash.hh"
60 #include "auto-change-iterator.hh"
61 #include "un-relativable-music.hh"
62 #include "chord.hh"
63 #include "ly-modules.hh"
64
65 bool
66 regular_identifier_b (SCM id)
67 {
68   String str = ly_scm2string (id);
69   char const *s = str.to_str0 () ;
70
71   bool v = true;
72   while (*s && v)
73    {
74         v = v && isalpha (*s);
75         s++;
76    }
77   return v;
78 }
79
80
81 bool
82 is_duration_b (int t)
83 {
84   return t && t == 1 << intlog2 (t);
85 }
86
87 void
88 set_music_properties (Music *p, SCM a)
89 {
90   for (SCM k = a; gh_pair_p (k); k = ly_cdr (k))
91         {
92         p->internal_set_mus_property (ly_caar (k), ly_cdar (k));
93         }
94 }
95
96
97 SCM make_music_proc;
98
99 Music*
100 parser_make_music (SCM sym)
101 {
102         if (!make_music_proc)
103                 make_music_proc = scm_primitive_eval (ly_symbol2scm ("make-music-by-name"));
104         
105         SCM rv = scm_call_1 (make_music_proc, sym);
106
107         /*
108         UGH.
109         */
110         scm_gc_protect_object (rv);
111         return unsmob_music (rv);
112 }
113
114 #define MY_MAKE_MUSIC(x)  parser_make_music (ly_symbol2scm (x))
115
116 Music* 
117 set_property_music (SCM sym, SCM value)
118 {
119         Music * p = MY_MAKE_MUSIC("PropertySet");
120         p->set_mus_property ("symbol", sym);
121         p->set_mus_property ("value", value);
122         return p;
123 }
124
125
126 // needed for bison.simple's malloc () and free ()
127
128 // #include <malloc.h>
129 #include <stdlib.h>
130
131
132
133 #define YYERROR_VERBOSE 1
134
135 #define YYPARSE_PARAM my_lily_parser
136 #define YYLEX_PARAM my_lily_parser
137 #define THIS\
138         ((My_lily_parser *) my_lily_parser)
139
140 #define yyerror THIS->parser_error
141
142 %}
143
144 /* We use SCMs to do strings, because it saves us the trouble of
145 deleting them.  Let's hope that a stack overflow doesnt trigger a move
146 of the parse stack onto the heap. */
147
148
149 %union {
150
151     Link_array<Music> *reqvec;
152
153     String *string; // needed by the lexer as temporary scratch area.
154     Music *music;
155     Score *score;
156     Scheme_hash_table *scmhash;
157     Music_output_def * outputdef;
158     SCM scm;
159     Tempo_req *tempo;
160     int i;
161 }
162 %{
163
164 int
165 yylex (YYSTYPE *s,  void * v)
166 {
167         My_lily_parser   *pars = (My_lily_parser*) v;
168         My_lily_lexer * lex = pars->lexer_;
169
170         lex->lexval = (void*) s;
171         return lex->yylex ();
172 }
173
174
175 %}
176
177 %pure_parser
178
179 /* tokens which are not keywords */
180 %token AUTOCHANGE
181 %token ALIAS
182 %token APPLY
183 %token ARPEGGIO
184 %token DYNAMICSCRIPT
185 %token ACCEPTS
186 %token ALTERNATIVE
187 %token BAR
188 %token BREATHE
189 %token CHORDMODIFIERS
190 %token CHORDS
191 %token CHAR_T
192 %token CLEF
193 %token CM_T
194 %token CONSISTS
195 %token DURATION
196 %token SEQUENTIAL
197 %token GROBDESCRIPTIONS
198 %token SIMULTANEOUS
199 %token CONSISTSEND
200 %token DENIES
201 %token DURATION
202 %token EXTENDER
203 %token FIGURES FIGURE_OPEN FIGURE_CLOSE
204 %token FIGURE_BRACKET_CLOSE FIGURE_BRACKET_OPEN
205 %token GLISSANDO
206 %token GRACE 
207 %token HEADER
208 %token HYPHEN
209 %token IN_T
210 %token INVALID
211 %token KEY
212 %token LYRICS
213 %token MARK
214 %token MULTI_MEASURE_REST
215 %token MIDI
216 %token MM_T
217 %token PITCH
218 %token DEFAULT
219 %token NAME
220 %token PITCHNAMES
221 %token NOTES
222 %token ONCE
223 %token PAPER
224 %token PARTIAL
225 %token PENALTY
226 %token PROPERTY
227 %token OVERRIDE SET REVERT 
228 %token PT_T
229 %token RELATIVE
230 %token REMOVE
231 %token REPEAT
232 %token ADDLYRICS
233 %token PARTCOMBINE
234 %token SCM_T
235 %token SCORE
236 %token SCRIPT
237 %token SKIP
238 %token SPANREQUEST
239 %token STYLESHEET
240 %token COMMANDSPANREQUEST
241 %token TEMPO
242 %token OUTPUTPROPERTY
243 %token TIME_T
244 %token TIMES
245 %token TRANSLATOR
246 %token TRANSPOSE
247 %token TYPE
248 %token UNSET
249 %token CONTEXT
250 %token REST
251
252 /* escaped */
253 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
254 %token E_LEFTSQUARE E_RIGHTSQUARE E_TILDE
255 %token E_BACKSLASH
256 %token <i> E_UNSIGNED
257 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET  CHORD_SLASH
258 %token FIGURE_SPACE
259
260 %type <i>       exclamations questions dots optional_rest
261 %type <i>       bass_number bass_mod
262 %type <scm>     br_bass_figure bass_figure figure_list figure_spec
263 %token <i>      DIGIT
264 %token <scm>    NOTENAME_PITCH
265 %token <scm>    TONICNAME_PITCH
266 %token <scm>    CHORDMODIFIER_PITCH
267 %token <scm>    DURATION_IDENTIFIER
268 %token <scm>    FRACTION
269 %token <id>     IDENTIFIER
270
271
272 %token <scm>    SCORE_IDENTIFIER
273 %token <scm>    MUSIC_OUTPUT_DEF_IDENTIFIER
274
275 %token <scm>    NUMBER_IDENTIFIER
276 %token <scm>    REQUEST_IDENTIFIER
277 %token <scm>    MUSIC_IDENTIFIER TRANSLATOR_IDENTIFIER
278 %token <scm>    STRING_IDENTIFIER SCM_IDENTIFIER 
279 %token <scm>    RESTNAME
280 %token <scm>    STRING   
281 %token <scm>    SCM_T
282 %token <i>      UNSIGNED
283 %token <scm>   REAL
284
285 %type <outputdef> output_def
286 %type <scm>     lilypond_header lilypond_header_body
287 %type <music>   open_request_parens close_request_parens open_request close_request
288 %type <music> request_with_dir request_that_take_dir verbose_request
289 %type <i>       sub_quotes sup_quotes
290 %type <music>   simple_element  request_chord command_element Simple_music  Composite_music 
291 %type <music>   Repeated_music
292 %type <scm>     Alternative_music
293 %type <i>       tremolo_type
294 %type <i>       bare_int  bare_unsigned
295 %type <i>       script_dir
296 %type <scm>     identifier_init 
297
298 %type <scm> steno_duration optional_notemode_duration multiplied_duration
299 %type <scm>  verbose_duration
300         
301 %type <reqvec>  pre_requests post_requests
302 %type <music> gen_text_def
303 %type <scm>   steno_pitch pitch absolute_pitch
304 %type <scm>   explicit_pitch steno_tonic_pitch
305
306 %type <scm>     chord_additions chord_subtractions chord_notes chord_step
307 %type <music>   chord
308 %type <scm>     chord_note chord_inversion chord_bass
309 %type <scm>     duration_length fraction
310
311 %type <scm>  embedded_scm scalar
312 %type <music>   Music Sequential_music Simultaneous_music 
313 %type <music>   relative_music re_rhythmed_music part_combined_music
314 %type <music>   property_def translator_change  simple_property_def
315 %type <scm> Music_list
316 %type <outputdef>  music_output_def_body
317 %type <music> shorthand_command_req
318 %type <music>   post_request 
319 %type <music> command_req verbose_command_req
320 %type <music>   extender_req
321 %type <music> hyphen_req
322 %type <music> string_request
323 %type <scm>     string bare_number number_expression number_term number_factor 
324
325 %type <score>   score_block score_body
326
327 %type <scm>     translator_spec_block translator_spec_body
328 %type <tempo>   tempo_request
329 %type <scm> notenames_body notenames_block chordmodifiers_block
330 %type <scm>     script_abbreviation
331
332
333
334 %left '-' '+'
335
336 /* We don't assign precedence to / and *, because we might need varied
337 prec levels in different prods */
338
339 %left UNARY_MINUS
340
341 %%
342
343 lilypond:       /* empty */
344         | lilypond toplevel_expression {}
345         | lilypond assignment  { }
346         | lilypond error {
347                 THIS->error_level_  = 1;
348         }
349         | lilypond INVALID      {
350                 THIS->error_level_  = 1;
351         }
352         ;
353
354 toplevel_expression:
355         notenames_block                 {
356                 THIS->lexer_->pitchname_tab_ =  $1;
357         }
358         | chordmodifiers_block                  {
359                 THIS->lexer_->chordmodifier_tab_  = $1;
360         }
361         | lilypond_header {
362                 THIS->input_file_->header_ = $1;
363         }
364         | score_block {
365                 THIS->input_file_->scores_.push ($1);
366         }
367         | output_def {
368                 if (dynamic_cast<Paper_def*> ($1))
369                         THIS->lexer_->set_identifier (scm_makfrom0str ("$defaultpaper"), $1->self_scm ());
370                 else if (dynamic_cast<Midi_def*> ($1))
371                         THIS->lexer_->set_identifier (scm_makfrom0str ("$defaultmidi"), $1->self_scm ());
372         }
373         | embedded_scm {
374                 // junk value
375         }       
376         ;
377
378 embedded_scm:
379         SCM_T
380         | SCM_IDENTIFIER 
381         ;
382
383
384 chordmodifiers_block:
385         CHORDMODIFIERS notenames_body   {  $$ = $2; }
386         ;
387
388 notenames_block:
389         PITCHNAMES notenames_body   {  $$ = $2; }
390         ;
391
392 notenames_body:
393         embedded_scm    {
394           int i = scm_ilength ($1);
395
396           SCM tab = scm_make_vector (gh_int2scm (i), SCM_EOL);
397           for (SCM s = $1; gh_pair_p (s); s = ly_cdr (s)) {
398                 SCM pt = ly_cdar (s);
399                 if (!unsmob_pitch (pt))
400                         THIS->parser_error ("Need pitch object.");
401                 else
402                         scm_hashq_set_x (tab, ly_caar (s), pt);
403           }
404
405           $$ = tab;
406         }
407         ;
408
409 lilypond_header_body:
410         {
411                 $$ = ly_make_anonymous_module (); 
412                 THIS->lexer_->add_scope ($$);
413         }
414         | lilypond_header_body assignment  { 
415                 
416         }
417         ;
418
419 lilypond_header:
420         HEADER '{' lilypond_header_body '}'     {
421                 $$ = THIS->lexer_-> remove_scope();
422         }
423         ;
424
425
426 /*
427         DECLARATIONS
428 */
429 assignment:
430         STRING {
431                 THIS->push_spot ();
432         }
433         /* cont */ '=' identifier_init  {
434
435         /*
436                 Should find generic way of associating input with objects.
437         */
438                 Input ip = THIS->pop_spot ();
439
440                 if (! regular_identifier_b ($1))
441                 {
442                         ip.warning (_ ("Identifier should have alphabetic characters only"));
443                 }
444
445                 THIS->lexer_->set_identifier ($1, $4);
446
447 /*
448  TODO: devise standard for protection in parser.
449
450   The parser stack lives on the C-stack, which means that
451 all objects can be unprotected as soon as they're here.
452
453 */
454         }
455         ;
456
457
458
459 identifier_init:
460         score_block {
461                 $$ = $1->self_scm ();
462                 scm_gc_unprotect_object ($$);
463         }
464         | output_def {
465                 $$ = $1->self_scm ();
466                 scm_gc_unprotect_object ($$);
467         }
468         | translator_spec_block {
469                 $$ = $1;
470         }
471         | Music  {
472                 $$ = $1->self_scm ();
473                 scm_gc_unprotect_object ($$);
474         }
475         | post_request {
476                 $$ = $1->self_scm ();
477                 scm_gc_unprotect_object ($$);
478         }
479         | verbose_duration {
480                 $$ = $1;
481         }
482         | number_expression {
483                 $$ = $1;
484         }
485         | string {
486                 $$ = $1;
487         }
488         | embedded_scm  {
489                 $$ = $1;
490         }
491         ;
492
493 translator_spec_block:
494         TRANSLATOR '{' translator_spec_body '}'
495                 {
496                 $$ = $3;
497         }
498         ;
499
500 translator_spec_body:
501         TRANSLATOR_IDENTIFIER   {
502                 $$ = unsmob_translator_def ($1)->clone_scm ();
503                 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
504         }
505         | TYPE STRING   {
506                 $$ = Translator_def::make_scm ();
507                 Translator_def*td =  unsmob_translator_def ($$);
508                 td->translator_group_type_ = $2;
509                 td->set_spot (THIS->here_input ());
510         }
511         | translator_spec_body STRING '=' embedded_scm                  {
512                 unsmob_translator_def ($$)->add_property_assign ($2, $4);
513         }
514         | translator_spec_body STRING OVERRIDE embedded_scm '=' embedded_scm {
515                 unsmob_translator_def ($$)
516                         ->add_push_property (scm_string_to_symbol ($2), $4, $6);
517         }
518         | translator_spec_body STRING SET embedded_scm '=' embedded_scm {
519                 unsmob_translator_def ($$)
520                         ->add_push_property (scm_string_to_symbol ($2), $4, $6);
521         }
522         | translator_spec_body STRING REVERT embedded_scm  {
523           unsmob_translator_def ($$)->add_pop_property (
524                 scm_string_to_symbol ($2), $4);
525         }
526         | translator_spec_body NAME STRING  {
527                 unsmob_translator_def ($$)->type_name_ = $3;
528         }
529         | translator_spec_body CONSISTS STRING  {
530                 unsmob_translator_def ($$)->add_element ($3);
531         }
532         | translator_spec_body ALIAS STRING  {
533                 Translator_def*td = unsmob_translator_def ($$);
534                 td->type_aliases_ = scm_cons ($3, td->type_aliases_);
535         }
536         | translator_spec_body GROBDESCRIPTIONS embedded_scm {
537                 Translator_def*td = unsmob_translator_def($$);
538                 // td->add_property_assign (ly_symbol2scm ("allGrobDescriptions"), $3);
539                 for (SCM p = $3; gh_pair_p (p); p = ly_cdr (p))
540                         td->add_property_assign (scm_symbol_to_string (ly_caar (p)), ly_cdar (p));
541         }
542         | translator_spec_body CONSISTSEND STRING  {
543                 unsmob_translator_def ($$)->add_last_element ( $3);
544         }
545         | translator_spec_body ACCEPTS STRING  {
546                 unsmob_translator_def ($$)->set_acceptor ($3,true);
547         }
548         | translator_spec_body DENIES STRING  {
549                 unsmob_translator_def ($$)->set_acceptor ($3,false);
550         }
551         | translator_spec_body REMOVE STRING  {
552                 unsmob_translator_def ($$)->remove_element ($3);
553         }
554         ;
555
556 /*
557         SCORE
558 */
559 score_block:
560         SCORE { 
561                 THIS->push_spot ();
562         }
563         /*cont*/ '{' score_body '}'     {
564                 THIS->pop_spot ();
565                 $$ = $4;
566                 if (!$$->defs_.size ())
567                 {
568                   Music_output_def *id =
569                         unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"));
570                   $$->add_output (id ? id->clone () :  new Paper_def );
571                 }
572         }
573         ;
574
575 score_body:
576         Music   {
577                 $$ = new Score;
578         
579                 $$->set_spot (THIS->here_input ());
580                 SCM m = $1->self_scm ();
581                 scm_gc_unprotect_object (m);
582
583                 /*
584                         guh.
585                 */
586                 SCM check_funcs = scm_c_eval_string ("toplevel-music-functions");
587                 for (; gh_pair_p (check_funcs); check_funcs = gh_cdr (check_funcs))
588                         m = gh_call1 (gh_car (check_funcs), m);
589                 $$->music_ = m;
590
591         }
592         | SCORE_IDENTIFIER {
593                 $$ = new Score (*unsmob_score ($1));
594                 $$->set_spot (THIS->here_input ());
595         }
596         | score_body lilypond_header    {
597                 $$->header_ = $2;
598         }
599         | score_body output_def {
600                 $$->add_output ($2);
601         }
602         | score_body error {
603
604         }
605         ;
606
607
608 /*
609         MIDI
610 */
611 output_def:
612         music_output_def_body '}' {
613                 $$ = $1;
614                 THIS-> lexer_-> remove_scope ();
615         }
616         ;
617
618 music_output_def_body:
619         MIDI '{'    {
620                 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultmidi"));
621
622
623                 Midi_def* p =0;
624                 if (id)
625                         p = dynamic_cast<Midi_def*> (id->clone ());
626                 else
627                         p = new Midi_def;
628
629                 $$ = p;
630                 THIS->lexer_->add_scope (p->scope_);
631         }
632         | PAPER '{'     {
633                 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"));
634                   Paper_def *p = 0;
635                 if (id)
636                         p = dynamic_cast<Paper_def*> (id->clone ());
637                 else
638                         p = new Paper_def;
639                 THIS-> lexer_->add_scope (p->scope_);
640                 $$ = p;
641         }
642         | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER         {
643                 Music_output_def *p = unsmob_music_output_def ($3);
644                 p = p->clone ();
645                 THIS->lexer_->add_scope (p->scope_);
646                 $$ = p;
647         }
648         | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER  {
649                 Music_output_def *p = unsmob_music_output_def ($3);
650                 p = p->clone ();
651
652                 THIS->lexer_->add_scope (p->scope_);
653                 $$ = p;
654         }
655         | music_output_def_body assignment  {
656
657         }
658         | music_output_def_body translator_spec_block   {
659                 $$->assign_translator ($2);
660         }
661         | music_output_def_body STYLESHEET embedded_scm {
662                 dynamic_cast<Paper_def*> ($$)-> style_sheet_ = $3;
663         }
664         | music_output_def_body tempo_request  {
665                 /*
666                         junk this ? there already is tempo stuff in
667                         music.
668                 */
669                 int m = gh_scm2int ( $2->get_mus_property ("metronome-count"));
670                 Duration *d = unsmob_duration ($2->get_mus_property ("duration"));
671                 Midi_def * md = dynamic_cast<Midi_def*> ($$);
672                 if (md)
673                         md->set_tempo (d->length_mom (), m);
674         }
675         | music_output_def_body error {
676
677         }
678         ;
679
680 tempo_request:
681         TEMPO steno_duration '=' bare_unsigned  {
682                 $$ = MY_MAKE_MUSIC("TempoEvent");
683                 $$->set_mus_property ("duration", $2);
684                 $$->set_mus_property ("metronome-count", gh_int2scm ( $4));
685         }
686         ;
687
688 /*
689 The representation of a  list is the
690
691   (LIST . LAST-CONS)
692
693  to have  efficient append.
694 */
695 Music_list: /* empty */ {
696                 $$ = scm_cons (SCM_EOL, SCM_EOL);
697         }
698         | Music_list Music {
699                 SCM s = $$;
700                 SCM c = scm_cons ($2->self_scm (), SCM_EOL);
701                 scm_gc_unprotect_object ($2->self_scm ()); /* UGH */
702                 if (gh_pair_p (ly_cdr (s)))
703                         gh_set_cdr_x (ly_cdr (s), c); /* append */
704                 else
705                         gh_set_car_x (s, c); /* set first cons */
706                 gh_set_cdr_x (s, c) ;  /* remember last cell */ 
707         }
708         | Music_list error {
709         }
710         ;
711
712
713 Music:
714         Simple_music
715         | Composite_music
716         ;
717
718 Alternative_music:
719         /* empty */ {
720                 $$ = SCM_EOL;
721         }
722         | ALTERNATIVE '{' Music_list '}' {
723                 $$ = $3;
724         }
725         ;
726
727 Repeated_music:
728         REPEAT string bare_unsigned Music Alternative_music
729         {
730                 Music *beg = $4;
731                 int times = $3;
732                 SCM alts = gh_pair_p ($5) ? gh_car ($5) : SCM_EOL;
733                 if (times < scm_ilength (alts)) {
734                   unsmob_music (gh_car (alts))
735                     ->origin ()->warning (
736                     _("More alternatives than repeats.  Junking excess alternatives."));
737                   alts = ly_truncate_list (times, alts);
738                 }
739                 
740                 Music *r = MY_MAKE_MUSIC("RepeatedMusic");
741                 if (beg)
742                         {
743                         r-> set_mus_property ("element", beg->self_scm ());
744                         scm_gc_unprotect_object (beg->self_scm ());
745                         }
746                 r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
747
748                 r-> set_mus_property ("elements",alts);
749                 SCM func = scm_primitive_eval (ly_symbol2scm ("repeat-name-to-ctor"));
750                 SCM result = gh_call1 (func, $2);
751
752                 if (gh_equal_p ($2, scm_makfrom0str ("tremolo")))
753                 {
754                 /*
755                 we can not get durations and other stuff correct down the line, so we have to
756                 add to the duration log here.
757                 */
758                         SCM func = scm_primitive_eval (ly_symbol2scm ("shift-duration-log"));
759                         if (($3 % 3) == 0)
760                           gh_call3 (func, r->self_scm (), gh_int2scm(-intlog2 ($3*2/3)),gh_int2scm(1));
761                         else
762                           gh_call3 (func, r->self_scm (), gh_int2scm(-intlog2 ($3)), gh_int2scm(0));
763                 }
764
765                 set_music_properties (r, result);
766
767                 r->set_spot (*$4->origin ());
768
769                 $$ = r;
770         }
771         ;
772
773 Sequential_music:
774         SEQUENTIAL '{' Music_list '}'           {
775                 $$ = MY_MAKE_MUSIC("SequentialMusic");
776                 $$->set_mus_property ("elements", ly_car ($3));
777                 $$->set_spot(THIS->here_input());
778         }
779         | '{' Music_list '}'            {
780                 $$ = MY_MAKE_MUSIC("SequentialMusic");
781                 $$->set_mus_property ("elements", ly_car ($2));
782                 $$->set_spot(THIS->here_input());
783         }
784         ;
785
786 Simultaneous_music:
787         SIMULTANEOUS '{' Music_list '}'{
788                 $$ = MY_MAKE_MUSIC("SimultaneousMusic");
789                 $$->set_mus_property ("elements", ly_car ($3));
790                 $$->set_spot(THIS->here_input());
791
792         }
793         | '<' Music_list '>'    {
794                 $$ = MY_MAKE_MUSIC("SimultaneousMusic");
795                 $$->set_mus_property ("elements", ly_car ($2));
796                 $$->set_spot(THIS->here_input());
797         }
798         ;
799
800 Simple_music:
801         request_chord           { $$ = $1; }
802         | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm     {
803                 SCM pred = $2;
804                 if (!gh_symbol_p ($3))
805                 {
806                         THIS->parser_error (_ ("Second argument must be a symbol")); 
807                 }
808                 /* Should check # args */
809                 if (!gh_procedure_p (pred))
810                 {
811                         THIS->parser_error (_ ("First argument must be a procedure taking one argument"));
812                 }
813
814         Music*m = MY_MAKE_MUSIC("OutputPropertySetMusic");
815                 m->set_mus_property ("predicate", pred);
816                 m->set_mus_property ("grob-property", $3);
817                 m->set_mus_property ("grob-value",  $5);
818
819                 $$ = m;
820         }
821         | MUSIC_IDENTIFIER {
822                 $$ = unsmob_music ($1)->clone ();
823
824                 $$->set_spot (THIS->here_input());
825         }
826         | property_def
827         | translator_change
828         ;
829
830
831 Composite_music:
832         CONTEXT STRING Music    {
833         Music*csm =TYPED_MAKE_MUSIC("ContextSpeccedMusic");
834
835                 csm->set_mus_property ("element", $3->self_scm ());
836                 scm_gc_unprotect_object ($3->self_scm ());
837
838                 csm->set_mus_property ("context-type",$2);
839                 csm->set_mus_property ("context-id", scm_makfrom0str (""));
840
841                 $$ = csm;
842         }
843         | AUTOCHANGE STRING Music       {
844         Music*chm = MY_MAKE_MUSIC("AutoChangeMusic");
845                 chm->set_mus_property ("element", $3->self_scm ());
846
847                 scm_gc_unprotect_object ($3->self_scm ());
848                 chm->set_mus_property ("what", $2); 
849
850                 $$ = chm;
851                 chm->set_spot (*$3->origin ());
852         }
853         | GRACE Music {
854 #if 1
855         /*
856                 The other version is for easier debugging  of
857                 Sequential_music_iterator in combination with grace notes.
858         */
859
860                 SCM start = THIS->lexer_->lookup_identifier ("startGraceMusic");
861                 SCM stop = THIS->lexer_->lookup_identifier ("stopGraceMusic");
862                 Music *startm = unsmob_music (start);
863                 Music *stopm = unsmob_music (stop);
864
865                 SCM ms = SCM_EOL;
866                 if (stopm) {
867                         stopm = stopm->clone ();
868                         ms = scm_cons (stopm->self_scm (), ms);
869                         scm_gc_unprotect_object (stopm->self_scm ());
870                 }
871                 ms = scm_cons ($2->self_scm (), ms);
872                 scm_gc_unprotect_object ($2->self_scm());
873                 if (startm) {
874                         startm = startm->clone ();
875                         ms = scm_cons (startm->self_scm () , ms);
876                         scm_gc_unprotect_object (startm->self_scm ());
877                 }
878
879         
880                 Music* seq = MY_MAKE_MUSIC("SequentialMusic");
881                 seq->set_mus_property ("elements", ms);
882
883                 
884                 $$ = MY_MAKE_MUSIC("GraceMusic");
885                 $$->set_mus_property ("element", seq->self_scm ());
886                 scm_gc_unprotect_object (seq->self_scm ());
887 #else
888                 $$ = MY_MAKE_MUSIC("GraceMusic");
889                 $$->set_mus_property ("element", $2->self_scm ());
890                 scm_gc_unprotect_object ($2->self_scm ());
891 #endif
892         }
893         | CONTEXT string '=' string Music {
894                 Music * csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
895
896                 csm->set_mus_property ("element", $5->self_scm ());
897                 scm_gc_unprotect_object ($5->self_scm ());
898
899                 csm->set_mus_property ("context-type", $2);
900                 csm->set_mus_property ("context-id", $4);
901
902                 $$ = csm;
903         }
904         | TIMES {
905                 THIS->push_spot ();
906         }
907         /* CONTINUED */ 
908                 fraction Music  
909
910         {
911                 int n = gh_scm2int (ly_car ($3)); int d = gh_scm2int (ly_cdr ($3));
912                 Music *mp = $4;
913         $$= MY_MAKE_MUSIC("TimeScaledMusic");
914                 $$->set_spot (THIS->pop_spot ());
915
916
917                 $$->set_mus_property ("element", mp->self_scm ());
918                 scm_gc_unprotect_object (mp->self_scm ());
919                 $$->set_mus_property ("numerator", gh_int2scm (n));
920                 $$->set_mus_property ("denominator", gh_int2scm (d));
921                 $$->compress (Moment (Rational (n,d)));
922
923         }
924         | Repeated_music                { $$ = $1; }
925         | Simultaneous_music            { $$ = $1; }
926         | Sequential_music              { $$ = $1; }
927         | TRANSPOSE pitch Music {
928                 $$ = MY_MAKE_MUSIC("TransposedMusic");
929                 Music *p = $3;
930                 Pitch pit = *unsmob_pitch ($2);
931
932                 p->transpose (pit);
933                 $$->set_mus_property ("element", p->self_scm ());
934                 scm_gc_unprotect_object (p->self_scm ());
935         }
936         | TRANSPOSE steno_tonic_pitch Music {
937                 $$ = MY_MAKE_MUSIC("TransposedMusic");
938                 Music *p = $3;
939                 Pitch pit = *unsmob_pitch ($2);
940
941                 p->transpose (pit);
942                 $$->set_mus_property ("element", p->self_scm ());
943                 scm_gc_unprotect_object (p->self_scm ());
944         
945         }
946         | APPLY embedded_scm Music  {
947                 SCM ret = gh_call1 ($2, $3->self_scm ());
948                 Music *m = unsmob_music (ret);
949                 if (!m) {
950                         THIS->parser_error ("\\apply must return a Music");
951                         m = MY_MAKE_MUSIC("Music");
952                         }
953                 $$ = m;
954         }
955         | NOTES
956                 { THIS->lexer_->push_note_state (); }
957         Music
958                 { $$ = $3;
959                   THIS->lexer_->pop_state ();
960                 }
961         | FIGURES
962                 { THIS->lexer_->push_figuredbass_state (); }
963         Music
964                 {
965                   Music * chm = MY_MAKE_MUSIC("UntransposableMusic");
966                   chm->set_mus_property ("element", $3->self_scm ());
967                   $$ = chm;
968                   scm_gc_unprotect_object ($3->self_scm());
969
970                   THIS->lexer_->pop_state ();
971         }
972         | CHORDS
973                 { THIS->lexer_->push_chord_state (); }
974         Music
975                 {
976                   Music * chm = MY_MAKE_MUSIC("UnrelativableMusic");
977                   chm->set_mus_property ("element", $3->self_scm ());
978                   scm_gc_unprotect_object ($3->self_scm());
979                   $$ = chm;
980
981                   THIS->lexer_->pop_state ();
982         }
983         | LYRICS
984                 { THIS->lexer_->push_lyric_state (); }
985         Music
986                 {
987                   $$ = $3;
988                   THIS->lexer_->pop_state ();
989         }
990         | relative_music        { $$ = $1; }
991         | re_rhythmed_music     { $$ = $1; } 
992         | part_combined_music   { $$ = $1; } 
993         ;
994
995 relative_music:
996         RELATIVE absolute_pitch Music {
997                 Music * p = $3;
998                 Pitch pit = *unsmob_pitch ($2);
999                 $$ = MY_MAKE_MUSIC("RelativeOctaveMusic");
1000
1001                 $$->set_mus_property ("element", p->self_scm ());
1002                 scm_gc_unprotect_object (p->self_scm ());
1003
1004                 $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
1005
1006         }
1007         ;
1008
1009 re_rhythmed_music:
1010         ADDLYRICS Music Music {
1011         Music*l =MY_MAKE_MUSIC("LyricCombineMusic");
1012           l->set_mus_property ("elements", gh_list ($2->self_scm (), $3->self_scm (), SCM_UNDEFINED));
1013           scm_gc_unprotect_object ($3->self_scm ());
1014           scm_gc_unprotect_object ($2->self_scm ());
1015           $$ = l;
1016         }
1017         ;
1018
1019 part_combined_music:
1020         PARTCOMBINE STRING Music Music {
1021         Music * p= MY_MAKE_MUSIC("PartCombineMusic");
1022                 p->set_mus_property ("what", $2);
1023                 p->set_mus_property ("elements", gh_list ($3->self_scm (),$4->self_scm (), SCM_UNDEFINED));  
1024
1025                 scm_gc_unprotect_object ($3->self_scm ());
1026                 scm_gc_unprotect_object ($4->self_scm ());  
1027
1028                 $$ = p;
1029         }
1030         ;
1031
1032 translator_change:
1033         TRANSLATOR STRING '=' STRING  {
1034                 Music*t= MY_MAKE_MUSIC("TranslatorChange");
1035                 t-> set_mus_property ("change-to-type", $2);
1036                 t-> set_mus_property ("change-to-id", $4);
1037
1038                 $$ = t;
1039                 $$->set_spot (THIS->here_input ());
1040         }
1041         ;
1042
1043 property_def:
1044         simple_property_def
1045         | ONCE simple_property_def {
1046                 $$ = $2;
1047                 SCM e = $2->get_mus_property ("element");
1048                 unsmob_music (e)->set_mus_property ("once", SCM_BOOL_T);
1049         }
1050         ;
1051
1052 simple_property_def:
1053         PROPERTY STRING '.' STRING '='  scalar {
1054                 Music *t = set_property_music (scm_string_to_symbol ($4), $6);
1055                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1056
1057                 csm->set_mus_property ("element", t->self_scm ());
1058                 scm_gc_unprotect_object (t->self_scm ());
1059
1060                 $$ = csm;
1061                 $$->set_spot (THIS->here_input ());
1062
1063                 csm-> set_mus_property ("context-type", $2);
1064         }
1065         | PROPERTY STRING '.' STRING UNSET {
1066                 
1067                 Music *t = MY_MAKE_MUSIC("PropertyUnset");
1068                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1069
1070                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1071                 csm->set_mus_property ("element", t->self_scm ());
1072                 scm_gc_unprotect_object (t->self_scm ());
1073
1074                 $$ = csm;
1075                 $$->set_spot (THIS->here_input ());
1076
1077                 csm-> set_mus_property ("context-type", $2);
1078         }
1079         | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
1080                 bool autobeam
1081                   = gh_equal_p ($4, scm_makfrom0str ("autoBeamSettings"));
1082                 bool itc = internal_type_checking_global_b;
1083                 Music *t = MY_MAKE_MUSIC("OverrideProperty");
1084
1085                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1086                 t->set_mus_property ("pop-first", SCM_BOOL_T);
1087                 if (autobeam)
1088                         internal_type_checking_global_b = false;
1089                 t->set_mus_property ("grob-property", $6);
1090                 if (autobeam)
1091                         internal_type_checking_global_b = itc;
1092                 t->set_mus_property ("grob-value", $8);
1093
1094                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1095                 csm->set_mus_property ("element", t->self_scm ());
1096                 scm_gc_unprotect_object (t->self_scm ());
1097                 $$ = csm;
1098                 $$->set_spot (THIS->here_input ());
1099
1100                 csm-> set_mus_property ("context-type", $2);
1101         }
1102         | PROPERTY STRING '.' STRING OVERRIDE
1103                 embedded_scm '=' embedded_scm
1104         {
1105                 /*
1106                         UGH UGH UGH UGH.
1107                 */
1108                 bool autobeam
1109                   = gh_equal_p ($4, scm_makfrom0str ("autoBeamSettings"));
1110                 bool itc = internal_type_checking_global_b;
1111
1112                 Music *t = MY_MAKE_MUSIC("OverrideProperty");
1113                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1114                 if (autobeam)
1115                         internal_type_checking_global_b = false;
1116                 t->set_mus_property ("grob-property", $6);
1117                 t->set_mus_property ("grob-value", $8);
1118                 if (autobeam)
1119                         internal_type_checking_global_b = itc;
1120
1121                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1122                 csm->set_mus_property ("element", t->self_scm ());
1123                 scm_gc_unprotect_object (t->self_scm ());
1124
1125                 $$ = csm;
1126                 $$->set_spot (THIS->here_input ());
1127
1128                 csm-> set_mus_property ("context-type", $2);
1129
1130         }
1131         | PROPERTY STRING '.' STRING REVERT embedded_scm {
1132                 Music *t = MY_MAKE_MUSIC("RevertProperty");
1133                 bool autobeam
1134                   = gh_equal_p ($4, scm_makfrom0str ("autoBeamSettings"));
1135                 bool itc = internal_type_checking_global_b;
1136
1137                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1138                 if (autobeam)
1139                         internal_type_checking_global_b = false;
1140                 t->set_mus_property ("grob-property", $6);
1141                 if (autobeam)
1142                         internal_type_checking_global_b = itc;
1143         
1144                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1145                 csm->set_mus_property ("element", t->self_scm ());
1146                 scm_gc_unprotect_object (t->self_scm ());
1147
1148                 $$ = csm;
1149                 $$->set_spot (THIS->here_input ());
1150
1151                 csm-> set_mus_property ("context-type", $2);
1152         }
1153         ;
1154
1155
1156 scalar:
1157         string          { $$ = $1; }
1158         | bare_int      { $$ = gh_int2scm ($1); }
1159         | embedded_scm  { $$ = $1; }
1160         ;
1161
1162
1163 request_chord:
1164         pre_requests {
1165                 THIS->push_spot ();
1166         } /*cont */ simple_element post_requests        {
1167                 Music_sequence *l = dynamic_cast<Music_sequence*> ($3);
1168                 
1169                 $1->concat (*$4);
1170                 for (int i=0; i < $1->size (); i++) {
1171                   Music * m = $1->elem (i);
1172                   l->append_music (m);
1173                 }
1174                 $$ = $3;
1175
1176                 delete $1;
1177                 delete $4;
1178         }
1179         | command_element
1180         ;
1181
1182 command_element:
1183         command_req {
1184                 $$ = MY_MAKE_MUSIC("RequestChord");
1185                 $$->set_mus_property ("elements", scm_cons ($1->self_scm (), SCM_EOL));
1186           scm_gc_unprotect_object ($1->self_scm());
1187
1188                 $$-> set_spot (THIS->here_input ());
1189                 $1-> set_spot (THIS->here_input ());
1190         }
1191         | E_LEFTSQUARE {
1192                 Music *l = MY_MAKE_MUSIC("SpanEvent");
1193                 l->set_mus_property ("span-direction", gh_int2scm (START));
1194                 l->set_mus_property ("span-type", scm_makfrom0str ("ligature"));
1195                 l->set_spot (THIS->here_input ());
1196
1197                 $$ = MY_MAKE_MUSIC("RequestChord");
1198                 $$->set_mus_property ("elements", scm_cons (l->self_scm (), SCM_EOL));
1199           scm_gc_unprotect_object (l->self_scm());
1200                 $$->set_spot (THIS->here_input ());
1201         }
1202         | E_RIGHTSQUARE {
1203                 Music *l = MY_MAKE_MUSIC("SpanEvent");
1204                 l->set_mus_property ("span-direction", gh_int2scm (STOP));
1205                 l->set_mus_property ("span-type", scm_makfrom0str ("ligature"));
1206                 l->set_spot (THIS->here_input ());
1207
1208                 $$ = MY_MAKE_MUSIC("RequestChord");
1209                 $$->set_mus_property ("elements", scm_cons (l->self_scm (), SCM_EOL));
1210                 $$->set_spot (THIS->here_input ());
1211           scm_gc_unprotect_object (l->self_scm());
1212
1213         }
1214         | E_BACKSLASH {
1215                 $$ = MY_MAKE_MUSIC("VoiceSeparator");
1216                 $$->set_spot (THIS->here_input ());
1217         }
1218         | '|'      {
1219
1220                 $$ = MY_MAKE_MUSIC("BarCheck");
1221                 $$->set_spot (THIS->here_input ());
1222         }
1223         | BAR STRING                    {
1224                 Music *t = set_property_music (ly_symbol2scm ("whichBar"), $2);
1225
1226                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1227                 csm->set_mus_property ("element", t->self_scm ());
1228                 scm_gc_unprotect_object (t->self_scm ());
1229
1230                 $$ = csm;
1231                 $$->set_spot (THIS->here_input ());
1232
1233                 csm->set_mus_property ("context-type", scm_makfrom0str ("Timing"));
1234         }
1235         | PARTIAL duration_length       {
1236                 Moment m = - unsmob_duration ($2)->length_mom ();
1237                 Music * p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1238
1239                 Music * sp = MY_MAKE_MUSIC("ContextSpeccedMusic");
1240                 sp->set_mus_property ("element", p->self_scm ());
1241                 scm_gc_unprotect_object (p->self_scm ());
1242
1243                 $$ =sp ;
1244                 sp-> set_mus_property ("context-type", scm_makfrom0str ("Timing"));
1245         }
1246         | CLEF STRING  {
1247                 SCM func = scm_primitive_eval (ly_symbol2scm ("clef-name-to-properties"));
1248                 SCM result = gh_call1 (func, $2);
1249
1250                 SCM l = SCM_EOL;
1251                 for (SCM s = result ; gh_pair_p (s); s = ly_cdr (s)) {
1252                         Music * p = MY_MAKE_MUSIC("Music");
1253                         set_music_properties (p, ly_car (s));
1254                         l = scm_cons (p->self_scm (), l);
1255                         scm_gc_unprotect_object (p->self_scm ());
1256                 }
1257                 Music * seq = MY_MAKE_MUSIC("SequentialMusic");
1258                 seq->set_mus_property ("elements", l);
1259
1260                 Music * sp = MY_MAKE_MUSIC("ContextSpeccedMusic");
1261                 sp->set_mus_property ("element", seq->self_scm ());
1262                 scm_gc_unprotect_object (seq->self_scm ());
1263
1264                 $$ =sp ;
1265                 sp-> set_mus_property ("context-type", scm_makfrom0str ("Staff"));
1266         }
1267         | TIME_T fraction  {
1268                 Music * p1 = set_property_music (ly_symbol2scm ( "timeSignatureFraction"), $2);
1269
1270                 int l = gh_scm2int (ly_car ($2));
1271                 int o = gh_scm2int (ly_cdr ($2));
1272
1273                 Moment one_beat = Moment (1)/Moment (o);
1274                 Moment len = Moment (l) * one_beat;
1275
1276
1277                 Music *p2 = set_property_music (ly_symbol2scm ("measureLength"), len.smobbed_copy ());
1278                 Music *p3 = set_property_music (ly_symbol2scm ("beatLength"), one_beat.smobbed_copy ());
1279
1280                 SCM list = scm_list_n (p1->self_scm (), p2->self_scm (), p3->self_scm(), SCM_UNDEFINED);
1281                 Music *seq = MY_MAKE_MUSIC("SequentialMusic");
1282                 seq->set_mus_property ("elements", list);
1283                 
1284
1285                 Music * sp = MY_MAKE_MUSIC("ContextSpeccedMusic");
1286                 sp->set_mus_property ("element", seq->self_scm ());
1287
1288                 scm_gc_unprotect_object (p3->self_scm ());
1289                 scm_gc_unprotect_object (p2->self_scm ());
1290                 scm_gc_unprotect_object (p1->self_scm ());
1291                 scm_gc_unprotect_object (seq->self_scm ());
1292
1293                 $$ = sp;
1294
1295                 sp-> set_mus_property ("context-type", scm_makfrom0str ( "Timing"));
1296         }
1297         ;
1298
1299 command_req:
1300         shorthand_command_req   { $$ = $1; }
1301         | verbose_command_req   { $$ = $1; }
1302         ;
1303
1304 shorthand_command_req:
1305         extender_req {
1306                 $$ = $1;
1307         }
1308         | hyphen_req {
1309                 $$ = $1;
1310         }
1311         | '~'   {
1312                 $$ = MY_MAKE_MUSIC("TieEvent");
1313         }
1314         | '['           {
1315                 Music *b= MY_MAKE_MUSIC("SpanEvent");
1316                 b->set_mus_property ("span-direction", gh_int2scm (START))
1317 ;
1318                 b->set_mus_property ("span-type", scm_makfrom0str ("beam"));
1319                 $$ =b;
1320
1321
1322                 THIS->last_beam_start_ = b->self_scm ();
1323         }
1324         | ']'           {
1325                 Music *b= MY_MAKE_MUSIC("SpanEvent");
1326                 b->set_mus_property ("span-direction", gh_int2scm (STOP))
1327 ;
1328                 b->set_mus_property ("span-type", scm_makfrom0str ("beam"));
1329                 $$ = b;
1330         }
1331         | BREATHE {
1332                 $$ = MY_MAKE_MUSIC("BreathingSignEvent");
1333         }
1334         | E_TILDE {
1335                 $$ = MY_MAKE_MUSIC("PorrectusEvent");
1336         }
1337         ;
1338
1339 verbose_command_req:
1340         COMMANDSPANREQUEST bare_int STRING { /*TODO: junkme */
1341                 Music * sp = MY_MAKE_MUSIC("SpanEvent");
1342                 sp->set_mus_property ("span-direction", gh_int2scm (Direction ($2)));
1343                 sp->set_mus_property ("span-type",$3);
1344                 sp->set_spot (THIS->here_input ());
1345                 $$ = sp;
1346         }
1347         | MARK DEFAULT  {
1348                 Music * m = MY_MAKE_MUSIC("MarkEvent");
1349                 $$ = m;
1350         }
1351         | MARK scalar {
1352                 Music *m = MY_MAKE_MUSIC("MarkEvent");
1353                 m->set_mus_property ("label", $2);
1354                 $$ = m;
1355         }
1356         | PENALTY SCM_T         {
1357                 Music * b = MY_MAKE_MUSIC("BreakEvent");
1358                 SCM s = $2;
1359                 if (!gh_number_p (s))
1360                         s  =gh_int2scm (0);
1361
1362                 b->set_mus_property ("penalty", s);
1363                 b->set_spot (THIS->here_input ());
1364                 $$ = b;
1365         }
1366         | SKIP duration_length {
1367                 Music * skip = MY_MAKE_MUSIC("SkipEvent");
1368                 skip->set_mus_property ("duration", $2);
1369
1370                 $$ = skip;
1371         }
1372         | tempo_request {
1373                 $$ = $1;
1374         }
1375         | KEY DEFAULT {
1376                 Music *key= MY_MAKE_MUSIC("KeyChangeEvent");
1377                 $$ = key;
1378         }
1379         | KEY NOTENAME_PITCH SCM_IDENTIFIER     {
1380                 Music *key= MY_MAKE_MUSIC("KeyChangeEvent");
1381                 
1382                 key->set_mus_property ("pitch-alist", $3);
1383                 ((Music*)key)->transpose (* unsmob_pitch ($2));
1384                 $$ = key; 
1385         }
1386         ;
1387
1388 post_requests:
1389         {
1390                 $$ = new Link_array<Music>;
1391         }
1392         | post_requests post_request {
1393                 $2->set_spot (THIS->here_input ());
1394                 $$->push ($2);
1395         }
1396         ;
1397
1398 post_request:
1399         verbose_request
1400         | request_with_dir
1401         | close_request
1402         | string_request
1403         ;
1404
1405
1406 string_request:
1407         E_UNSIGNED {
1408                 Music * s = MY_MAKE_MUSIC("StringNumberEvent");
1409                 s->set_mus_property ("string-number",  gh_int2scm($1));
1410                 s->set_spot (THIS->here_input ());
1411                 $$ = s;
1412         }
1413         ;
1414
1415
1416 request_that_take_dir:
1417         gen_text_def
1418         | verbose_request
1419         | script_abbreviation {
1420                 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1421                 Music *a = MY_MAKE_MUSIC("ArticulationEvent");
1422                 if (gh_string_p (s))
1423                         a->set_mus_property ("articulation-type", s);
1424                 else THIS->parser_error (_ ("Expecting string as script definition"));
1425                 $$ = a;
1426         }
1427         ;
1428
1429 request_with_dir:
1430         script_dir request_that_take_dir        {
1431                 $2->set_mus_property ("direction", gh_int2scm ($1));
1432                 $$ = $2;
1433         }
1434         ;
1435         
1436 verbose_request:
1437         REQUEST_IDENTIFIER      {
1438                 $$ = unsmob_music ($1)->clone ();
1439                 $$->set_spot (THIS->here_input ());
1440         }
1441         | DYNAMICSCRIPT embedded_scm {
1442                 /*
1443                         TODO: junkme, use text-type == dynamic
1444                 */
1445                 Music *d = MY_MAKE_MUSIC("TextScriptEvent");
1446                 SCM dyn = ly_symbol2scm ("dynamic");
1447                 d->set_mus_property ("text-type" , dyn);
1448                 d->set_mus_property ("text", $2);
1449                 d->set_spot (THIS->here_input ());
1450                 $$ = d;
1451         }
1452         | SPANREQUEST bare_int STRING {
1453                 Music * sp = MY_MAKE_MUSIC("SpanEvent");
1454                 sp->set_mus_property ("span-direction", gh_int2scm ( $2));
1455                 sp->set_mus_property ("span-type", $3);
1456                 sp->set_spot (THIS->here_input ());
1457                 $$ = sp;
1458         }
1459         | tremolo_type  {
1460                Music * a = MY_MAKE_MUSIC("TremoloEvent");
1461                a->set_spot (THIS->here_input ());
1462                a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1463                $$ = a;
1464         }
1465         | SCRIPT STRING         { 
1466                 Music * a = MY_MAKE_MUSIC("ArticulationEvent");
1467                 a->set_mus_property ("articulation-type", $2);
1468                 a->set_spot (THIS->here_input ());
1469                 $$ = a;
1470         }
1471
1472         /*
1473                 duh, junk this syntax from the parser, if possible. 
1474         */
1475         | ARPEGGIO {
1476                 Music *a = MY_MAKE_MUSIC("ArpeggioEvent");
1477                 a->set_spot (THIS->here_input ());
1478                 $$ = a;
1479         }
1480         | GLISSANDO {
1481                 Music *g = MY_MAKE_MUSIC("GlissandoEvent");
1482                 g->set_spot /* No pun intended */ (THIS->here_input ());
1483                 $$ = g;
1484         }       
1485         ;
1486
1487 sup_quotes:
1488         '\'' {
1489                 $$ = 1;
1490         }
1491         | sup_quotes '\'' {
1492                 $$ ++;
1493         }
1494         ;
1495
1496 sub_quotes:
1497         ',' {
1498                 $$ = 1;
1499         }
1500         | sub_quotes ',' {
1501                 $$ ++ ;
1502         }
1503         ;
1504
1505 steno_pitch:
1506         NOTENAME_PITCH  {
1507                 $$ = $1;
1508         }
1509         | NOTENAME_PITCH sup_quotes     {
1510                 Pitch p = *unsmob_pitch ($1);
1511                 p.octave_ +=  $2;
1512                 $$ = p.smobbed_copy ();
1513         }
1514         | NOTENAME_PITCH sub_quotes      {
1515                 Pitch p =* unsmob_pitch ($1);
1516
1517                 p.octave_ +=  -$2;
1518                 $$ = p.smobbed_copy ();
1519
1520         }
1521         ;
1522
1523 /*
1524 ugh. duplication
1525 */
1526
1527 steno_tonic_pitch:
1528         TONICNAME_PITCH {
1529                 $$ = $1;
1530         }
1531         | TONICNAME_PITCH sup_quotes    {
1532                 Pitch p = *unsmob_pitch ($1);
1533                 p.octave_ +=  $2;
1534                 $$ = p.smobbed_copy ();
1535         }
1536         | TONICNAME_PITCH sub_quotes     {
1537                 Pitch p =* unsmob_pitch ($1);
1538
1539                 p.octave_ +=  -$2;
1540                 $$ = p.smobbed_copy ();
1541
1542         }
1543         ;
1544
1545 pitch:
1546         steno_pitch {
1547                 $$ = $1;
1548         }
1549         | explicit_pitch {
1550                 $$ = $1;
1551         }
1552         ;
1553
1554 explicit_pitch:
1555         PITCH embedded_scm {
1556                 $$ = $2;
1557                 if (!unsmob_pitch ($2)) {
1558                         THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1559                          $$ = Pitch ().smobbed_copy ();
1560                 }
1561         }
1562         ;
1563
1564 verbose_duration:
1565         DURATION embedded_scm   {
1566                 $$ = $2;
1567                 if (!unsmob_duration ($2))
1568                 {
1569                         THIS->parser_error (_ ("Must have duration object"));
1570                         $$ = Duration ().smobbed_copy ();
1571                 }
1572         }
1573         ;
1574
1575 extender_req:
1576         EXTENDER {
1577                 if (!THIS->lexer_->lyric_state_b ())
1578                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1579                 $$ = MY_MAKE_MUSIC("ExtenderEvent");
1580         }
1581         ;
1582
1583 hyphen_req:
1584         HYPHEN {
1585                 if (!THIS->lexer_->lyric_state_b ())
1586                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1587                 $$ = MY_MAKE_MUSIC("HyphenEvent");
1588         }
1589         ;
1590
1591 close_request:
1592         close_request_parens {
1593                 $$ = $1;
1594                 dynamic_cast<Music *> ($$)->set_mus_property ("span-direction", gh_int2scm (START))
1595 ;
1596         }
1597         ;
1598  
1599 close_request_parens:
1600         '('     {
1601                 Music * s= MY_MAKE_MUSIC("SpanEvent");
1602                 $$ = s;
1603                 s->set_mus_property ("span-type", scm_makfrom0str ( "slur"));
1604                 s->set_spot (THIS->here_input());
1605         }
1606         | E_OPEN        {
1607                 Music * s= MY_MAKE_MUSIC("SpanEvent");
1608                 $$ = s;
1609                 s->set_mus_property ("span-type", scm_makfrom0str ( "phrasing-slur"));
1610                 s->set_spot (THIS->here_input());
1611         }
1612         | E_SMALLER {
1613                 Music *s =MY_MAKE_MUSIC("SpanEvent");
1614                 $$ = s;
1615                 s->set_mus_property ("span-type", scm_makfrom0str ( "crescendo"));
1616                 s->set_spot (THIS->here_input());
1617         }
1618         | E_BIGGER {
1619                 Music *s =MY_MAKE_MUSIC("SpanEvent");
1620                 $$ = s;
1621                 s->set_mus_property ("span-type", scm_makfrom0str ("decrescendo"));
1622                 s->set_spot (THIS->here_input());
1623         }
1624         ;
1625
1626
1627 open_request:
1628         open_request_parens {
1629                 $$ = $1;
1630                 dynamic_cast<Music *> ($$)->set_mus_property ("span-direction", gh_int2scm (STOP))
1631 ;
1632         }
1633         ;
1634
1635 open_request_parens:
1636         E_EXCLAMATION   {
1637                 Music *s =  MY_MAKE_MUSIC("SpanEvent");
1638                 s->set_mus_property ("span-type", scm_makfrom0str ( "crescendo"));
1639                 s->set_spot (THIS->here_input());
1640
1641                 $$ = s;
1642         }
1643         | ')'   {
1644                 Music * s= MY_MAKE_MUSIC("SpanEvent");
1645                 $$ = s;
1646                 s->set_mus_property ("span-type", scm_makfrom0str ( "slur"));
1647                 s->set_spot (THIS->here_input());
1648
1649         }
1650         | E_CLOSE       {
1651                 Music * s= MY_MAKE_MUSIC("SpanEvent");
1652                 $$ = s;
1653                 s->set_mus_property ("span-type", scm_makfrom0str ( "phrasing-slur"));
1654                 s->set_spot (THIS->here_input());
1655         }
1656         ;
1657
1658 gen_text_def:
1659         embedded_scm {
1660                 Music *t = MY_MAKE_MUSIC("TextScriptEvent");
1661                 t->set_mus_property ("text", $1);
1662                 t->set_spot (THIS->here_input ());
1663                 $$ = t;
1664         }
1665         | string {
1666                 Music *t = MY_MAKE_MUSIC("TextScriptEvent");
1667                 t->set_mus_property ("text", $1);
1668                 t->set_spot (THIS->here_input ());
1669                 $$ = t;
1670         }
1671         | DIGIT {
1672                 String ds = to_string ($1);
1673                 Music * t = MY_MAKE_MUSIC("TextScriptEvent");
1674                 SCM finger = ly_symbol2scm ("finger");
1675                 t->set_mus_property ("text",  scm_makfrom0str (ds.to_str0 ()));
1676                 t->set_mus_property ("text-type" , finger);
1677                 t->set_spot (THIS->here_input ());
1678                 $$ = t;
1679         }
1680         ;
1681
1682 script_abbreviation:
1683         '^'             {
1684                 $$ = scm_makfrom0str ("Hat");
1685         }
1686         | '+'           {
1687                 $$ = scm_makfrom0str ("Plus");
1688         }
1689         | '-'           {
1690                 $$ = scm_makfrom0str ("Dash");
1691         }
1692         | '|'           {
1693                 $$ = scm_makfrom0str ("Bar");
1694         }
1695         | '>'           {
1696                 $$ = scm_makfrom0str ("Larger");
1697         }
1698         | '.'           {
1699                 $$ = scm_makfrom0str ("Dot");
1700         }
1701         | '_' {
1702                 $$ = scm_makfrom0str ("Underscore");
1703         }
1704         ;
1705
1706 script_dir:
1707         '_'     { $$ = DOWN; }
1708         | '^'   { $$ = UP; }
1709         | '-'   { $$ = CENTER; }
1710         ;
1711
1712 pre_requests:
1713         {
1714                 $$ = new Link_array<Music>;
1715         }
1716         | pre_requests open_request {
1717                 $$->push ($2);
1718         }
1719         ;
1720
1721 absolute_pitch:
1722         steno_pitch     {
1723                 $$ = $1;
1724         }
1725         ;
1726
1727 duration_length:
1728         multiplied_duration {
1729                 $$ = $1;
1730         }
1731         | verbose_duration {
1732                 $$ = $1;
1733         }       
1734         ;
1735
1736 optional_notemode_duration:
1737         {
1738                 Duration dd = THIS->default_duration_;
1739                 $$ = dd.smobbed_copy ();
1740
1741                 THIS->beam_check ($$);
1742         }
1743         | multiplied_duration   {
1744                 $$ = $1;
1745                 THIS->default_duration_ = *unsmob_duration ($$);
1746
1747                 THIS->beam_check ($$);
1748         }
1749         | verbose_duration {
1750                 $$ = $1;
1751                 THIS->default_duration_ = *unsmob_duration ($$);
1752         }       
1753         ;
1754
1755 steno_duration:
1756         bare_unsigned dots              {
1757                 int l = 0;
1758                 if (!is_duration_b ($1))
1759                         THIS->parser_error (_f ("not a duration: %d", $1));
1760                 else
1761                         l =  intlog2 ($1);
1762
1763                 $$ = Duration (l, $2).smobbed_copy ();
1764         }
1765         | DURATION_IDENTIFIER dots      {
1766                 Duration *d =unsmob_duration ($1);
1767                 Duration k (d->duration_log (),d->dot_count () + $2);
1768                 $$ = k.smobbed_copy ();
1769         }
1770         ;
1771
1772
1773
1774
1775 multiplied_duration:
1776         steno_duration {
1777                 $$ = $1;
1778         }
1779         | multiplied_duration '*' bare_unsigned {
1780                 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1781         }
1782         | multiplied_duration '*' FRACTION {
1783                 Rational  m (gh_scm2int (ly_car ($3)), gh_scm2int (ly_cdr ($3)));
1784
1785                 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1786         }
1787         ;
1788
1789 fraction:
1790         FRACTION { $$ = $1; }
1791         | UNSIGNED '/' UNSIGNED {
1792                 $$ = scm_cons (gh_int2scm ($1), gh_int2scm ($3));
1793         }
1794         ;
1795
1796 dots:
1797         /* empty */     {
1798                 $$ = 0;
1799         }
1800         | dots '.' {
1801                 $$ ++;
1802         }
1803         ;
1804
1805
1806 tremolo_type: 
1807         ':'     {
1808                 $$ =0;
1809         }
1810         | ':' bare_unsigned {
1811                 if (!is_duration_b ($2))
1812                         THIS->parser_error (_f ("not a duration: %d", $2));
1813                 $$ = $2;
1814         }
1815         ;
1816
1817
1818 bass_number:
1819         DIGIT
1820         | UNSIGNED 
1821         ;
1822
1823 bass_mod:
1824         '-'     { $$ = -1; }
1825         | '+'   { $$ = 1; } 
1826         | '!'   { $$ = 0; }
1827         ;
1828
1829 bass_figure:
1830         FIGURE_SPACE {
1831                 Music *bfr = MY_MAKE_MUSIC("BassFigureEvent");
1832                 $$ = bfr->self_scm();
1833                 scm_gc_unprotect_object ($$);
1834         }
1835         | bass_number  {
1836                 Music *bfr = MY_MAKE_MUSIC("BassFigureEvent");
1837                 $$ = bfr->self_scm();
1838
1839                 bfr->set_mus_property ("figure", gh_int2scm ($1));
1840
1841                 scm_gc_unprotect_object ($$);
1842         }
1843         | bass_figure bass_mod {
1844                 Music *m = unsmob_music ($1);
1845                 if ($2) {
1846                         SCM salter =m->get_mus_property ("alteration");
1847                         int alter = gh_number_p ( salter) ? gh_scm2int (salter) : 0;
1848                         m->set_mus_property ("alteration",
1849                                 gh_int2scm (alter + $2));
1850                 } else {
1851                         m->set_mus_property ("alteration", gh_int2scm (0));
1852                 }
1853         }
1854         ;
1855
1856 br_bass_figure:
1857         '[' bass_figure {
1858                 $$ = $2;
1859                 unsmob_music ($$)->set_mus_property ("bracket-start", SCM_BOOL_T);
1860         }
1861         | bass_figure   {
1862                 $$ = $1;
1863         }
1864         | br_bass_figure ']' {
1865                 $$ = $1;
1866                 unsmob_music ($1)->set_mus_property ("bracket-stop", SCM_BOOL_T);
1867         }
1868         ;
1869
1870 figure_list:
1871         /**/            {
1872                 $$ = SCM_EOL;
1873         }
1874         | figure_list br_bass_figure {
1875                 $$ = scm_cons ($2, $1); 
1876         }
1877         ;
1878
1879 figure_spec:
1880         FIGURE_OPEN figure_list FIGURE_CLOSE {
1881                 Music * m = MY_MAKE_MUSIC("RequestChord");
1882                 $2 = scm_reverse_x ($2, SCM_EOL);
1883                 m->set_mus_property ("elements",  $2);
1884                 $$ = m->self_scm ();
1885         }
1886         ;
1887
1888
1889 optional_rest:
1890         /**/   { $$ = 0; }
1891         | REST { $$ = 1; }
1892         ;
1893
1894 simple_element:
1895         pitch exclamations questions optional_notemode_duration optional_rest {
1896
1897                 Input i = THIS->pop_spot ();
1898                 if (!THIS->lexer_->note_state_b ())
1899                         THIS->parser_error (_ ("Have to be in Note mode for notes"));
1900
1901                 Music *n = 0;
1902                 if ($5)
1903                         n =  MY_MAKE_MUSIC("RestEvent");
1904                 else
1905                         n =  MY_MAKE_MUSIC("NoteEvent");
1906                 
1907                 n->set_mus_property ("pitch", $1);
1908                 n->set_mus_property ("duration", $4);
1909
1910
1911                 if ($3 % 2)
1912                         n->set_mus_property ("cautionary", SCM_BOOL_T);
1913                 if ($2 % 2 || $3 % 2)
1914                         n->set_mus_property ("force-accidental", SCM_BOOL_T);
1915
1916                 Music *v = MY_MAKE_MUSIC("RequestChord");
1917                 v->set_mus_property ("elements", scm_list_n (n->self_scm (), SCM_UNDEFINED));
1918                 scm_gc_unprotect_object (n->self_scm());
1919
1920                 v->set_spot (i);
1921                 n->set_spot (i);
1922                 $$ = v;
1923         }
1924         | figure_spec optional_notemode_duration {
1925                 Music * m = unsmob_music ($1);
1926                 Input i = THIS->pop_spot (); 
1927                 m->set_spot (i);
1928                 for (SCM s = m->get_mus_property ("elements"); gh_pair_p (s); s = ly_cdr (s))
1929                         {
1930                                 unsmob_music (ly_car (s))->set_mus_property ("duration", $2);
1931                         }
1932                 $$ = m;
1933         }       
1934         | RESTNAME optional_notemode_duration           {
1935
1936                 Input i = THIS->pop_spot ();
1937                 SCM e = SCM_UNDEFINED;
1938                 if (ly_scm2string ($1) =="s") {
1939                         /* Space */
1940                         Music * skip = MY_MAKE_MUSIC("SkipEvent");
1941                         skip->set_mus_property ("duration" ,$2);
1942                         skip->set_spot (i);
1943                         e = skip->self_scm ();
1944                   }
1945                   else {
1946                         Music * rest_req = MY_MAKE_MUSIC("RestEvent");
1947                         rest_req->set_mus_property ("duration", $2);
1948                         rest_req->set_spot (i);
1949                         e = rest_req->self_scm ();
1950                     }
1951                 Music * velt = MY_MAKE_MUSIC("RequestChord");
1952                 velt-> set_mus_property ("elements", scm_list_n (e,SCM_UNDEFINED));
1953                 velt->set_spot (i);
1954
1955                 $$ = velt;
1956         }
1957         | MULTI_MEASURE_REST optional_notemode_duration         {
1958                 THIS->pop_spot ();
1959
1960                 Music * sk = MY_MAKE_MUSIC("SkipEvent");
1961                 sk->set_mus_property ("duration", $2);
1962                 Music *sp1 = MY_MAKE_MUSIC("SpanEvent");
1963                 Music *sp2 = MY_MAKE_MUSIC("SpanEvent");
1964                 sp1-> set_mus_property ("span-direction", gh_int2scm (START))
1965 ;
1966                 sp2-> set_mus_property ("span-direction", gh_int2scm (STOP))
1967 ;
1968                 SCM r = scm_makfrom0str ("rest");
1969                 sp1->set_mus_property ("span-type", r);
1970                 sp2->set_mus_property ("span-type", r);
1971
1972                 Music *rqc1 = MY_MAKE_MUSIC("RequestChord");
1973                 rqc1->set_mus_property ("elements", scm_list_n (sp1->self_scm (), SCM_UNDEFINED));
1974                 Music *rqc2 = MY_MAKE_MUSIC("RequestChord");
1975                 rqc2->set_mus_property ("elements", scm_list_n (sk->self_scm (), SCM_UNDEFINED));;
1976                 Music *rqc3 = MY_MAKE_MUSIC("RequestChord");
1977                 rqc3->set_mus_property ("elements", scm_list_n (sp2->self_scm (), SCM_UNDEFINED));;
1978
1979                 SCM ms = scm_list_n (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1980
1981                 $$ = MY_MAKE_MUSIC("SequentialMusic");
1982                 $$->set_mus_property ("elements", ms);
1983         }
1984         | STRING optional_notemode_duration     {
1985                 Input i = THIS->pop_spot ();
1986
1987                 Music * lreq = MY_MAKE_MUSIC("LyricEvent");
1988                 lreq->set_mus_property ("text", $1);
1989                 lreq->set_mus_property ("duration",$2);
1990                 lreq->set_spot (i);
1991                 Music * velt = MY_MAKE_MUSIC("RequestChord");
1992                 velt->set_mus_property ("elements", scm_list_n (lreq->self_scm (), SCM_UNDEFINED));
1993
1994                 $$= velt;
1995         }
1996         | chord {
1997                 Input i = THIS->pop_spot ();
1998
1999                 if (!THIS->lexer_->chord_state_b ())
2000                         THIS->parser_error (_ ("Have to be in Chord mode for chords"));
2001                 $$ = $1;
2002         }
2003         ;
2004
2005
2006 chord:
2007         steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
2008                 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
2009                 $$->set_spot (THIS->here_input ());
2010         };
2011
2012 chord_additions: 
2013         {
2014                 $$ = SCM_EOL;
2015         } 
2016         | CHORD_COLON chord_notes {
2017                 $$ = $2;
2018         }
2019         ;
2020
2021 chord_notes:
2022         chord_step {
2023                 $$ = $1;
2024         }
2025         | chord_notes '.' chord_step {
2026                 $$ = gh_append2 ($$, $3);
2027         }
2028         ;
2029
2030 chord_subtractions: 
2031         {
2032                 $$ = SCM_EOL;
2033         } 
2034         | CHORD_CARET chord_notes {
2035                 $$ = $2;
2036         }
2037         ;
2038
2039
2040 chord_inversion:
2041         {
2042                 $$ = SCM_EOL;
2043         }
2044         | CHORD_SLASH steno_tonic_pitch {
2045                 $$ = $2;
2046         }
2047         ;
2048
2049 chord_bass:
2050         {
2051                 $$ = SCM_EOL;
2052         }
2053         | CHORD_BASS steno_tonic_pitch {
2054                 $$ = $2;
2055         }
2056         ;
2057
2058 chord_step:
2059         chord_note {
2060                 $$ = scm_cons ($1, SCM_EOL);
2061         }
2062         | CHORDMODIFIER_PITCH {
2063                 $$ = scm_cons (unsmob_pitch ($1)->smobbed_copy (), SCM_EOL);
2064         }
2065         | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
2066                 $$ = scm_list_n (unsmob_pitch ($1)->smobbed_copy (),
2067                         $2, SCM_UNDEFINED);
2068         }
2069         ;
2070
2071 chord_note:
2072         bare_unsigned {
2073                  Pitch m;
2074                 m.notename_ = ($1 - 1) % 7;
2075                 m.octave_ = $1 > 7 ? 1 : 0;
2076                 m.alteration_ = 0;
2077
2078                 $$ = m.smobbed_copy ();
2079         } 
2080         | bare_unsigned '+' {
2081                 Pitch m;
2082                 m.notename_ = ($1 - 1) % 7;
2083                 m.octave_ = $1 > 7 ? 1 : 0;
2084                 m.alteration_ = 1;
2085
2086
2087                 $$ = m.smobbed_copy ();
2088         }
2089         | bare_unsigned CHORD_MINUS {
2090                 Pitch m;
2091                 m.notename_ = ($1 - 1) % 7;
2092                 m.octave_ = $1 > 7 ? 1 : 0;
2093                 m.alteration_ = -1;
2094
2095                 $$ = m.smobbed_copy ();
2096         }
2097         ;
2098
2099 /*
2100         UTILITIES
2101  */
2102 number_expression:
2103         number_expression '+' number_term {
2104                 $$ = scm_sum ($1, $3);
2105         }
2106         | number_expression '-' number_term {
2107                 $$ = scm_difference ($1, $3);
2108         }
2109         | number_term 
2110         ;
2111
2112 number_term:
2113         number_factor {
2114                 $$ = $1;
2115         }
2116         | number_factor '*' number_factor {
2117                 $$ = scm_product ($1, $3);
2118         }
2119         | number_factor '/' number_factor {
2120                 $$ = scm_divide ($1, $3);
2121         }
2122         ;
2123
2124 number_factor:
2125         '(' number_expression ')'       {
2126                 $$ = $2;
2127         }
2128         | '-'  number_factor { /* %prec UNARY_MINUS */
2129                 $$ = scm_difference ($2, SCM_UNDEFINED);
2130         }
2131         | bare_number
2132         ;
2133
2134
2135 bare_number:
2136         UNSIGNED        {
2137                 $$ = gh_int2scm ($1);
2138         }
2139         | REAL          {
2140                 $$ = $1;
2141         }
2142         | NUMBER_IDENTIFIER             {
2143                 $$ = $1;
2144         }
2145         | REAL CM_T     {
2146                 $$ = gh_double2scm (gh_scm2double ($1) CM );
2147         }
2148         | REAL PT_T     {
2149                 $$ = gh_double2scm (gh_scm2double ($1) PT);
2150         }
2151         | REAL IN_T     {
2152                 $$ = gh_double2scm (gh_scm2double ($1) INCH);
2153         }
2154         | REAL MM_T     {
2155                 $$ = gh_double2scm (gh_scm2double ($1) MM);
2156         }
2157         | REAL CHAR_T   {
2158                 $$ = gh_double2scm (gh_scm2double ($1) CHAR);
2159         }
2160         ;
2161
2162
2163 bare_unsigned:
2164         UNSIGNED {
2165                         $$ = $1;
2166         }
2167         | DIGIT {
2168                 $$ = $1;
2169         }
2170         ;
2171
2172 bare_int:
2173         bare_number {
2174                 if (scm_integer_p ($1) == SCM_BOOL_T)
2175                 {
2176                         int k = gh_scm2int ($1);
2177                         $$ = k;
2178                 } else
2179                 {
2180                         THIS->parser_error (_ ("need integer number arg"));
2181                         $$ = 0;
2182                 }
2183         }
2184         | '-' bare_int {
2185                 $$ = -$2;
2186         }
2187         ;
2188
2189
2190 string:
2191         STRING          {
2192                 $$ = $1;
2193         }
2194         | STRING_IDENTIFIER     {
2195                 $$ = $1;
2196         }
2197         | string '+' string {
2198                 $$ = scm_string_append (scm_list_n ($1, $3, SCM_UNDEFINED));
2199         }
2200         ;
2201
2202
2203 exclamations:
2204                 { $$ = 0; }
2205         | exclamations '!'      { $$ ++; }
2206         ;
2207
2208 questions:
2209                 { $$ = 0; }
2210         | questions '?' { $$ ++; }
2211         ;
2212
2213
2214 %%
2215
2216 void
2217 My_lily_parser::set_yydebug (bool )
2218 {
2219 #if 0
2220         yydebug = b;
2221 #endif
2222 }
2223
2224 extern My_lily_parser * current_parser;
2225
2226 void
2227 My_lily_parser::do_yyparse ()
2228 {
2229
2230         current_parser = this;;
2231         yyparse ((void*)this);
2232 }
2233
2234
2235 /*
2236 Should make this optional?    It will also complain when you do
2237
2238         [s4]
2239
2240 which is entirely legitimate.
2241
2242 Or we can scrap it. Barchecks should detect wrong durations, and
2243 skipTypesetting speeds it up a lot.
2244 */
2245 void
2246 My_lily_parser::beam_check (SCM dur)
2247 {
2248   Duration *d = unsmob_duration (dur);
2249   if (unsmob_music (last_beam_start_) && d->duration_log () <= 2)
2250     {
2251       Music * m = unsmob_music (last_beam_start_);
2252       m->origin ()->warning (_("Suspect duration found following this beam"));
2253     }
2254   last_beam_start_ = SCM_EOL;
2255 }