]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
patch::: 1.3.98.jcn2
[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 ARPEGGIO
131 %token DYNAMICSCRIPT
132 %token TEXTSCRIPT
133 %token ACCEPTS
134 %token ALTERNATIVE
135 %token BAR
136 %token BREATHE
137 %token CHORDMODIFIERS
138 %token CHORDS
139 %token CHAR_T
140 %token CLEF
141 %token CM_T
142 %token CONSISTS
143 %token SEQUENTIAL
144 %token ELEMENTDESCRIPTIONS
145 %token SIMULTANEOUS
146 %token CONSISTSEND
147 %token DENIES
148 %token DURATION
149 %token EXTENDER
150 %token FONT
151 %token GRACE
152 %token HEADER
153 %token HYPHEN
154 %token IN_T
155 %token INVALID
156 %token KEY
157 %token LYRICS
158 %token MARK
159 %token MEASURES
160 %token MIDI
161 %token MM_T
162 %token MUSICAL_PITCH
163 %token NAME
164 %token NOTENAMES
165 %token NOTES
166 %token PAPER
167 %token PARTIAL
168 %token PENALTY
169 %token PROPERTY
170 %token PUSH POP 
171 %token PT_T
172 %token RELATIVE
173 %token REMOVE
174 %token REPEAT
175 %token ADDLYRICS
176 %token PARTCOMBINE
177 %token SCM_T
178 %token SCORE
179 %token SCRIPT
180 %token SKIP
181 %token SPANREQUEST
182 %token COMMANDSPANREQUEST
183 %token TEMPO
184 %token OUTPUTPROPERTY
185 %token TIME_T
186 %token TIMES
187 %token TRANSLATOR
188 %token TRANSPOSE
189 %token TYPE
190 %token CONTEXT
191
192 /* escaped */
193 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER 
194 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET 
195
196 %type <i>       exclamations questions
197 %token <i>      DIGIT
198 %token <pitch>  NOTENAME_PITCH
199 %token <pitch>  TONICNAME_PITCH
200 %token <pitch>  CHORDMODIFIER_PITCH
201 %token <id>     DURATION_IDENTIFIER
202 %token <id>     IDENTIFIER
203
204
205 %token <id>     SCORE_IDENTIFIER
206 %token <id>     MUSIC_OUTPUT_DEF_IDENTIFIER
207
208 %token <scm>    NUMBER_IDENTIFIER
209 %token <scm>    REQUEST_IDENTIFIER
210 %token <scm>    MUSIC_IDENTIFIER TRANSLATOR_IDENTIFIER
211 %token <scm>    STRING_IDENTIFIER SCM_IDENTIFIER 
212 %token <scm>    DURATION RESTNAME
213 %token <scm>    STRING 
214 %token <scm>    SCM_T
215 %token <i>      UNSIGNED
216 %token <real>   REAL
217
218 %type <outputdef> output_def
219 %type <scope>   mudela_header mudela_header_body
220 %type <request> open_request_parens close_request_parens open_request close_request
221 %type <request> request_with_dir request_that_take_dir verbose_request
222 %type <i>       sub_quotes sup_quotes
223 %type <music>   simple_element  request_chord command_element Simple_music  Composite_music 
224 %type <music>   Alternative_music Repeated_music
225 %type <i>       tremolo_type
226 %type <i>       bare_int  bare_unsigned
227 %type <i>       script_dir
228
229 %type <scm>     identifier_init 
230
231 %type <duration> steno_duration optional_notemode_duration
232 %type <duration> entered_notemode_duration explicit_duration
233         
234 %type <reqvec>  pre_requests post_requests
235 %type <request> gen_text_def
236 %type <pitch>   steno_musical_pitch musical_pitch absolute_musical_pitch
237 %type <pitch>   steno_tonic_pitch
238
239 %type <pitch_arr>       chord_additions chord_subtractions chord_notes chord_step
240 %type <music>   chord
241 %type <pitch>   chord_note chord_inversion chord_bass
242 %type <duration>        duration_length
243
244 %type <scm>  embedded_scm scalar
245 %type <music>   Music Sequential_music Simultaneous_music Music_sequence
246 %type <music>   relative_music re_rhythmed_music part_combined_music
247 %type <music>   property_def translator_change
248 %type <scm> Music_list
249 %type <outputdef>  music_output_def_body
250 %type <request> shorthand_command_req
251 %type <request> post_request 
252 %type <request> command_req verbose_command_req
253 %type <request> extender_req
254 %type <request> hyphen_req
255 %type <scm>     string bare_number number_expression
256 %type <score>   score_block score_body
257
258 %type <scm>     translator_spec_block translator_spec_body
259 %type <tempo>   tempo_request
260 %type <scm> notenames_body notenames_block chordmodifiers_block
261 %type <scm>     script_abbreviation
262
263
264
265 %left '-' '+'
266 %left '*' '/'
267 %left UNARY_MINUS
268
269 %%
270
271 mudela: /* empty */
272         | mudela toplevel_expression {}
273         | mudela assignment  { }
274         | mudela error {
275                 THIS->error_level_i_  = 1;
276                 //THIS->parser_error (_ ("ly invalid"));
277         }
278         | mudela INVALID        {
279                 THIS->error_level_i_  = 1;
280                 //THIS->parser_error (_ ("ly invalid"));
281         }
282         ;
283
284 toplevel_expression:
285         notenames_block                 {
286                 THIS->lexer_p_->pitchname_tab_ =  $1;
287         }
288         | chordmodifiers_block                  {
289                 THIS->lexer_p_->chordmodifier_tab_  = $1;
290         }
291         | mudela_header {
292                 delete header_global_p;
293                 header_global_p = $1;
294         }
295         | score_block {
296                 score_global_array.push ($1);
297         }
298         | output_def {
299                 Identifier * id = new
300                         Music_output_def_identifier ($1, MUSIC_OUTPUT_DEF_IDENTIFIER);
301                 if (dynamic_cast<Paper_def*> ($1))
302                         THIS->lexer_p_->set_identifier ("$defaultpaper", id->self_scm ());
303                 else if (dynamic_cast<Midi_def*> ($1))
304                         THIS->lexer_p_->set_identifier ("$defaultmidi", id->self_scm ());
305         }
306         | embedded_scm {
307                 // junk value
308         }       
309         ;
310
311 embedded_scm:
312         SCM_T
313         | SCM_IDENTIFIER 
314         ;
315
316
317 chordmodifiers_block:
318         CHORDMODIFIERS notenames_body   {  $$ = $2; }
319         ;
320
321
322 notenames_block:
323         NOTENAMES notenames_body   {  $$ = $2; }
324         ;
325
326
327
328 notenames_body:
329         embedded_scm    {
330           int i = scm_ilength ($1);
331
332           SCM tab = scm_make_vector (gh_int2scm (i), SCM_EOL);
333           for (SCM s = $1; s != SCM_EOL; s = gh_cdr (s)) {
334                 SCM pt = gh_cdar (s);
335                 if (scm_ilength (pt) != 3)
336                         THIS->parser_error ("Need three args");
337                 scm_hashq_set_x (tab, gh_caar(s), pt);
338           }
339
340           $$ = tab;
341         }
342         ;
343
344 mudela_header_body:
345         {
346                 $$ = new Scope;
347                 THIS->lexer_p_-> scope_l_arr_.push ($$);
348         }
349         | mudela_header_body assignment semicolon { 
350
351         }
352         ;
353
354 mudela_header:
355         HEADER '{' mudela_header_body '}'       {
356                 $$ = $3;
357                 THIS->lexer_p_-> scope_l_arr_.pop ();           
358         }
359         ;
360
361
362 /*
363         DECLARATIONS
364 */
365 assignment:
366         STRING {
367                 THIS->remember_spot ();
368         }
369         /* cont */ '=' identifier_init  {
370                 THIS->lexer_p_->set_identifier (ly_scm2string ($1), $4);
371
372 /*
373  TODO: devise standard for protection in parser.
374
375   The parser stack lives on the C-stack, which means that
376 all objects can be unprotected as soon as they're here.
377
378 */
379                 Identifier * id =unsmob_identifier ($4);
380                 Input spot = THIS->pop_spot ();
381                 if (id) id->set_spot (spot);
382         }
383         ;
384
385
386
387 identifier_init:
388         score_block {
389                 $$ = (new Score_identifier ($1, SCORE_IDENTIFIER))->self_scm();
390         }
391         | output_def {
392                 $$ = (new Music_output_def_identifier ($1, MUSIC_OUTPUT_DEF_IDENTIFIER))->self_scm();
393         }
394         | translator_spec_block {
395                 $$ = $1;
396         }
397         | Music  {
398                 $$ = $1->self_scm ();
399                 scm_unprotect_object ($$);
400         }
401         | post_request {
402                 $$ = $1->self_scm ();
403                 scm_unprotect_object ($$);
404         }
405         | explicit_duration {
406                 $$ = (new Duration_identifier ($1, DURATION_IDENTIFIER))->self_scm ();
407         }
408         | number_expression {
409                 $$ = $1;
410         }
411         | string {
412                 $$ = $1;
413         }
414         | embedded_scm  {
415                 $$ = $1;
416         }
417         ;
418
419 translator_spec_block:
420         TRANSLATOR '{' translator_spec_body '}'
421                 {
422                 $$ = $3;
423         }
424         ;
425
426 translator_spec_body:
427         TRANSLATOR_IDENTIFIER   {
428                 $$ = unsmob_translator_def ($1)->clone_scm ();
429                 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
430         }
431         | TYPE STRING semicolon {
432                 $$ = Translator_def::make_scm ();
433                 Translator_def*td =  unsmob_translator_def ($$);
434                 td->translator_group_type_ = $2;
435                 td->set_spot (THIS->here_input ());
436         }
437         | translator_spec_body STRING '=' embedded_scm                  {
438                 unsmob_translator_def ($$)->add_property_assign ($2, $4);
439         }
440         | translator_spec_body STRING PUSH embedded_scm '=' embedded_scm {
441                 unsmob_translator_def ($$)
442                         ->add_push_property (scm_string_to_symbol ($2), $4, $6);
443         }
444         | translator_spec_body STRING POP embedded_scm  {
445           unsmob_translator_def($$)->add_pop_property (
446                 scm_string_to_symbol ($2), $4);
447         }
448         | translator_spec_body STRING '=' identifier_init semicolon     { 
449                 SCM v = gh_int2scm (0);
450                 if (gh_string_p ($4) || gh_number_p ($4) || gh_boolean_p ($4))
451                         v = $4;
452                 else 
453                         THIS->parser_error (_("Wrong type for property value"));
454
455                 /* ugh*/
456                 unsmob_translator_def($$)->add_property_assign ($2, v);
457         }
458         | translator_spec_body NAME STRING semicolon {
459                 unsmob_translator_def ($$)->type_name_ = $3;
460         }
461         | translator_spec_body CONSISTS STRING semicolon {
462                 unsmob_translator_def ($$)->add_element ($3);
463         }
464         | translator_spec_body ELEMENTDESCRIPTIONS embedded_scm {
465                 for (SCM p = $3; gh_pair_p (p); p = gh_cdr (p))
466                         unsmob_translator_def ($$)
467                         ->add_property_assign (scm_symbol_to_string (gh_caar (p)), gh_cdar (p));
468
469         }
470         | translator_spec_body CONSISTSEND STRING semicolon {
471                 unsmob_translator_def ($$)->add_last_element ( $3);
472         }
473         | translator_spec_body ACCEPTS STRING semicolon {
474                 unsmob_translator_def ($$)->set_acceptor ($3,true);
475         }
476         | translator_spec_body DENIES STRING semicolon {
477                 unsmob_translator_def ($$)->set_acceptor ($3,false);
478         }
479         | translator_spec_body REMOVE STRING semicolon {
480                 unsmob_translator_def ($$)->remove_element ($3);
481         }
482         ;
483
484 /*
485         SCORE
486 */
487 score_block:
488         SCORE { 
489                 THIS->remember_spot ();
490         }
491         /*cont*/ '{' score_body '}'     {
492                 THIS->pop_spot ();
493                 $$ = $4;
494                 if (!$$->def_p_arr_.size ())
495                 {
496                   Identifier *id =
497                         unsmob_identifier (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
498                   $$->add_output (id ? id->access_content_Music_output_def (true) : new Paper_def );
499                 }
500         }
501 /*
502         | SCORE '{' score_body error {
503                 $$ = $3
504                 $$->set_spot (THIS->here_input ());
505                 // THIS->here_input ().error ("SCORE INVALID");
506                 $$->error ("SCORE INVALID");
507                 THIS->parser_error (_f ("SCORE ERROR"));
508         }
509 */
510         ;
511
512 score_body:
513         Music   {
514                 $$ = new Score;
515
516                 $$->set_spot (THIS->here_input ());
517                 SCM m = $1->self_scm ();
518                 scm_unprotect_object (m);
519                 $$->music_ = m;
520         }
521         | SCORE_IDENTIFIER {
522                 $$ = $1->access_content_Score (true);
523         }
524         | score_body mudela_header      {
525                 $$->header_p_ = $2;
526         }
527         | score_body output_def {
528                 $$->add_output ($2);
529         }
530         | score_body error {
531
532         }
533         ;
534
535
536 /*
537         MIDI
538 */
539 output_def:
540         music_output_def_body '}' {
541                 $$ = $1;
542                 THIS-> lexer_p_-> scope_l_arr_.pop();
543         }
544         ;
545
546 music_output_def_body:
547         MIDI '{'    {
548          Identifier *id = unsmob_identifier (THIS->lexer_p_->lookup_identifier ("$defaultmidi"));
549
550                 
551          Midi_def* p =0;
552         if (id)
553                 p = dynamic_cast<Midi_def*> (id->access_content_Music_output_def (true));
554         else
555                 p = new Midi_def;
556
557          $$ = p;
558          THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
559         }
560         | PAPER '{'     {
561                   Identifier *id = unsmob_identifier (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
562                   Paper_def *p = 0;
563                 if (id)
564                         p = dynamic_cast<Paper_def*> (id->access_content_Music_output_def (true));
565                 else
566                         p = new Paper_def;
567                 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
568                 $$ = p;
569         }
570         | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER         {
571                 Music_output_def *p = $3->access_content_Music_output_def (true);
572                 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
573                 $$ = p;
574         }
575         | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER  {
576                 Music_output_def *p = $3->access_content_Music_output_def (true);
577                 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
578                 $$ = p;
579         }
580         | music_output_def_body assignment semicolon {
581
582         }
583         | music_output_def_body translator_spec_block   {
584                 $$->assign_translator ($2);
585         }
586         | music_output_def_body tempo_request semicolon {
587                 /*
588                         junk this ? there already is tempo stuff in
589                         music.
590                 */
591                 dynamic_cast<Midi_def*> ($$)->set_tempo ($2->dur_.length_mom (), $2->metronome_i_);
592         }
593         | music_output_def_body bare_int '=' FONT STRING                { // ugh, what a syntax
594                 SCM sl = Lookup::make_lookup();
595                 Lookup * l =unsmob_lookup (sl);
596                 l->font_name_ = ly_scm2string ($5);
597                 dynamic_cast<Paper_def*> ($$)->set_lookup ($2, sl);
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                 $$-> metronome_i_ = $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->translator_type_str_ = ly_scm2string ($2);
733                 csm->translator_id_str_ = "";
734
735
736                 $$ = csm;
737         }
738         | AUTOCHANGE STRING Music       {
739                 Auto_change_music * chm = new Auto_change_music ($3);
740                 chm->set_mus_property ("what", $2); 
741
742                 $$ = chm;
743                 chm->set_spot (*$3->origin ());
744         }
745         | GRACE Music {
746                 $$ = new Grace_music ($2);
747         }
748         | CONTEXT STRING '=' STRING Music {
749                 Context_specced_music *csm =  new Context_specced_music ($5);
750
751                 csm->translator_type_str_ = ly_scm2string ($2);
752                 csm->translator_id_str_ = ly_scm2string ($4);
753
754                 $$ = csm;
755         }
756         | TIMES {
757                 THIS->remember_spot ();
758         }
759         /* CONTINUED */ 
760                 bare_unsigned '/' bare_unsigned Music   
761
762         {
763                 $$ = new Time_scaled_music ($3, $5, $6);
764                 $$->set_spot (THIS->pop_spot ());
765         }
766         | Repeated_music                { $$ = $1; }
767         | Simultaneous_music            { $$ = $1; }
768         | Sequential_music              { $$ = $1; }
769         | TRANSPOSE musical_pitch Music {
770                 $$ = new Transposed_music ($3, *$2);
771                 delete $2; // ugh
772         }
773         | TRANSPOSE steno_tonic_pitch Music {
774                 $$ = new Transposed_music ($3, *$2);
775                 delete $2; // ugh
776         }
777         | NOTES
778                 { THIS->lexer_p_->push_note_state (); }
779         Music
780                 { $$ = $3;
781                   THIS->lexer_p_->pop_state ();
782                 }
783         | CHORDS
784                 { THIS->lexer_p_->push_chord_state (); }
785         Music
786                 {
787                   $$ = $3;
788                   THIS->lexer_p_->pop_state ();
789         }
790         | LYRICS
791                 { THIS->lexer_p_->push_lyric_state (); }
792         Music
793                 {
794                   $$ = $3;
795                   THIS->lexer_p_->pop_state ();
796         }
797         | relative_music        { $$ = $1; }
798         | re_rhythmed_music     { $$ = $1; } 
799         | part_combined_music   { $$ = $1; } 
800         ;
801
802 relative_music:
803         RELATIVE absolute_musical_pitch Music {
804                 $$ = new Relative_octave_music ($3, *$2);
805                 delete $2; // ugh
806         }
807         ;
808
809 re_rhythmed_music:
810         ADDLYRICS Music Music {
811                 Lyric_combine_music * l = new Lyric_combine_music ($2, $3);
812                 $$ = l;
813         }
814         ;
815
816 part_combined_music:
817         PARTCOMBINE STRING Music Music {
818                 Part_combine_music * p = new Part_combine_music (ly_scm2string ($2), $3, $4);
819                 $$ = p;
820         }
821         ;
822
823 translator_change:
824         TRANSLATOR STRING '=' STRING  {
825                 Music * t = new Music;
826                 t->set_mus_property ("type",
827                         ly_symbol2scm ("change-translator"));
828                 t-> set_mus_property ("change-to-type", $2);
829                 t-> set_mus_property ("change-to-id", $4);
830
831                 $$ = t;
832                 $$->set_spot (THIS->here_input ());
833         }
834         ;
835
836 property_def:
837         PROPERTY STRING '.' STRING '='  scalar {
838                 Music *t = new Music;
839
840                 t->set_mus_property ("type", ly_symbol2scm ("property-set"));
841                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
842                 t->set_mus_property ("value", $6);
843
844                 Context_specced_music *csm = new Context_specced_music (t);
845                 $$ = csm;
846                 $$->set_spot (THIS->here_input ());
847
848                 csm-> translator_type_str_ = ly_scm2string ($2);
849         }
850         | PROPERTY STRING '.' STRING PUSH embedded_scm '=' embedded_scm {
851                 Music *t = new Music;
852                 t->set_mus_property ("type", ly_symbol2scm ("property-push"));
853                 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
854                 t->set_mus_property ("element-property", $6);
855                 t->set_mus_property ("element-value", $8);
856                 Context_specced_music *csm = new Context_specced_music (t);
857                 $$ = csm;
858                 $$->set_spot (THIS->here_input ());
859
860                 csm-> translator_type_str_ = ly_scm2string ($2);
861         }
862         | PROPERTY STRING '.' STRING POP embedded_scm {
863                 Music *t = new Music;
864                 t->set_mus_property ("type", ly_symbol2scm ("property-pop"));
865                 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
866                 t->set_mus_property ("element-property", $6);
867
868                 Context_specced_music *csm = new Context_specced_music (t);
869                 $$ = csm;
870                 $$->set_spot (THIS->here_input ());
871
872                 csm-> translator_type_str_ = ly_scm2string ($2);
873         }
874         ;
875
876 scalar:
877         string          { $$ = $1; }
878         | bare_int      { $$ = gh_int2scm ($1); }
879         | embedded_scm  { $$ = $1; }
880         ;
881
882
883 request_chord:
884         pre_requests simple_element post_requests       {
885                 Music_sequence *l = dynamic_cast<Music_sequence*>($2);
886                 if (l) {
887                         for (int i=0; i < $1->size(); i++)
888                                 l->append_music ($1->elem(i));
889                         for (int i=0; i < $3->size(); i++)
890                                 l->append_music ($3->elem(i));
891                         }
892                 else
893                         programming_error ("Need Sequence to add music to");
894                 $$ = $2;
895                 
896         }
897         | command_element
898         ;
899
900 command_element:
901         command_req {
902                 $$ = new Request_chord (gh_cons ($1->self_scm (), SCM_EOL));
903                 $$-> set_spot (THIS->here_input ());
904                 $1-> set_spot (THIS->here_input ());
905         }
906         | PARTIAL duration_length ';'   {
907                 Music * p = new Music;
908                 p->set_mus_property ("symbol", ly_symbol2scm ( "measurePosition"));
909                 p->set_mus_property ("type", ly_symbol2scm ("property-set"));
910
911                 Moment m = - $2->length_mom ();
912                 p->set_mus_property ("value", m.make_scm());
913                 delete $2; // ugh
914                 Context_specced_music * sp = new Context_specced_music (p);
915                 $$ =sp ;
916                 sp-> translator_type_str_ = "Score";
917         }
918         ;
919
920 command_req:
921         shorthand_command_req
922         | verbose_command_req semicolon { $$ = $1; }
923         ;
924
925 shorthand_command_req:
926         extender_req {
927                 $$ = $1;
928         }
929         | hyphen_req {
930                 $$ = $1;
931         }
932         | '|'                           {
933                 $$ = new Barcheck_req;
934         }
935         | '~'   {
936                 $$ = new Tie_req;
937         }
938         | '['           {
939                 Span_req*b= new Span_req;
940                 b->span_dir_ = START;
941                 b->span_type_str_ = "beam";
942                 $$ =b;
943         }
944         | ']'           {
945              Span_req*b= new Span_req;
946              b->span_dir_ = STOP;
947              b->span_type_str_ = "beam";
948              $$ = b;
949         }
950         | BREATHE {
951                 $$ = new Breathing_sign_req;
952         }
953         ;
954
955
956 verbose_command_req:
957         
958         BAR STRING                      {
959                 $$ = new Bar_req (ly_scm2string ($2));
960         }
961         | COMMANDSPANREQUEST bare_int STRING {
962                 Span_req * sp_p = new Span_req;
963                 sp_p-> span_dir_  = Direction($2);
964                 sp_p->span_type_str_ = ly_scm2string ($3);
965                 sp_p->set_spot (THIS->here_input ());
966                 $$ = sp_p;
967         }
968         | MARK  {
969                 Mark_req * m = new Mark_req;
970                 $$ = m;
971         }
972         | MARK STRING {
973                 Mark_req *m = new Mark_req;
974                 m->set_mus_property ("label", $2);
975                 $$ = m;
976
977         }
978         | MARK bare_unsigned {
979                 Mark_req *m = new Mark_req;
980                 m->set_mus_property ("label",  gh_int2scm ($2));
981                 $$ = m;
982         }
983
984         | TIME_T bare_unsigned '/' bare_unsigned        {
985                 Time_signature_change_req *m = new Time_signature_change_req;
986                 m->beats_i_ = $2;
987                 m->one_beat_i_=$4;
988                 $$ = m;
989         }
990         | PENALTY bare_int      {
991                 Break_req * b = new Break_req;
992                 b->penalty_f_ = $2 / 100.0;
993                 b->set_spot (THIS->here_input ());
994                 $$ = b;
995         }
996         | SKIP duration_length {
997                 Skip_req * skip_p = new Skip_req;
998                 skip_p->duration_ = *$2;
999                 delete $2; // ugh
1000                 $$ = skip_p;
1001         }
1002         | tempo_request {
1003                 $$ = $1;
1004         }
1005         | CLEF STRING {
1006                 $$ = new Clef_change_req (ly_scm2string ($2));
1007
1008         }
1009         | KEY {
1010                 Key_change_req *key_p= new Key_change_req;
1011                 $$ = key_p;
1012         }
1013         | KEY NOTENAME_PITCH SCM_IDENTIFIER     {
1014                 Key_change_req *key_p= new Key_change_req;
1015                 
1016                 key_p->set_mus_property ("pitch-alist", $3);
1017                 ((Music* )key_p)->transpose (* $2);
1018                 $$ = key_p; 
1019         }
1020         ;
1021
1022 post_requests:
1023         {
1024                 $$ = new Link_array<Request>;
1025         }
1026         | post_requests post_request {
1027                 $2->set_spot (THIS->here_input ());
1028                 $$->push ($2);
1029         }
1030         ;
1031
1032 post_request:
1033         verbose_request
1034         | request_with_dir
1035         | close_request
1036         ;
1037
1038
1039 request_that_take_dir:
1040         gen_text_def
1041         | verbose_request
1042         | script_abbreviation {
1043                 SCM s = THIS->lexer_p_->lookup_identifier ("dash-" + ly_scm2string ($1));
1044                 Articulation_req *a = new Articulation_req;
1045                 if (gh_string_p (s))
1046                         a->articulation_str_ = ly_scm2string (s);
1047                 else THIS->parser_error (_ ("Expecting string as script definition"));
1048                 $$ = a;
1049         }
1050         ;
1051
1052 request_with_dir:
1053         script_dir request_that_take_dir        {
1054                 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1055                         gs->set_direction (Direction ($1));
1056                 else if ($1)
1057                         $2->origin ()->warning (_ ("Can't specify direction for this request"));
1058                 $$ = $2;
1059         }
1060         ;
1061         
1062 verbose_request:
1063         REQUEST_IDENTIFIER      {
1064                 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1065                 $$->set_spot (THIS->here_input ());
1066         }
1067         | DYNAMICSCRIPT embedded_scm {
1068                 /*
1069                         TODO: junkme, use text-type == dynamic
1070                 */
1071                 Text_script_req *d = new Text_script_req;
1072                 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1073                 d->set_mus_property ("text", $2);
1074                 d->set_spot (THIS->here_input ());
1075                 $$ = d;
1076         }
1077         | TEXTSCRIPT embedded_scm {
1078                 Text_script_req *t = new Text_script_req;
1079                 t->set_mus_property ("text", $2);
1080                 t->set_spot (THIS->here_input ());
1081                 $$ = t;
1082         }
1083         | SPANREQUEST bare_int STRING {
1084                 Span_req * sp_p = new Span_req;
1085                 sp_p->span_dir_  = Direction($2);
1086                 sp_p->span_type_str_ = ly_scm2string ($3);
1087                 sp_p->set_spot (THIS->here_input ());
1088                 $$ = sp_p;
1089         }
1090         | tremolo_type  {
1091                 Tremolo_req* a = new Tremolo_req;
1092                 a->set_spot (THIS->here_input ());
1093                 a->type_i_ = $1;
1094                 $$ = a;
1095         }
1096         | SCRIPT STRING         { 
1097                 Articulation_req * a = new Articulation_req;
1098                 a->articulation_str_ = ly_scm2string ($2);
1099                 a->set_spot (THIS->here_input ());
1100                 $$ = a;
1101         }
1102         | ARPEGGIO {
1103                 Arpeggio_req *a = new Arpeggio_req;
1104                 a->set_spot (THIS->here_input ());
1105                 $$ = a;
1106         }
1107         ;
1108
1109 sup_quotes:
1110         '\'' {
1111                 $$ = 1;
1112         }
1113         | sup_quotes '\'' {
1114                 $$ ++;
1115         }
1116         ;
1117
1118 sub_quotes:
1119         ',' {
1120                 $$ = 1;
1121         }
1122         | sub_quotes ',' {
1123                 $$ ++ ;
1124         }
1125         ;
1126
1127 steno_musical_pitch:
1128         NOTENAME_PITCH  {
1129                 $$ = $1;
1130         }
1131         | NOTENAME_PITCH sup_quotes     {
1132                 $$ = $1;
1133                 $$->octave_i_ +=  $2;
1134         }
1135         | NOTENAME_PITCH sub_quotes      {
1136                 $$ = $1;
1137                 $$->octave_i_ += - $2;
1138         }
1139         ;
1140
1141 steno_tonic_pitch:
1142         TONICNAME_PITCH {
1143                 $$ = $1;
1144         }
1145         | TONICNAME_PITCH sup_quotes    {
1146                 $$ = $1;
1147                 $$->octave_i_ +=  $2;
1148         }
1149         | TONICNAME_PITCH sub_quotes     {
1150                 $$ = $1;
1151                 $$->octave_i_ += - $2;
1152         }
1153         ;
1154
1155 musical_pitch:
1156         steno_musical_pitch {
1157                 $$ = $1;
1158         }
1159         | MUSICAL_PITCH embedded_scm {
1160                 int sz = scm_ilength ($2);
1161                 if (sz != 3) {
1162                         THIS->parser_error (_f ("Expecting %d arguments", 3));
1163                         $2 = gh_list (gh_int2scm (0), gh_int2scm (0), gh_int2scm (0), SCM_UNDEFINED);
1164                 }
1165                 $$ = new Musical_pitch ($2);
1166         }
1167         ;
1168
1169 explicit_duration:
1170         DURATION embedded_scm   {
1171                 $$ = new Duration;
1172                 if (scm_ilength ($2) == 2)
1173                         {
1174                         $$-> durlog_i_ = gh_scm2int (gh_car($2));
1175                         $$-> dots_i_ = gh_scm2int (gh_cadr($2));
1176                         }
1177                 else
1178                         THIS->parser_error (_("Must have 2 arguments for duration"));
1179         }
1180         ;
1181
1182 extender_req:
1183         EXTENDER {
1184                 if (!THIS->lexer_p_->lyric_state_b ())
1185                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1186                 $$ = new Extender_req;
1187         }
1188         ;
1189
1190 hyphen_req:
1191         HYPHEN {
1192                 if (!THIS->lexer_p_->lyric_state_b ())
1193                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1194                 $$ = new Hyphen_req;
1195         }
1196         ;
1197
1198 close_request:
1199         close_request_parens {
1200                 $$ = $1;
1201                 dynamic_cast<Span_req*> ($$)->span_dir_ = START;
1202         }
1203         
1204 close_request_parens:
1205         '('     {
1206                 Span_req* s= new Span_req;
1207                 $$ = s;
1208                 s->span_type_str_ = "slur";
1209         }
1210         | E_SMALLER {
1211                 Span_req*s =new Span_req;
1212                 $$ = s;
1213                 s->span_type_str_ = "crescendo";
1214         }
1215         | E_BIGGER {
1216                 Span_req*s =new Span_req;
1217                 $$ = s;
1218                 s->span_type_str_ = "decrescendo";
1219         }
1220         ;
1221
1222
1223 open_request:
1224         open_request_parens {
1225                 $$ = $1;
1226                 dynamic_cast<Span_req*> ($$)->span_dir_ = STOP;
1227         }
1228         ;
1229
1230 open_request_parens:
1231         E_EXCLAMATION   {
1232                 Span_req *s =  new Span_req;
1233                 s->span_type_str_ = "crescendo";
1234                 $$ = s;
1235         }
1236         | ')'   {
1237                 Span_req* s= new Span_req;
1238                 $$ = s;
1239                 s->span_type_str_ = "slur";
1240         }
1241         ;
1242
1243 gen_text_def:
1244         embedded_scm {
1245                 Text_script_req *t = new Text_script_req;
1246                 t->set_mus_property ("text", $1);
1247                 t->set_spot (THIS->here_input ());
1248                 $$ = t;
1249         }
1250         | string {
1251                 Text_script_req *t = new Text_script_req;
1252                 t->set_mus_property ("text", $1);
1253                 t->set_spot (THIS->here_input ());
1254                 $$ = t;
1255         }
1256         | DIGIT {
1257                 String ds = to_str ($1);
1258                 Text_script_req* t = new Text_script_req;
1259
1260                 t->set_mus_property ("text",  ly_str02scm (ds.ch_C()));
1261                 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1262                 t->set_spot (THIS->here_input ());
1263                 $$ = t;
1264         }
1265         ;
1266
1267 script_abbreviation:
1268         '^'             {
1269                 $$ = gh_str02scm  ("hat");
1270         }
1271         | '+'           {
1272                 $$ = gh_str02scm("plus");
1273         }
1274         | '-'           {
1275                 $$ = gh_str02scm ("dash");
1276         }
1277         | '|'           {
1278                 $$ = gh_str02scm ("bar");
1279         }
1280         | '>'           {
1281                 $$ = gh_str02scm ("larger");
1282         }
1283         | '.'           {
1284                 $$ = gh_str02scm ("dot");
1285         }
1286         ;
1287
1288
1289 script_dir:
1290         '_'     { $$ = DOWN; }
1291         | '^'   { $$ = UP; }
1292         | '-'   { $$ = CENTER; }
1293         ;
1294
1295 pre_requests:
1296         {
1297                 $$ = new Link_array<Request>;
1298         }
1299         | pre_requests open_request {
1300                 $$->push ($2);
1301         }
1302         ;
1303
1304 absolute_musical_pitch:
1305         steno_musical_pitch     {
1306                 $$ = $1;
1307         }
1308         ;
1309
1310 duration_length:
1311         steno_duration {
1312                 $$ = $1;
1313         }
1314         | duration_length '*' bare_unsigned {
1315                 $$->tuplet_iso_i_ *= $3;
1316         }
1317         | duration_length '/' bare_unsigned {
1318                 $$->tuplet_type_i_ *= $3;
1319         }
1320         ;
1321
1322 entered_notemode_duration:
1323         steno_duration  {
1324                 THIS->set_last_duration ($1);
1325         }
1326         ;
1327
1328 optional_notemode_duration:
1329         {
1330                 $$ = new Duration (THIS->default_duration_);
1331         }
1332         | entered_notemode_duration {
1333                 $$ = $1;
1334         }
1335         ;
1336
1337 steno_duration:
1338         bare_unsigned           {
1339                 $$ = new Duration;
1340                 if (!is_duration_b ($1))
1341                         THIS->parser_error (_f ("not a duration: %d", $1));
1342                 else {
1343                         $$->durlog_i_ = intlog2 ($1);
1344                      }
1345         }
1346         | DURATION_IDENTIFIER   {
1347                 $$ = $1->access_content_Duration (true);
1348         }
1349         | steno_duration '.'    {
1350                 $$->dots_i_ ++;
1351         }
1352         ;
1353
1354
1355 tremolo_type: 
1356         ':'     {
1357                 $$ =0;
1358         }
1359         | ':' bare_unsigned {
1360                 if (!is_duration_b ($2))
1361                         THIS->parser_error (_f ("not a duration: %d", $2));
1362                 $$ = $2;
1363         }
1364         ;
1365
1366
1367 simple_element:
1368         musical_pitch exclamations questions optional_notemode_duration {
1369                 if (!THIS->lexer_p_->note_state_b ())
1370                         THIS->parser_error (_ ("Have to be in Note mode for notes"));
1371
1372
1373                 Note_req *n = new Note_req;
1374                 
1375                 n->pitch_ = *$1;
1376                 n->duration_ = *$4;
1377
1378                 n->cautionary_b_ = $3 % 2;
1379                 n->forceacc_b_ = $2 % 2 || n->cautionary_b_;
1380
1381
1382                 Simultaneous_music*v = new Request_chord (gh_list (n->self_scm (), SCM_UNDEFINED));
1383                 v->set_spot ($1->spot ());
1384                 n->set_spot ($1->spot ());
1385                 $$ = v;
1386
1387                 delete $1;
1388                 delete $4;
1389         }
1390         | RESTNAME optional_notemode_duration           {
1391
1392                 SCM e = SCM_UNDEFINED;
1393                   if (ly_scm2string ($1) =="s")
1394                     { /* Space */
1395                       Skip_req * skip_p = new Skip_req;
1396                       skip_p->duration_ = *$2;
1397
1398                       skip_p->set_spot (THIS->here_input());
1399                         e = skip_p->self_scm ();
1400                     }
1401                   else
1402                     {
1403                       Rest_req * rest_req_p = new Rest_req;
1404                       rest_req_p->duration_ = *$2;
1405                       rest_req_p->set_spot (THIS->here_input());
1406                         e = rest_req_p->self_scm ();
1407                     }
1408                   Simultaneous_music* velt_p = new Request_chord (gh_list (e,SCM_UNDEFINED));
1409                   velt_p->set_spot (THIS->here_input());
1410
1411                   delete $2; // ugh
1412                   $$ = velt_p;
1413         }
1414         | MEASURES optional_notemode_duration   {
1415                 Skip_req * sk = new Skip_req;
1416                 sk->duration_ = *$2;
1417                 
1418
1419                 Span_req *sp1 = new Span_req;
1420                 Span_req *sp2 = new Span_req;
1421                 sp1-> span_dir_ = START;
1422                 sp2-> span_dir_ = STOP;
1423                 sp1->span_type_str_ = sp2->span_type_str_ = "rest";
1424
1425                 Request_chord * rqc1 = new Request_chord (gh_list (sp1->self_scm (), SCM_UNDEFINED));
1426                 Request_chord * rqc2 = new Request_chord (gh_list (sk->self_scm (), SCM_UNDEFINED));;
1427                 Request_chord * rqc3 = new Request_chord(gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1428
1429                 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1430
1431                 $$ = new Sequential_music (ms);
1432         }
1433         | STRING { 
1434                 THIS->remember_spot ();
1435         } 
1436         /* cont */
1437         optional_notemode_duration      {
1438                 if (!THIS->lexer_p_->lyric_state_b ()) {
1439                         THIS->pop_spot ().error (_ ("Have to be in Lyric mode for lyrics"));
1440                         THIS->error_level_i_  = 1;
1441                         THIS->parser_error (_ ("Giving up"));
1442                 } 
1443                 else
1444                         THIS->pop_spot ();
1445                 Lyric_req* lreq_p = new Lyric_req;
1446                 lreq_p->set_mus_property ("text", $1);
1447                 lreq_p->duration_ = *$3;
1448                 lreq_p->set_spot (THIS->here_input());
1449                 Simultaneous_music* velt_p = new Request_chord (gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1450
1451                 delete  $3; // ugh
1452                 $$= velt_p;
1453
1454         }
1455         | chord {
1456                 if (!THIS->lexer_p_->chord_state_b ())
1457                         THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1458                 $$ = $1;
1459         }
1460         ;
1461
1462
1463 chord:
1464         steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1465                 $$ = get_chord (*$1, $3, $4, $5, $6, *$2);
1466                 $$->set_spot (THIS->here_input ());
1467         };
1468
1469 chord_additions: 
1470         {
1471                 $$ = new Array<Musical_pitch>;
1472         } 
1473         | CHORD_COLON chord_notes {
1474                 $$ = $2;
1475         }
1476         ;
1477
1478 chord_notes:
1479         chord_step {
1480                 $$ = $1
1481         }
1482         | chord_notes '.' chord_step {
1483                 $$ = $1;
1484                 $$->concat (*$3);
1485         }
1486         ;
1487
1488 chord_subtractions: 
1489         {
1490                 $$ = new Array<Musical_pitch>;
1491         } 
1492         | CHORD_CARET chord_notes {
1493                 $$ = $2;
1494         }
1495         ;
1496
1497
1498 chord_inversion:
1499         {
1500                 $$ = 0;
1501         }
1502         | '/' steno_tonic_pitch {
1503                 $$ = $2;
1504                 $$->set_spot (THIS->here_input ());
1505         }
1506         ;
1507
1508 chord_bass:
1509         {
1510                 $$ = 0;
1511         }
1512         | CHORD_BASS steno_tonic_pitch {
1513                 $$ = $2;
1514                 $$->set_spot (THIS->here_input ());
1515         }
1516         ;
1517
1518 chord_step:
1519         chord_note {
1520                 $$ = new Array<Musical_pitch>;
1521                 $$->push (*$1);
1522         }
1523         | CHORDMODIFIER_PITCH {
1524                 $$ = new Array<Musical_pitch>;
1525                 $$->push (*$1);
1526         }
1527         | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1528                 $$ = new Array<Musical_pitch>;
1529                 $$->push (*$1);
1530                 $$->push (*$2);
1531         }
1532         ;
1533
1534 chord_note:
1535         bare_unsigned {
1536                 $$ = new Musical_pitch;
1537                 $$->notename_i_ = ($1 - 1) % 7;
1538                 $$->octave_i_ = $1 > 7 ? 1 : 0;
1539                 $$->accidental_i_ = 0;
1540         } 
1541         | bare_unsigned '+' {
1542                 $$ = new Musical_pitch;
1543                 $$->notename_i_ = ($1 - 1) % 7;
1544                 $$->octave_i_ = $1 > 7 ? 1 : 0;
1545                 $$->accidental_i_ = 1;
1546         }
1547         | bare_unsigned CHORD_MINUS {
1548                 $$ = new Musical_pitch;
1549                 $$->notename_i_ = ($1 - 1) % 7;
1550                 $$->octave_i_ = $1 > 7 ? 1 : 0;
1551                 $$->accidental_i_ = -1;
1552         }
1553         ;
1554
1555 /*
1556         UTILITIES
1557  */
1558 number_expression:
1559         bare_number {
1560                 $$ = $1;
1561         }
1562         | '-'  number_expression %prec UNARY_MINUS {
1563                 $$ = scm_difference ($2, SCM_UNDEFINED);
1564         }
1565         | number_expression '*' number_expression {
1566                 $$ = scm_product ($1, $3);
1567         }
1568         | number_expression '/' number_expression {
1569                 $$ = scm_divide ($1, $3);
1570         }
1571         | number_expression '+' number_expression {
1572                 $$ = scm_sum ($1, $3);
1573         }
1574         | number_expression '-' number_expression {
1575                 $$ = scm_difference ($1, $3);
1576         }
1577         | '(' number_expression ')'     {
1578                 $$ = $2;
1579         }
1580         ;
1581
1582 bare_number:
1583         UNSIGNED        {
1584                 $$ = gh_int2scm ($1);
1585         }
1586         | DIGIT         {
1587                 $$ = gh_int2scm ($1);
1588         }
1589         | REAL          {
1590                 $$ = gh_double2scm ($1);
1591         }
1592         | NUMBER_IDENTIFIER             {
1593                 $$ = $1;
1594         }
1595         | REAL CM_T     {
1596                 $$ = gh_double2scm ($1 CM);
1597         }
1598         | REAL PT_T     {
1599                 $$ = gh_double2scm ($1 PT);
1600         }
1601         | REAL IN_T     {
1602                 $$ = gh_double2scm ($1 INCH);
1603         }
1604         | REAL MM_T     {
1605                 $$ = gh_double2scm ($1 MM);
1606         }
1607         | REAL CHAR_T   {
1608                 $$ = gh_double2scm ($1 CHAR);
1609         }
1610         ;
1611
1612
1613 bare_unsigned:
1614         bare_number {
1615                 if (scm_integer_p ($1) == SCM_BOOL_T) {
1616                         $$ = gh_scm2int ($1);
1617
1618                 } else {
1619                         THIS->parser_error (_("need integer number arg"));
1620                         $$ = 0;
1621                 }
1622                 if ($$ < 0) {
1623                         THIS->parser_error (_("Must be positive integer"));
1624                         $$ = -$$;
1625                         }
1626
1627         }
1628         ;
1629 bare_int:
1630         bare_number {
1631                 if (scm_integer_p ($1) == SCM_BOOL_T)
1632                 {
1633                         int k = gh_scm2int ($1);
1634                         $$ = k;
1635                 } else
1636                 {
1637                         THIS->parser_error (_("need integer number arg"));
1638                         $$ = 0;
1639                 }
1640         }
1641         | '-' bare_int {
1642                 $$ = -$2;
1643         }
1644         ;
1645
1646
1647 string:
1648         STRING          {
1649                 $$ = $1;
1650         }
1651         | STRING_IDENTIFIER     {
1652                 $$ = $1;
1653         }
1654         | string '+' string {
1655                 $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
1656         }
1657         ;
1658
1659
1660 exclamations:
1661                 { $$ = 0; }
1662         | exclamations '!'      { $$ ++; }
1663         ;
1664
1665 questions:
1666                 { $$ = 0; }
1667         | questions '?' { $$ ++; }
1668         ;
1669
1670
1671 semicolon:
1672         ';'
1673         ;
1674
1675 %%
1676
1677 void
1678 My_lily_parser::set_yydebug (bool b)
1679 {
1680 #ifdef YYDEBUG
1681         yydebug = b;
1682 #endif
1683 }
1684 void
1685 My_lily_parser::do_yyparse ()
1686 {
1687         yyparse ((void*)this);
1688 }
1689
1690