]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
release: 1.0.4
[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 <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.0");
48 Mudela_version version ("1.0.0");
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 ACCIDENTALS
141 %token ALIAS
142 %token BAR
143 %token BEAMPLET
144 %token MAEBTELP
145 %token PENALTY
146 %token CADENZA
147 %token CLEAR
148 %token CLEF
149 %token CONTAINS
150 %token RELATIVE
151 %token CONSISTS
152 %token ACCEPTS
153 %token CM_T
154 %token DURATION
155 %token ABSDYNAMIC
156 %token END
157 %token GROUPING
158 %token TRANSLATOR
159 %token HEADER
160 %token IN_T
161 %token LYRIC
162 %token KEY
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         ;
503
504
505 /*
506         PAPER
507 */
508 paper_block:
509         PAPER '{' paper_body '}'        { 
510                 $$ = $3;
511                 THIS-> lexer_p_->scope_l_arr_.pop ();
512         }
513         ;
514
515 optional_semicolon:
516         /* empty */
517         | ';'
518         ;
519
520 paper_body:
521         /* empty */                     {
522                 Paper_def *p = THIS->default_paper_p ();
523                 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
524                 $$ = p;
525         }
526         | PAPER_IDENTIFIER optional_semicolon   {
527                 Paper_def *p = $1->access_Paper_def ();
528                 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
529                 $$ = p;
530         }
531         | paper_body OUTPUT STRING ';'  { 
532                 $$->outfile_str_ = *$3;
533                 delete $3;
534         }
535         | paper_body int '=' symtables          { // ugh, what a syntax
536                 $$->set_lookup ($2, $4);
537         }
538         | paper_body STRING '=' simple_identifier_init optional_semicolon {
539             Identifier* id = $4;
540             id->init_b_ = THIS->init_parse_b_;
541             if (id->is_type_b (Translator_identifier::static_name ()))
542               {
543                 $$->assign_translator (*$2, id->access_Translator ());
544                 delete id;
545               }
546             else
547               THIS->lexer_p_->set_identifier (*$2, id);
548               delete $2;
549         }
550         | paper_body SHAPE '=' shape_array ';' {
551                 $$->shape_int_a_ = *$4;
552                 delete $4;
553         }
554         | paper_body error {
555
556         }
557         ;
558
559 real_primary:
560         REAL            {
561                 $$ = $1;
562         }
563         | REAL_IDENTIFIER               {
564                 Real *r_p = $1->access_Real ();
565                 $$ = * r_p;
566                 DOUT << "Lookup real: " << *r_p << "\n";
567                 delete r_p;
568         }
569         | dim
570         | '(' real ')' {
571                 $$ = $2;
572         }
573         ;
574
575 real:
576         real_mult_expression
577         | real '+' real_mult_expression {
578                 $$ = $1 + $3;
579         }
580         | real '-' real_mult_expression {
581                 $$ = $1 - $3;
582         }
583         ;
584
585 real_mult_expression:
586         real_primary
587         | real_mult_expression '*' real_primary {
588                 $$ = $1 * $3;
589         }
590         | real_mult_expression '/' real_primary {
591                 $$ = $1 / $3;
592         }
593         ;
594
595 shape_array:
596         /* empty */ {
597                 $$ = new Array<Interval>;
598         }
599         | shape_array dim dim {
600                 $$->push(Interval($2, $2 + $3));
601         };
602
603 /*
604         MIDI
605 */
606 midi_block:
607         MIDI
608
609         '{' midi_body '}'       { $$ = $3; }
610         ;
611
612 midi_body: /* empty */          {
613                 $$ = THIS->default_midi_p ();
614         }
615         | midi_body STRING '=' translator_spec  {
616                 $$-> assign_translator (*$2, $4);
617                 delete $2;
618         }
619         | midi_body OUTPUT STRING ';'   {
620                 $$->outfile_str_ = *$3;
621                 delete $3;
622         }
623         | midi_body tempo_request ';' {
624                 $$->set_tempo ($2->dur_.length (), $2->metronome_i_);
625                 delete $2;
626         }
627         | midi_body error {
628
629         }
630         ;
631
632 tempo_request:
633         TEMPO entered_notemode_duration '=' unsigned    {
634                 $$ = new Tempo_req;
635                 $$->dur_ = *$2;
636                 delete $2;
637                 $$-> metronome_i_ = $4;
638         }
639         ;
640
641 Voice:
642         '{' Voice_body '}'      {
643                 $$ = $2;
644         }
645         ;
646
647 Voice_body:
648         /**/            {
649                 $$ = new Voice;
650                 $$->set_spot (THIS->here_input ());
651         }
652         | Voice_body Music      {
653                 $$->add ($2);
654         }
655         | Voice_body error                      {
656                 $$ = new Music_list;
657         }
658         ;
659
660 Music:
661         request_chord           { $$ = $1; }
662         | TYPE STRING Music     {
663                 $$ = $3;
664                 $$->translator_type_str_ = *$2;
665                 delete $2;
666         }
667         | TYPE STRING '=' STRING Music {
668                 $$ = $5;
669                 $$->translator_type_str_ = *$2;
670                 $$->translator_id_str_ = *$4;
671                 delete $2;
672                 delete $4;
673         }
674         | Voice         { $$ = $1; }
675         | Chord                 { $$ = $1; }
676         | transposed_music      { $$ = $1; }
677         | MUSIC_IDENTIFIER { $$ = $1->access_Music (); }
678         | MELODIC
679                 { THIS->lexer_p_->push_note_state (); }
680         Music
681                 { $$ = $3;
682                   THIS->lexer_p_->pop_state ();
683                 }
684
685         | LYRIC
686                 { THIS->lexer_p_->push_lyric_state (); }
687         Music
688                 {
689                   $$ = $3;
690                   THIS->lexer_p_->pop_state ();
691                 }
692         | property_def
693         | translator_change
694         | relative_music        { $$ = $1; }
695         ;
696
697 relative_music:
698         RELATIVE absolute_musical_pitch Music {
699                 $$ = new Relative_octave_music ($3, *$2);
700                 delete $2;
701         }
702         ;
703
704 translator_change:
705         TRANSLATOR STRING '=' STRING  {
706                 Change_translator * t = new Change_translator;
707                 t-> change_to_type_str_ = *$2;
708                 t-> change_to_id_str_ = *$4;
709
710                 $$ = t;
711                 $$->set_spot (THIS->here_input ());
712                 delete $2;
713                 delete $4;
714         }
715         ;
716
717 property_def:
718         PROPERTY STRING '.' STRING '=' scalar   {
719                 Translation_property *t = new Translation_property;
720                 t-> translator_type_str_ = *$2;
721                 t-> var_str_ = *$4;
722                 t-> value_ = *$6;
723                 $$ = t;
724                 $$->set_spot (THIS->here_input ());
725                 delete $2;
726                 delete $4;
727                 delete $6;
728         }
729         ;
730
731 scalar:
732         STRING          { $$ = new Scalar (*$1); delete $1; }
733         | int           { $$ = new Scalar ($1); }
734         ;
735
736
737 Chord:
738         '<' Chord_body '>'      { $$  = $2; }
739         ;
740
741 Chord_body:
742         /**/    {
743                 $$ = new Chord;
744                 $$-> multi_level_i_ = 0;
745                 $$->set_spot (THIS->here_input ());
746         }
747         | Chord_body Music {
748                 $$->add ($2);
749         }
750         | Chord_body error {
751                 $$ = new Chord;
752         }
753         ;
754
755 transposed_music:
756         TRANSPOSE musical_pitch Music {
757                 $$ = $3;
758                 $$ -> transpose (*$2);
759                 delete $2;
760         }
761         ;
762
763
764 /*
765         VOICE ELEMENTS
766 */
767 request_chord:
768         pre_requests simple_element post_requests       {
769                 THIS->add_requests ((Chord*)$2);//ugh
770                 $$ = $2;
771         }
772         | command_element
773         ;
774
775
776
777
778 command_element:
779         command_req {
780                 $$ = new Request_chord;
781                 $$-> set_spot (THIS->here_input ());
782                 $1-> set_spot (THIS->here_input ());
783                 ((Chord*)$$) ->add ($1);//ugh
784
785         }
786         ;
787
788 command_req:
789         abbrev_command_req
790         | verbose_command_req ';'       { $$ = $1; }
791         ;
792
793 abbrev_command_req:
794         '|'                             {
795                 $$ = new Barcheck_req;
796         }
797         | COMMAND_IDENTIFIER    {
798                 $$ = $1->access_Request ();
799         }
800         ;
801
802 verbose_command_req:
803         BAR STRING                      {
804                 $$ = new Bar_req (*$2);
805                 delete $2;
806         }
807         | MARK STRING {
808                 $$ = new Mark_req (*$2);
809                 delete $2;
810         }
811         | MARK unsigned {
812                 $$ = new Mark_req (to_str ($2));
813         }
814         | TIME_T unsigned '/' unsigned  {
815                 Time_signature_change_req *m = new Time_signature_change_req;
816                 m->beats_i_ = $2;
817                 m->one_beat_i_=$4;
818                 $$ = m;
819         }
820         | PENALTY '=' int       {
821                 Break_req * b = new Break_req;
822                 b->penalty_i_ = $3;
823                 b-> set_spot (THIS->here_input ());
824                 $$ = b;
825         }
826         | SKIP duration_length {
827                 Skip_req * skip_p = new Skip_req;
828                 skip_p->duration_ = *$2;
829                 delete $2;
830                 $$ = skip_p;
831         }
832         | tempo_request {
833                 $$ = $1;
834         }
835         | CADENZA unsigned      {
836                 $$ = new Cadenza_req ($2);
837         }
838         | PARTIAL duration_length       {
839                 $$ = new Partial_measure_req ($2->length ());
840                 delete $2;
841         }
842         | CLEF STRING {
843                 $$ = new Clef_change_req (*$2);
844                 delete $2;
845         }
846         | KEY NOTENAME_PITCH    {
847                 Key_change_req *key_p= new Key_change_req;
848                 key_p->pitch_arr_.push(*$2);
849                 key_p->ordinary_key_b_ = true;
850                 $$ = key_p;
851                 delete $2;
852         }
853         | ACCIDENTALS pitch_list        {
854                 Key_change_req *key_p= new Key_change_req;
855                 key_p->pitch_arr_ = *$2;
856                 key_p->ordinary_key_b_ = false;
857                 $$ = key_p;
858                 delete $2;
859         }
860         | GROUPING intastint_list {
861                 $$ = get_grouping_req (*$2); delete $2;
862         }
863         ;
864
865 post_requests:
866         {
867                 /* something silly happened.  Junk this stuff*/
868                 if (!THIS->post_reqs.empty ())
869                 {
870                         warning ("Junking post-requests");
871                         THIS->post_reqs.clear ();
872                 }
873         }
874         | post_requests structured_post_request {
875                 $2->set_spot (THIS->here_input ());
876                 THIS->post_reqs.push ($2);
877         }
878         | post_requests close_request_parens    {
879                 Array<Request*>& r = *THIS->get_parens_request ($2);
880                 for (int i = 0; i < r.size (); i++ )
881                         r[i]->set_spot (THIS->here_input ());
882                 THIS->post_reqs.concat (r);
883                 delete &r;
884         }
885         ;
886
887 structured_post_request:
888         script_req
889         | post_request
890         ;
891
892 post_request:
893         POST_REQUEST_IDENTIFIER {
894                 $$ = (Request*)$1->access_Request ();
895         }
896         | dynamic_req {
897                 $$ = $1;
898         }
899         | abbrev_type   {
900 #if 1 // re-instating
901                 Abbreviation_req* a = new Abbreviation_req;
902                 a->type_i_ = $1;
903                 $$ = a;
904 #else // and disabling just created ugly sticky abbrev_req
905                 THIS->default_abbrev_i_ = $1;
906 #endif
907         }
908         ;
909
910 sup_quotes:
911         '\'' {
912                 $$ = 1;
913         }
914         | sup_quotes '\'' {
915                 $$ ++;
916         }
917         ;
918 sub_quotes:
919         ',' {
920                 $$ = 1;
921         }
922         | sub_quotes ',' {
923                 $$ ++ ;
924         }
925         ;
926
927 steno_musical_pitch:
928         NOTENAME_PITCH  {
929                 $$ = $1;
930                 // $$->octave_i_ += THIS->default_octave_i_;
931         }
932         | NOTENAME_PITCH sup_quotes     {
933                 $$ = $1;
934                 // $$->octave_i_ += THIS->default_octave_i_ + $2;
935                 $$->octave_i_ +=  $2;
936         }
937         | NOTENAME_PITCH sub_quotes      {
938                 $$ = $1;
939                 $$->octave_i_ += - $2;
940                 // $$->octave_i_ += THIS->default_octave_i_ - $2;
941         }
942         ;
943
944 explicit_musical_pitch:
945         MUSICAL_PITCH '{' int int int '}'       {/* ugh */
946                 $$ = new Musical_pitch;
947                 $$->octave_i_ = $3;
948                 $$->notename_i_ = $4;
949                 $$->accidental_i_ = $5;
950         }
951         ;
952 musical_pitch:
953         steno_musical_pitch
954         | explicit_musical_pitch
955         ;
956
957 steno_notepitch:
958         musical_pitch   {
959                 $$ = new Note_req;
960                 
961                 $$->pitch_ = *$1;
962                 delete $1;
963         }
964         | steno_notepitch  '!'          {
965                 $$->forceacc_b_ = ! $$->forceacc_b_;
966         }
967         ;
968
969
970 explicit_duration:
971         DURATION '{' int unsigned '}'   {
972                 $$ = new Duration;
973                 $$-> durlog_i_ = $3;
974                 $$-> dots_i_ = $4;
975         }
976         ;
977
978 dynamic_req:
979         ABSDYNAMIC '{' unsigned '}'     {
980                 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
981                 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
982                 $$ =ad_p;
983         }
984         | SPANDYNAMIC '{' int int '}' {
985                 Span_dynamic_req * sp_p = new Span_dynamic_req;
986                 sp_p->spantype = (Span_req::Spantype)$4;
987                 sp_p-> dynamic_dir_  = (Direction)$3;
988                 $$ = sp_p;
989         }
990         ;
991
992 plet_fraction:
993         unsigned '/' unsigned {
994                 $$[0] = $1;
995                 $$[1] = $3;
996         }
997         |
998         '/' unsigned {
999                 int num = $2 >? 1;
1000                 $$[0] = guess_plet_a[(num <? GUESS_PLET) - 1];
1001                 $$[1] = num;
1002         }
1003         ;
1004
1005 close_plet_parens:
1006         ']' plet_fraction {
1007                 $$ = MAEBTELP;
1008                 THIS->plet_.type_i_ = $2[1];
1009                 THIS->plet_.iso_i_ = $2[0];
1010                 THIS->default_duration_.plet_ = THIS->plet_;
1011         }
1012         | TELP {
1013                 $$ = TELP;
1014                 THIS->plet_.type_i_ = 1;
1015                 THIS->plet_.iso_i_ = 1;
1016                 THIS->default_duration_.plet_ = THIS->plet_;
1017         }
1018         | TELP plet_fraction {
1019                 $$ = TELP;
1020                 THIS->plet_.type_i_ = $2[1];
1021                 THIS->plet_.iso_i_ = $2[0];
1022                 THIS->default_duration_.plet_ = THIS->plet_;
1023         }
1024         ;
1025
1026 close_request_parens:
1027         '~'     {
1028                 $$ = '~';
1029         }
1030         | '('   {
1031                 $$='(';
1032         }
1033         | ']'   {
1034                 $$ = ']';
1035         }
1036         | E_SMALLER {
1037                 $$ = '<';
1038         }
1039         | E_BIGGER {
1040                 $$ = '>';
1041         }
1042         | close_plet_parens
1043         ;
1044
1045 open_abbrev_parens:
1046         '[' ':' unsigned {
1047                 $$ = '[';
1048                 if (!Duration::duration_type_b ($3))
1049                         THIS->parser_error (_f ("not a duration: %d", $3));
1050                 else if ($3 < 8)
1051                         THIS->parser_error (_ ("can't abbreviate"));
1052                 else
1053                         THIS->set_abbrev_beam ($3);
1054         }
1055         ;
1056
1057 open_plet_parens:
1058         '[' plet_fraction {
1059                 $$ = BEAMPLET;
1060                 THIS->plet_.type_i_ = $2[1];
1061                 THIS->plet_.iso_i_ = $2[0];
1062                 THIS->default_duration_.plet_ = THIS->plet_;
1063         }
1064         | PLET plet_fraction {
1065                 $$ = PLET;
1066                 THIS->plet_.type_i_ = $2[1];
1067                 THIS->plet_.iso_i_ = $2[0];
1068                 THIS->default_duration_.plet_ = THIS->plet_;
1069         }
1070         ;
1071
1072 open_request_parens:
1073         E_EXCLAMATION   {
1074                 $$ = '!';
1075         }
1076         | ')'   {
1077                 $$=')';
1078         }
1079         | '['   {
1080                 $$='[';
1081         }
1082         | open_abbrev_parens
1083         | open_plet_parens
1084         ;
1085
1086
1087
1088 script_definition:
1089         SCRIPT '{' script_body '}'      { $$ = $3; }
1090         ;
1091
1092 script_body:
1093         STRING int int int int int              {
1094                 Script_def *s = new Script_def;
1095                 s->set_from_input (*$1,$2, $3,$4,$5, $6);
1096                 $$  = s;
1097                 delete $1;
1098         }
1099         ;
1100
1101 script_req:
1102         script_dir gen_script_def       {
1103                 Musical_script_req *m = new Musical_script_req;
1104                 $$ = m;
1105                 m->scriptdef_p_ = $2;
1106                 m->set_spot (THIS->here_input ());
1107                 if (!m->dir_)
1108                   m->dir_  = (Direction)$1;
1109         }
1110         ;
1111
1112 gen_script_def:
1113         text_def        { 
1114                 $$ = $1;
1115                 ((Text_def*) $$)->align_dir_ = LEFT; /* UGH */
1116         }
1117         | mudela_script { 
1118                 $$ = $1;
1119                 $$-> set_spot (THIS->here_input ());
1120         }
1121         | finger {
1122                 $$ = $1;
1123                 ((Text_def*)$$)->align_dir_ = RIGHT; /* UGH */
1124         }
1125         ;
1126
1127 text_def:
1128         STRING {
1129                 Text_def *t  = new Text_def;
1130                 $$ = t;
1131                 t->text_str_ = *$1;
1132                 delete $1;
1133                 $$->set_spot (THIS->here_input ());
1134         }
1135         ;
1136
1137 finger:
1138          DIGIT {
1139                 Text_def* t  = new Text_def;
1140                 $$ = t;
1141                 t->text_str_ = to_str ($1);
1142                 t->style_str_ = "finger";
1143                 $$->set_spot (THIS->here_input ());
1144         }
1145         ;
1146
1147 script_abbreviation:
1148         '^'             { $$ = get_scriptdef ('^'); }
1149         | '+'           { $$ = get_scriptdef ('+'); }
1150         | '-'           { $$ = get_scriptdef ('-'); }
1151         | '|'           { $$ = get_scriptdef ('|'); }
1152         | 'o'           { $$ = get_scriptdef ('o'); }
1153         | '>'           { $$ = get_scriptdef ('>'); }
1154         | '.'           {
1155                 $$ = get_scriptdef ('.');
1156         }
1157         ;
1158
1159 mudela_script:
1160         SCRIPT_IDENTIFIER               { $$ = $1->access_General_script_def (true); }
1161         | script_definition             { $$ = $1; }
1162         | script_abbreviation           {
1163                 $$ = THIS->lexer_p_->lookup_identifier (*$1)->access_General_script_def (true);
1164                 delete $1;
1165         }
1166         ;
1167
1168 script_dir:
1169         '_'     { $$ = -1; }
1170         | '^'   { $$ = 1; }
1171         | '-'   { $$ = 0; }
1172         ;
1173
1174 pre_requests:
1175         {
1176         }
1177         | pre_requests open_request_parens {
1178                 Array<Request*>& r = *THIS->get_parens_request ($2);
1179                 for (int i = 0; i < r.size (); i++ )
1180                         r[i]->set_spot (THIS->here_input ());
1181                 THIS->pre_reqs.concat (r);
1182                 delete &r;
1183         }
1184         ;
1185
1186 absolute_musical_pitch:
1187         steno_musical_pitch     {
1188                 $$ = $1;
1189                 // $$->octave_i_ -=  THIS->default_octave_i_;
1190         }
1191         ;
1192
1193 duration_length:
1194         steno_duration {
1195                 $$ = $1;
1196         }
1197         ;
1198
1199 dots:
1200         '.'             { $$ = 1; }
1201         | dots '.'      { $$ ++; }
1202         ;
1203
1204 entered_notemode_duration:
1205         /* */           {
1206                 $$ = new Duration (THIS->default_duration_);
1207         }
1208         | dots          {
1209                 $$ = new Duration (THIS->default_duration_);
1210                 $$->dots_i_  = $1;
1211         }
1212         | steno_duration        {
1213                 THIS->set_last_duration ($1);
1214         }
1215         ;
1216
1217 notemode_duration:
1218         entered_notemode_duration {
1219                 $$ = $1;
1220         }
1221         ;
1222
1223 steno_duration:
1224         unsigned                {
1225                 $$ = new Duration;
1226                 if (!Duration::duration_type_b ($1))
1227                         THIS->parser_error (_f ("not a duration: %d", $1));
1228                 else {
1229                         $$->durlog_i_ = Duration_convert::i2_type ($1);
1230                         $$->set_plet (THIS->plet_.iso_i_, THIS->plet_.type_i_);
1231                      }
1232         }
1233         | DURATION_IDENTIFIER   {
1234                 $$ = $1->access_Duration ();
1235         }
1236         | steno_duration '.'    {
1237                 $$->dots_i_ ++;
1238         }
1239         | steno_duration '*' unsigned  {
1240                 $$->plet_.iso_i_ *= $3;
1241         }
1242         | steno_duration '/' unsigned {
1243                 $$->plet_.type_i_ *= $3;
1244         }
1245         ;
1246
1247
1248 abbrev_type: 
1249         ':'     {
1250                 $$ =0;
1251         }
1252         | ':' unsigned {
1253                 if (!Duration::duration_type_b ($2))
1254                         THIS->parser_error (_f ("not a duration: %d", $2));
1255                 else if ($2 < 8)
1256                         THIS->parser_error (_ ("can't abbreviate"));
1257                 $$ = $2;
1258         }
1259         ;
1260
1261
1262
1263 simple_element:
1264         steno_notepitch notemode_duration  {
1265                 if (!THIS->lexer_p_->note_state_b ())
1266                         THIS->parser_error (_ ("have to be in Note mode for notes"));
1267                 $1->set_duration (*$2);
1268                 int durlog_i = $2->durlog_i_;
1269                 $$ = THIS->get_note_element ($1, $2);
1270         }
1271         | RESTNAME notemode_duration            {
1272                 $$ = THIS->get_rest_element (*$1, $2);
1273                 delete $1;  // delete notename
1274         }
1275         | MEASURES notemode_duration    {
1276                 Multi_measure_rest_req* m = new Multi_measure_rest_req;
1277                 m->duration_ = *$2;
1278                 delete $2;
1279
1280                 Chord*velt_p = new Request_chord;
1281                 velt_p->set_spot (THIS->here_input ());
1282                 velt_p->add (m);
1283                 $$ = velt_p;
1284
1285         }
1286         | STRING notemode_duration                      {
1287                 if (!THIS->lexer_p_->lyric_state_b ())
1288                         THIS->parser_error (_ ("have to be in Lyric mode for lyrics"));
1289                 $$ = THIS->get_word_element (*$1, $2);
1290                 delete $1;
1291         }
1292         ;
1293
1294
1295 /*
1296         UTILITIES
1297  */
1298 pitch_list:                     {
1299                 $$ = new Array<Musical_pitch>;
1300         }
1301         | pitch_list musical_pitch      {
1302                 $$->push (*$2);
1303                 delete $2;
1304         }
1305         ;
1306
1307 unsigned:
1308         UNSIGNED        {
1309                 $$ = $1;
1310         }
1311         | DIGIT {
1312                 $$ = $1;
1313         };
1314
1315 int:
1316         unsigned {
1317                 $$ = $1;
1318         }
1319         | '-' unsigned {
1320                 $$ = -$2;
1321         }
1322         | INT_IDENTIFIER        {
1323                 int *i_p = $1->access_int ();
1324                 $$ = *i_p;
1325                 delete i_p;
1326         }
1327         ;
1328
1329 string_primary:
1330         STRING          {
1331                 $$ = $1;
1332         }
1333         | STRING_IDENTIFIER     {
1334                 String *s_p = $1->access_String ();
1335
1336                 $$ = s_p;
1337                 DOUT << "Lookup string: " << *s_p << "\n";
1338         }
1339         ;
1340
1341 string:
1342         string_primary {
1343                 $$ = $1;
1344         }
1345         | string '+' string_primary {
1346                 *$$ += *$3;
1347                 delete $3;
1348         }
1349         ;
1350
1351 dim:
1352         real_primary unit       { $$ = $1*$2; }
1353         ;
1354
1355
1356 unit:   CM_T            { $$ = 1 CM; }
1357         |IN_T           { $$ = 1 INCH; }
1358         |MM_T           { $$ = 1 MM; }
1359         |PT_T           { $$ = 1 PT; }
1360         ;
1361
1362 /*
1363         symbol tables
1364 */
1365 symtables:
1366         SYMBOLTABLES '{' symtables_body '}'     { $$ = $3; }
1367         ;
1368
1369 symtables_body:
1370                         {
1371                 $$ = new Lookup;
1372         }
1373         | IDENTIFIER            {
1374                 $$ = $1->access_Lookup ();
1375         }
1376         | symtables_body FONT STRING            {
1377                 $$->font_ = *$3;
1378                 $$->font_path_ = global_path.find (*$3);
1379                 if  (!$$->font_path_.length_i ())
1380                         THIS->here_input ().error (_f("can't open file: `%s'", $3->ch_C()));
1381
1382                 delete $3;
1383         }
1384         | symtables_body STRING '=' symtable            {
1385                 $$->add (*$2, $4);
1386                 delete $2;
1387         }
1388         ;
1389
1390 symtable:
1391         TABLE '{' symtable_body '}' { $$ = $3; }
1392         ;
1393
1394 symtable_body:
1395                                 { $$ = new Symtable; }
1396         | symtable_body STRING  symboldef {
1397                 $$->add (*$2, *$3);
1398                 delete $2;
1399                 delete $3;
1400         }
1401         ;
1402
1403 symboldef:
1404         STRING  box             {
1405                 $$ = new Atom (*$1, *$2);
1406                 delete $1;
1407                 delete $2;
1408         }
1409         | STRING {
1410                 Box b (Interval (0,0), Interval (0,0));
1411                 $$ = new Atom (*$1, b);
1412                 delete $1;
1413         }
1414         ;
1415
1416 box:
1417         dinterval dinterval     {
1418                 $$ = new Box (*$1, *$2);
1419                 delete $1;
1420                 delete $2;
1421         }
1422         ;
1423
1424 dinterval: dim  dim             {
1425                 $$ = new Interval ($1, $2);
1426         }
1427         ;
1428
1429 %%
1430
1431 void
1432 My_lily_parser::set_yydebug (bool b)
1433 {
1434 #ifdef YYDEBUG
1435         yydebug = b;
1436 #endif
1437 }
1438 void
1439 My_lily_parser::do_yyparse ()
1440 {
1441         yyparse ((void*)this);
1442 }
1443