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