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