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