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