]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy.orig
patch::: 1.0.16.mb1: Re: LilyPond 1.0.16
[lilypond.git] / lily / parser.yy.orig
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         ;
1035
1036
1037 explicit_duration:
1038         DURATION '{' int_list '}'       {
1039                 $$ = new Duration;
1040                 Array<int> &a = *$3;
1041                 ARRAY_SIZE(a,2);
1042                         
1043                 $$-> durlog_i_ = a[0];
1044                 $$-> dots_i_ = a[1];
1045
1046                 delete &a;              
1047         }
1048         ;
1049
1050 dynamic_req:
1051         ABSDYNAMIC '{' unsigned '}'     {
1052                 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
1053                 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
1054                 $$ =ad_p;
1055         }
1056         | SPANDYNAMIC '{' int int '}' {
1057                 Span_dynamic_req * sp_p = new Span_dynamic_req;
1058                 sp_p->spantype = (Span_req::Spantype)$4;
1059                 sp_p-> dynamic_dir_  = (Direction)$3;
1060                 $$ = sp_p;
1061         }
1062         ;
1063
1064 plet_fraction:
1065         unsigned '/' unsigned {
1066                 $$[0] = $1;
1067                 $$[1] = $3;
1068         }
1069         |
1070         '/' unsigned {
1071                 int num = $2 >? 1;
1072                 $$[0] = guess_plet_a[(num <? GUESS_PLET) - 1];
1073                 $$[1] = num;
1074         }
1075         ;
1076
1077 close_plet_parens:
1078         ']' plet_fraction {
1079                 $$ = MAEBTELP;
1080                 THIS->plet_.type_i_ = $2[1];
1081                 THIS->plet_.iso_i_ = $2[0];
1082                 THIS->default_duration_.plet_ = THIS->plet_;
1083         }
1084         | TELP {
1085                 $$ = TELP;
1086                 THIS->plet_.type_i_ = 1;
1087                 THIS->plet_.iso_i_ = 1;
1088                 THIS->default_duration_.plet_ = THIS->plet_;
1089         }
1090         | TELP plet_fraction {
1091                 $$ = TELP;
1092                 THIS->plet_.type_i_ = $2[1];
1093                 THIS->plet_.iso_i_ = $2[0];
1094                 THIS->default_duration_.plet_ = THIS->plet_;
1095         }
1096         ;
1097
1098 close_request_parens:
1099         '~'     {
1100                 $$ = '~';
1101         }
1102         | '('   {
1103                 $$='(';
1104         }
1105         | ']'   {
1106                 $$ = ']';
1107         }
1108         | E_SMALLER {
1109                 $$ = '<';
1110         }
1111         | E_BIGGER {
1112                 $$ = '>';
1113         }
1114         | close_plet_parens
1115         ;
1116
1117 open_abbrev_parens:
1118         '[' ':' unsigned {
1119                 $$ = '[';
1120                 if (!Duration::duration_type_b ($3))
1121                         THIS->parser_error (_f ("not a duration: %d", $3));
1122                 else if ($3 < 8)
1123                         THIS->parser_error (_ ("can't abbreviate"));
1124                 else
1125                         THIS->set_abbrev_beam ($3);
1126         }
1127         ;
1128
1129 open_plet_parens:
1130         '[' plet_fraction {
1131                 $$ = BEAMPLET;
1132                 THIS->plet_.type_i_ = $2[1];
1133                 THIS->plet_.iso_i_ = $2[0];
1134                 THIS->default_duration_.plet_ = THIS->plet_;
1135         }
1136         | PLET plet_fraction {
1137                 $$ = PLET;
1138                 THIS->plet_.type_i_ = $2[1];
1139                 THIS->plet_.iso_i_ = $2[0];
1140                 THIS->default_duration_.plet_ = THIS->plet_;
1141         }
1142         ;
1143
1144 open_request_parens:
1145         E_EXCLAMATION   {
1146                 $$ = '!';
1147         }
1148         | ')'   {
1149                 $$=')';
1150         }
1151         | '['   {
1152                 $$='[';
1153         }
1154         | open_abbrev_parens
1155         | open_plet_parens
1156         ;
1157
1158
1159
1160 script_definition:
1161         SCRIPT '{' script_body '}'      { $$ = $3; }
1162         ;
1163
1164 script_body:
1165         STRING int int int int int              {
1166                 Script_def *s = new Script_def;
1167                 s->set_from_input (*$1,$2, $3,$4,$5, $6);
1168                 $$  = s;
1169                 delete $1;
1170         }
1171         ;
1172
1173 script_req:
1174         script_dir gen_script_def       {
1175                 Musical_script_req *m = new Musical_script_req;
1176                 $$ = m;
1177                 m->scriptdef_p_ = $2;
1178                 m->set_spot (THIS->here_input ());
1179                 if (!m->dir_)
1180                   m->dir_  = (Direction)$1;
1181         }
1182         ;
1183
1184 gen_script_def:
1185         text_def        { 
1186                 $$ = $1;
1187                 ((Text_def*) $$)->align_dir_ = LEFT; /* UGH */
1188         }
1189         | mudela_script { 
1190                 $$ = $1;
1191                 $$-> set_spot (THIS->here_input ());
1192         }
1193         | finger {
1194                 $$ = $1;
1195                 ((Text_def*)$$)->align_dir_ = RIGHT; /* UGH */
1196         }
1197         ;
1198
1199 text_def:
1200         string {
1201                 Text_def *t  = new Text_def;
1202                 $$ = t;
1203                 t->text_str_ = *$1;
1204                 delete $1;
1205                 $$->set_spot (THIS->here_input ());
1206         }
1207         ;
1208
1209 finger:
1210          DIGIT {
1211                 Text_def* t  = new Text_def;
1212                 $$ = t;
1213                 t->text_str_ = to_str ($1);
1214                 t->style_str_ = "finger";
1215                 $$->set_spot (THIS->here_input ());
1216         }
1217         ;
1218
1219 script_abbreviation:
1220         '^'             { $$ = get_scriptdef ('^'); }
1221         | '+'           { $$ = get_scriptdef ('+'); }
1222         | '-'           { $$ = get_scriptdef ('-'); }
1223         | '|'           { $$ = get_scriptdef ('|'); }
1224         | 'o'           { $$ = get_scriptdef ('o'); }
1225         | '>'           { $$ = get_scriptdef ('>'); }
1226         | '.'           {
1227                 $$ = get_scriptdef ('.');
1228         }
1229         ;
1230
1231 mudela_script:
1232         SCRIPT_IDENTIFIER               { $$ = $1->access_General_script_def (true); }
1233         | script_definition             { $$ = $1; }
1234         | script_abbreviation           {
1235                 $$ = THIS->lexer_p_->lookup_identifier (*$1)->access_General_script_def (true);
1236                 delete $1;
1237         }
1238         ;
1239
1240 script_dir:
1241         '_'     { $$ = -1; }
1242         | '^'   { $$ = 1; }
1243         | '-'   { $$ = 0; }
1244         ;
1245
1246 pre_requests:
1247         {
1248         }
1249         | pre_requests open_request_parens {
1250                 Array<Request*>& r = *THIS->get_parens_request ($2);
1251                 for (int i = 0; i < r.size (); i++ )
1252                         r[i]->set_spot (THIS->here_input ());
1253                 THIS->pre_reqs.concat (r);
1254                 delete &r;
1255         }
1256         ;
1257
1258 absolute_musical_pitch:
1259         steno_musical_pitch     {
1260                 $$ = $1;
1261         }
1262         ;
1263
1264 duration_length:
1265         steno_duration {
1266                 $$ = $1;
1267         }
1268         ;
1269
1270 dots:
1271         '.'             { $$ = 1; }
1272         | dots '.'      { $$ ++; }
1273         ;
1274
1275 entered_notemode_duration:
1276         /* */           {
1277                 $$ = new Duration (THIS->default_duration_);
1278         }
1279         | dots          {
1280                 $$ = new Duration (THIS->default_duration_);
1281                 $$->dots_i_  = $1;
1282         }
1283         | steno_duration        {
1284                 THIS->set_last_duration ($1);
1285         }
1286         ;
1287
1288 notemode_duration:
1289         entered_notemode_duration {
1290                 $$ = $1;
1291         }
1292         ;
1293
1294 steno_duration:
1295         unsigned                {
1296                 $$ = new Duration;
1297                 if (!Duration::duration_type_b ($1))
1298                         THIS->parser_error (_f ("not a duration: %d", $1));
1299                 else {
1300                         $$->durlog_i_ = Duration_convert::i2_type ($1);
1301                         $$->set_plet (THIS->plet_.iso_i_, THIS->plet_.type_i_);
1302                      }
1303         }
1304         | DURATION_IDENTIFIER   {
1305                 $$ = $1->access_Duration (true);
1306         }
1307         | steno_duration '.'    {
1308                 $$->dots_i_ ++;
1309         }
1310         | steno_duration '*' unsigned  {
1311                 $$->plet_.iso_i_ *= $3;
1312         }
1313         | steno_duration '/' unsigned {
1314                 $$->plet_.type_i_ *= $3;
1315         }
1316         ;
1317
1318
1319 abbrev_type: 
1320         ':'     {
1321                 $$ =0;
1322         }
1323         | ':' unsigned {
1324                 if (!Duration::duration_type_b ($2))
1325                         THIS->parser_error (_f ("not a duration: %d", $2));
1326                 else if ($2 < 8)
1327                         THIS->parser_error (_ ("can't abbreviate"));
1328                 $$ = $2;
1329         }
1330         ;
1331
1332
1333
1334 simple_element:
1335         steno_notepitch notemode_duration  {
1336                 if (!THIS->lexer_p_->note_state_b ())
1337                         THIS->parser_error (_ ("have to be in Note mode for notes"));
1338                 $1->duration_ = *$2;
1339                 $$ = THIS->get_note_element ($1, $2);
1340         }
1341         | RESTNAME notemode_duration            {
1342                 $$ = THIS->get_rest_element (*$1, $2);
1343                 delete $1;  // delete notename
1344         }
1345         | MEASURES notemode_duration    {
1346                 Multi_measure_rest_req* m = new Multi_measure_rest_req;
1347                 m->duration_ = *$2;
1348                 delete $2;
1349
1350                 Simultaneous_music*velt_p = new Request_chord;
1351                 velt_p->set_spot (THIS->here_input ());
1352                 velt_p->add_music (m);
1353                 $$ = velt_p;
1354         }
1355         | STRING notemode_duration                      {
1356                 if (!THIS->lexer_p_->lyric_state_b ())
1357                         THIS->parser_error (_ ("have to be in Lyric mode for lyrics"));
1358                 $$ = THIS->get_word_element (*$1, $2);
1359                 delete $1;
1360         }
1361         ;
1362
1363
1364 /*
1365         UTILITIES
1366  */
1367 pitch_list:                     {
1368                 $$ = new Array<Musical_pitch>;
1369         }
1370         | pitch_list musical_pitch      {
1371                 $$->push (*$2);
1372                 delete $2;
1373         }
1374         ;
1375
1376
1377 int_list:
1378         /**/                    {
1379                 $$ = new Array<int>
1380         }
1381         | int_list int          {
1382                 $$->push ($2);          
1383         }
1384         ;
1385
1386 unsigned:
1387         UNSIGNED        {
1388                 $$ = $1;
1389         }
1390         | DIGIT {
1391                 $$ = $1;
1392         };
1393
1394 int:
1395         unsigned {
1396                 $$ = $1;
1397         }
1398         | '-' unsigned {
1399                 $$ = -$2;
1400         }
1401         | INT_IDENTIFIER        {
1402                 $$ = *$1->access_int (false);
1403         }
1404         ;
1405
1406
1407 string:
1408         STRING          {
1409                 $$ = $1;
1410         }
1411         | STRING_IDENTIFIER     {
1412                 $$ = $1->access_String (true);
1413         }
1414         | string '+' string {
1415                 *$$ += *$3;
1416                 delete $3;
1417         }
1418         ;
1419
1420
1421
1422 /*
1423         symbol tables
1424 */
1425 symtables:
1426         SYMBOLTABLES '{' symtables_body '}'     { $$ = $3; }
1427         ;
1428
1429 symtables_body:
1430                         {
1431                 $$ = new Symtables;
1432         }
1433         | IDENTIFIER            {
1434                 $$ = $1->access_Symtables (true);
1435         }
1436         | symtables_body FONT STRING            {
1437                 $$->font_ = *$3;
1438                 $$->font_path_ = global_path.find (*$3);
1439                 if  (!$$->font_path_.length_i ())
1440                         THIS->here_input ().error (_f("can't open file: `%s'", $3->ch_C()));
1441
1442                 delete $3;
1443         }
1444         | symtables_body STRING '=' symtable            {
1445                 $$->add (*$2, $4);
1446                 delete $2;
1447         }
1448         ;
1449
1450 symtable:
1451         TABLE '{' symtable_body '}' { $$ = $3; }
1452         ;
1453
1454 symtable_body:
1455                                 { $$ = new Symtable; }
1456         | symtable_body STRING  symboldef {
1457                 $$->add (*$2, *$3);
1458                 delete $2;
1459                 delete $3;
1460         }
1461         ;
1462
1463 symboldef:
1464         STRING unsigned box             {
1465                 $$ = global_lookup_l->atom_p (*$1, $2, *$3);
1466                 delete $1;
1467                 delete $3;
1468         }
1469         | STRING unsigned {
1470                 Box b (Interval (0,0), Interval (0,0));
1471                 $$ = global_lookup_l->atom_p (*$1, $2, b);
1472                 delete $1;
1473         }
1474         ;
1475
1476 box:
1477         dinterval dinterval     {
1478                 $$ = new Box (*$1, *$2);
1479                 delete $1;
1480                 delete $2;
1481         }
1482         ;
1483
1484 dinterval: real real            {
1485                 $$ = new Interval ($1, $2);
1486         }
1487         ;
1488
1489 %%
1490
1491 void
1492 My_lily_parser::set_yydebug (bool b)
1493 {
1494 #ifdef YYDEBUG
1495         yydebug = b;
1496 #endif
1497 }
1498 void
1499 My_lily_parser::do_yyparse ()
1500 {
1501         yyparse ((void*)this);
1502 }
1503
1504