]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
release: 1.3.106
[lilypond.git] / lily / parser.yy
1 %{ // -*-Fundamental-*-
2
3 /*
4   parser.yy -- Bison/C++ parser for mudela
5
6   source file of the GNU LilyPond music typesetter
7
8   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9            Jan Nieuwenhuizen <janneke@gnu.org>
10 */
11
12 #include <iostream.h>
13 #include "translator-def.hh"
14 #include "lily-guile.hh"
15
16 #include "lookup.hh"
17 #include "misc.hh"
18 #include "my-lily-lexer.hh"
19 #include "paper-def.hh"
20 #include "midi-def.hh"
21 #include "main.hh"
22 #include "file-path.hh"
23 #include "debug.hh"
24 #include "dimensions.hh"
25 #include "identifier.hh"
26 #include "command-request.hh"
27 #include "musical-request.hh"
28 #include "my-lily-parser.hh"
29 #include "context-specced-music.hh"
30 #include "score.hh"
31 #include "music-list.hh"
32
33 #include "file-results.hh"
34 #include "input.hh"
35 #include "scope.hh"
36 #include "relative-music.hh"
37 #include "lyric-combine-music.hh"
38 #include "transposed-music.hh"
39 #include "time-scaled-music.hh"
40 #include "repeated-music.hh"
41 #include "mudela-version.hh"
42 #include "grace-music.hh"
43 #include "auto-change-music.hh"
44 #include "part-combine-music.hh"
45
46 #include "chord.hh"
47
48 bool
49 is_duration_b (int t)
50 {
51   return t && t == 1 << intlog2(t);
52 }
53
54
55 // mmm JUNKME ?
56 Mudela_version oldest_version ("1.3.59");
57
58 void
59 print_mudela_versions (ostream &os)
60 {
61   os << _f ("Oldest supported input version: %s", oldest_version.str ()) 
62     << endl;
63 }
64
65
66 // needed for bison.simple's malloc() and free()
67 #include <malloc.h>
68
69 #ifndef NDEBUG
70 #define YYDEBUG 1
71 #endif
72
73 #define YYERROR_VERBOSE 1
74
75 #define YYPARSE_PARAM my_lily_parser_l
76 #define YYLEX_PARAM my_lily_parser_l
77 #define THIS ((My_lily_parser *) my_lily_parser_l)
78
79 #define yyerror THIS->parser_error
80 #define ARRAY_SIZE(a,s)   if (a.size () != s) THIS->parser_error (_f ("Expecting %d arguments", s))
81
82 %}
83
84
85 %union {
86     Array<Musical_pitch> *pitch_arr;
87     Link_array<Request> *reqvec;
88     Duration *duration;
89     Identifier *id;
90     String * string;
91     Music *music;
92     Score *score;
93     Scope *scope;
94
95     Musical_req* musreq;
96     Music_output_def * outputdef;
97     Musical_pitch * pitch;
98     Midi_def* midi;
99     Real real;
100     Request * request;
101
102     /* We use SCMs to do strings, because it saves us the trouble of
103 deleting them.  Let's hope that a stack overflow doesnt trigger a move
104 of the parse stack onto the heap. */
105
106     SCM scm;
107
108     Tempo_req *tempo;
109     int i;
110 }
111 %{
112
113 int
114 yylex (YYSTYPE *s,  void * v_l)
115 {
116         My_lily_parser   *pars_l = (My_lily_parser*) v_l;
117         My_lily_lexer * lex_l = pars_l->lexer_p_;
118
119         lex_l->lexval_l = (void*) s;
120         return lex_l->yylex ();
121 }
122
123
124 %}
125
126 %pure_parser
127
128 /* tokens which are not keywords */
129 %token AUTOCHANGE
130 %token APPLY
131 %token ARPEGGIO
132 %token DYNAMICSCRIPT
133 %token TEXTSCRIPT
134 %token ACCEPTS
135 %token ALTERNATIVE
136 %token BAR
137 %token BREATHE
138 %token CHORDMODIFIERS
139 %token CHORDS
140 %token CHAR_T
141 %token CLEF
142 %token CM_T
143 %token CONSISTS
144 %token SEQUENTIAL
145 %token ELEMENTDESCRIPTIONS
146 %token SIMULTANEOUS
147 %token CONSISTSEND
148 %token DENIES
149 %token DURATION
150 %token EXTENDER
151 %token FONT
152 %token GRACE
153 %token HEADER
154 %token HYPHEN
155 %token IN_T
156 %token INVALID
157 %token KEY
158 %token LYRICS
159 %token MARK
160 %token MEASURES
161 %token MIDI
162 %token MM_T
163 %token MUSICAL_PITCH
164 %token NAME
165 %token NOTENAMES
166 %token NOTES
167 %token PAPER
168 %token PARTIAL
169 %token PENALTY
170 %token PROPERTY
171 %token PUSH POP 
172 %token PT_T
173 %token RELATIVE
174 %token REMOVE
175 %token REPEAT
176 %token ADDLYRICS
177 %token PARTCOMBINE
178 %token SCM_T
179 %token SCORE
180 %token SCRIPT
181 %token SKIP
182 %token SPANREQUEST
183 %token STYLESHEET
184 %token COMMANDSPANREQUEST
185 %token TEMPO
186 %token OUTPUTPROPERTY
187 %token TIME_T
188 %token TIMES
189 %token TRANSLATOR
190 %token TRANSPOSE
191 %token TYPE
192 %token CONTEXT
193
194 /* escaped */
195 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER 
196 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET 
197
198 %type <i>       exclamations questions
199 %token <i>      DIGIT
200 %token <pitch>  NOTENAME_PITCH
201 %token <pitch>  TONICNAME_PITCH
202 %token <pitch>  CHORDMODIFIER_PITCH
203 %token <id>     DURATION_IDENTIFIER
204 %token <id>     IDENTIFIER
205
206
207 %token <id>     SCORE_IDENTIFIER
208 %token <id>     MUSIC_OUTPUT_DEF_IDENTIFIER
209
210 %token <scm>    NUMBER_IDENTIFIER
211 %token <scm>    REQUEST_IDENTIFIER
212 %token <scm>    MUSIC_IDENTIFIER TRANSLATOR_IDENTIFIER
213 %token <scm>    STRING_IDENTIFIER SCM_IDENTIFIER 
214 %token <scm>    DURATION RESTNAME
215 %token <scm>    STRING 
216 %token <scm>    SCM_T
217 %token <i>      UNSIGNED
218 %token <real>   REAL
219
220 %type <outputdef> output_def
221 %type <scope>   mudela_header mudela_header_body
222 %type <request> open_request_parens close_request_parens open_request close_request
223 %type <request> request_with_dir request_that_take_dir verbose_request
224 %type <i>       sub_quotes sup_quotes
225 %type <music>   simple_element  request_chord command_element Simple_music  Composite_music 
226 %type <music>   Alternative_music Repeated_music
227 %type <i>       tremolo_type
228 %type <i>       bare_int  bare_unsigned
229 %type <i>       script_dir
230
231 %type <scm>     identifier_init 
232
233 %type <duration> steno_duration optional_notemode_duration
234 %type <duration> entered_notemode_duration explicit_duration
235         
236 %type <reqvec>  pre_requests post_requests
237 %type <request> gen_text_def
238 %type <pitch>   steno_musical_pitch musical_pitch absolute_musical_pitch
239 %type <pitch>   steno_tonic_pitch
240
241 %type <pitch_arr>       chord_additions chord_subtractions chord_notes chord_step
242 %type <music>   chord
243 %type <pitch>   chord_note chord_inversion chord_bass
244 %type <duration>        duration_length
245
246 %type <scm>  embedded_scm scalar
247 %type <music>   Music Sequential_music Simultaneous_music Music_sequence
248 %type <music>   relative_music re_rhythmed_music part_combined_music
249 %type <music>   property_def translator_change
250 %type <scm> Music_list
251 %type <outputdef>  music_output_def_body
252 %type <request> shorthand_command_req
253 %type <request> post_request 
254 %type <music> command_req verbose_command_req
255 %type <request> extender_req
256 %type <request> hyphen_req
257 %type <scm>     string bare_number number_expression
258 %type <score>   score_block score_body
259
260 %type <scm>     translator_spec_block translator_spec_body
261 %type <tempo>   tempo_request
262 %type <scm> notenames_body notenames_block chordmodifiers_block
263 %type <scm>     script_abbreviation
264
265
266
267 %left '-' '+'
268 %left '*' '/'
269 %left UNARY_MINUS
270
271 %%
272
273 mudela: /* empty */
274         | mudela toplevel_expression {}
275         | mudela assignment  { }
276         | mudela error {
277                 THIS->error_level_i_  = 1;
278                 //THIS->parser_error (_ ("ly invalid"));
279         }
280         | mudela INVALID        {
281                 THIS->error_level_i_  = 1;
282                 //THIS->parser_error (_ ("ly invalid"));
283         }
284         ;
285
286 toplevel_expression:
287         notenames_block                 {
288                 THIS->lexer_p_->pitchname_tab_ =  $1;
289         }
290         | chordmodifiers_block                  {
291                 THIS->lexer_p_->chordmodifier_tab_  = $1;
292         }
293         | mudela_header {
294                 delete header_global_p;
295                 header_global_p = $1;
296         }
297         | score_block {
298                 score_global_array.push ($1);
299         }
300         | output_def {
301                 Identifier * id = new
302                         Music_output_def_identifier ($1, MUSIC_OUTPUT_DEF_IDENTIFIER);
303                 if (dynamic_cast<Paper_def*> ($1))
304                         THIS->lexer_p_->set_identifier ("$defaultpaper", id->self_scm ());
305                 else if (dynamic_cast<Midi_def*> ($1))
306                         THIS->lexer_p_->set_identifier ("$defaultmidi", id->self_scm ());
307         }
308         | embedded_scm {
309                 // junk value
310         }       
311         ;
312
313 embedded_scm:
314         SCM_T
315         | SCM_IDENTIFIER 
316         ;
317
318
319 chordmodifiers_block:
320         CHORDMODIFIERS notenames_body   {  $$ = $2; }
321         ;
322
323
324 notenames_block:
325         NOTENAMES notenames_body   {  $$ = $2; }
326         ;
327
328
329
330 notenames_body:
331         embedded_scm    {
332           int i = scm_ilength ($1);
333
334           SCM tab = scm_make_vector (gh_int2scm (i), SCM_EOL);
335           for (SCM s = $1; s != SCM_EOL; s = gh_cdr (s)) {
336                 SCM pt = gh_cdar (s);
337                 if (scm_ilength (pt) != 3)
338                         THIS->parser_error ("Need three args");
339                 scm_hashq_set_x (tab, gh_caar(s), pt);
340           }
341
342           $$ = tab;
343         }
344         ;
345
346 mudela_header_body:
347         {
348                 $$ = new Scope;
349                 THIS->lexer_p_-> scope_l_arr_.push ($$);
350         }
351         | mudela_header_body assignment semicolon { 
352
353         }
354         ;
355
356 mudela_header:
357         HEADER '{' mudela_header_body '}'       {
358                 $$ = $3;
359                 THIS->lexer_p_-> scope_l_arr_.pop ();           
360         }
361         ;
362
363
364 /*
365         DECLARATIONS
366 */
367 assignment:
368         STRING {
369                 THIS->remember_spot ();
370         }
371         /* cont */ '=' identifier_init  {
372                 THIS->lexer_p_->set_identifier (ly_scm2string ($1), $4);
373
374 /*
375  TODO: devise standard for protection in parser.
376
377   The parser stack lives on the C-stack, which means that
378 all objects can be unprotected as soon as they're here.
379
380 */
381                 Identifier * id =unsmob_identifier ($4);
382                 Input spot = THIS->pop_spot ();
383                 if (id) id->set_spot (spot);
384         }
385         ;
386
387
388
389 identifier_init:
390         score_block {
391                 $$ = (new Score_identifier ($1, SCORE_IDENTIFIER))->self_scm();
392         }
393         | output_def {
394                 $$ = (new Music_output_def_identifier ($1, MUSIC_OUTPUT_DEF_IDENTIFIER))->self_scm();
395         }
396         | translator_spec_block {
397                 $$ = $1;
398         }
399         | Music  {
400                 $$ = $1->self_scm ();
401                 scm_unprotect_object ($$);
402         }
403         | post_request {
404                 $$ = $1->self_scm ();
405                 scm_unprotect_object ($$);
406         }
407         | explicit_duration {
408                 $$ = (new Duration_identifier ($1, DURATION_IDENTIFIER))->self_scm ();
409         }
410         | number_expression {
411                 $$ = $1;
412         }
413         | string {
414                 $$ = $1;
415         }
416         | embedded_scm  {
417                 $$ = $1;
418         }
419         ;
420
421 translator_spec_block:
422         TRANSLATOR '{' translator_spec_body '}'
423                 {
424                 $$ = $3;
425         }
426         ;
427
428 translator_spec_body:
429         TRANSLATOR_IDENTIFIER   {
430                 $$ = unsmob_translator_def ($1)->clone_scm ();
431                 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
432         }
433         | TYPE STRING semicolon {
434                 $$ = Translator_def::make_scm ();
435                 Translator_def*td =  unsmob_translator_def ($$);
436                 td->translator_group_type_ = $2;
437                 td->set_spot (THIS->here_input ());
438         }
439         | translator_spec_body STRING '=' embedded_scm                  {
440                 unsmob_translator_def ($$)->add_property_assign ($2, $4);
441         }
442         | translator_spec_body STRING PUSH embedded_scm '=' embedded_scm {
443                 unsmob_translator_def ($$)
444                         ->add_push_property (scm_string_to_symbol ($2), $4, $6);
445         }
446         | translator_spec_body STRING POP embedded_scm  {
447           unsmob_translator_def($$)->add_pop_property (
448                 scm_string_to_symbol ($2), $4);
449         }
450         | translator_spec_body STRING '=' identifier_init semicolon     { 
451                 SCM v = gh_int2scm (0);
452                 if (gh_string_p ($4) || gh_number_p ($4) || gh_boolean_p ($4))
453                         v = $4;
454                 else 
455                         THIS->parser_error (_("Wrong type for property value"));
456
457                 /* ugh*/
458                 unsmob_translator_def($$)->add_property_assign ($2, v);
459         }
460         | translator_spec_body NAME STRING semicolon {
461                 unsmob_translator_def ($$)->type_name_ = $3;
462         }
463         | translator_spec_body CONSISTS STRING semicolon {
464                 unsmob_translator_def ($$)->add_element ($3);
465         }
466         | translator_spec_body ELEMENTDESCRIPTIONS embedded_scm {
467                 for (SCM p = $3; gh_pair_p (p); p = gh_cdr (p))
468                         unsmob_translator_def ($$)
469                         ->add_property_assign (scm_symbol_to_string (gh_caar (p)), gh_cdar (p));
470
471         }
472         | translator_spec_body CONSISTSEND STRING semicolon {
473                 unsmob_translator_def ($$)->add_last_element ( $3);
474         }
475         | translator_spec_body ACCEPTS STRING semicolon {
476                 unsmob_translator_def ($$)->set_acceptor ($3,true);
477         }
478         | translator_spec_body DENIES STRING semicolon {
479                 unsmob_translator_def ($$)->set_acceptor ($3,false);
480         }
481         | translator_spec_body REMOVE STRING semicolon {
482                 unsmob_translator_def ($$)->remove_element ($3);
483         }
484         ;
485
486 /*
487         SCORE
488 */
489 score_block:
490         SCORE { 
491                 THIS->remember_spot ();
492         }
493         /*cont*/ '{' score_body '}'     {
494                 THIS->pop_spot ();
495                 $$ = $4;
496                 if (!$$->def_p_arr_.size ())
497                 {
498                   Identifier *id =
499                         unsmob_identifier (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
500                   $$->add_output (id ? id->access_content_Music_output_def (true) : new Paper_def );
501                 }
502         }
503 /*
504         | SCORE '{' score_body error {
505                 $$ = $3
506                 $$->set_spot (THIS->here_input ());
507                 // THIS->here_input ().error ("SCORE INVALID");
508                 $$->error ("SCORE INVALID");
509                 THIS->parser_error (_f ("SCORE ERROR"));
510         }
511 */
512         ;
513
514 score_body:
515         Music   {
516                 $$ = new Score;
517
518                 $$->set_spot (THIS->here_input ());
519                 SCM m = $1->self_scm ();
520                 scm_unprotect_object (m);
521                 $$->music_ = m;
522         }
523         | SCORE_IDENTIFIER {
524                 $$ = $1->access_content_Score (true);
525         }
526         | score_body mudela_header      {
527                 $$->header_p_ = $2;
528         }
529         | score_body output_def {
530                 $$->add_output ($2);
531         }
532         | score_body error {
533
534         }
535         ;
536
537
538 /*
539         MIDI
540 */
541 output_def:
542         music_output_def_body '}' {
543                 $$ = $1;
544                 THIS-> lexer_p_-> scope_l_arr_.pop();
545         }
546         ;
547
548 music_output_def_body:
549         MIDI '{'    {
550          Identifier *id = unsmob_identifier (THIS->lexer_p_->lookup_identifier ("$defaultmidi"));
551
552                 
553          Midi_def* p =0;
554         if (id)
555                 p = dynamic_cast<Midi_def*> (id->access_content_Music_output_def (true));
556         else
557                 p = new Midi_def;
558
559          $$ = p;
560          THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
561         }
562         | PAPER '{'     {
563                   Identifier *id = unsmob_identifier (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
564                   Paper_def *p = 0;
565                 if (id)
566                         p = dynamic_cast<Paper_def*> (id->access_content_Music_output_def (true));
567                 else
568                         p = new Paper_def;
569                 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
570                 $$ = p;
571         }
572         | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER         {
573                 Music_output_def *p = $3->access_content_Music_output_def (true);
574                 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
575                 $$ = p;
576         }
577         | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER  {
578                 Music_output_def *p = $3->access_content_Music_output_def (true);
579                 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
580                 $$ = p;
581         }
582         | music_output_def_body assignment semicolon {
583
584         }
585         | music_output_def_body translator_spec_block   {
586                 $$->assign_translator ($2);
587         }
588         | music_output_def_body STYLESHEET embedded_scm {
589                 dynamic_cast<Paper_def*> ($$)-> style_sheet_ = $3;
590         }
591         | music_output_def_body tempo_request semicolon {
592                 /*
593                         junk this ? there already is tempo stuff in
594                         music.
595                 */
596                 int m = gh_scm2int ( $2->get_mus_property ("metronome-count")); 
597                 dynamic_cast<Midi_def*> ($$)->set_tempo ($2->dur_.length_mom (), m);
598         }
599         | music_output_def_body error {
600
601         }
602         ;
603
604 tempo_request:
605         TEMPO steno_duration '=' bare_unsigned  {
606                 $$ = new Tempo_req;
607                 $$->dur_ = *$2;
608                 delete $2;
609                 $$-> set_mus_property ("metronome-count", gh_int2scm ( $4));
610         }
611         ;
612
613 Music_list: /* empty */ {
614                 $$ = gh_cons (SCM_EOL, SCM_EOL);
615         }
616         | Music_list Music {
617                 SCM s = $$;
618                 SCM c = gh_cons ($2->self_scm (), SCM_EOL);
619                 scm_unprotect_object ($2->self_scm ()); /* UGH */
620
621         
622                 if (gh_pair_p (gh_cdr (s)))
623                         gh_set_cdr_x (gh_cdr (s), c); /* append */
624                 else
625                         gh_set_car_x (s, c); /* set first cons */
626                 gh_set_cdr_x (s, c) ;  /* remember last cell */ 
627         }
628         | Music_list error {
629         }
630         ;
631
632
633 Music:
634         Simple_music
635         | Composite_music
636         ;
637
638 Alternative_music:
639         /* empty */ {
640                 $$ = 0;
641         }
642         | ALTERNATIVE Music_sequence {
643                 $$ = $2;
644                 $2->set_spot (THIS->here_input ());
645         }
646         ;
647
648
649
650
651 Repeated_music:
652         REPEAT STRING bare_unsigned Music Alternative_music
653         {
654                 Music_sequence* m = dynamic_cast <Music_sequence*> ($5);
655                 if (m && $3 < m->length_i ())
656                         $5->origin ()->warning (_ ("More alternatives than repeats.  Junking excess alternatives."));
657
658                 Repeated_music * r = new Repeated_music ($4, $3 >? 1, m);
659                 $$ = r;
660                 r->type_ = ly_scm2string ($2);
661                 r->fold_b_ = (r->type_ == "fold");
662                 r->volta_fold_b_ =  (r->type_ == "volta");
663                 r->set_spot (*$4->origin ());
664         }
665         ;
666
667 Music_sequence: '{' Music_list '}'      {
668                 $$ = new Music_sequence (gh_car ($2));
669         }
670         ;
671
672 Sequential_music:
673         SEQUENTIAL '{' Music_list '}'           {
674                 $$ = new Sequential_music (gh_car ($3));
675         }
676         | '{' Music_list '}'            {
677                 $$ = new Sequential_music (gh_car ($2));
678         }
679         ;
680
681 Simultaneous_music:
682         SIMULTANEOUS '{' Music_list '}'{
683                 $$ = new Simultaneous_music (gh_car ($3));
684         }
685         | '<' Music_list '>'    {
686                 $$ = new Simultaneous_music (gh_car ($2));
687         }
688         ;
689
690 Simple_music:
691         request_chord           { $$ = $1; }
692         | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm     {
693                 SCM pred = $2;
694                 if (!gh_symbol_p ($3))
695                 {
696                         THIS->parser_error (_("Second argument must be a symbol")); 
697                 }
698                 /*hould check # args */
699                 if (!gh_procedure_p (pred))
700                 {
701                         THIS->parser_error (_("First argument must be a procedure taking 1 argument"));
702                 }
703
704           Music *m = new Music;
705           m->set_mus_property ("predicate", pred);
706           m->set_mus_property ("symbol", $3);
707           m->set_mus_property ("value",  $5);
708           m->set_mus_property ("type", ly_symbol2scm ("output-property"));
709
710                 $$ = m;
711         }
712         | MUSIC_IDENTIFIER {
713                 $$ = unsmob_music ($1)->clone ();
714         }
715         | property_def
716         | translator_change
717         | Simple_music '*' bare_unsigned '/' bare_unsigned      {
718                 $$ = $1;
719                 $$->compress (Moment($3, $5 ));
720         }
721         | Simple_music '*' bare_unsigned                 {
722                 $$ = $1;
723                 $$->compress (Moment ($3, 1));
724         }
725         ;
726
727
728 Composite_music:
729         CONTEXT STRING Music    {
730                 Context_specced_music *csm =  new Context_specced_music ($3);
731
732                 csm->set_mus_property ("context-type",$2);
733                 csm->set_mus_property ("context-id", ly_str02scm (""));
734
735                 $$ = csm;
736         }
737         | AUTOCHANGE STRING Music       {
738                 Auto_change_music * chm = new Auto_change_music ($3);
739                 chm->set_mus_property ("what", $2); 
740
741                 $$ = chm;
742                 chm->set_spot (*$3->origin ());
743         }
744         | GRACE Music {
745                 $$ = new Grace_music ($2);
746         }
747         | CONTEXT STRING '=' STRING Music {
748                 Context_specced_music *csm =  new Context_specced_music ($5);
749
750                 csm->set_mus_property ("context-type", $2);
751                 csm->set_mus_property ("context-id", $4);
752
753                 $$ = csm;
754         }
755         | TIMES {
756                 THIS->remember_spot ();
757         }
758         /* CONTINUED */ 
759                 bare_unsigned '/' bare_unsigned Music   
760
761         {
762                 $$ = new Time_scaled_music ($3, $5, $6);
763                 $$->set_spot (THIS->pop_spot ());
764         }
765         | Repeated_music                { $$ = $1; }
766         | Simultaneous_music            { $$ = $1; }
767         | Sequential_music              { $$ = $1; }
768         | TRANSPOSE musical_pitch Music {
769                 $$ = new Transposed_music ($3, *$2);
770                 delete $2; // ugh
771         }
772         | TRANSPOSE steno_tonic_pitch Music {
773                 $$ = new Transposed_music ($3, *$2);
774                 delete $2; // ugh
775         }
776         | APPLY embedded_scm Music  {
777                 SCM ret = gh_call1 ($2, $3->self_scm ());
778                 Music *m = unsmob_music (ret);
779                 if (!m) {
780                         THIS->parser_error ("\\apply must return a Music");
781                         m = new Music ();
782                         }
783                 $$ = m;
784         }
785         | NOTES
786                 { THIS->lexer_p_->push_note_state (); }
787         Music
788                 { $$ = $3;
789                   THIS->lexer_p_->pop_state ();
790                 }
791         | CHORDS
792                 { THIS->lexer_p_->push_chord_state (); }
793         Music
794                 {
795                   $$ = $3;
796                   THIS->lexer_p_->pop_state ();
797         }
798         | LYRICS
799                 { THIS->lexer_p_->push_lyric_state (); }
800         Music
801                 {
802                   $$ = $3;
803                   THIS->lexer_p_->pop_state ();
804         }
805         | relative_music        { $$ = $1; }
806         | re_rhythmed_music     { $$ = $1; } 
807         | part_combined_music   { $$ = $1; } 
808         ;
809
810 relative_music:
811         RELATIVE absolute_musical_pitch Music {
812                 $$ = new Relative_octave_music ($3, *$2);
813                 delete $2; // ugh
814         }
815         ;
816
817 re_rhythmed_music:
818         ADDLYRICS Music Music {
819                 Lyric_combine_music * l = new Lyric_combine_music ($2, $3);
820                 $$ = l;
821         }
822         ;
823
824 part_combined_music:
825         PARTCOMBINE STRING Music Music {
826                 Part_combine_music * p = new Part_combine_music ($2, $3, $4);
827                 $$ = p;
828         }
829         ;
830
831 translator_change:
832         TRANSLATOR STRING '=' STRING  {
833                 Music * t = new Music;
834                 t->set_mus_property ("type",
835                         ly_symbol2scm ("change-translator"));
836                 t-> set_mus_property ("change-to-type", $2);
837                 t-> set_mus_property ("change-to-id", $4);
838
839                 $$ = t;
840                 $$->set_spot (THIS->here_input ());
841         }
842         ;
843
844 property_def:
845         PROPERTY STRING '.' STRING '='  scalar {
846                 Music *t = new Music;
847
848                 t->set_mus_property ("type", ly_symbol2scm ("property-set"));
849                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
850                 t->set_mus_property ("value", $6);
851
852                 Context_specced_music *csm = new Context_specced_music (t);
853                 $$ = csm;
854                 $$->set_spot (THIS->here_input ());
855
856                 csm-> set_mus_property ("context-type", $2);
857         }
858         | PROPERTY STRING '.' STRING PUSH embedded_scm '=' embedded_scm {
859                 Music *t = new Music;
860                 t->set_mus_property ("type", ly_symbol2scm ("property-push"));
861                 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
862                 t->set_mus_property ("element-property", $6);
863                 t->set_mus_property ("element-value", $8);
864                 Context_specced_music *csm = new Context_specced_music (t);
865                 $$ = csm;
866                 $$->set_spot (THIS->here_input ());
867
868                 csm-> set_mus_property ("context-type", $2);
869         }
870         | PROPERTY STRING '.' STRING POP embedded_scm {
871                 Music *t = new Music;
872                 t->set_mus_property ("type", ly_symbol2scm ("property-pop"));
873                 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
874                 t->set_mus_property ("element-property", $6);
875
876                 Context_specced_music *csm = new Context_specced_music (t);
877                 $$ = csm;
878                 $$->set_spot (THIS->here_input ());
879
880                 csm-> set_mus_property ("context-type", $2);
881         }
882         ;
883
884 scalar:
885         string          { $$ = $1; }
886         | bare_int      { $$ = gh_int2scm ($1); }
887         | embedded_scm  { $$ = $1; }
888         ;
889
890
891 request_chord:
892         pre_requests simple_element post_requests       {
893                 Music_sequence *l = dynamic_cast<Music_sequence*>($2);
894                 if (l) {
895                         for (int i=0; i < $1->size(); i++)
896                                 l->append_music ($1->elem(i));
897                         for (int i=0; i < $3->size(); i++)
898                                 l->append_music ($3->elem(i));
899                         }
900                 else
901                         programming_error ("Need Sequence to add music to");
902                 $$ = $2;
903                 
904         }
905         | command_element
906         ;
907
908 command_element:
909         command_req {
910                 $$ = new Request_chord (gh_cons ($1->self_scm (), SCM_EOL));
911                 $$-> set_spot (THIS->here_input ());
912                 $1-> set_spot (THIS->here_input ());
913         }
914         | BAR STRING ';'                        {
915                 Music *t = new Music;
916
917                 t->set_mus_property ("type", ly_symbol2scm ("property-set"));
918                 t->set_mus_property ("symbol", ly_symbol2scm ("whichBar"));
919                 t->set_mus_property ("value", $2);
920
921                 Context_specced_music *csm = new Context_specced_music (t);
922                 $$ = csm;
923                 $$->set_spot (THIS->here_input ());
924
925                 csm->set_mus_property ("context-type", ly_str02scm ("Score"));
926         }
927         | PARTIAL duration_length ';'   {
928                 Music * p = new Music;
929                 p->set_mus_property ("symbol", ly_symbol2scm ( "measurePosition"));
930                 p->set_mus_property ("type", ly_symbol2scm ("property-set"));
931
932                 Moment m = - $2->length_mom ();
933                 p->set_mus_property ("value", m.make_scm());
934                 delete $2; // ugh
935                 Context_specced_music * sp = new Context_specced_music (p);
936                 $$ =sp ;
937                 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
938         }
939         | CLEF STRING ';' {
940                 SCM func = scm_eval2 (ly_symbol2scm ("clef-name-to-properties"), SCM_EOL);
941                 SCM result = gh_call1 (func, $2);
942
943                 SCM l = SCM_EOL; 
944                 for (SCM s = result ; gh_pair_p (s); s = gh_cdr (s)) {
945                         Music * p = new Music;
946                         for (SCM k = gh_car (s) ; gh_pair_p (k); k = gh_cdr (k)) {
947                                 p->set_mus_property (gh_caar (k), gh_cdar (k));
948                         }
949                         l = gh_cons (p->self_scm (), l);
950                         scm_unprotect_object (p->self_scm ());
951                 }
952                 Sequential_music * seq = new Sequential_music (l);
953
954                 Context_specced_music * sp = new Context_specced_music (seq);
955                 $$ =sp ;
956                 sp-> set_mus_property("context-type", ly_str02scm("Staff"));
957         }
958         ;
959
960 command_req:
961         shorthand_command_req   { $$ = $1; }
962         | verbose_command_req semicolon { $$ = $1; }
963         ;
964
965 shorthand_command_req:
966         extender_req {
967                 $$ = $1;
968         }
969         | hyphen_req {
970                 $$ = $1;
971         }
972         | '|'                           {
973                 $$ = new Barcheck_req;
974         }
975         | '~'   {
976                 $$ = new Tie_req;
977         }
978         | '['           {
979                 Span_req*b= new Span_req;
980                 b->set_span_dir(START);
981                 b->set_mus_property ("span-type", ly_str02scm ("beam"));
982                 $$ =b;
983         }
984         | ']'           {
985                 Span_req*b= new Span_req;
986                 b->set_span_dir( STOP);
987                 b->set_mus_property ("span-type", ly_str02scm ("beam"));
988                 $$ = b;
989         }
990         | BREATHE {
991                 $$ = new Breathing_sign_req;
992         }
993         ;
994
995
996 verbose_command_req:
997         COMMANDSPANREQUEST bare_int STRING {
998                 Span_req * sp_p = new Span_req;
999                 sp_p-> set_span_dir ( Direction($2));
1000                 sp_p->set_mus_property ("span-type",$3);
1001                 sp_p->set_spot (THIS->here_input ());
1002                 $$ = sp_p;
1003         }
1004         | MARK  {
1005                 Mark_req * m = new Mark_req;
1006                 $$ = m;
1007         }
1008         | MARK STRING {
1009                 Mark_req *m = new Mark_req;
1010                 m->set_mus_property ("label", $2);
1011                 $$ = m;
1012
1013         }
1014         | MARK bare_unsigned {
1015                 Mark_req *m = new Mark_req;
1016                 m->set_mus_property ("label",  gh_int2scm ($2));
1017                 $$ = m;
1018         }
1019
1020         | TIME_T bare_unsigned '/' bare_unsigned        {
1021                 Time_signature_change_req *m = new Time_signature_change_req;
1022                 m->set_mus_property ("beats", gh_int2scm ( $2));
1023                 m->set_mus_property ("one-beat", gh_int2scm ($4));
1024                 $$ = m;
1025         }
1026         | PENALTY bare_int      {
1027                 Break_req * b = new Break_req;
1028                 b->set_mus_property ("penalty", gh_double2scm ( $2 / 100.0));
1029                 b->set_spot (THIS->here_input ());
1030                 $$ = b;
1031         }
1032         | SKIP duration_length {
1033                 Skip_req * skip_p = new Skip_req;
1034                 skip_p->duration_ = *$2;
1035                 delete $2; // ugh
1036                 $$ = skip_p;
1037         }
1038         | tempo_request {
1039                 $$ = $1;
1040         }
1041         | KEY {
1042                 Key_change_req *key_p= new Key_change_req;
1043                 $$ = key_p;
1044         }
1045         | KEY NOTENAME_PITCH SCM_IDENTIFIER     {
1046                 Key_change_req *key_p= new Key_change_req;
1047                 
1048                 key_p->set_mus_property ("pitch-alist", $3);
1049                 ((Music* )key_p)->transpose (* $2);
1050                 $$ = key_p; 
1051         }
1052         ;
1053
1054 post_requests:
1055         {
1056                 $$ = new Link_array<Request>;
1057         }
1058         | post_requests post_request {
1059                 $2->set_spot (THIS->here_input ());
1060                 $$->push ($2);
1061         }
1062         ;
1063
1064 post_request:
1065         verbose_request
1066         | request_with_dir
1067         | close_request
1068         ;
1069
1070
1071 request_that_take_dir:
1072         gen_text_def
1073         | verbose_request
1074         | script_abbreviation {
1075                 SCM s = THIS->lexer_p_->lookup_identifier ("dash-" + ly_scm2string ($1));
1076                 Articulation_req *a = new Articulation_req;
1077                 if (gh_string_p (s))
1078                         a->set_mus_property ("articulation-type", s);
1079                 else THIS->parser_error (_ ("Expecting string as script definition"));
1080                 $$ = a;
1081         }
1082         ;
1083
1084 request_with_dir:
1085         script_dir request_that_take_dir        {
1086                 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1087                         gs->set_direction (Direction ($1));
1088                 else if ($1)
1089                         $2->origin ()->warning (_ ("Can't specify direction for this request"));
1090                 $$ = $2;
1091         }
1092         ;
1093         
1094 verbose_request:
1095         REQUEST_IDENTIFIER      {
1096                 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1097                 $$->set_spot (THIS->here_input ());
1098         }
1099         | DYNAMICSCRIPT embedded_scm {
1100                 /*
1101                         TODO: junkme, use text-type == dynamic
1102                 */
1103                 Text_script_req *d = new Text_script_req;
1104                 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1105                 d->set_mus_property ("text", $2);
1106                 d->set_spot (THIS->here_input ());
1107                 $$ = d;
1108         }
1109         | TEXTSCRIPT embedded_scm {
1110                 Text_script_req *t = new Text_script_req;
1111                 t->set_mus_property ("text", $2);
1112                 t->set_spot (THIS->here_input ());
1113                 $$ = t;
1114         }
1115         | SPANREQUEST bare_int STRING {
1116                 Span_req * sp_p = new Span_req;
1117                 sp_p->set_span_dir( Direction($2));
1118                 sp_p->set_mus_property ("span-type", $3);
1119                 sp_p->set_spot (THIS->here_input ());
1120                 $$ = sp_p;
1121         }
1122         | tremolo_type  {
1123                 Tremolo_req* a = new Tremolo_req;
1124                 a->set_spot (THIS->here_input ());
1125                 a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1126                 $$ = a;
1127         }
1128         | SCRIPT STRING         { 
1129                 Articulation_req * a = new Articulation_req;
1130                 a->set_mus_property ("articulation-type", $2);
1131                 a->set_spot (THIS->here_input ());
1132                 $$ = a;
1133         }
1134         | ARPEGGIO {
1135                 Arpeggio_req *a = new Arpeggio_req;
1136                 a->set_spot (THIS->here_input ());
1137                 $$ = a;
1138         }
1139         ;
1140
1141 sup_quotes:
1142         '\'' {
1143                 $$ = 1;
1144         }
1145         | sup_quotes '\'' {
1146                 $$ ++;
1147         }
1148         ;
1149
1150 sub_quotes:
1151         ',' {
1152                 $$ = 1;
1153         }
1154         | sub_quotes ',' {
1155                 $$ ++ ;
1156         }
1157         ;
1158
1159 steno_musical_pitch:
1160         NOTENAME_PITCH  {
1161                 $$ = $1;
1162         }
1163         | NOTENAME_PITCH sup_quotes     {
1164                 $$ = $1;
1165                 $$->octave_i_ +=  $2;
1166         }
1167         | NOTENAME_PITCH sub_quotes      {
1168                 $$ = $1;
1169                 $$->octave_i_ += - $2;
1170         }
1171         ;
1172
1173 steno_tonic_pitch:
1174         TONICNAME_PITCH {
1175                 $$ = $1;
1176         }
1177         | TONICNAME_PITCH sup_quotes    {
1178                 $$ = $1;
1179                 $$->octave_i_ +=  $2;
1180         }
1181         | TONICNAME_PITCH sub_quotes     {
1182                 $$ = $1;
1183                 $$->octave_i_ += - $2;
1184         }
1185         ;
1186
1187 musical_pitch:
1188         steno_musical_pitch {
1189                 $$ = $1;
1190         }
1191         | MUSICAL_PITCH embedded_scm {
1192                 int sz = scm_ilength ($2);
1193                 if (sz != 3) {
1194                         THIS->parser_error (_f ("Expecting %d arguments", 3));
1195                         $2 = gh_list (gh_int2scm (0), gh_int2scm (0), gh_int2scm (0), SCM_UNDEFINED);
1196                 }
1197                 $$ = new Musical_pitch ($2);
1198         }
1199         ;
1200
1201 explicit_duration:
1202         DURATION embedded_scm   {
1203                 $$ = new Duration;
1204                 if (scm_ilength ($2) == 2)
1205                         {
1206                         $$-> durlog_i_ = gh_scm2int (gh_car($2));
1207                         $$-> dots_i_ = gh_scm2int (gh_cadr($2));
1208                         }
1209                 else
1210                         THIS->parser_error (_("Must have 2 arguments for duration"));
1211         }
1212         ;
1213
1214 extender_req:
1215         EXTENDER {
1216                 if (!THIS->lexer_p_->lyric_state_b ())
1217                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1218                 $$ = new Extender_req;
1219         }
1220         ;
1221
1222 hyphen_req:
1223         HYPHEN {
1224                 if (!THIS->lexer_p_->lyric_state_b ())
1225                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1226                 $$ = new Hyphen_req;
1227         }
1228         ;
1229
1230 close_request:
1231         close_request_parens {
1232                 $$ = $1;
1233                 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1234         }
1235         
1236 close_request_parens:
1237         '('     {
1238                 Span_req* s= new Span_req;
1239                 $$ = s;
1240                 s->set_mus_property ("span-type", ly_str02scm( "slur"));
1241         }
1242         | E_SMALLER {
1243                 Span_req*s =new Span_req;
1244                 $$ = s;
1245                 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1246         }
1247         | E_BIGGER {
1248                 Span_req*s =new Span_req;
1249                 $$ = s;
1250                 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1251         }
1252         ;
1253
1254
1255 open_request:
1256         open_request_parens {
1257                 $$ = $1;
1258                 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1259         }
1260         ;
1261
1262 open_request_parens:
1263         E_EXCLAMATION   {
1264                 Span_req *s =  new Span_req;
1265                 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1266
1267                 $$ = s;
1268         }
1269         | ')'   {
1270                 Span_req* s= new Span_req;
1271                 $$ = s;
1272                 s->set_mus_property ("span-type", ly_str02scm( "slur"));
1273         }
1274         ;
1275
1276 gen_text_def:
1277         embedded_scm {
1278                 Text_script_req *t = new Text_script_req;
1279                 t->set_mus_property ("text", $1);
1280                 t->set_spot (THIS->here_input ());
1281                 $$ = t;
1282         }
1283         | string {
1284                 Text_script_req *t = new Text_script_req;
1285                 t->set_mus_property ("text", $1);
1286                 t->set_spot (THIS->here_input ());
1287                 $$ = t;
1288         }
1289         | DIGIT {
1290                 String ds = to_str ($1);
1291                 Text_script_req* t = new Text_script_req;
1292
1293                 t->set_mus_property ("text",  ly_str02scm (ds.ch_C()));
1294                 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1295                 t->set_spot (THIS->here_input ());
1296                 $$ = t;
1297         }
1298         ;
1299
1300 script_abbreviation:
1301         '^'             {
1302                 $$ = gh_str02scm  ("hat");
1303         }
1304         | '+'           {
1305                 $$ = gh_str02scm("plus");
1306         }
1307         | '-'           {
1308                 $$ = gh_str02scm ("dash");
1309         }
1310         | '|'           {
1311                 $$ = gh_str02scm ("bar");
1312         }
1313         | '>'           {
1314                 $$ = gh_str02scm ("larger");
1315         }
1316         | '.'           {
1317                 $$ = gh_str02scm ("dot");
1318         }
1319         ;
1320
1321
1322 script_dir:
1323         '_'     { $$ = DOWN; }
1324         | '^'   { $$ = UP; }
1325         | '-'   { $$ = CENTER; }
1326         ;
1327
1328 pre_requests:
1329         {
1330                 $$ = new Link_array<Request>;
1331         }
1332         | pre_requests open_request {
1333                 $$->push ($2);
1334         }
1335         ;
1336
1337 absolute_musical_pitch:
1338         steno_musical_pitch     {
1339                 $$ = $1;
1340         }
1341         ;
1342
1343 duration_length:
1344         steno_duration {
1345                 $$ = $1;
1346         }
1347         | duration_length '*' bare_unsigned {
1348                 $$->tuplet_iso_i_ *= $3;
1349         }
1350         | duration_length '/' bare_unsigned {
1351                 $$->tuplet_type_i_ *= $3;
1352         }
1353         ;
1354
1355 entered_notemode_duration:
1356         steno_duration  {
1357                 THIS->set_last_duration ($1);
1358         }
1359         ;
1360
1361 optional_notemode_duration:
1362         {
1363                 $$ = new Duration (THIS->default_duration_);
1364         }
1365         | entered_notemode_duration {
1366                 $$ = $1;
1367         }
1368         ;
1369
1370 steno_duration:
1371         bare_unsigned           {
1372                 $$ = new Duration;
1373                 if (!is_duration_b ($1))
1374                         THIS->parser_error (_f ("not a duration: %d", $1));
1375                 else {
1376                         $$->durlog_i_ = intlog2 ($1);
1377                      }
1378         }
1379         | DURATION_IDENTIFIER   {
1380                 $$ = $1->access_content_Duration (true);
1381         }
1382         | steno_duration '.'    {
1383                 $$->dots_i_ ++;
1384         }
1385         ;
1386
1387
1388 tremolo_type: 
1389         ':'     {
1390                 $$ =0;
1391         }
1392         | ':' bare_unsigned {
1393                 if (!is_duration_b ($2))
1394                         THIS->parser_error (_f ("not a duration: %d", $2));
1395                 $$ = $2;
1396         }
1397         ;
1398
1399
1400 simple_element:
1401         musical_pitch exclamations questions optional_notemode_duration {
1402                 if (!THIS->lexer_p_->note_state_b ())
1403                         THIS->parser_error (_ ("Have to be in Note mode for notes"));
1404
1405
1406                 Note_req *n = new Note_req;
1407                 
1408                 n->pitch_ = *$1;
1409                 n->duration_ = *$4;
1410
1411                 if ($3 % 2)
1412                         n->set_mus_property ("cautionary", SCM_BOOL_T);
1413                 if ( $2 % 2 || $3 % 2)
1414                         n->set_mus_property ("force-accidental", SCM_BOOL_T);
1415
1416
1417                 Simultaneous_music*v = new Request_chord (gh_list (n->self_scm (), SCM_UNDEFINED));
1418                 v->set_spot ($1->spot ());
1419                 n->set_spot ($1->spot ());
1420                 $$ = v;
1421
1422                 delete $1;
1423                 delete $4;
1424         }
1425         | RESTNAME optional_notemode_duration           {
1426
1427                 SCM e = SCM_UNDEFINED;
1428                   if (ly_scm2string ($1) =="s")
1429                     { /* Space */
1430                       Skip_req * skip_p = new Skip_req;
1431                       skip_p->duration_ = *$2;
1432
1433                       skip_p->set_spot (THIS->here_input());
1434                         e = skip_p->self_scm ();
1435                     }
1436                   else
1437                     {
1438                       Rest_req * rest_req_p = new Rest_req;
1439                       rest_req_p->duration_ = *$2;
1440                       rest_req_p->set_spot (THIS->here_input());
1441                         e = rest_req_p->self_scm ();
1442                     }
1443                   Simultaneous_music* velt_p = new Request_chord (gh_list (e,SCM_UNDEFINED));
1444                   velt_p->set_spot (THIS->here_input());
1445
1446                   delete $2; // ugh
1447                   $$ = velt_p;
1448         }
1449         | MEASURES optional_notemode_duration   {
1450                 Skip_req * sk = new Skip_req;
1451                 sk->duration_ = *$2;
1452                 
1453
1454                 Span_req *sp1 = new Span_req;
1455                 Span_req *sp2 = new Span_req;
1456                 sp1-> set_span_dir ( START);
1457                 sp2-> set_span_dir ( STOP);
1458                 SCM r = ly_str02scm ("rest");
1459                 sp1->set_mus_property ("span-type", r);
1460                 sp2->set_mus_property ("span-type", r);
1461
1462                 Request_chord * rqc1 = new Request_chord (gh_list (sp1->self_scm (), SCM_UNDEFINED));
1463                 Request_chord * rqc2 = new Request_chord (gh_list (sk->self_scm (), SCM_UNDEFINED));;
1464                 Request_chord * rqc3 = new Request_chord(gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1465
1466                 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1467
1468                 $$ = new Sequential_music (ms);
1469         }
1470         | STRING { 
1471                 THIS->remember_spot ();
1472         } 
1473         /* cont */
1474         optional_notemode_duration      {
1475                 if (!THIS->lexer_p_->lyric_state_b ()) {
1476                         THIS->pop_spot ().error (_ ("Have to be in Lyric mode for lyrics"));
1477                         THIS->error_level_i_  = 1;
1478                         THIS->parser_error (_ ("Giving up"));
1479                 } 
1480                 else
1481                         THIS->pop_spot ();
1482                 Lyric_req* lreq_p = new Lyric_req;
1483                 lreq_p->set_mus_property ("text", $1);
1484                 lreq_p->duration_ = *$3;
1485                 lreq_p->set_spot (THIS->here_input());
1486                 Simultaneous_music* velt_p = new Request_chord (gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1487
1488                 delete  $3; // ugh
1489                 $$= velt_p;
1490
1491         }
1492         | chord {
1493                 if (!THIS->lexer_p_->chord_state_b ())
1494                         THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1495                 $$ = $1;
1496         }
1497         ;
1498
1499
1500 chord:
1501         steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1502                 $$ = get_chord (*$1, $3, $4, $5, $6, *$2);
1503                 $$->set_spot (THIS->here_input ());
1504         };
1505
1506 chord_additions: 
1507         {
1508                 $$ = new Array<Musical_pitch>;
1509         } 
1510         | CHORD_COLON chord_notes {
1511                 $$ = $2;
1512         }
1513         ;
1514
1515 chord_notes:
1516         chord_step {
1517                 $$ = $1
1518         }
1519         | chord_notes '.' chord_step {
1520                 $$ = $1;
1521                 $$->concat (*$3);
1522         }
1523         ;
1524
1525 chord_subtractions: 
1526         {
1527                 $$ = new Array<Musical_pitch>;
1528         } 
1529         | CHORD_CARET chord_notes {
1530                 $$ = $2;
1531         }
1532         ;
1533
1534
1535 chord_inversion:
1536         {
1537                 $$ = 0;
1538         }
1539         | '/' steno_tonic_pitch {
1540                 $$ = $2;
1541                 $$->set_spot (THIS->here_input ());
1542         }
1543         ;
1544
1545 chord_bass:
1546         {
1547                 $$ = 0;
1548         }
1549         | CHORD_BASS steno_tonic_pitch {
1550                 $$ = $2;
1551                 $$->set_spot (THIS->here_input ());
1552         }
1553         ;
1554
1555 chord_step:
1556         chord_note {
1557                 $$ = new Array<Musical_pitch>;
1558                 $$->push (*$1);
1559         }
1560         | CHORDMODIFIER_PITCH {
1561                 $$ = new Array<Musical_pitch>;
1562                 $$->push (*$1);
1563         }
1564         | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1565                 $$ = new Array<Musical_pitch>;
1566                 $$->push (*$1);
1567                 $$->push (*$2);
1568         }
1569         ;
1570
1571 chord_note:
1572         bare_unsigned {
1573                 $$ = new Musical_pitch;
1574                 $$->notename_i_ = ($1 - 1) % 7;
1575                 $$->octave_i_ = $1 > 7 ? 1 : 0;
1576                 $$->accidental_i_ = 0;
1577         } 
1578         | bare_unsigned '+' {
1579                 $$ = new Musical_pitch;
1580                 $$->notename_i_ = ($1 - 1) % 7;
1581                 $$->octave_i_ = $1 > 7 ? 1 : 0;
1582                 $$->accidental_i_ = 1;
1583         }
1584         | bare_unsigned CHORD_MINUS {
1585                 $$ = new Musical_pitch;
1586                 $$->notename_i_ = ($1 - 1) % 7;
1587                 $$->octave_i_ = $1 > 7 ? 1 : 0;
1588                 $$->accidental_i_ = -1;
1589         }
1590         ;
1591
1592 /*
1593         UTILITIES
1594  */
1595 number_expression:
1596         bare_number {
1597                 $$ = $1;
1598         }
1599         | '-'  number_expression %prec UNARY_MINUS {
1600                 $$ = scm_difference ($2, SCM_UNDEFINED);
1601         }
1602         | number_expression '*' number_expression {
1603                 $$ = scm_product ($1, $3);
1604         }
1605         | number_expression '/' number_expression {
1606                 $$ = scm_divide ($1, $3);
1607         }
1608         | number_expression '+' number_expression {
1609                 $$ = scm_sum ($1, $3);
1610         }
1611         | number_expression '-' number_expression {
1612                 $$ = scm_difference ($1, $3);
1613         }
1614         | '(' number_expression ')'     {
1615                 $$ = $2;
1616         }
1617         ;
1618
1619 bare_number:
1620         UNSIGNED        {
1621                 $$ = gh_int2scm ($1);
1622         }
1623         | DIGIT         {
1624                 $$ = gh_int2scm ($1);
1625         }
1626         | REAL          {
1627                 $$ = gh_double2scm ($1);
1628         }
1629         | NUMBER_IDENTIFIER             {
1630                 $$ = $1;
1631         }
1632         | REAL CM_T     {
1633                 $$ = gh_double2scm ($1 CM);
1634         }
1635         | REAL PT_T     {
1636                 $$ = gh_double2scm ($1 PT);
1637         }
1638         | REAL IN_T     {
1639                 $$ = gh_double2scm ($1 INCH);
1640         }
1641         | REAL MM_T     {
1642                 $$ = gh_double2scm ($1 MM);
1643         }
1644         | REAL CHAR_T   {
1645                 $$ = gh_double2scm ($1 CHAR);
1646         }
1647         ;
1648
1649
1650 bare_unsigned:
1651         bare_number {
1652                 if (scm_integer_p ($1) == SCM_BOOL_T) {
1653                         $$ = gh_scm2int ($1);
1654
1655                 } else {
1656                         THIS->parser_error (_("need integer number arg"));
1657                         $$ = 0;
1658                 }
1659                 if ($$ < 0) {
1660                         THIS->parser_error (_("Must be positive integer"));
1661                         $$ = -$$;
1662                         }
1663
1664         }
1665         ;
1666 bare_int:
1667         bare_number {
1668                 if (scm_integer_p ($1) == SCM_BOOL_T)
1669                 {
1670                         int k = gh_scm2int ($1);
1671                         $$ = k;
1672                 } else
1673                 {
1674                         THIS->parser_error (_("need integer number arg"));
1675                         $$ = 0;
1676                 }
1677         }
1678         | '-' bare_int {
1679                 $$ = -$2;
1680         }
1681         ;
1682
1683
1684 string:
1685         STRING          {
1686                 $$ = $1;
1687         }
1688         | STRING_IDENTIFIER     {
1689                 $$ = $1;
1690         }
1691         | string '+' string {
1692                 $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
1693         }
1694         ;
1695
1696
1697 exclamations:
1698                 { $$ = 0; }
1699         | exclamations '!'      { $$ ++; }
1700         ;
1701
1702 questions:
1703                 { $$ = 0; }
1704         | questions '?' { $$ ++; }
1705         ;
1706
1707
1708 semicolon:
1709         ';'
1710         ;
1711
1712 %%
1713
1714 void
1715 My_lily_parser::set_yydebug (bool b)
1716 {
1717 #ifdef YYDEBUG
1718         yydebug = b;
1719 #endif
1720 }
1721
1722 extern My_lily_parser * current_parser;
1723
1724 void
1725 My_lily_parser::do_yyparse ()
1726 {
1727
1728         current_parser = this;;
1729         yyparse ((void*)this);
1730 }
1731
1732