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