]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
patch::: 1.0.12.jcn2: opniewvisite
[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 "dimension.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 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 <symtables>       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 Symtables_identifier ($1, IDENTIFIER);
399         }
400         | post_request {
401                 $$ = new Request_identifier ($1, POST_REQUEST_IDENTIFIER);
402         }
403         | explicit_duration {
404                 $$ = new Duration_identifier ($1, DURATION_IDENTIFIER);
405         }
406         | real {
407                 $$ = new Real_identifier (new Real ($1), REAL_IDENTIFIER);
408         }
409         | string {
410                 $$ = new String_identifier ($1, STRING_IDENTIFIER);
411         }
412         | int   {
413                 $$ = new int_identifier (new int ($1), INT_IDENTIFIER);
414         }
415         | translator_spec {
416                 $$ = new Translator_identifier ($1, TRANS_IDENTIFIER);
417         }
418         ;
419
420 translator_spec:
421         TRANSLATOR '{' translator_spec_body '}'
422                 { $$ = $3; }
423         ;
424
425 translator_spec_body:
426         TRANS_IDENTIFIER        {
427                 $$ = $1->access_Translator (true);
428                 $$-> set_spot (THIS->here_input ());
429         }
430         | TYPE STRING ';'       {
431                 Translator* t = get_translator_l (*$2);
432                 Translator_group * tg = t->access_Translator_group ();
433
434                 if (!tg)
435                         THIS->parser_error (_("Need a translator group for a context"));
436                 
437                 t = t->clone ();
438                 t->set_spot (THIS->here_input ());
439                 $$ = t;
440                 delete $2;
441         }
442         | translator_spec_body STRING '=' simple_identifier_init ';'    { 
443                 Identifier* id = $4;
444                 String_identifier *s = id->access_String_identifier ();
445                 Real_identifier *r= id->access_Real_identifier ();
446                 int_identifier *i = id->access_int_identifier ();
447         
448                 String str;
449                 if (s) str = *s->access_String (false); 
450                 if (i) str = to_str (*i->access_int (false));
451                 if (r) str = to_str (*r->access_Real (false));
452                 if (!s && !i && !r)
453                         THIS->parser_error (_("Wrong type for property value"));
454
455                 delete $4;
456                 $$->set_property (*$2, str);
457         }
458         | translator_spec_body STRING ';' {
459                 $$->type_str_ = *$2;
460                 delete $2;
461         }
462         | translator_spec_body CONSISTS STRING ';' {
463                 $$->access_Translator_group ()-> set_element (*$3, true);
464                 delete $3;
465         }
466         | translator_spec_body ACCEPTS STRING ';' {
467                 $$->access_Translator_group ()-> set_acceptor (*$3, true);
468                 delete $3;
469         }
470         | translator_spec_body REMOVE STRING ';' {
471                 $$->access_Translator_group ()-> set_element (*$3, false);
472                 delete $3;
473         }
474         ;
475
476 /*
477         SCORE
478 */
479 score_block:
480         SCORE { THIS->remember_spot ();
481                 THIS->error_level_i_ =0;
482         }
483         /*cont*/ '{' score_body '}'     {
484                 $$ = $4;
485                 $$->set_spot (THIS->pop_spot ());
486                 if (!$$->def_p_arr_.size ())
487                         $$->add_output (THIS->default_paper_p ());
488
489                 /* handle error levels. */
490                 $$->errorlevel_i_ = THIS->error_level_i_;
491                 THIS->error_level_i_ = 0;
492         }
493         ;
494
495 score_body:             {
496                 $$ = new Score;
497         }
498         | SCORE_IDENTIFIER {
499                 $$ = $1->access_Score (true);
500         }
501         | score_body mudela_header      {
502                 $$->header_p_ = $2;
503         }
504         | score_body Music      {
505                 if ($$->music_p_)
506                         $2->warning (_ ("More than one music block"));  
507                 $$->music_p_ = $2;
508         }
509         | score_body output_def {
510                 $$->add_output ($2);
511         }
512         | score_body error {
513
514         }
515         ;
516
517 output_def:
518         paper_block {
519                 $$ = $1;
520         }
521         |  midi_block           {
522                 $$= $1;
523         }
524         ;
525
526 intastint_list:
527         /* */   { $$ =new Array<int>; }
528         | intastint_list int '*' int    {
529                 $$->push ($2); $$->push ($4);
530         }
531         | intastint_list int    {
532                 $$->push ($2); $$->push (1);
533         }
534         ;       
535
536
537 /*
538         PAPER
539 */
540 paper_block:
541         PAPER '{' paper_def_body '}'    { 
542                 $$ = $3;
543                 THIS-> lexer_p_->scope_l_arr_.pop ();
544         }
545         ;
546
547 optional_semicolon:
548         /* empty */
549         | ';'
550         ;
551
552 paper_def_body:
553         /* empty */                     {
554                 Paper_def *p = THIS->default_paper_p ();
555                 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
556                 $$ = p;
557         }
558         | PAPER_IDENTIFIER optional_semicolon   {
559                 Paper_def *p = $1->access_Paper_def (true);
560                 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
561                 $$ = p;
562         }
563         | paper_def_body int '=' symtables              { // ugh, what a syntax
564                 Lookup * l = ps_output_global_b ? new Ps_lookup (*$4)
565                   : new Tex_lookup (*$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                 int durlog_i = $2->durlog_i_;
1265                 $$ = THIS->get_note_element ($1, $2);
1266         }
1267         | RESTNAME notemode_duration            {
1268                 $$ = THIS->get_rest_element (*$1, $2);
1269                 delete $1;  // delete notename
1270         }
1271         | MEASURES notemode_duration    {
1272                 Multi_measure_rest_req* m = new Multi_measure_rest_req;
1273                 m->duration_ = *$2;
1274                 delete $2;
1275
1276                 Simultaneous_music*velt_p = new Request_chord;
1277                 velt_p->set_spot (THIS->here_input ());
1278                 velt_p->add_music (m);
1279                 $$ = velt_p;
1280         }
1281         | STRING notemode_duration                      {
1282                 if (!THIS->lexer_p_->lyric_state_b ())
1283                         THIS->parser_error (_ ("have to be in Lyric mode for lyrics"));
1284                 $$ = THIS->get_word_element (*$1, $2);
1285                 delete $1;
1286         }
1287         ;
1288
1289
1290 /*
1291         UTILITIES
1292  */
1293 pitch_list:                     {
1294                 $$ = new Array<Musical_pitch>;
1295         }
1296         | pitch_list musical_pitch      {
1297                 $$->push (*$2);
1298                 delete $2;
1299         }
1300         ;
1301
1302
1303 int_list:
1304         /**/                    {
1305                 $$ = new Array<int>
1306         }
1307         | int_list int          {
1308                 $$->push ($2);          
1309         }
1310         ;
1311
1312 unsigned:
1313         UNSIGNED        {
1314                 $$ = $1;
1315         }
1316         | DIGIT {
1317                 $$ = $1;
1318         };
1319
1320 int:
1321         unsigned {
1322                 $$ = $1;
1323         }
1324         | '-' unsigned {
1325                 $$ = -$2;
1326         }
1327         | INT_IDENTIFIER        {
1328                 $$ = *$1->access_int (false);
1329         }
1330         ;
1331
1332 string_primary:
1333         STRING          {
1334                 $$ = $1;
1335         }
1336         | STRING_IDENTIFIER     {
1337                 $$ = $1->access_String (true);
1338         }
1339         ;
1340
1341 string:
1342         string_primary {
1343                 $$ = $1;
1344         }
1345         | string '+' string_primary {
1346                 *$$ += *$3;
1347                 delete $3;
1348         }
1349         ;
1350
1351 dim:
1352         real_primary unit       { $$ = $1*$2; }
1353         ;
1354
1355
1356 unit:   CM_T            { $$ = 1 CM; }
1357         |IN_T           { $$ = 1 INCH; }
1358         |MM_T           { $$ = 1 MM; }
1359         |PT_T           { $$ = 1 PT; }
1360         ;
1361
1362 /*
1363         symbol tables
1364 */
1365 symtables:
1366         SYMBOLTABLES '{' symtables_body '}'     { $$ = $3; }
1367         ;
1368
1369 symtables_body:
1370                         {
1371                 $$ = new Symtables;
1372         }
1373         | IDENTIFIER            {
1374                 $$ = $1->access_Symtables (true);
1375         }
1376         | symtables_body FONT STRING            {
1377                 $$->font_ = *$3;
1378                 $$->font_path_ = global_path.find (*$3);
1379                 if  (!$$->font_path_.length_i ())
1380                         THIS->here_input ().error (_f("can't open file: `%s'", $3->ch_C()));
1381
1382                 delete $3;
1383         }
1384         | symtables_body STRING '=' symtable            {
1385                 $$->add (*$2, $4);
1386                 delete $2;
1387         }
1388         ;
1389
1390 symtable:
1391         TABLE '{' symtable_body '}' { $$ = $3; }
1392         ;
1393
1394 symtable_body:
1395                                 { $$ = new Symtable; }
1396         | symtable_body STRING  symboldef {
1397                 $$->add (*$2, *$3);
1398                 delete $2;
1399                 delete $3;
1400         }
1401         ;
1402
1403 symboldef:
1404         STRING  box             {
1405                 $$ = new Atom (*$1, *$2);
1406                 delete $1;
1407                 delete $2;
1408         }
1409         | STRING {
1410                 Box b (Interval (0,0), Interval (0,0));
1411                 $$ = new Atom (*$1, b);
1412                 delete $1;
1413         }
1414         ;
1415
1416 box:
1417         dinterval dinterval     {
1418                 $$ = new Box (*$1, *$2);
1419                 delete $1;
1420                 delete $2;
1421         }
1422         ;
1423
1424 dinterval: dim  dim             {
1425                 $$ = new Interval ($1, $2);
1426         }
1427         ;
1428
1429 %%
1430
1431 void
1432 My_lily_parser::set_yydebug (bool b)
1433 {
1434 #ifdef YYDEBUG
1435         yydebug = b;
1436 #endif
1437 }
1438 void
1439 My_lily_parser::do_yyparse ()
1440 {
1441         yyparse ((void*)this);
1442 }
1443
1444