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