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