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