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