]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
release: 0.1.65
[lilypond.git] / lily / parser.yy
1 %{ // -*-Fundamental-*-
2
3 /*
4   parser.yy -- YACC -> C++ parser for mudela
5
6   source file of the GNU LilyPond music typesetter
7
8   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
9            Jan Nieuwenhuizen <jan@digicash.com>
10 */
11
12 #include <iostream.h>
13
14 #include "scalar.hh"
15 #include "translation-property.hh"
16 #include "script-def.hh"
17 #include "symtable.hh"
18 #include "lookup.hh"
19 #include "misc.hh"
20 #include "my-lily-lexer.hh"
21 #include "paper-def.hh"
22 #include "midi-def.hh"
23 #include "main.hh"
24 #include "keyword.hh"
25 #include "debug.hh"
26 #include "parseconstruct.hh"
27 #include "dimen.hh"
28 #include "identifier.hh"
29 #include "command-request.hh"
30 #include "musical-request.hh"
31 #include "my-lily-parser.hh"
32 #include "text-def.hh"
33 #include "translator-group.hh"
34 #include "score.hh"
35 #include "music-list.hh"
36 #include "header.hh"
37 #include "duration-convert.hh"
38 #include "change-translator.hh"
39 #include "file-results.hh"
40 #include "mudela-version.hh"
41 #include "scope.hh"
42 #include "relative-music.hh"
43
44
45 // mmm
46 Mudela_version oldest_version ("0.1.15");
47 Mudela_version version ("0.1.15");
48
49
50 // needed for bison.simple's malloc() and free()
51 #include <malloc.h>
52
53 int const GUESS_PLET = 5;
54 int guess_plet_a[GUESS_PLET] =
55
56   1,
57   3,
58   2,
59   3,
60   4
61 };
62
63 Paper_def* current_paper = 0;
64
65 #ifndef NDEBUG
66 #define YYDEBUG 1
67 #endif
68
69 #define YYERROR_VERBOSE 1
70
71 #define YYPARSE_PARAM my_lily_parser_l
72 #define YYLEX_PARAM my_lily_parser_l
73 #define THIS ((My_lily_parser *) my_lily_parser_l)
74
75 #define yyerror THIS->parser_error
76
77 %}
78
79
80 %union {
81     Array<Interval>* intarr;
82     Array<Musical_pitch> *pitch_arr;
83     Array<String> * strvec;
84     Array<int> *intvec;
85     Box *box;
86     Chord * chord;
87     Duration *duration;
88     Identifier *id;
89     Translator* trans;
90     Music *music;
91     Music_list *musiclist;
92     Score *score;
93     Header *header;
94     Interval *interval;
95     Lookup*lookup;
96
97     Musical_req* musreq;
98     Music_output_def * outputdef;
99     Musical_pitch * pitch;
100     Midi_def* midi;
101     Moment *moment;
102     Note_req *notereq;
103     Paper_def *paper;
104     Real real;
105     Request * request;
106     General_script_def * script;
107     Scalar *scalar;
108     String *string;
109     Atom * symbol;
110     Symtable * symtable;
111     Symtables * symtables;
112     Text_def * textdef;
113     Tempo_req *tempo;
114     char c;
115     const char *consstr;
116     int i;
117     int pair[2];
118     int ii[10];
119 }
120 %{
121
122 int
123 yylex (YYSTYPE *s,  void * v_l)
124 {
125         My_lily_parser   *pars_l = (My_lily_parser*) v_l;
126         My_lily_lexer * lex_l = pars_l->lexer_p_;
127
128         lex_l->lexval_l = (void*) s;
129         return lex_l->yylex ();
130 }
131
132
133 %}
134
135 %pure_parser
136
137 /* tokens which are not keywords */
138
139 %token ALIAS
140 %token BAR
141 %token BEAMPLET
142 %token MAEBTELP
143 %token PENALTY
144 %token CADENZA
145 %token CLEAR
146 %token CLEF
147 %token CONTAINS
148 %token RELATIVE
149 %token CONSISTS
150 %token ACCEPTS
151 %token CM_T
152 %token DURATION
153 %token ABSDYNAMIC
154 %token END
155 %token GROUPING
156 %token TRANSLATOR
157 %token HEADER
158 %token IN_T
159 %token LYRIC
160 %token KEY
161 %token MUSICAL_PITCH
162 %token MELODIC
163 %token MIDI
164
165 %token METER
166 %token MM_T
167 %token MULTI
168 %token NOTENAMES
169 %token OCTAVE
170 %token OUTPUT
171 %token PAPER
172 %token PARTIAL
173 %token PLET
174 %token TELP
175 %token PT_T
176 %token SCORE
177 %token SCRIPT
178 %token SHAPE
179 %token SKIP
180 %token SPANDYNAMIC
181 %token STAFF
182 %token START_T
183 %token SYMBOLTABLES
184 %token TABLE
185 %token TRANSPOSE
186 %token TEMPO
187 %token TYPE
188 %token TEXID
189 %token MEASURES
190 %token TEXTSTYLE
191 %token TITLE
192 %token PROPERTY
193 %token VERSION
194
195 /* escaped */
196 %token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
197
198 %type <i>       dots
199 %token <i>      DIGIT
200 %token <pitch>  NOTENAME_PITCH
201 %token <id>     DURATION_IDENTIFIER
202 %token <id>     IDENTIFIER
203
204 %token <id>     MUSIC_IDENTIFIER
205 %token <id>     VOICE_IDENTIFIER
206 %token <id>     POST_REQUEST_IDENTIFIER
207 %token <id>     SCRIPT_IDENTIFIER
208 %token <id>     COMMAND_IDENTIFIER
209 %token <id>     REAL_IDENTIFIER
210 %token <id>     STRING_IDENTIFIER
211 %token <id>     TRANS_IDENTIFIER
212 %token <id>     INT_IDENTIFIER
213 %token <id>     SCORE_IDENTIFIER
214 %token <id>     MIDI_IDENTIFIER
215 %token <id>     PAPER_IDENTIFIER
216 %token <id>     REQUEST_IDENTIFIER
217 %token <real>   REAL
218 %token <string> DURATION RESTNAME
219 %token <string> STRING
220 %token <i>      UNSIGNED
221
222
223 %type <outputdef> output_def
224 %type <header>  mudela_header mudela_header_body
225 %type <box>     box
226 %type <i>       open_request_parens close_request_parens
227 %type <i>       open_abbrev_parens
228 %type <i>       open_plet_parens close_plet_parens
229 %type <i>       sub_quotes sup_quotes
230 %type <music>   simple_element music_elt full_element lyrics_elt command_elt
231 %type <i>       abbrev_type
232 %type <i>       int unsigned
233 %type <i>       script_dir
234 %type <id>      identifier_init simple_identifier_init
235 %type <duration> steno_duration notemode_duration
236 %type <duration> entered_notemode_duration explicit_duration
237 %type <interval>        dinterval
238 %type <intvec>  intastint_list
239 %type <lookup>  symtables symtables_body
240
241 %type <pitch>   explicit_musical_pitch steno_musical_pitch musical_pitch absolute_musical_pitch
242 %type <notereq> steno_notepitch
243 %type <pitch_arr>       pitch_list
244 %type <midi>    midi_block midi_body
245 %type <moment>  duration_length
246
247 %type <scalar>  scalar
248 %type <music>   Music transposed_music relative_music
249 %type <music>   property_def translator_change
250 %type <musiclist> Voice Voice_body
251 %type <chord>   Chord Chord_body
252 %type <paper>   paper_block paper_body
253 %type <real>    dim real
254 %type <real>    real_mult_expression real_primary
255 %type <real>    unit
256 %type <request> abbrev_command_req
257 %type <request> post_request structured_post_request
258 %type <pair>    plet_fraction
259 %type <request> command_req verbose_command_req
260 %type <request> script_req  dynamic_req
261 %type <string>  string
262 %type <string>  string_primary
263 %type <score>   score_block score_body
264 %type <intarr>  shape_array
265 %type <script>  script_definition script_body mudela_script gen_script_def
266 %type <textdef> text_def finger
267 %type <string>  script_abbreviation
268 %type <symbol>  symboldef
269 %type <symtable>        symtable symtable_body
270 %type <trans>   translator_spec translator_spec_body
271 %type <tempo>   tempo_request
272 %type <string>  concat_strings
273
274 %expect 1
275
276
277 %%
278
279 mudela: /* empty */
280         | mudela mudela_header {
281                 delete THIS->default_header_p_ ;
282                 THIS->default_header_p_ = $2;
283         }
284         | mudela score_block {
285                 score_global_array.push ($2);
286         }
287         | mudela add_declaration { }
288         | mudela error
289         | mudela check_version { }
290         | mudela add_notenames { }
291         ;
292
293 check_version:
294         VERSION STRING ';'              {
295                 Mudela_version ver (*$2);
296                 if (!((ver >= oldest_version) && (ver <= version))) {
297                         if (THIS->ignore_version_b_) {
298                                 THIS->here_input ().error ("Incorrect mudela version");
299                         } else {
300                                 THIS->fatal_error_i_ = 1;
301                                 THIS->parser_error ("Incorrect mudela version");
302                         }
303                 }
304         }
305         ;
306
307 add_notenames:
308         NOTENAMES '{' notenames_body '}'
309         ;
310 notenames_body:
311         /**/    {
312         }
313         | notenames_body CLEAR  {
314                 THIS->clear_notenames ();
315         }
316         | notenames_body STRING '=' explicit_musical_pitch {
317                 THIS->add_notename (*$2, *$4);
318                 delete $4;
319                 delete $2;
320         }
321         ;
322
323 mudela_header_body:
324                 {
325                 $$ = new Header;
326         }
327         | mudela_header_body STRING '=' concat_strings ';' {
328                 (*$$)[*$2] = *$4;
329                 delete $2;
330                 delete $4;
331         }
332         ;
333
334 mudela_header:
335         HEADER '{' mudela_header_body '}'       {
336                 $$ = $3;
337         }
338         ;
339
340
341 concat_strings:
342                 {
343                 $$ = new String;
344         }
345         | concat_strings STRING {
346                 *$$ += *$2;
347         }
348
349
350 /*
351         DECLARATIONS
352 */
353
354 add_declaration:
355         STRING {
356                 THIS->remember_spot ();
357         }
358         /* cont */ '=' identifier_init optional_semicolon {
359             THIS->lexer_p_->set_identifier (*$1, $4);
360             $4->init_b_ = THIS->init_parse_b_;
361             $4->set_spot (THIS->pop_spot ());
362         }
363         ;
364
365 identifier_init:
366         score_block {
367                 $$ = new Score_identifier ($1, SCORE_IDENTIFIER);
368
369         }
370         | paper_block {
371                 $$ = new Paper_def_identifier ($1, PAPER_IDENTIFIER);
372         }
373         | midi_block {
374                 $$ = new Midi_def_identifier ($1, MIDI_IDENTIFIER);
375
376         }
377         | script_definition {
378                 $$ = new General_script_def_identifier ($1, SCRIPT_IDENTIFIER);
379
380         }
381         | Music  {
382                 $$ = new Music_identifier ($1, MUSIC_IDENTIFIER);
383
384         }
385         | symtables {
386                 $$ = new Lookup_identifier ($1, IDENTIFIER);
387
388         }
389         | post_request {
390                 $$ = new Request_identifier ($1, POST_REQUEST_IDENTIFIER);
391         }
392 /*      | melodic_request {
393                 $$ = new Request_identifier ($1, MELODIC_REQUEST_IDENTIFIER);
394
395         }
396         */
397         | explicit_duration {
398                 $$ = new Duration_identifier ($1, DURATION_IDENTIFIER);
399         }
400         | simple_identifier_init
401         ;
402
403 simple_identifier_init:
404         real {
405                 $$ = new Real_identifier (new Real ($1), REAL_IDENTIFIER);
406         }
407         | string {
408                 $$ = new String_identifier ($1, STRING_IDENTIFIER);
409         }
410         | int   {
411                 $$ = new int_identifier (new int ($1), INT_IDENTIFIER);
412         }
413         | translator_spec {
414                 $$ = new Translator_identifier ($1, TRANS_IDENTIFIER);
415         }
416         ;
417
418 translator_spec:
419         TRANSLATOR '{' translator_spec_body '}'
420                 { $$ = $3; }
421         ;
422
423 translator_spec_body:
424         TRANS_IDENTIFIER        {
425                 $$ = $1->translator ();
426                 $$-> set_spot (THIS->here_input ());
427         }
428         | TYPE STRING ';'       {
429                 $$ = get_translator_l (*$2)->clone ();
430                 $$->set_spot (THIS->here_input ());
431                 delete $2;
432         }
433         | translator_spec_body STRING '=' scalar ';'    { 
434                 $$-> set_property (*$2, *$4);
435                 delete $2;
436                 delete $4;
437         }
438         | translator_spec_body CONSISTS STRING ';' {
439                 $$->group_l ()->consists_str_arr_.push (*$3);
440                 delete $3;
441         }
442         | translator_spec_body ACCEPTS STRING ';' {
443                 $$->group_l ()->accepts_str_arr_.push (*$3);
444                 delete $3;
445         }
446         ;
447
448 /*
449         SCORE
450 */
451 score_block:
452         SCORE { THIS->remember_spot ();
453                 THIS->error_level_i_ =0;
454         }
455         /*cont*/ '{' score_body '}'     {
456                 $$ = $4;
457                 $$->set_spot (THIS->pop_spot ());
458                 if (!$$->def_p_arr_.size ())
459                         $$->add (THIS->default_paper_p ());
460
461                 /* handle error levels. */
462                 $$->errorlevel_i_ = THIS->error_level_i_;
463                 THIS->error_level_i_ = 0;
464                 if (!$$->header_p_ && THIS->default_header_p_)
465                         $$->header_p_ = new Header (*THIS->default_header_p_);
466         }
467         ;
468
469 score_body:             {
470                 $$ = new Score;
471         }
472         | SCORE_IDENTIFIER {
473                 $$ = $1->score ();
474         }
475         | score_body mudela_header      {
476                 $$->header_p_ = $2;
477         }
478         | score_body Music      {
479                 if ($$->music_p_)
480                         $2->warning ("More than one music block");      
481                 $$->music_p_ = $2;
482         }
483         | score_body output_def {
484                 $$->add ($2);
485         }
486         | score_body error {
487
488         }
489         ;
490
491 output_def:
492         paper_block {
493                 $$ = $1;
494         }
495         |  midi_block           {
496                 $$= $1;
497         }
498         ;
499
500 intastint_list:
501         /* */   { $$ =new Array<int>; }
502         | intastint_list int '*' int    {
503                 $$->push ($2); $$->push ($4);
504         }
505         ;
506
507
508 /*
509         PAPER
510 */
511 paper_block:
512         PAPER '{' paper_body '}'        { 
513                 $$ = $3;
514                 THIS-> lexer_p_->scope_l_arr_.pop ();
515         }
516         ;
517
518 optional_semicolon:
519         /* empty */
520         | ';'
521         ;
522
523 paper_body:
524         /* empty */                     {
525                 Paper_def *p = THIS->default_paper_p ();
526                 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
527                 $$ = p;
528         }
529         | PAPER_IDENTIFIER optional_semicolon   {
530                 Paper_def *p = $1->paperdef ();
531                 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
532                 $$ = p;
533         }
534         | paper_body OUTPUT STRING ';'  { 
535                 $$->outfile_str_ = *$3;
536                 delete $3;
537         }
538         | paper_body symtables          { $$->set ($2); }
539         | paper_body STRING '=' simple_identifier_init optional_semicolon {
540             Identifier* id = $4;
541             id->init_b_ = THIS->init_parse_b_;
542             if (id->is_type_b (Translator_identifier::static_name ()))
543               {
544                 $$->assign_translator (*$2, id->translator ());
545                 delete id;
546               }
547             else
548               THIS->lexer_p_->set_identifier (*$2, id);
549         }
550 /*
551         | paper_body STRING '=' translator_spec {
552                 $$-> assign_translator (*$2, $4);
553                 delete $2;
554         }
555 */
556         | paper_body SHAPE '=' shape_array ';' {
557                 $$->shape_int_a_ = *$4;
558                 delete $4;
559         }
560         | paper_body error {
561
562         }
563         ;
564
565 real_primary:
566         REAL            {
567                 $$ = $1;
568         }
569         | REAL_IDENTIFIER               {
570                 Real *r_p = $1->real ();
571                 $$ = * r_p;
572                 DOUT << "Lookup real: " << *r_p << "\n";
573                 delete r_p;
574         }
575         | dim
576         | '(' real ')' {
577                 $$ = $2;
578         }
579         ;
580
581 real:
582         real_mult_expression
583         | real '+' real_mult_expression {
584                 $$ = $1 + $3;
585         }
586         | real '-' real_mult_expression {
587                 $$ = $1 - $3;
588         }
589         ;
590
591 real_mult_expression:
592         real_primary
593         | real_mult_expression '*' real_primary {
594                 $$ = $1 * $3;
595         }
596         | real_mult_expression '/' real_primary {
597                 $$ = $1 / $3;
598         }
599         ;
600
601 shape_array:
602         /* empty */ {
603                 $$ = new Array<Interval>;
604         }
605         | shape_array dim dim {
606                 $$->push(Interval($2, $2 + $3));
607         };
608
609 /*
610         MIDI
611 */
612 midi_block:
613         MIDI
614
615         '{' midi_body '}'       { $$ = $3; }
616         ;
617
618 midi_body: /* empty */          {
619                 $$ = THIS->default_midi_p ();
620         }
621         | midi_body STRING '=' translator_spec  {
622                 $$-> assign_translator (*$2, $4);
623                 delete $2;
624         }
625         | midi_body OUTPUT STRING ';'   {
626                 $$->outfile_str_ = *$3;
627                 delete $3;
628         }
629         | midi_body tempo_request ';' {
630                 $$->set_tempo ($2->dur_.length (), $2->metronome_i_);
631                 delete $2;
632         }
633         | midi_body error {
634
635         }
636         ;
637
638 tempo_request:
639         TEMPO entered_notemode_duration '=' unsigned    {
640                 $$ = new Tempo_req;
641                 $$->dur_ = *$2;
642                 delete $2;
643                 $$-> metronome_i_ = $4;
644         }
645         ;
646
647 /*
648         MUSIC
649 */
650
651 Voice:
652         '{' Voice_body '}'      {
653                 $$ = $2;
654         }
655         ;
656
657 Voice_body:
658         /**/            {
659                 $$ = new Voice;
660                 $$->set_spot (THIS->here_input ());
661         }
662         | Voice_body Music      {
663                 $$->add ($2);
664         }
665         ;
666
667 Music:
668         full_element            { $$ = $1; }
669         | TYPE STRING Music     {
670                 $$ = $3;
671                 $$->translator_type_str_ = *$2;
672                 delete $2;
673         }
674         | TYPE STRING '=' STRING Music {
675                 $$ = $5;
676                 $$->translator_type_str_ = *$2;
677                 $$->translator_id_str_ = *$4;
678                 delete $2;
679                 delete $4;
680         }
681         | Voice         { $$ = $1; }
682         | Chord                 { $$ = $1; }
683         | transposed_music      { $$ = $1; }
684         | MUSIC_IDENTIFIER { $$ = $1->music (); }
685         | MELODIC
686                 { THIS->lexer_p_->push_note_state (); }
687         Music
688                 { $$=$3; THIS->lexer_p_->pop_state (); }
689
690         | LYRIC
691                 { THIS->lexer_p_->push_lyric_state (); }
692         Music
693                 { $$ = $3; THIS->lexer_p_->pop_state (); }
694         | property_def
695         | translator_change
696         | relative_music        { $$ = $1; }
697         ;
698
699 relative_music:
700         RELATIVE absolute_musical_pitch Music
701         {
702                 $$ = new Relative_octave_music ($3, *$2);
703                 delete $2;
704         }
705         ;
706
707 translator_change:
708         TRANSLATOR STRING '=' STRING  {
709                 Change_translator * t = new Change_translator;
710                 t-> change_to_type_str_ = *$2;
711                 t-> change_to_id_str_ = *$4;
712
713                 $$ = t;
714                 $$->set_spot (THIS->here_input ());
715                 delete $2;
716                 delete $4;
717         }
718         ;
719
720 property_def:
721         PROPERTY STRING '.' STRING '=' scalar   {
722                 Translation_property *t = new Translation_property;
723                 t-> translator_type_str_ = *$2;
724                 t-> var_str_ = *$4;
725                 t-> value_ = *$6;
726                 $$ = t;
727                 $$->set_spot (THIS->here_input ());
728                 delete $2;
729                 delete $4;
730                 delete $6;
731         }
732         ;
733
734 scalar:
735         STRING          { $$ = new Scalar (*$1); delete $1; }
736         | int           { $$ = new Scalar ($1); }
737         ;
738
739
740 Chord:
741         '<' Chord_body '>'      { $$  = $2; }
742         | MULTI unsigned Chord {
743                 $$ = $3;
744                 $$->multi_level_i_=$2;
745         }
746         ;
747
748 Chord_body:
749         /**/    {
750                 $$ = new Chord;
751                 $$-> multi_level_i_ = 1;
752                 $$->set_spot (THIS->here_input ());
753         }
754         | Chord_body Music {
755                 $$->add ($2);
756         }
757         ;
758
759 transposed_music:
760         TRANSPOSE musical_pitch Music {
761                 $$ = $3;
762                 $$ -> transpose (*$2);
763
764                 delete $2;
765         }
766         ;
767
768
769 /*
770         VOICE ELEMENTS
771 */
772 full_element:
773         pre_requests simple_element post_requests       {
774                 THIS->add_requests ((Chord*)$2);//ugh
775                 $$ = $2;
776         }
777         | command_elt
778         | voice_command ';'     { $$ = 0; }
779         ;
780
781 simple_element:
782         music_elt
783         | lyrics_elt
784         ;
785
786 command_elt:
787         command_req {
788                 $$ = new Request_chord;
789                 $$-> set_spot (THIS->here_input ());
790                 $1-> set_spot (THIS->here_input ());
791                 ((Chord*)$$) ->add ($1);//ugh
792
793         }
794         ;
795
796 command_req:
797         abbrev_command_req
798         | verbose_command_req ';'       { $$ = $1; }
799         ;
800
801 abbrev_command_req:
802         '|'                             {
803                 $$ = new Barcheck_req;
804         }
805         | COMMAND_IDENTIFIER    {
806                 $$ = $1->request ();
807         }
808         ;
809
810 verbose_command_req:
811         BAR STRING                      {
812                 $$ = new Bar_req (*$2);
813                 delete $2;
814         }
815         | PENALTY '=' int       {
816                 Break_req * b = new Break_req;
817                 b->penalty_i_ = $3;
818                 b-> set_spot (THIS->here_input ());
819                 $$ = b;
820         }
821         | METER unsigned '/' unsigned   {
822                 Meter_change_req *m = new Meter_change_req;
823                 m->set ($2,$4);
824                 $$ = m;
825         }
826         | SKIP duration_length {
827                 Skip_req * skip_p = new Skip_req;
828                 skip_p->duration_.set_plet ($2->num (),
829                         $2->den ());
830
831                 delete $2;
832                 $$ = skip_p;
833         }
834         | tempo_request {
835                 $$ = $1;
836         }
837         | CADENZA unsigned      {
838                 $$ = new Cadenza_req ($2);
839         }
840         | PARTIAL duration_length       {
841                 $$ = new Partial_measure_req (*$2);
842                 delete $2;
843         }
844         | CLEF STRING {
845                 $$ = new Clef_change_req (*$2);
846                 delete $2;
847         }
848         | KEY pitch_list        {
849                 Key_change_req *key_p= new Key_change_req;
850                 key_p->pitch_arr_ = *$2;
851                 $$ = key_p;
852                 delete $2;
853         }
854         | GROUPING intastint_list {
855                 $$ = get_grouping_req (*$2); delete $2;
856         }
857         ;
858
859 post_requests:
860         {
861                 /* something silly happened.  Junk this stuff*/
862                 if (!THIS->post_reqs.empty ())
863                 {
864                         warning ("Junking post-requests");
865                         THIS->post_reqs.clear ();
866                 }
867         }
868         | post_requests structured_post_request {
869                 $2->set_spot (THIS->here_input ());
870                 THIS->post_reqs.push ($2);
871         }
872         | post_requests close_request_parens    {
873                 Array<Request*>& r = *THIS->get_parens_request ($2);
874                 for (int i = 0; i < r.size (); i++ )
875                         r[i]->set_spot (THIS->here_input ());
876                 THIS->post_reqs.concat (r);
877                 delete &r;
878         }
879         ;
880
881 structured_post_request:
882         script_req
883         | post_request
884         ;
885
886 post_request:
887         POST_REQUEST_IDENTIFIER {
888                 $$ = (Request*)$1->request ();
889         }
890         | dynamic_req {
891                 $$ = $1;
892         }
893         | abbrev_type   {
894                 Abbreviation_req* a = new Abbreviation_req;
895                 a->type_i_ = $1;
896                 $$ = a;
897         }
898         ;
899
900 sup_quotes:
901         '\'' {
902                 $$ = 1;
903         }
904         | sup_quotes '\'' {
905                 $$ ++;
906         }
907         ;
908 sub_quotes:
909         ',' {
910                 $$ = 1;
911         }
912         | sub_quotes ',' {
913                 $$ ++ ;
914         }
915         ;
916
917 steno_musical_pitch:
918         NOTENAME_PITCH  {
919                 $$ = $1;
920                 $$->octave_i_ += THIS->default_octave_i_;
921         }
922         | NOTENAME_PITCH sup_quotes     {
923                 $$ = $1;
924                 $$->octave_i_ += $2 +  THIS->default_octave_i_;
925
926         }
927         | NOTENAME_PITCH sub_quotes      {
928                 $$ = $1;
929                 $$->octave_i_ += THIS->default_octave_i_ - $2 ;
930         }
931         ;
932
933 explicit_musical_pitch:
934         MUSICAL_PITCH '{' int int int '}'       {/* ugh */
935                 $$ = new Musical_pitch;
936                 $$->octave_i_ = $3;
937                 $$->notename_i_ = $4;
938                 $$->accidental_i_ = $5;
939         }
940         ;
941 musical_pitch:
942         steno_musical_pitch
943         | explicit_musical_pitch
944         ;
945
946 steno_notepitch:
947         musical_pitch   {
948                 $$ = new Note_req;
949                 
950                 $$->pitch_ = *$1;
951                 delete $1;
952         }
953         | steno_notepitch  '!'          {
954                 $$->forceacc_b_ = ! $$->forceacc_b_;
955         }
956         ;
957
958
959 explicit_duration:
960         DURATION '{' int unsigned '}'   {
961                 $$ = new Duration;
962                 $$-> durlog_i_ = $3;
963                 $$-> dots_i_ = $4;
964         }
965         ;
966
967 dynamic_req:
968         ABSDYNAMIC '{' unsigned '}'     {
969                 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
970                 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
971                 $$ =ad_p;
972         }
973         | SPANDYNAMIC '{' int int '}' {
974                 Span_dynamic_req * sp_p = new Span_dynamic_req;
975                 sp_p->spantype = (Span_req::Spantype)$4;
976                 sp_p-> dynamic_dir_  = (Direction)$3;
977                 $$ = sp_p;
978         }
979         ;
980
981 plet_fraction:
982         unsigned '/' unsigned {
983                 $$[0] = $1;
984                 $$[1] = $3;
985         }
986         |
987         '/' unsigned {
988                 int num = $2 >? 1;
989                 $$[0] = guess_plet_a[(num <? GUESS_PLET) - 1];
990                 $$[1] = num;
991         }
992         ;
993
994 close_plet_parens:
995         ']' plet_fraction {
996                 $$ = MAEBTELP;
997                 THIS->plet_.type_i_ = $2[1];
998                 THIS->plet_.iso_i_ = $2[0];
999                 THIS->default_duration_.plet_.type_i_ = $2[1];
1000                 THIS->default_duration_.plet_.iso_i_ = $2[0];
1001         }
1002         | TELP {
1003                 $$ = TELP;
1004                 THIS->plet_.type_i_ = 1;
1005                 THIS->plet_.iso_i_ = 1;
1006                 THIS->default_duration_.plet_.iso_i_ = 1;
1007                 THIS->default_duration_.plet_.type_i_ = 1;
1008         }
1009         | TELP plet_fraction {
1010                 $$ = TELP;
1011                 THIS->plet_.type_i_ = $2[1];
1012                 THIS->plet_.iso_i_ = $2[0];
1013                 THIS->default_duration_.plet_.type_i_ = $2[1];
1014                 THIS->default_duration_.plet_.iso_i_ = $2[0];
1015         }
1016         ;
1017
1018 close_request_parens:
1019         '~'     {
1020                 $$ = '~';
1021         }
1022         | '('   {
1023                 $$='(';
1024         }
1025         | ']'   {
1026                 $$ = ']';
1027         }
1028         | E_SMALLER {
1029                 $$ = '<';
1030         }
1031         | E_BIGGER {
1032                 $$ = '>';
1033         }
1034         | close_plet_parens
1035         ;
1036
1037 open_abbrev_parens:
1038         '[' ':' unsigned {
1039                 $$ = '[';
1040                 if (!Duration::duration_type_b ($3))
1041                         THIS->parser_error (String ("Not a duration: ") + $3);
1042                 else if ($3 < 8)
1043                         THIS->parser_error ("Can't abbreviate");
1044                 else
1045                         THIS->set_abbrev_beam ($3);
1046         }
1047         ;
1048
1049 open_plet_parens:
1050         '[' plet_fraction {
1051                 $$ = BEAMPLET;
1052                 THIS->plet_.type_i_ = $2[1];
1053                 THIS->plet_.iso_i_ = $2[0];
1054                 THIS->default_duration_.plet_.type_i_ = $2[1];
1055                 THIS->default_duration_.plet_.iso_i_ = $2[0];
1056         }
1057         | PLET plet_fraction {
1058                 $$ = PLET;
1059                 THIS->plet_.type_i_ = $2[1];
1060                 THIS->plet_.iso_i_ = $2[0];
1061                 THIS->default_duration_.plet_.type_i_ = $2[1];
1062                 THIS->default_duration_.plet_.iso_i_ = $2[0];
1063         }
1064         ;
1065
1066 open_request_parens:
1067         E_EXCLAMATION   {
1068                 $$ = '!';
1069         }
1070         | ')'   {
1071                 $$=')';
1072         }
1073         | '['   {
1074                 $$='[';
1075         }
1076         | open_abbrev_parens
1077         | open_plet_parens
1078         ;
1079
1080
1081
1082 script_definition:
1083         SCRIPT '{' script_body '}'      { $$ = $3; }
1084         ;
1085
1086 script_body:
1087         STRING int int int int int              {
1088                 Script_def *s = new Script_def;
1089                 s->set_from_input (*$1,$2, $3,$4,$5, $6);
1090                 $$  = s;
1091                 delete $1;
1092         }
1093         ;
1094
1095 script_req:
1096         script_dir gen_script_def       {
1097                 Musical_script_req *m = new Musical_script_req;
1098                 $$ = m;
1099                 m->scriptdef_p_ = $2;
1100                 m->set_spot (THIS->here_input ());
1101                 if (!m->dir_)
1102                   m->dir_  = (Direction)$1;
1103         }
1104         ;
1105
1106 gen_script_def:
1107         text_def        { 
1108                 $$ = $1;
1109                 ((Text_def*) $$)->align_i_ = CENTER; /* UGH */
1110         }
1111         | mudela_script { 
1112                 $$ = $1;
1113                 $$-> set_spot (THIS->here_input ());
1114         }
1115         | finger {
1116                 $$ = $1;
1117                 ((Text_def*)$$)->align_i_ = CENTER;
1118         }
1119         ;
1120
1121 text_def:
1122         STRING {
1123                 Text_def *t  = new Text_def;
1124                 $$ = t;
1125                 t->text_str_ = *$1;
1126                 delete $1;
1127                 t->style_str_ = THIS->textstyle_str_;
1128                 $$->set_spot (THIS->here_input ());
1129         }
1130         ;
1131
1132 finger:
1133          DIGIT {
1134                 Text_def* t  = new Text_def;
1135                 $$ = t;
1136                 t->text_str_ = String ($1);
1137                 t->style_str_ = "finger";
1138                 $$->set_spot (THIS->here_input ());
1139         }
1140         ;
1141
1142 script_abbreviation:
1143         '^'             { $$ = get_scriptdef ('^'); }
1144         | '+'           { $$ = get_scriptdef ('+'); }
1145         | '-'           { $$ = get_scriptdef ('-'); }
1146         | '|'           { $$ = get_scriptdef ('|'); }
1147         | 'o'           { $$ = get_scriptdef ('o'); }
1148         | '>'           { $$ = get_scriptdef ('>'); }
1149         | '.'           {
1150                 $$ = get_scriptdef ('.');
1151         }
1152         ;
1153
1154 mudela_script:
1155         SCRIPT_IDENTIFIER               { $$ = $1->script (); }
1156         | script_definition             { $$ = $1; }
1157         | script_abbreviation           {
1158                 $$ = THIS->lexer_p_->lookup_identifier (*$1)->script ();
1159                 delete $1;
1160         }
1161         ;
1162
1163 script_dir:
1164         '_'     { $$ = -1; }
1165         | '^'   { $$ = 1; }
1166         | '-'   { $$ = 0; }
1167         ;
1168
1169 pre_requests:
1170         {
1171         }
1172         | pre_requests open_request_parens {
1173                 Array<Request*>& r = *THIS->get_parens_request ($2);
1174                 for (int i = 0; i < r.size (); i++ )
1175                         r[i]->set_spot (THIS->here_input ());
1176                 THIS->pre_reqs.concat (r);
1177                 delete &r;
1178         }
1179         ;
1180
1181 absolute_musical_pitch:
1182         steno_musical_pitch     {
1183                 $$ = $1;
1184                 $$->octave_i_ -=  THIS->default_octave_i_;
1185         }
1186         ;
1187 voice_command:
1188         OCTAVE absolute_musical_pitch   {
1189                 THIS->default_octave_i_ = $2->octave_i_;
1190                 delete $2;
1191         }
1192         | TEXTSTYLE STRING      {
1193                 THIS->textstyle_str_ = *$2;
1194                 delete $2;
1195         }
1196         ;
1197
1198 duration_length:
1199         {
1200                 $$ = new Moment (0,1);
1201         }
1202         | duration_length steno_duration                {
1203                 *$$ += $2->length ();
1204         }
1205         ;
1206
1207 dots:
1208         '.'             { $$ = 1; }
1209         | dots '.'      { $$ ++; }
1210         ;
1211
1212 entered_notemode_duration:
1213         /* */           {
1214                 $$ = new Duration (THIS->default_duration_);
1215                 // get sticky plet part too
1216                 $$->set_plet (THIS->plet_.iso_i_, THIS->plet_.type_i_);
1217         }
1218         | dots          {
1219                 $$ = new Duration (THIS->default_duration_);
1220                 // get sticky plet part too
1221                 $$->set_plet (THIS->plet_.iso_i_, THIS->plet_.type_i_);
1222                 $$->dots_i_  = $1;
1223         }
1224         | steno_duration        {
1225                 THIS->set_last_duration ($1);
1226                 $$ = $1;
1227         }
1228         ;
1229
1230 notemode_duration:
1231         entered_notemode_duration {
1232                 $$ = $1;
1233         }
1234         ;
1235
1236 steno_duration:
1237         unsigned                {
1238                 $$ = new Duration;
1239                 if (!Duration::duration_type_b ($1))
1240                         THIS->parser_error ("Not a duration:" + String ($1));
1241                 else {
1242                         $$->durlog_i_ = Duration_convert::i2_type ($1);
1243                         $$->set_plet (THIS->plet_.iso_i_, THIS->plet_.type_i_);
1244                      }
1245         }
1246         | DURATION_IDENTIFIER   {
1247                 $$ = $1->duration ();
1248         }
1249         | steno_duration '.'    {
1250                 $$->dots_i_ ++;
1251         }
1252         | steno_duration '*' unsigned  {
1253                 $$->plet_.iso_i_ = $3;  /* ugh.  should do *= */
1254         }
1255         | steno_duration '/' unsigned {
1256                 $$->plet_.type_i_ = $3; /* ugh. should do *= iso = */
1257         }
1258         ;
1259
1260
1261 abbrev_type: 
1262         ':'     {
1263                 $$ =0;
1264         }
1265         | ':' unsigned {
1266                 if (!Duration::duration_type_b ($2))
1267                         THIS->parser_error ("Not a duration:" + String ($2));
1268                 else if ($2 < 8)
1269                         THIS->parser_error ("Can't abbreviate");
1270                 $$ = $2;
1271         }
1272
1273         ;
1274
1275
1276
1277 music_elt:
1278         steno_notepitch notemode_duration  {
1279                 if (!THIS->lexer_p_->note_state_b ())
1280                         THIS->parser_error ("have to be in Note mode for notes");
1281                 $1->set_duration (*$2);
1282                 int durlog_i = $2->durlog_i_;
1283                 $$ = THIS->get_note_element ($1, $2);
1284         }
1285         | RESTNAME notemode_duration            {
1286                 $$ = THIS->get_rest_element (*$1, $2);
1287                 delete $1;  // delete notename
1288         }
1289         | MEASURES notemode_duration    {
1290                 Multi_measure_rest_req* m = new Multi_measure_rest_req;
1291                 m->duration_ = *$2;
1292                 delete $2;
1293
1294                 Chord*velt_p = new Request_chord;
1295                 velt_p->set_spot (THIS->here_input ());
1296                 velt_p->add (m);
1297                 $$ = velt_p;
1298
1299         }
1300         ;
1301
1302 lyrics_elt:
1303         text_def notemode_duration                      {
1304         /* this sux! text-def should be feature of lyric-engraver. */
1305                 if (!THIS->lexer_p_->lyric_state_b ())
1306                         THIS->parser_error ("Have to be in Lyric mode for lyrics");
1307                 $$ = THIS->get_word_element ($1, $2);
1308
1309         };
1310
1311 /*
1312         UTILITIES
1313  */
1314 pitch_list:                     {
1315                 $$ = new Array<Musical_pitch>;
1316         }
1317         | pitch_list NOTENAME_PITCH     {
1318                 $$->push (*$2);
1319                 delete $2;
1320         }
1321         ;
1322
1323 unsigned:
1324         UNSIGNED        {
1325                 $$ = $1;
1326         }
1327         | DIGIT {
1328                 $$ = $1;
1329         };
1330
1331 int:
1332         unsigned {
1333                 $$ = $1;
1334         }
1335         | '-' unsigned {
1336                 $$ = -$2;
1337         }
1338         | INT_IDENTIFIER        {
1339                 int *i_p = $1->intid ();
1340                 $$ = *i_p;
1341                 delete i_p;
1342         }
1343         ;
1344
1345 string_primary:
1346         STRING          {
1347                 $$ = $1;
1348         }
1349         | STRING_IDENTIFIER     {
1350                 String *s_p = $1->string ();
1351                 // $$ = * r_p;
1352                 $$ = s_p;
1353                 DOUT << "Lookup string: " << *s_p << "\n";
1354         }
1355         ;
1356
1357 string:
1358         string_primary {
1359                 $$ = $1;
1360         }
1361         | string '+' string_primary {
1362                 *$$ += *$3;
1363                 delete $3;
1364         }
1365         ;
1366
1367 dim:
1368         real_primary unit       { $$ = $1*$2; }
1369         ;
1370
1371
1372 unit:   CM_T            { $$ = 1 CM; }
1373         |IN_T           { $$ = 1 INCH; }
1374         |MM_T           { $$ = 1 MM; }
1375         |PT_T           { $$ = 1 PT; }
1376         ;
1377
1378 /*
1379         symbol tables
1380 */
1381 symtables:
1382         SYMBOLTABLES '{' symtables_body '}'     { $$ = $3; }
1383         ;
1384
1385 symtables_body:
1386                         {
1387                 $$ = new Lookup;
1388         }
1389         | IDENTIFIER            {
1390                 $$ = $1->lookup ();
1391         }
1392         | symtables_body TEXID STRING           {
1393                 $$->texsetting = *$3;
1394                 delete $3;
1395         }
1396         | symtables_body STRING '=' symtable            {
1397                 $$->add (*$2, $4);
1398                 delete $2;
1399         }
1400         ;
1401
1402 symtable:
1403         TABLE '{' symtable_body '}' { $$ = $3; }
1404         ;
1405
1406 symtable_body:
1407                                 { $$ = new Symtable; }
1408         | symtable_body STRING  symboldef {
1409                 $$->add (*$2, *$3);
1410                 delete $2;
1411                 delete $3;
1412         }
1413         ;
1414
1415 symboldef:
1416         STRING  box             {
1417                 $$ = new Atom (*$1, *$2);
1418                 delete $1;
1419                 delete $2;
1420         }
1421         | STRING {
1422                 Box b (Interval (0,0), Interval (0,0));
1423                 $$ = new Atom (*$1, b);
1424                 delete $1;
1425         }
1426         ;
1427
1428 box:
1429         dinterval dinterval     {
1430                 $$ = new Box (*$1, *$2);
1431                 delete $1;
1432                 delete $2;
1433         }
1434         ;
1435
1436 dinterval: dim  dim             {
1437                 $$ = new Interval ($1, $2);
1438         }
1439         ;
1440
1441 %%
1442
1443 void
1444 My_lily_parser::set_yydebug (bool b)
1445 {
1446 #ifdef YYDEBUG
1447         yydebug = b;
1448 #endif
1449 }
1450 void
1451 My_lily_parser::do_yyparse ()
1452 {
1453         yyparse ((void*)this);
1454 }
1455