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