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