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