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