]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.y
159978d3dcd8fb0e5c6b3289e498110f9534e509
[lilypond.git] / lily / parser.y
1 %{ // -*-Fundamental-*-
2
3 /*
4   parser.y -- YACC parser for mudela
5
6   source file of the GNU LilyPond music typesetter
7
8   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
9            Jan Nieuwenhuizen <jan@digicash.com>
10 */
11
12 #include <iostream.h>
13
14 // mmm
15 #define MUDELA_VERSION "0.1.9"
16
17 #include "scalar.hh"
18 #include "translation-property.hh"
19 #include "script-def.hh"
20 #include "symtable.hh"
21 #include "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 "keyword.hh"
28 #include "debug.hh"
29 #include "parseconstruct.hh"
30 #include "dimen.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 "header.hh"
40 #include "duration-convert.hh"
41 #include "change-translator.hh"
42
43 #ifndef NDEBUG
44 #define YYDEBUG 1
45 #endif
46
47 #define YYERROR_VERBOSE 1
48
49 #define YYPARSE_PARAM my_lily_parser_l
50 #define YYLEX_PARAM my_lily_parser_l
51 #define THIS ((My_lily_parser *) my_lily_parser_l)
52
53 #define yyerror THIS->parser_error
54
55 %}
56
57
58 %union {
59     Array<Interval>* intarr;
60     Array<Melodic_req*> *melreqvec;/* should clean up naming */
61     Array<String> * strvec;
62     Array<int> *intvec;
63     Box *box;
64     Chord * chord;
65     Duration *duration;
66     Identifier *id;
67     Translator* trans;
68     Music *music;
69     Music_list *musiclist;
70     Score *score;
71     Header *header;
72     Interval *interval;
73     Lookup*lookup;
74     Melodic_req * melreq;
75     Musical_req* musreq;
76     Music_output_def * outputdef;
77     Midi_def* midi;
78     Moment *moment;
79     Note_req *notereq;
80     Paper_def *paper;
81     Real real;
82     Request * request;
83     General_script_def * script;
84     Scalar *scalar;
85     String *string;
86     Atom * symbol;
87     Symtable * symtable;
88     Symtables * symtables;
89     Text_def * textdef;
90     Tempo_req *tempo;
91     char c;
92     const char *consstr;
93     int i;
94     int ii[10];
95 }
96 %{
97
98 int
99 yylex (YYSTYPE *s,  void * v_l)
100 {
101         My_lily_parser   *pars_l = (My_lily_parser*) v_l;
102         My_lily_lexer * lex_l = pars_l->lexer_p_;
103
104         lex_l->lexval_l = (void*) s;
105         return lex_l->yylex ();
106 }
107
108
109 %}
110
111 %pure_parser
112
113 /* tokens which are not keywords */
114
115 %token ALIAS
116 %token BAR
117 %token BEAMPLET
118 %token MAEBTELP
119 %token CADENZA
120 %token CLEAR
121 %token CLEF
122 %token CONTAINS
123 %token CONSISTS
124 %token ACCEPTS
125 %token CM_T
126 %token DURATION
127 %token ABSDYNAMIC
128 %token END
129 %token GROUPING
130 %token TRANSLATOR
131 %token HEADER
132 %token IN_T
133 %token LYRIC
134 %token KEY
135 %token MELODIC
136 %token MIDI
137 %token MELODIC_REQUEST
138 %token METER
139 %token MM_T
140 %token MULTI
141 %token NOTENAMES
142 %token OCTAVE
143 %token OUTPUT
144 %token PAPER
145 %token PARTIAL
146 %token PLET
147 %token TELP
148 %token PT_T
149 %token SCORE
150 %token SCRIPT
151 %token SHAPE
152 %token SKIP
153 %token SPANDYNAMIC
154 %token STAFF
155 %token START_T
156 %token SYMBOLTABLES
157 %token TABLE
158 %token TRANSPOSE
159 %token TEMPO
160 %token TYPE
161 %token TEXID
162 %token TEXTSTYLE
163 %token TITLE
164 %token PROPERTY
165 %token VERSION
166
167 /* escaped */
168 %token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
169
170 %type <i>       dots
171 %token <i>      DIGIT
172 %token <melreq> NOTENAME_ID
173 %token <id>     DURATION_IDENTIFIER
174 %token <id>     IDENTIFIER
175 %token <id>     MELODIC_REQUEST_IDENTIFIER
176 %token <id>     MUSIC_IDENTIFIER
177 %token <id>     VOICE_IDENTIFIER
178 %token <id>     POST_REQUEST_IDENTIFIER
179 %token <id>     SCRIPT_IDENTIFIER
180 %token <id>     COMMAND_IDENTIFIER
181 %token <id>     REAL_IDENTIFIER
182 %token <id>     TRANS_IDENTIFIER
183 %token <id>     INT_IDENTIFIER
184 %token <id>     SCORE_IDENTIFIER
185 %token <id>     MIDI_IDENTIFIER
186 %token <id>     PAPER_IDENTIFIER
187 %token <id>     REQUEST_IDENTIFIER
188 %token <real>   REAL
189 %token <string> DURATION RESTNAME
190 %token <string> STRING
191 %token <i>      UNSIGNED
192 %token <i>      POST_QUOTES
193 %token <i>      PRE_QUOTES
194
195 %type <outputdef> output_def
196 %type <header>  mudela_header mudela_header_body
197 %type <box>     box
198 %type <i>       open_request_parens close_request_parens
199 %type <c>       open_abbrev_parens
200 %type <i>       open_plet_parens close_plet_parens
201 %type <music>   simple_element music_elt full_element lyrics_elt command_elt
202 %type <i>       abbrev_type
203 %type <i>       int unsigned
204 %type <i>       script_dir
205 %type <id>      identifier_init
206 %type <duration> explicit_steno_duration notemode_duration
207 %type <duration> entered_notemode_duration explicit_duration
208 %type <interval>        dinterval
209 %type <intvec>  intastint_list
210 %type <lookup>  symtables symtables_body
211 %type <melreq>  melodic_request steno_melodic_req
212 %type <notereq> steno_note_req
213 %type <melreqvec>       pitch_list
214 %type <midi>    midi_block midi_body
215 %type <moment>  duration_length
216
217 %type <scalar>  scalar
218 %type <music>   Music transposed_music
219 %type <music>   property_def translator_change
220 %type <musiclist> Voice Voice_body
221 %type <chord>   Chord Chord_body
222 %type <paper>   paper_block paper_body
223 %type <real>    dim real
224 %type <real>    unit
225 %type <request> abbrev_command_req
226 %type <request> post_request structured_post_request
227 %type <request> command_req verbose_command_req
228 %type <request> script_req  dynamic_req
229 %type <score>   score_block score_body
230 %type <intarr>  shape_array
231 %type <script>  script_definition script_body mudela_script gen_script_def
232 %type <textdef> text_def finger
233 %type <string>  script_abbreviation
234 %type <symbol>  symboldef
235 %type <symtable>        symtable symtable_body
236 %type <trans>   translator_spec translator_spec_body
237 %type <tempo>   tempo_request
238 %type <string>  concat_strings
239
240 %expect 1
241
242
243 %%
244
245 mudela: /* empty */
246         | mudela mudela_header {
247                 delete THIS->default_header_p_ ;
248                 THIS->default_header_p_ = $2;
249         }
250         | mudela score_block {
251                 add_score ($2);
252         }
253         | mudela add_declaration { }
254         | mudela error
255         | mudela check_version { }
256         | mudela add_notenames { }
257         ;
258
259 check_version:
260         VERSION STRING ';'              {
261                 if (String (*$2) != MUDELA_VERSION) {
262                         if (THIS->ignore_version_b_) {
263                                 THIS->here_input ().error ("Incorrect mudela version");
264                         } else {
265                                 THIS->fatal_error_i_ = 1;
266                                 THIS->parser_error ("Incorrect mudela version");
267                         }
268                 }
269         }
270         ;
271
272 add_notenames:
273         NOTENAMES '{' notenames_body '}'
274         ;
275 notenames_body:
276         /**/    {
277         }
278         | notenames_body CLEAR  {
279                 THIS->clear_notenames ();
280         }
281         | notenames_body STRING '=' melodic_request {
282                 THIS->add_notename (*$2, $4);
283                 delete $2;
284         }
285         ;
286
287 mudela_header_body:
288                 {
289                 $$ = new Header;
290         }
291         | mudela_header_body STRING '=' concat_strings ';' {
292                 (*$$)[*$2] = *$4;
293                 delete $2;
294                 delete $4;
295         }
296         ;
297
298 mudela_header:
299         HEADER '{' mudela_header_body '}'       {
300                 $$ = $3;
301         }
302         ;
303
304
305 concat_strings:
306                 {
307                 $$ = new String;
308         }
309         | concat_strings STRING {
310                 *$$ += *$2;
311         }
312
313
314 /*
315         DECLARATIONS
316 */
317
318 add_declaration:
319         STRING {
320                 THIS->remember_spot ();
321         }
322         /* cont */ '=' identifier_init {
323             THIS->lexer_p_->set_identifier (*$1, $4);
324             $4->init_b_ = THIS->init_parse_b_;
325             $4->set_spot (THIS->pop_spot ());
326         }
327         ;
328
329 identifier_init:
330         score_block {
331                 $$ = new Score_id ($1, SCORE_IDENTIFIER);
332
333         }
334         | paper_block {
335                 $$ = new Paper_def_id ($1, PAPER_IDENTIFIER);
336
337         }
338         | midi_block {
339                 $$ = new Midi_def_id ($1, MIDI_IDENTIFIER);
340
341         }
342         | script_definition {
343                 $$ = new Script_id ($1, SCRIPT_IDENTIFIER);
344
345         }
346         | Music  {
347                 $$ = new Music_id ($1, MUSIC_IDENTIFIER);
348
349         }
350         | symtables {
351                 $$ = new Lookup_id ($1, IDENTIFIER);
352
353         }
354         | real  {
355                 $$ = new Real_id (new Real ($1), REAL_IDENTIFIER);
356
357         }
358         | int   {
359                 $$ = new Int_id (new int ($1), INT_IDENTIFIER);
360         }
361         | post_request {
362                 $$ = new Request_id ($1, POST_REQUEST_IDENTIFIER);
363         }
364         | melodic_request {
365                 $$ = new Request_id ($1, MELODIC_REQUEST_IDENTIFIER);
366
367         }
368         | translator_spec {
369                 $$ = new Translator_id ($1, TRANS_IDENTIFIER);
370         }
371         | explicit_duration {
372                 $$ = new Duration_id ($1, DURATION_IDENTIFIER);
373         }
374         ;
375
376
377
378 translator_spec:
379         TRANSLATOR '{' translator_spec_body '}'
380                 { $$ = $3; }
381         ;
382
383 translator_spec_body:
384         TRANS_IDENTIFIER        {
385                 $$ = $1->translator ();
386                 $$-> set_spot (THIS->here_input ());
387         }
388         | TYPE STRING ';'       {
389                 $$ = get_translator_l (*$2)->clone ();
390                 $$->set_spot (THIS->here_input ());
391                 delete $2;
392         }
393         | translator_spec_body STRING '=' scalar ';'    {
394                 $$-> set_property (*$2, *$4);
395                 delete $2;
396                 delete $4;
397         }
398         | translator_spec_body CONSISTS STRING ';'      {
399                 $$->group_l ()->consists_str_arr_.push (*$3);
400                 delete $3;
401         }
402         | translator_spec_body ACCEPTS STRING ';' {
403                 $$->group_l ()->accepts_str_arr_.push (*$3);
404                 delete $3;
405         }
406         ;
407
408 /*
409         SCORE
410 */
411 score_block:
412         SCORE { THIS->remember_spot ();
413                 THIS->error_level_i_ =0;
414         }
415         /*cont*/ '{' score_body '}'     {
416                 $$ = $4;
417                 $$->set_spot (THIS->pop_spot ());
418                 if (!$$->def_p_arr_.size ())
419                         $$->add (THIS->default_paper ());
420
421                 /* handle error levels. */
422                 $$->errorlevel_i_ = THIS->error_level_i_;
423                 THIS->error_level_i_ = 0;
424                 if (!$$->header_p_ && THIS->default_header_p_)
425                         $$->header_p_ = new Header (*THIS->default_header_p_);
426         }
427         ;
428
429 score_body:             {
430                 $$ = new Score;
431         }
432         | SCORE_IDENTIFIER {
433                 $$ = $1->score ();
434         }
435         | score_body mudela_header      {
436                 $$->header_p_ = $2;
437         }
438         | score_body Music      {
439                 if ($$->music_p_)
440                         $2->warning ("More than one music block");      
441                 $$->music_p_ = $2;
442         }
443         | score_body output_def {
444                 $$->add ($2);
445         }
446         | score_body error {
447
448         }
449         ;
450
451 output_def:
452         paper_block {
453                 $$ = $1;
454         }
455         |  midi_block           {
456                 $$= $1;
457         }
458         ;
459
460 intastint_list:
461         /* */   { $$ =new Array<int>; }
462         | intastint_list int '*' int    {
463                 $$->push ($2); $$->push ($4);
464         }
465         ;
466
467
468 /*
469         PAPER
470 */
471 paper_block:
472         PAPER
473         '{' paper_body '}'      { $$ = $3; }
474         ;
475
476 paper_body:
477         /* empty */                     {
478                 $$ = THIS->default_paper ();
479         }
480         | PAPER_IDENTIFIER      {
481                 $$ = $1->paperdef ();
482         }
483         | paper_body OUTPUT STRING ';'  { 
484                 $$->outfile_str_ = *$3;
485                 delete $3;
486         }
487         | paper_body symtables          { $$->set ($2); }
488         | paper_body STRING '=' dim ';'         {
489                 $$->set_var (*$2, $4);
490         }
491         | paper_body STRING '=' real ';' {
492                 $$->set_var (*$2, $4);
493         }
494         | paper_body STRING '=' translator_spec {
495                 $$-> assign_translator (*$2, $4);
496                 delete $2;
497         }
498         | paper_body SHAPE '=' shape_array ';' {
499                 $$->shape_int_a_ = *$4;
500                 delete $4;
501         }
502         | paper_body error {
503
504         }
505         ;
506
507 shape_array:
508         /* empty */ {
509                 $$ = new Array<Interval>;
510         }
511         | shape_array dim dim {
512                 $$->push(Interval($2, $2 + $3));
513         };
514
515 /*
516         MIDI
517 */
518 midi_block:
519         MIDI
520
521         '{' midi_body '}'       { $$ = $3; }
522         ;
523
524 midi_body: /* empty */          {
525                 $$ = THIS->default_midi ();
526         }
527         | midi_body STRING '=' translator_spec  {
528                 $$-> assign_translator (*$2, $4);
529                 delete $2;
530         }
531         | midi_body OUTPUT STRING ';'   {
532                 $$->outfile_str_ = *$3;
533                 delete $3;
534         }
535         | midi_body tempo_request ';' {
536                 $$->set_tempo ($2->dur_.length (), $2->metronome_i_);
537                 delete $2;
538         }
539         | midi_body error {
540
541         }
542         ;
543
544 tempo_request:
545         TEMPO entered_notemode_duration '=' unsigned    {
546                 $$ = new Tempo_req;
547                 $$->dur_ = *$2;
548                 delete $2;
549                 $$-> metronome_i_ = $4;
550         }
551         ;
552
553 /*
554         MUSIC
555 */
556
557 Voice:
558         '{' Voice_body '}'      {
559                 $$ = $2;
560         }
561         ;
562
563 Voice_body:
564         /**/            {
565                 $$ = new Voice;
566                 $$->set_spot (THIS->here_input ());
567         }
568         | Voice_body Music              {
569                 $$->add ($2);
570         }
571         ;
572
573 Music:
574         full_element            { $$ = $1; }
575         | TYPE STRING Music     {
576                 $$ = $3;
577                 $$->translator_type_str_ = *$2;
578                 delete $2;
579         }
580         | TYPE STRING '=' STRING Music {
581                 $$ = $5;
582                 $$->translator_type_str_ = *$2;
583                 $$->translator_id_str_ = *$4;
584                 delete $2;
585                 delete $4;
586         }
587         | Voice         { $$ = $1; }
588         | Chord                 { $$ = $1; }
589         | transposed_music      { $$ = $1; }
590         | MUSIC_IDENTIFIER      { $$ = $1->music (); }
591         | MUSIC_IDENTIFIER ';'  { $$ = $1->music (); }
592         | MELODIC
593                 { THIS->lexer_p_->push_note_state (); }
594         Music
595                 { $$=$3; THIS->lexer_p_->pop_state (); }
596
597         | LYRIC
598                 { THIS->lexer_p_->push_lyric_state (); }
599         Music
600                 { $$ = $3; THIS->lexer_p_->pop_state (); }
601         | property_def
602         | translator_change
603         ;
604
605 translator_change:
606         TRANSLATOR STRING '=' STRING  {
607                 Change_translator * t = new Change_translator;
608                 t-> change_to_type_str_ = *$2;
609                 t-> change_to_id_str_ = *$4;
610
611                 $$ = t;
612                 $$->set_spot (THIS->here_input ());
613                 delete $2;
614                 delete $4;
615         }
616         ;
617
618 property_def:
619         PROPERTY STRING '.' STRING '=' scalar   {
620                 Translation_property *t = new Translation_property;
621                 t-> translator_type_str_ = *$2;
622                 t-> var_str_ = *$4;
623                 t-> value_ = *$6;
624                 $$ = t;
625                 $$->set_spot (THIS->here_input ());
626                 delete $2;
627                 delete $4;
628                 delete $6;
629         }
630         ;
631
632 scalar:
633         STRING          { $$ = new Scalar (*$1); delete $1; }
634         | int           { $$ = new Scalar ($1); }
635         ;
636
637
638 Chord:
639         '<' Chord_body '>'      { $$  = $2; }
640         | MULTI unsigned Chord {
641                 $$ = $3;
642                 $$->multi_level_i_=$2;
643         }
644         ;
645
646 Chord_body:
647         /**/    {
648                 $$ = new Chord;
649                 $$-> multi_level_i_ = 1;
650                 $$->set_spot (THIS->here_input ());
651         }
652         | Chord_body Music {
653                 $$->add ($2);
654         }
655         ;
656
657 transposed_music:
658         TRANSPOSE steno_melodic_req Music {
659                 $$ = $3;
660                 $$ -> transpose ($2);
661
662                 delete $2;
663         }
664         ;
665
666
667 /*
668         VOICE ELEMENTS
669 */
670 full_element:
671         pre_requests simple_element post_requests       {
672                 THIS->add_requests ((Chord*)$2);//ugh
673                 $$ = $2;
674         }
675         | command_elt
676         | voice_command ';'     { $$ = 0; }
677         ;
678
679 simple_element:
680         music_elt
681         | lyrics_elt
682         ;
683
684 command_elt:
685         command_req {
686                 $$ = new Request_chord;
687                 $$-> set_spot (THIS->here_input ());
688                 $1-> set_spot (THIS->here_input ());
689                 ((Chord*)$$) ->add ($1);//ugh
690
691         }
692         ;
693
694 command_req:
695         abbrev_command_req
696         | verbose_command_req ';'       { $$ = $1; }
697         ;
698
699 abbrev_command_req:
700          '|'                            {
701                 $$ = new Barcheck_req;
702         }
703         | COMMAND_IDENTIFIER    {
704                 $$ = $1->request ();
705         }
706         ;
707
708 verbose_command_req:
709         BAR STRING                      {
710                 $$ = new Bar_req (*$2);
711                 delete $2;
712         }
713         | METER unsigned '/' unsigned   {
714                 Meter_change_req *m = new Meter_change_req;
715                 m->set ($2,$4);
716                 $$ = m;
717         }
718         | SKIP duration_length {
719                 Skip_req * skip_p = new Skip_req;
720                 skip_p->duration_.set_plet ($2->numerator ().as_long (),
721                         $2->denominator ().as_long ());
722
723                 delete $2;
724                 $$ = skip_p;
725         }
726         | tempo_request {
727                 $$ = $1;
728         }
729         | CADENZA unsigned      {
730                 $$ = new Cadenza_req ($2);
731         }
732         | PARTIAL duration_length       {
733                 $$ = new Partial_measure_req (*$2);
734                 delete $2;
735         }
736         | CLEF STRING {
737                 $$ = new Clef_change_req (*$2);
738                 delete $2;
739         }
740         | KEY pitch_list        {
741                 Key_change_req *key_p= new Key_change_req;
742                 key_p->melodic_p_arr_ = *$2;
743                 $$ = key_p;
744                 delete $2;
745         }
746         | GROUPING intastint_list {
747                 $$ = get_grouping_req (*$2); delete $2;
748         }
749         ;
750
751 post_requests:
752         {
753                 assert (THIS->post_reqs.empty ());
754         }
755         | post_requests structured_post_request {
756                 $2->set_spot (THIS->here_input ());
757                 THIS->post_reqs.push ($2);
758         }
759         | post_requests close_request_parens    {
760                 Array<Request*>& r = *THIS->get_parens_request ($2);
761                 for (int i = 0; i < r.size (); i++ )
762                         r[i]->set_spot (THIS->here_input ());
763                 THIS->post_reqs.concat (r);
764                 delete &r;
765         }
766         ;
767
768 structured_post_request:
769         script_req
770         | post_request
771         ;
772
773 post_request:
774         POST_REQUEST_IDENTIFIER {
775                 $$ = (Request*)$1->request ();
776         }
777         | dynamic_req {
778                 $$ = $1;
779         }
780         | abbrev_type   {
781                 Abbreviation_req* a = new Abbreviation_req;
782                 a->type_i_ = $1;
783                 $$ = a;
784         }
785         ;
786
787
788
789 /*
790         URG!!
791 */
792 steno_melodic_req:
793         NOTENAME_ID     {
794                 $$ = $1->clone ()->musical ()->melodic ();
795                 $$->octave_i_ += THIS->default_octave_i_;
796         }
797         | steno_melodic_req POST_QUOTES         {
798                 $$-> octave_i_ += $2;
799         }
800         | PRE_QUOTES steno_melodic_req   {
801                 $$ = $2;
802                 $2-> octave_i_ -= $1;
803         }
804         ;
805
806 steno_note_req:
807         steno_melodic_req       {
808                 $$ = new Note_req;
809                 * (Melodic_req *) $$ = *$1;
810                 delete $1;
811         }
812         | steno_note_req   '!'          {
813                 $$->forceacc_b_ = ! $$->forceacc_b_;
814         }
815         /* have to duration here. */
816         ;
817
818 melodic_request:
819         MELODIC_REQUEST '{' int int int '}'     {/* ugh */
820                 $$ = new Melodic_req;
821                 $$->octave_i_ = $3;
822                 $$->notename_i_ = $4;
823                 $$->accidental_i_ = $5;
824         }
825         ;
826
827 explicit_duration:
828         DURATION '{' int unsigned '}'   {
829                 $$ = new Duration;
830                 $$-> durlog_i_ = $3;
831                 $$-> dots_i_ = $4;
832         }
833         ;
834
835 dynamic_req:
836         ABSDYNAMIC '{' unsigned '}'     {
837                 Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
838                 ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
839                 $$ =ad_p;
840         }
841         | SPANDYNAMIC '{' int int '}' {
842                 Span_dynamic_req * sp_p = new Span_dynamic_req;
843                 sp_p->spantype = $4;
844                 sp_p-> dynamic_dir_  = $3;
845                 $$ = sp_p;
846         }
847         ;
848
849 close_plet_parens:
850         ']' unsigned '/' unsigned {
851                 $$ = MAEBTELP;
852                 THIS->plet_.type_i_ = $4;
853                 THIS->plet_.iso_i_ = $2;
854                 THIS->default_duration_.plet_.type_i_ = $4;
855                 THIS->default_duration_.plet_.iso_i_ = $2;
856         }
857         | TELP {
858                 $$ = TELP;
859                 THIS->plet_.type_i_ = 1;
860                 THIS->plet_.iso_i_ = 1;
861                 THIS->default_duration_.plet_.iso_i_ = 1;
862                 THIS->default_duration_.plet_.type_i_ = 1;
863         }
864         | TELP unsigned '/' unsigned {
865                 $$ = TELP;
866                 THIS->plet_.type_i_ = $4;
867                 THIS->plet_.iso_i_ = $2;
868                 THIS->default_duration_.plet_.type_i_ = $4;
869                 THIS->default_duration_.plet_.iso_i_ = $2;
870         }
871         ;
872
873 close_request_parens:
874         '~'     {
875                 $$ = '~';
876         }
877         | '('   {
878                 $$='(';
879         }
880         | ']'   {
881                 $$ = ']';
882         }
883         | E_SMALLER {
884                 $$ = '<';
885         }
886         | E_BIGGER {
887                 $$ = '>';
888         }
889         | close_plet_parens {
890         }
891         ;
892
893 open_abbrev_parens:
894         '[' ':' unsigned {
895                 $$ = '[';
896                 if (!Duration::duration_type_b ($3))
897                         THIS->parser_error ("1:Not a duration");
898                 else if ($3 < 8)
899                         THIS->parser_error ("Can't abbreviate");
900                 else
901                         THIS->set_abbrev_beam ($3);
902         }
903         ;
904
905 open_plet_parens:
906         '[' unsigned '/' unsigned {
907                 $$ = BEAMPLET;
908                 THIS->plet_.type_i_ = $4;
909                 THIS->plet_.iso_i_ = $2;
910                 THIS->default_duration_.plet_.type_i_ = $4;
911                 THIS->default_duration_.plet_.iso_i_ = $2;
912         }
913         | PLET unsigned '/' unsigned {
914                 $$ = PLET;
915                 THIS->plet_.type_i_ = $4;
916                 THIS->plet_.iso_i_ = $2;
917                 THIS->default_duration_.plet_.type_i_ = $4;
918                 THIS->default_duration_.plet_.iso_i_ = $2;
919         }
920         ;
921
922 open_request_parens:
923         E_EXCLAMATION   {
924                 $$ = '!';
925         }
926         | ')'   {
927                 $$=')';
928         }
929         | '['   {
930                 $$='[';
931         }
932         | open_abbrev_parens {
933         }
934         | open_plet_parens {
935         }
936         ;
937
938
939
940 script_definition:
941         SCRIPT '{' script_body '}'      { $$ = $3; }
942         ;
943
944 script_body:
945         STRING int int int int int              {
946                 Script_def *s = new Script_def;
947                 s->set_from_input (*$1,$2, $3,$4,$5, $6);
948                 $$  = s;
949                 delete $1;
950         }
951         ;
952
953 script_req:
954         script_dir gen_script_def       {
955                 Musical_script_req *m = new Musical_script_req;
956                 $$ = m;
957                 m->scriptdef_p_ = $2;
958                 m->set_spot (THIS->here_input ());
959                 if (!m->dir_)
960                   m->dir_  = $1;
961         }
962         ;
963
964 gen_script_def:
965         text_def        { 
966                 $$ = $1;
967                 ((Text_def*) $$)->align_i_ = CENTER; /* UGH */
968         }
969         | mudela_script { 
970                 $$ = $1;
971                 $$-> set_spot (THIS->here_input ());
972         }
973         | finger {
974                 $$ = $1;
975                 ((Text_def*)$$)->align_i_ = CENTER;
976         }
977         ;
978
979 text_def:
980         STRING {
981                 Text_def *t  = new Text_def;
982                 $$ = t;
983                 t->text_str_ = *$1;
984                 delete $1;
985                 t->style_str_ = THIS->textstyle_str_;
986                 $$->set_spot (THIS->here_input ());
987         }
988         ;
989
990 finger:
991          DIGIT {
992                 Text_def* t  = new Text_def;
993                 $$ = t;
994                 t->text_str_ = String ($1);
995                 t->style_str_ = "finger";
996                 $$->set_spot (THIS->here_input ());
997         }
998         ;
999
1000 script_abbreviation:
1001         '^'             { $$ = get_scriptdef ('^'); }
1002         | '+'           { $$ = get_scriptdef ('+'); }
1003         | '-'           { $$ = get_scriptdef ('-'); }
1004         | '|'           { $$ = get_scriptdef ('|'); }
1005         | 'o'           { $$ = get_scriptdef ('o'); }
1006         | '>'           { $$ = get_scriptdef ('>'); }
1007         | '.'           {
1008                 $$ = get_scriptdef ('.');
1009         }
1010         ;
1011
1012 mudela_script:
1013         SCRIPT_IDENTIFIER               { $$ = $1->script (); }
1014         | script_definition             { $$ = $1; }
1015         | script_abbreviation           {
1016                 $$ = THIS->lexer_p_->lookup_identifier (*$1)->script ();
1017                 delete $1;
1018         }
1019         ;
1020
1021 script_dir:
1022         '_'     { $$ = -1; }
1023         | '^'   { $$ = 1; }
1024         | '-'   { $$ = 0; }
1025         ;
1026
1027 pre_requests:
1028         {
1029         }
1030         | pre_requests open_request_parens {
1031                 Array<Request*>& r = *THIS->get_parens_request ($2);
1032                 for (int i = 0; i < r.size (); i++ )
1033                         r[i]->set_spot (THIS->here_input ());
1034                 THIS->pre_reqs.concat (r);
1035                 delete &r;
1036         }
1037         ;
1038
1039 voice_command:
1040         DURATION STRING {
1041                 THIS->set_duration_mode (*$2);
1042                 delete $2;
1043         }
1044         | DURATION entered_notemode_duration {
1045                 THIS->set_default_duration ($2);
1046                 delete $2;
1047         }
1048         | OCTAVE {
1049                 /*
1050                         This is weird, but default_octave_i_
1051                         is used in steno_note_req too
1052
1053                         c' -> default_octave_i_ == 1
1054                 */
1055                 /* why can't we have \oct 0 iso \oct{c'}*/
1056                 THIS->default_octave_i_ = 1; }
1057 /* cont */
1058         steno_melodic_req {
1059                 THIS->default_octave_i_ = $3->octave_i_;
1060                 delete $3;
1061         }
1062         | TEXTSTYLE STRING      {
1063                 THIS->textstyle_str_ = *$2;
1064                 delete $2;
1065         }
1066         ;
1067
1068 duration_length:
1069         {
1070                 $$ = new Moment (0,1);
1071         }
1072         | duration_length explicit_steno_duration               {
1073                 *$$ += $2->length ();
1074         }
1075         ;
1076
1077 dots:
1078         '.'             { $$ = 1; }
1079         | dots '.'      { $$ ++; }
1080         ;
1081
1082 entered_notemode_duration:
1083         /* */           {
1084                 $$ = new Duration (THIS->default_duration_);
1085         }
1086         | dots          {
1087                 $$ = new Duration (THIS->default_duration_);
1088                 $$->dots_i_  = $1;
1089         }
1090         | explicit_steno_duration       {
1091                 THIS->set_last_duration ($1);
1092                 $$ = $1;
1093         }
1094         ;
1095
1096 notemode_duration:
1097         entered_notemode_duration {
1098                 $$ = $1;
1099         }
1100         ;
1101
1102 explicit_steno_duration:
1103         unsigned                {
1104                 $$ = new Duration;
1105                 if (!Duration::duration_type_b ($1))
1106                         THIS->parser_error ("2:Not a duration");
1107                 else {
1108                         $$->durlog_i_ = Duration_convert::i2_type ($1);
1109                         $$->set_plet (THIS->default_duration_);
1110                      }
1111         }
1112         | DURATION_IDENTIFIER   {
1113                 $$ = $1->duration ();
1114         }
1115         | explicit_steno_duration '.'   {
1116                 $$->dots_i_ ++;
1117         }
1118         | explicit_steno_duration '*' unsigned  {
1119                 $$->plet_.iso_i_ = $3;
1120         }
1121         | explicit_steno_duration '/' unsigned {
1122                 $$->plet_.type_i_ = $3;
1123         }
1124         ;
1125
1126
1127 abbrev_type: 
1128         ':'     {
1129                 $$ =0;
1130         }
1131         | ':' unsigned {
1132                 if (!Duration::duration_type_b ($2))
1133                         THIS->parser_error ("3:Not a duration");
1134                 else if ($2 < 8)
1135                         THIS->parser_error ("Can't abbreviate");
1136                 $$ = $2;
1137         }
1138
1139         ;
1140
1141 music_elt:
1142         steno_note_req notemode_duration  {
1143                 if (!THIS->lexer_p_->note_state_b ())
1144                         THIS->parser_error ("have to be in Note mode for notes");
1145                 $1->set_duration (*$2);
1146                 int durlog_i = $2->durlog_i_;
1147                 $$ = THIS->get_note_element ($1, $2);
1148         }
1149         | RESTNAME notemode_duration            {
1150                 $$ = THIS->get_rest_element (*$1, $2);
1151                 delete $1;
1152         }
1153         ;
1154
1155 lyrics_elt:
1156         text_def notemode_duration                      {
1157         /* this sux! text-def should be feature of lyric-engraver. */
1158                 if (!THIS->lexer_p_->lyric_state_b ())
1159                         THIS->parser_error ("Have to be in Lyric mode for lyrics");
1160                 $$ = THIS->get_word_element ($1, $2);
1161
1162         };
1163
1164 /*
1165         UTILITIES
1166  */
1167 pitch_list:                     {
1168                 $$ = new Array<Melodic_req*>;
1169         }
1170         | pitch_list NOTENAME_ID        {
1171                 $$->push ($2->clone ()->musical ()->melodic ());
1172         }
1173         ;
1174
1175 unsigned:
1176         UNSIGNED        {
1177                 $$ = $1;
1178         }
1179         | DIGIT {
1180                 $$ = $1;
1181         };
1182
1183 int:
1184         unsigned {
1185                 $$ = $1;
1186         }
1187         | '-' unsigned {
1188                 $$ = -$2;
1189         }
1190         | INT_IDENTIFIER        {
1191                 int *i_p = $1->intid ();
1192                 $$ = *i_p;
1193                 delete i_p;
1194         }
1195         ;
1196
1197 real:
1198         REAL            {
1199                 $$ = $1;
1200         }
1201         | REAL_IDENTIFIER               {
1202                 Real *r_p = $1->real ();
1203                 $$ = * r_p;
1204                 delete r_p;
1205         }
1206         ;
1207
1208
1209
1210 dim:
1211         real unit       { $$ = $1*$2; }
1212         ;
1213
1214
1215 unit:   CM_T            { $$ = 1 CM; }
1216         |IN_T           { $$ = 1 INCH; }
1217         |MM_T           { $$ = 1 MM; }
1218         |PT_T           { $$ = 1 PT; }
1219         ;
1220
1221 /*
1222         symbol tables
1223 */
1224 symtables:
1225         SYMBOLTABLES '{' symtables_body '}'     { $$ = $3; }
1226         ;
1227
1228 symtables_body:
1229                         {
1230                 $$ = new Lookup;
1231         }
1232         | IDENTIFIER            {
1233                 $$ = $1->lookup ();
1234         }
1235         | symtables_body TEXID STRING           {
1236                 $$->texsetting = *$3;
1237                 delete $3;
1238         }
1239         | symtables_body STRING '=' symtable            {
1240                 $$->add (*$2, $4);
1241                 delete $2;
1242         }
1243         ;
1244
1245 symtable:
1246         TABLE '{' symtable_body '}' { $$ = $3; }
1247         ;
1248
1249 symtable_body:
1250                                 { $$ = new Symtable; }
1251         | symtable_body STRING  symboldef {
1252                 $$->add (*$2, *$3);
1253                 delete $2;
1254                 delete $3;
1255         }
1256         ;
1257
1258 symboldef:
1259         STRING  box             {
1260                 $$ = new Atom (*$1, *$2);
1261                 delete $1;
1262                 delete $2;
1263         }
1264         | STRING {
1265                 Box b (Interval (0,0), Interval (0,0));
1266                 $$ = new Atom (*$1, b);
1267                 delete $1;
1268         }
1269         ;
1270
1271 box:
1272         dinterval dinterval     {
1273                 $$ = new Box (*$1, *$2);
1274                 delete $1;
1275                 delete $2;
1276         }
1277         ;
1278
1279 dinterval: dim  dim             {
1280                 $$ = new Interval ($1, $2);
1281         }
1282         ;
1283
1284 %%
1285
1286 void
1287 My_lily_parser::set_yydebug (bool b)
1288 {
1289 #ifdef YYDEBUG
1290         yydebug = b;
1291 #endif
1292 }
1293 void
1294 My_lily_parser::do_yyparse ()
1295 {
1296         yyparse ((void*)this);
1297 }
1298
1299 Paper_def*
1300 My_lily_parser::default_paper ()
1301 {
1302         Identifier *id = lexer_p_->lookup_identifier ("default_paper");
1303         return id ? id->paperdef () : new Paper_def ;
1304 }
1305
1306 Midi_def*
1307 My_lily_parser::default_midi ()
1308 {
1309         Identifier *id = lexer_p_->lookup_identifier ("default_midi");
1310         return id ? id->mididef () : new Midi_def ;
1311 }
1312