]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
f6e9764a17d55a379bb222255a4b3b9e3329da54
[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 "dimensions.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     Musical_req* musreq;
99     Music_output_def * outputdef;
100     Musical_pitch * pitch;
101     Midi_def* midi;
102     Moment *moment;
103     Note_req *notereq;
104     Notename_table *notenametab;
105     Paper_def *paper;
106     Real real;
107     Request * request;
108     General_script_def * script;
109     Scalar *scalar;
110     String *string;
111     Atom * symbol;
112     Symtable * symtable;
113     Symtables* symtables;
114     Text_def * textdef;
115     Tempo_req *tempo;
116     char c;
117     const char *consstr;
118     int i;
119     int pair[2];
120     int ii[10];
121 }
122 %{
123
124 int
125 yylex (YYSTYPE *s,  void * v_l)
126 {
127         My_lily_parser   *pars_l = (My_lily_parser*) v_l;
128         My_lily_lexer * lex_l = pars_l->lexer_p_;
129
130         lex_l->lexval_l = (void*) s;
131         return lex_l->yylex ();
132 }
133
134
135 %}
136
137 %pure_parser
138
139 /* tokens which are not keywords */
140
141 %token ABSDYNAMIC
142 %token ACCEPTS
143 %token BAR
144 %token BEAMPLET
145 %token CADENZA
146 %token CLEF
147 %token CM_T
148 %token CONSISTS
149 %token DURATION
150 %token END
151 %token FONT
152 %token GROUPING
153 %token HEADER
154 %token IN_T
155 %token KEY
156 %token KEYSIGNATURE
157 %token LYRIC
158 %token MAEBTELP
159 %token MARK
160 %token MEASURES
161 %token MIDI
162 %token MM_T
163 %token MUSIC
164 %token MUSICAL_PITCH
165 %token NAME
166 %token NOTENAMES
167 %token NOTES
168 %token OCTAVE
169 %token OUTPUT
170 %token PAPER
171 %token PARTIAL
172 %token PENALTY
173 %token PLET
174 %token PROPERTY
175 %token PT_T
176 %token RELATIVE
177 %token REMOVE
178 %token SCORE
179 %token SCRIPT
180 %token SHAPE
181 %token SKIP
182 %token SPANDYNAMIC
183 %token SYMBOLTABLES
184 %token TABLE
185 %token TELP
186 %token TEMPO
187 %token TIME_T
188 %token TRANSLATOR
189 %token TRANSPOSE
190 %token TYPE
191 %token VERSION
192
193 /* escaped */
194 %token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
195
196 %type <i>       dots
197 %token <i>      DIGIT
198 %token <pitch>  NOTENAME_PITCH
199 %token <id>     DURATION_IDENTIFIER
200 %token <id>     IDENTIFIER
201 %token <id>     NOTENAME_TABLE_IDENTIFIER
202 %token <id>     MUSIC_IDENTIFIER
203 %token <id>     POST_REQUEST_IDENTIFIER
204 %token <id>     SCRIPT_IDENTIFIER
205 %token <id>     COMMAND_IDENTIFIER
206 %token <id>     REAL_IDENTIFIER
207 %token <id>     STRING_IDENTIFIER
208 %token <id>     TRANS_IDENTIFIER
209 %token <id>     INT_IDENTIFIER
210 %token <id>     SCORE_IDENTIFIER
211 %token <id>     MIDI_IDENTIFIER
212 %token <id>     PAPER_IDENTIFIER
213 %token <id>     REQUEST_IDENTIFIER
214 %token <real>   REAL
215 %token <string> DURATION RESTNAME
216 %token <string> STRING
217 %token <i>      UNSIGNED
218
219
220 %type <outputdef> output_def
221 %type <header>  mudela_header mudela_header_body
222 %type <box>     box
223 %type <i>       open_request_parens close_request_parens
224 %type <i>       open_abbrev_parens
225 %type <i>       open_plet_parens close_plet_parens
226 %type <i>       sub_quotes sup_quotes
227 %type <music>   simple_element  request_chord command_element
228 %type <i>       abbrev_type
229 %type <i>       int unsigned
230 %type <i>       script_dir
231 %type <id>      identifier_init simple_identifier_init
232 %type <duration> steno_duration notemode_duration
233 %type <duration> entered_notemode_duration explicit_duration
234 %type <interval>        dinterval
235 %type <intvec>  intastint_list int_list
236 %type <symtables>       symtables symtables_body
237
238 %type <pitch>   explicit_musical_pitch steno_musical_pitch musical_pitch absolute_musical_pitch
239 %type <notereq> steno_notepitch
240 %type <pitch_arr>       pitch_list
241 %type <midi>    midi_block midi_body
242 %type <duration>        duration_length
243
244 %type <scalar>  scalar
245 %type <music>   Music  relative_music Sequential_music Simultaneous_music
246 %type <music>   property_def translator_change
247 %type <music_list> Music_list
248 %type <paper>   paper_block paper_def_body
249 %type <real>    dim real
250 %type <real>    real_mult_expression real_primary
251 %type <real>    unit
252 %type <request> abbrev_command_req
253 %type <request> post_request structured_post_request
254 %type <pair>    plet_fraction
255 %type <request> command_req verbose_command_req
256 %type <request> script_req  dynamic_req
257 %type <string>  string
258 %type <string>  string_primary
259 %type <score>   score_block score_body
260 %type <intarr>  shape_array
261 %type <script>  script_definition script_body mudela_script gen_script_def
262 %type <textdef> text_def finger
263 %type <string>  script_abbreviation
264 %type <symbol>  symboldef
265 %type <symtable>        symtable symtable_body
266 %type <trans>   translator_spec translator_spec_body
267 %type <tempo>   tempo_request
268 %type <notenametab> notenames_body notenames_block
269 %expect 1
270
271
272 %%
273
274 mudela: /* empty */
275         | mudela toplevel_expression {}
276         | mudela add_declaration { }
277         | mudela error
278         | mudela check_version { }
279         ;
280
281 toplevel_expression:
282         notenames_block                 {
283                 THIS->lexer_p_->set_notename_table ($1);
284         }
285         | mudela_header {
286                 delete header_global_p;
287                 header_global_p = $1;
288         }
289         | score_block {
290                 score_global_array.push ($1);
291         }
292         | paper_block {
293                 Identifier * id = new
294                         Paper_def_identifier ($1, PAPER_IDENTIFIER);
295                 THIS->lexer_p_->set_identifier ("$defaultpaper", id)
296         }
297         | midi_block {
298                 Identifier * id = new
299                         Midi_def_identifier ($1, MIDI_IDENTIFIER);
300                 THIS->lexer_p_->set_identifier ("$defaultmidi", id)
301         }
302         ;
303
304 check_version:
305         VERSION STRING ';'              {
306                 Mudela_version ver (*$2);
307                 if (!((ver >= oldest_version) && (ver <= version))) {
308                         if (THIS->ignore_version_b_) {
309                                 THIS->here_input ().error (_f ("incorrect mudela version: %s (%s, %s)", ver.str (), oldest_version.str (), version.str ()));
310                         } else {
311                                 THIS->fatal_error_i_ = 1;
312                                 THIS->parser_error (_f ("incorrect mudela version: %s (%s, %s)", ver.str (), oldest_version.str (), version.str ()));
313                         }
314                 }
315         }
316         ;
317
318
319 notenames_block:
320         NOTENAMES '{' notenames_body '}'  {  $$ = $3; }
321         ;
322
323
324
325 notenames_body:
326         /**/    {
327                 $$ = new Notename_table;
328         }
329         | NOTENAME_TABLE_IDENTIFIER     {
330                 $$ = $1-> access_Notename_table(true);
331         }
332         | notenames_body STRING '=' explicit_musical_pitch {
333                 (*$$)[*$2] = *$4;
334
335                 delete $4;
336                 delete $2;
337         }
338         ;
339
340 mudela_header_body:
341                 {
342                 $$ = new Header;
343         }
344         | mudela_header_body STRING '=' string ';' {
345                 (*$$)[*$2] = *$4;
346                 delete $2;
347                 delete $4;
348         }
349         ;
350
351 mudela_header:
352         HEADER '{' mudela_header_body '}'       {
353                 $$ = $3;
354         }
355         ;
356
357
358 /*
359         DECLARATIONS
360 */
361 add_declaration:
362         STRING {
363                 THIS->remember_spot ();
364         }
365         /* cont */ '=' identifier_init optional_semicolon {
366             THIS->lexer_p_->set_identifier (*$1, $4);
367             $4->init_b_ = THIS->init_parse_b_;
368             $4->set_spot (THIS->pop_spot ());
369         }
370         ;
371
372
373 simple_identifier_init: identifier_init
374         ;
375 identifier_init:
376         score_block {
377                 $$ = new Score_identifier ($1, SCORE_IDENTIFIER);
378
379         }
380         | notenames_block {
381                 $$ = new Notename_table_identifier ($1, NOTENAME_TABLE_IDENTIFIER);
382         }
383         | paper_block {
384                 $$ = new Paper_def_identifier ($1, PAPER_IDENTIFIER);
385         }
386         | midi_block {
387                 $$ = new Midi_def_identifier ($1, MIDI_IDENTIFIER);
388
389         }
390         | script_definition {
391                 $$ = new General_script_def_identifier ($1, SCRIPT_IDENTIFIER);
392
393         }
394         | Music  {
395                 $$ = new Music_identifier ($1, MUSIC_IDENTIFIER);
396
397         }
398         | symtables {
399                 $$ = new Symtables_identifier ($1, IDENTIFIER);
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 NAME STRING ';' {
460                 $$->type_str_ = *$3;
461                 delete $3;
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                 Lookup * l = THIS->default_paper_p ()->lookup_p (*$4);
566                 $$->set_lookup ($2, l);
567         }
568         | paper_def_body STRING '=' simple_identifier_init ';' {
569               THIS->lexer_p_->set_identifier (*$2, $4);
570               delete $2;
571         }
572         | paper_def_body translator_spec {
573                 $$-> assign_translator ($2);
574         }
575         | paper_def_body SHAPE '=' shape_array ';' {
576                 $$->shape_int_a_ = *$4;
577                 delete $4;
578         }
579         | paper_def_body error {
580
581         }
582         ;
583
584 real_primary:
585         REAL            {
586                 $$ = $1;
587         }
588         | REAL_IDENTIFIER               {
589                 $$= *$1->access_Real (false);
590         }
591         | dim
592         | '(' real ')' {
593                 $$ = $2;
594         }
595         ;
596
597 real:
598         real_mult_expression
599         | real '+' real_mult_expression {
600                 $$ = $1 + $3;
601         }
602         | real '-' real_mult_expression {
603                 $$ = $1 - $3;
604         }
605         ;
606
607 real_mult_expression:
608         real_primary
609         | real_mult_expression '*' real_primary {
610                 $$ = $1 * $3;
611         }
612         | real_mult_expression '/' real_primary {
613                 $$ = $1 / $3;
614         }
615         ;
616
617 shape_array:
618         /* empty */ {
619                 $$ = new Array<Interval>;
620         }
621         | shape_array dim dim {
622                 $$->push(Interval($2, $2 + $3));
623         };
624
625 /*
626         MIDI
627 */
628 midi_block:
629         MIDI
630
631         '{' midi_body '}'       { $$ = $3; }
632         ;
633
634 midi_body: /* empty */          {
635                 $$ = THIS->default_midi_p ();
636         }
637         | MIDI_IDENTIFIER       {
638                 $$ = $1-> access_Midi_def (true);
639         }
640         | midi_body translator_spec     {
641                 $$-> assign_translator ($2);
642         }
643         | midi_body tempo_request ';' {
644                 $$->set_tempo ($2->dur_.length (), $2->metronome_i_);
645                 delete $2;
646         }
647         | midi_body error {
648
649         }
650         ;
651
652 tempo_request:
653         TEMPO entered_notemode_duration '=' unsigned    {
654                 $$ = new Tempo_req;
655                 $$->dur_ = *$2;
656                 delete $2;
657                 $$-> metronome_i_ = $4;
658         }
659         ;
660
661 Music_list: /* empty */ {
662                 $$ = new Music_list;
663         }
664         | Music_list Music {
665                 $$->add_music ($2);
666         }
667         | Music_list error {
668         }
669         ;
670
671
672 Sequential_music: '{' Music_list '}'            {
673                 $$ = new Sequential_music ($2);
674         }
675         ;
676
677 Simultaneous_music: '<' Music_list '>'  {
678                 $$ = new Simultaneous_music ($2);
679         }
680         ;
681 Music:
682         request_chord           { $$ = $1; }
683         | TYPE STRING Music     {
684                 $$ = $3;
685                 $$->translator_type_str_ = *$2;
686                 delete $2;
687         }
688         | TYPE STRING '=' STRING Music {
689                 $$ = $5;
690                 $$->translator_type_str_ = *$2;
691                 $$->translator_id_str_ = *$4;
692                 delete $2;
693                 delete $4;
694         }
695         | Simultaneous_music            { $$ = $1; }
696         | Sequential_music              { $$ = $1; }
697         | TRANSPOSE musical_pitch Music {
698                 $$ = new Transposed_music ($3, *$2);
699                 delete $2;
700         }
701         | MUSIC_IDENTIFIER { $$ = $1->access_Music (true); }
702         | NOTES
703                 { THIS->lexer_p_->push_note_state (); }
704         Music
705                 { $$ = $3;
706                   THIS->lexer_p_->pop_state ();
707                 }
708
709         | LYRIC
710                 { THIS->lexer_p_->push_lyric_state (); }
711         Music
712                 {
713                   $$ = $3;
714                   THIS->lexer_p_->pop_state ();
715                 }
716         | property_def
717         | translator_change
718         | relative_music        { $$ = $1; }
719         ;
720
721 relative_music:
722         RELATIVE absolute_musical_pitch Music {
723                 $$ = new Relative_octave_music ($3, *$2);
724                 delete $2;
725         }
726         ;
727
728 translator_change:
729         TRANSLATOR STRING '=' STRING  {
730                 Change_translator * t = new Change_translator;
731                 t-> change_to_type_str_ = *$2;
732                 t-> change_to_id_str_ = *$4;
733
734                 $$ = t;
735                 $$->set_spot (THIS->here_input ());
736                 delete $2;
737                 delete $4;
738         }
739         ;
740
741 property_def:
742         PROPERTY STRING '.' STRING '=' scalar   {
743                 Translation_property *t = new Translation_property;
744                 t-> translator_type_str_ = *$2;
745                 t-> var_str_ = *$4;
746                 t-> value_ = *$6;
747                 $$ = t;
748                 $$->set_spot (THIS->here_input ());
749                 delete $2;
750                 delete $4;
751                 delete $6;
752         }
753         ;
754
755 scalar:
756         STRING          { $$ = new Scalar (*$1); delete $1; }
757         | int           { $$ = new Scalar ($1); }
758         ;
759
760
761
762 request_chord:
763         pre_requests simple_element post_requests       {
764                 THIS->add_requests ((Simultaneous_music*)$2);//ugh
765                 $$ = $2;
766         }
767         | command_element
768         ;
769
770
771
772
773 command_element:
774         command_req {
775                 $$ = new Request_chord;
776                 $$-> set_spot (THIS->here_input ());
777                 $1-> set_spot (THIS->here_input ());
778                 ((Simultaneous_music*)$$) ->add_music ($1);//ugh
779
780         }
781         ;
782
783 command_req:
784         abbrev_command_req
785         | verbose_command_req ';'       { $$ = $1; }
786         ;
787
788 abbrev_command_req:
789         '|'                             {
790                 $$ = new Barcheck_req;
791         }
792         | COMMAND_IDENTIFIER    {
793                 $$ = $1->access_Request (true);
794         }
795         ;
796
797 verbose_command_req:
798         BAR STRING                      {
799                 $$ = new Bar_req (*$2);
800                 delete $2;
801         }
802         | MARK STRING {
803                 $$ = new Mark_req (*$2);
804                 delete $2;
805         }
806         | MARK unsigned {
807                 $$ = new Mark_req (to_str ($2));
808         }
809         | TIME_T unsigned '/' unsigned  {
810                 Time_signature_change_req *m = new Time_signature_change_req;
811                 m->beats_i_ = $2;
812                 m->one_beat_i_=$4;
813                 $$ = m;
814         }
815         | PENALTY '=' int       {
816                 Break_req * b = new Break_req;
817                 b->penalty_i_ = $3;
818                 b-> set_spot (THIS->here_input ());
819                 $$ = b;
820         }
821         | SKIP duration_length {
822                 Skip_req * skip_p = new Skip_req;
823                 skip_p->duration_ = *$2;
824                 delete $2;
825                 $$ = skip_p;
826         }
827         | tempo_request {
828                 $$ = $1;
829         }
830         | CADENZA unsigned      {
831                 $$ = new Cadenza_req ($2);
832         }
833         | PARTIAL duration_length       {
834                 $$ = new Partial_measure_req ($2->length ());
835                 delete $2;
836         }
837         | CLEF STRING {
838                 $$ = new Clef_change_req (*$2);
839                 delete $2;
840         }
841         | KEY NOTENAME_PITCH    {
842                 Key_change_req *key_p= new Key_change_req;
843                 key_p->pitch_arr_.push(*$2);
844                 key_p->ordinary_key_b_ = true;
845                 $$ = key_p;
846                 delete $2;
847         }
848         | KEYSIGNATURE pitch_list       {
849                 Key_change_req *key_p= new Key_change_req;
850                 key_p->pitch_arr_ = *$2;
851                 key_p->ordinary_key_b_ = false;
852                 $$ = key_p;
853                 delete $2;
854         }
855         | GROUPING intastint_list {
856                 $$ = get_grouping_req (*$2); delete $2;
857         }
858         ;
859
860 post_requests:
861         {
862                 /* something silly happened.  Junk this stuff*/
863                 if (!THIS->post_reqs.empty ())
864                 {
865                         warning ("Junking post-requests");
866                         THIS->post_reqs.clear ();
867                 }
868         }
869         | post_requests structured_post_request {
870                 $2->set_spot (THIS->here_input ());
871                 THIS->post_reqs.push ($2);
872         }
873         | post_requests close_request_parens    {
874                 Array<Request*>& r = *THIS->get_parens_request ($2);
875                 for (int i = 0; i < r.size (); i++ )
876                         r[i]->set_spot (THIS->here_input ());
877                 THIS->post_reqs.concat (r);
878                 delete &r;
879         }
880         ;
881
882 structured_post_request:
883         script_req
884         | post_request
885         ;
886
887 post_request:
888         POST_REQUEST_IDENTIFIER {
889                 $$ = (Request*)$1->access_Request (true);
890         }
891         | dynamic_req {
892                 $$ = $1;
893         }
894         | abbrev_type   {
895                 Abbreviation_req* a = new Abbreviation_req;
896                 a->type_i_ = $1;
897                 $$ = a;
898         }
899         ;
900
901 sup_quotes:
902         '\'' {
903                 $$ = 1;
904         }
905         | sup_quotes '\'' {
906                 $$ ++;
907         }
908         ;
909 sub_quotes:
910         ',' {
911                 $$ = 1;
912         }
913         | sub_quotes ',' {
914                 $$ ++ ;
915         }
916         ;
917
918 steno_musical_pitch:
919         NOTENAME_PITCH  {
920                 $$ = $1;
921         }
922         | NOTENAME_PITCH sup_quotes     {
923                 $$ = $1;
924                 $$->octave_i_ +=  $2;
925         }
926         | NOTENAME_PITCH sub_quotes      {
927                 $$ = $1;
928                 $$->octave_i_ += - $2;
929         }
930         ;
931
932 explicit_musical_pitch:
933         MUSICAL_PITCH '{' int_list '}'  {/* ugh */
934                 Array<int> &a = *$3;
935                 ARRAY_SIZE(a,3);
936                 $$ = new Musical_pitch;
937                 $$->octave_i_ = a[0];
938                 $$->notename_i_ = a[1];
939                 $$->accidental_i_ = a[2];
940                 delete &a;
941         }
942         ;
943
944 musical_pitch:
945         steno_musical_pitch
946         | explicit_musical_pitch
947         ;
948
949 steno_notepitch:
950         musical_pitch   {
951                 $$ = new Note_req;
952                 
953                 $$->pitch_ = *$1;
954                 delete $1;
955         }
956         | steno_notepitch  '!'          {
957                 $$->forceacc_b_ = ! $$->forceacc_b_;
958         }
959         ;
960
961
962 explicit_duration:
963         DURATION '{' int_list '}'       {
964                 $$ = new Duration;
965                 Array<int> &a = *$3;
966                 ARRAY_SIZE(a,2);
967                         
968                 $$-> durlog_i_ = a[0];
969                 $$-> dots_i_ = a[1];
970
971                 delete &a;              
972         }
973         ;
974
975 dynamic_req:
976         ABSDYNAMIC '{' unsigned '}'     {
977                 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
978                 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
979                 $$ =ad_p;
980         }
981         | SPANDYNAMIC '{' int int '}' {
982                 Span_dynamic_req * sp_p = new Span_dynamic_req;
983                 sp_p->spantype = (Span_req::Spantype)$4;
984                 sp_p-> dynamic_dir_  = (Direction)$3;
985                 $$ = sp_p;
986         }
987         ;
988
989 plet_fraction:
990         unsigned '/' unsigned {
991                 $$[0] = $1;
992                 $$[1] = $3;
993         }
994         |
995         '/' unsigned {
996                 int num = $2 >? 1;
997                 $$[0] = guess_plet_a[(num <? GUESS_PLET) - 1];
998                 $$[1] = num;
999         }
1000         ;
1001
1002 close_plet_parens:
1003         ']' plet_fraction {
1004                 $$ = MAEBTELP;
1005                 THIS->plet_.type_i_ = $2[1];
1006                 THIS->plet_.iso_i_ = $2[0];
1007                 THIS->default_duration_.plet_ = THIS->plet_;
1008         }
1009         | TELP {
1010                 $$ = TELP;
1011                 THIS->plet_.type_i_ = 1;
1012                 THIS->plet_.iso_i_ = 1;
1013                 THIS->default_duration_.plet_ = THIS->plet_;
1014         }
1015         | TELP plet_fraction {
1016                 $$ = TELP;
1017                 THIS->plet_.type_i_ = $2[1];
1018                 THIS->plet_.iso_i_ = $2[0];
1019                 THIS->default_duration_.plet_ = THIS->plet_;
1020         }
1021         ;
1022
1023 close_request_parens:
1024         '~'     {
1025                 $$ = '~';
1026         }
1027         | '('   {
1028                 $$='(';
1029         }
1030         | ']'   {
1031                 $$ = ']';
1032         }
1033         | E_SMALLER {
1034                 $$ = '<';
1035         }
1036         | E_BIGGER {
1037                 $$ = '>';
1038         }
1039         | close_plet_parens
1040         ;
1041
1042 open_abbrev_parens:
1043         '[' ':' unsigned {
1044                 $$ = '[';
1045                 if (!Duration::duration_type_b ($3))
1046                         THIS->parser_error (_f ("not a duration: %d", $3));
1047                 else if ($3 < 8)
1048                         THIS->parser_error (_ ("can't abbreviate"));
1049                 else
1050                         THIS->set_abbrev_beam ($3);
1051         }
1052         ;
1053
1054 open_plet_parens:
1055         '[' plet_fraction {
1056                 $$ = BEAMPLET;
1057                 THIS->plet_.type_i_ = $2[1];
1058                 THIS->plet_.iso_i_ = $2[0];
1059                 THIS->default_duration_.plet_ = THIS->plet_;
1060         }
1061         | PLET plet_fraction {
1062                 $$ = PLET;
1063                 THIS->plet_.type_i_ = $2[1];
1064                 THIS->plet_.iso_i_ = $2[0];
1065                 THIS->default_duration_.plet_ = THIS->plet_;
1066         }
1067         ;
1068
1069 open_request_parens:
1070         E_EXCLAMATION   {
1071                 $$ = '!';
1072         }
1073         | ')'   {
1074                 $$=')';
1075         }
1076         | '['   {
1077                 $$='[';
1078         }
1079         | open_abbrev_parens
1080         | open_plet_parens
1081         ;
1082
1083
1084
1085 script_definition:
1086         SCRIPT '{' script_body '}'      { $$ = $3; }
1087         ;
1088
1089 script_body:
1090         STRING int int int int int              {
1091                 Script_def *s = new Script_def;
1092                 s->set_from_input (*$1,$2, $3,$4,$5, $6);
1093                 $$  = s;
1094                 delete $1;
1095         }
1096         ;
1097
1098 script_req:
1099         script_dir gen_script_def       {
1100                 Musical_script_req *m = new Musical_script_req;
1101                 $$ = m;
1102                 m->scriptdef_p_ = $2;
1103                 m->set_spot (THIS->here_input ());
1104                 if (!m->dir_)
1105                   m->dir_  = (Direction)$1;
1106         }
1107         ;
1108
1109 gen_script_def:
1110         text_def        { 
1111                 $$ = $1;
1112                 ((Text_def*) $$)->align_dir_ = LEFT; /* UGH */
1113         }
1114         | mudela_script { 
1115                 $$ = $1;
1116                 $$-> set_spot (THIS->here_input ());
1117         }
1118         | finger {
1119                 $$ = $1;
1120                 ((Text_def*)$$)->align_dir_ = RIGHT; /* UGH */
1121         }
1122         ;
1123
1124 text_def:
1125         string {
1126                 Text_def *t  = new Text_def;
1127                 $$ = t;
1128                 t->text_str_ = *$1;
1129                 delete $1;
1130                 $$->set_spot (THIS->here_input ());
1131         }
1132         ;
1133
1134 finger:
1135          DIGIT {
1136                 Text_def* t  = new Text_def;
1137                 $$ = t;
1138                 t->text_str_ = to_str ($1);
1139                 t->style_str_ = "finger";
1140                 $$->set_spot (THIS->here_input ());
1141         }
1142         ;
1143
1144 script_abbreviation:
1145         '^'             { $$ = get_scriptdef ('^'); }
1146         | '+'           { $$ = get_scriptdef ('+'); }
1147         | '-'           { $$ = get_scriptdef ('-'); }
1148         | '|'           { $$ = get_scriptdef ('|'); }
1149         | 'o'           { $$ = get_scriptdef ('o'); }
1150         | '>'           { $$ = get_scriptdef ('>'); }
1151         | '.'           {
1152                 $$ = get_scriptdef ('.');
1153         }
1154         ;
1155
1156 mudela_script:
1157         SCRIPT_IDENTIFIER               { $$ = $1->access_General_script_def (true); }
1158         | script_definition             { $$ = $1; }
1159         | script_abbreviation           {
1160                 $$ = THIS->lexer_p_->lookup_identifier (*$1)->access_General_script_def (true);
1161                 delete $1;
1162         }
1163         ;
1164
1165 script_dir:
1166         '_'     { $$ = -1; }
1167         | '^'   { $$ = 1; }
1168         | '-'   { $$ = 0; }
1169         ;
1170
1171 pre_requests:
1172         {
1173         }
1174         | pre_requests open_request_parens {
1175                 Array<Request*>& r = *THIS->get_parens_request ($2);
1176                 for (int i = 0; i < r.size (); i++ )
1177                         r[i]->set_spot (THIS->here_input ());
1178                 THIS->pre_reqs.concat (r);
1179                 delete &r;
1180         }
1181         ;
1182
1183 absolute_musical_pitch:
1184         steno_musical_pitch     {
1185                 $$ = $1;
1186         }
1187         ;
1188
1189 duration_length:
1190         steno_duration {
1191                 $$ = $1;
1192         }
1193         ;
1194
1195 dots:
1196         '.'             { $$ = 1; }
1197         | dots '.'      { $$ ++; }
1198         ;
1199
1200 entered_notemode_duration:
1201         /* */           {
1202                 $$ = new Duration (THIS->default_duration_);
1203         }
1204         | dots          {
1205                 $$ = new Duration (THIS->default_duration_);
1206                 $$->dots_i_  = $1;
1207         }
1208         | steno_duration        {
1209                 THIS->set_last_duration ($1);
1210         }
1211         ;
1212
1213 notemode_duration:
1214         entered_notemode_duration {
1215                 $$ = $1;
1216         }
1217         ;
1218
1219 steno_duration:
1220         unsigned                {
1221                 $$ = new Duration;
1222                 if (!Duration::duration_type_b ($1))
1223                         THIS->parser_error (_f ("not a duration: %d", $1));
1224                 else {
1225                         $$->durlog_i_ = Duration_convert::i2_type ($1);
1226                         $$->set_plet (THIS->plet_.iso_i_, THIS->plet_.type_i_);
1227                      }
1228         }
1229         | DURATION_IDENTIFIER   {
1230                 $$ = $1->access_Duration (true);
1231         }
1232         | steno_duration '.'    {
1233                 $$->dots_i_ ++;
1234         }
1235         | steno_duration '*' unsigned  {
1236                 $$->plet_.iso_i_ *= $3;
1237         }
1238         | steno_duration '/' unsigned {
1239                 $$->plet_.type_i_ *= $3;
1240         }
1241         ;
1242
1243
1244 abbrev_type: 
1245         ':'     {
1246                 $$ =0;
1247         }
1248         | ':' unsigned {
1249                 if (!Duration::duration_type_b ($2))
1250                         THIS->parser_error (_f ("not a duration: %d", $2));
1251                 else if ($2 < 8)
1252                         THIS->parser_error (_ ("can't abbreviate"));
1253                 $$ = $2;
1254         }
1255         ;
1256
1257
1258
1259 simple_element:
1260         steno_notepitch notemode_duration  {
1261                 if (!THIS->lexer_p_->note_state_b ())
1262                         THIS->parser_error (_ ("have to be in Note mode for notes"));
1263                 $1->set_duration (*$2);
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 Symtables;
1371         }
1372         | IDENTIFIER            {
1373                 $$ = $1->access_Symtables (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 unsigned box             {
1404                 $$ = global_lookup_l->atom_p (*$1, $2, *$3);
1405                 delete $1;
1406                 delete $3;
1407         }
1408         | STRING unsigned {
1409                 Box b (Interval (0,0), Interval (0,0));
1410                 $$ = global_lookup_l->atom_p (*$1, $2, 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
1443