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