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