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