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