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