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