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