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