]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/parser.yy
release: 1.5.4
[lilypond.git] / lily / parser.yy
index 043a658fcff27c91f8719b7514afa3a2c80a6e8d..b9f4793d2c50450cad3c7c9bd15b1d567ff385f2 100644 (file)
@@ -8,6 +8,13 @@
   (c)  1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
            Jan Nieuwenhuizen <janneke@gnu.org>
 */
+
+/*
+  Two shift/reduce problems:
+    -
+    -
+ */
+
 #include <ctype.h>
 #include <iostream.h>
 
@@ -181,7 +188,7 @@ yylex (YYSTYPE *s,  void * v_l)
 %token EXTENDER
 %token FONT
 %token GLISSANDO
-%token GRACE
+%token GRACE NGRACE
 %token HEADER
 %token HYPHEN
 %token IN_T
@@ -329,7 +336,7 @@ toplevel_expression:
        }
        | lilypond_header {
                if (global_header_p)
-                       scm_unprotect_object (global_header_p->self_scm ());
+                       scm_gc_unprotect_object (global_header_p->self_scm ());
                global_header_p = $1;
        }
        | score_block {
@@ -433,22 +440,22 @@ all objects can be unprotected as soon as they're here.
 identifier_init:
        score_block {
                $$ = $1->self_scm ();
-               scm_unprotect_object ($$);
+               scm_gc_unprotect_object ($$);
        }
        | output_def {
                $$ = $1->self_scm ();
-               scm_unprotect_object ($$);
+               scm_gc_unprotect_object ($$);
        }
        | translator_spec_block {
                $$ = $1;
        }
        | Music  {
                $$ = $1->self_scm ();
-               scm_unprotect_object ($$);
+               scm_gc_unprotect_object ($$);
        }
        | post_request {
                $$ = $1->self_scm ();
-               scm_unprotect_object ($$);
+               scm_gc_unprotect_object ($$);
        }
        | explicit_duration {
                $$ = $1;
@@ -548,7 +555,7 @@ score_body:
        
                $$->set_spot (THIS->here_input ());
                SCM m = $1->self_scm ();
-               scm_unprotect_object (m);
+               scm_gc_unprotect_object (m);
                $$->music_ = m;
        }
        | SCORE_IDENTIFIER {
@@ -556,7 +563,7 @@ score_body:
                $$->set_spot (THIS->here_input ());
        }
        | score_body lilypond_header    {
-               scm_unprotect_object ($2->self_scm ()); 
+               scm_gc_unprotect_object ($2->self_scm ()); 
                $$->header_p_ = $2;
        }
        | score_body output_def {
@@ -652,7 +659,7 @@ Music_list: /* empty */ {
        | Music_list Music {
                SCM s = $$;
                SCM c = gh_cons ($2->self_scm (), SCM_EOL);
-               scm_unprotect_object ($2->self_scm ()); /* UGH */
+               scm_gc_unprotect_object ($2->self_scm ()); /* UGH */
                if (gh_pair_p (gh_cdr (s)))
                        gh_set_cdr_x (gh_cdr (s), c); /* append */
                else
@@ -696,7 +703,7 @@ Repeated_music:
                if (beg)
                        {
                        r-> set_mus_property ("body", beg->self_scm ());
-                       scm_unprotect_object (beg->self_scm ());
+                       scm_gc_unprotect_object (beg->self_scm ());
                        }
                r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
 
@@ -704,9 +711,9 @@ Repeated_music:
                        {
                        alts->truncate (times);
                        r-> set_mus_property ("alternatives", alts->self_scm ());
-                       scm_unprotect_object (alts->self_scm ());  
+                       scm_gc_unprotect_object (alts->self_scm ());  
                        }
-               SCM func = scm_eval2 (ly_symbol2scm ("repeat-name-to-ctor"), SCM_EOL);
+               SCM func = scm_primitive_eval (ly_symbol2scm ("repeat-name-to-ctor"));
                SCM result = gh_call1 (func, $2);
 
                set_music_properties (r, result);
@@ -780,7 +787,7 @@ Composite_music:
        CONTEXT STRING Music    {
                Context_specced_music *csm =  new Context_specced_music (SCM_EOL);
                csm->set_mus_property ("element", $3->self_scm ());
-               scm_unprotect_object ($3->self_scm ());
+               scm_gc_unprotect_object ($3->self_scm ());
 
                csm->set_mus_property ("context-type",$2);
                csm->set_mus_property ("context-id", ly_str02scm (""));
@@ -792,22 +799,56 @@ Composite_music:
                chm->set_mus_property ("element", $3->self_scm ());
                chm->set_mus_property ("iterator-ctor", Auto_change_iterator::constructor_cxx_function);
 
-               scm_unprotect_object ($3->self_scm ());
+               scm_gc_unprotect_object ($3->self_scm ());
                chm->set_mus_property ("what", $2); 
 
                $$ = chm;
                chm->set_spot (*$3->origin ());
        }
        | GRACE Music {
+#if 0
+       /*
+               The other version is for easier debugging  of
+               Sequential_music_iterator in combination with grace notes.
+       */
+
+               SCM start = THIS->lexer_p_->lookup_identifier ("startGraceMusic");
+               SCM stop = THIS->lexer_p_->lookup_identifier ("stopGraceMusic");
+               Music *startm = unsmob_music (start);
+               Music *stopm = unsmob_music (stop);
+
+               SCM ms = SCM_EOL;
+               if (stopm) {
+                       stopm = stopm->clone ();
+                       ms = gh_cons (stopm->self_scm (), ms);
+                       scm_gc_unprotect_object (stopm->self_scm ());
+               }
+               ms = gh_cons ($2->self_scm (), ms);
+               scm_gc_unprotect_object ($2->self_scm());
+               if (startm) {
+                       startm = startm->clone ();
+                       ms = gh_cons (startm->self_scm () , ms);
+                       scm_gc_unprotect_object (startm->self_scm ());
+               }
+
+               Music* seq = new Sequential_music (SCM_EOL);
+               seq->set_mus_property ("elements", ms);
+
+               $$ = new Grace_music (SCM_EOL);
+               $$->set_mus_property ("element", seq->self_scm ());
+               scm_gc_unprotect_object (seq->self_scm ());
+#else
                $$ = new Grace_music (SCM_EOL);
                $$->set_mus_property ("element", $2->self_scm ());
-               scm_unprotect_object ($2->self_scm ());
+               scm_gc_unprotect_object ($2->self_scm ());
+#endif
+
 
        }
        | CONTEXT string '=' string Music {
                Context_specced_music *csm =  new Context_specced_music (SCM_EOL);
                csm->set_mus_property ("element", $5->self_scm ());
-               scm_unprotect_object ($5->self_scm ());
+               scm_gc_unprotect_object ($5->self_scm ());
 
                csm->set_mus_property ("context-type", $2);
                csm->set_mus_property ("context-id", $4);
@@ -828,7 +869,7 @@ Composite_music:
 
 
                $$->set_mus_property ("element", mp->self_scm ());
-               scm_unprotect_object (mp->self_scm ());
+               scm_gc_unprotect_object (mp->self_scm ());
                $$->set_mus_property ("numerator", gh_int2scm (n));
                $$->set_mus_property ("denominator", gh_int2scm (d));
                $$->compress (Moment (n,d));
@@ -844,7 +885,7 @@ Composite_music:
 
                p->transpose (pit);
                $$->set_mus_property ("element", p->self_scm ());
-               scm_unprotect_object (p->self_scm ());
+               scm_gc_unprotect_object (p->self_scm ());
        }
        | TRANSPOSE steno_tonic_pitch Music {
                $$ = new Transposed_music (SCM_EOL);
@@ -853,7 +894,7 @@ Composite_music:
 
                p->transpose (pit);
                $$->set_mus_property ("element", p->self_scm ());
-               scm_unprotect_object (p->self_scm ());
+               scm_gc_unprotect_object (p->self_scm ());
        
        }
        | APPLY embedded_scm Music  {
@@ -900,7 +941,7 @@ relative_music:
                $$ = new Relative_octave_music (SCM_EOL);
 
                $$->set_mus_property ("element", p->self_scm ());
-               scm_unprotect_object (p->self_scm ());
+               scm_gc_unprotect_object (p->self_scm ());
 
                $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
 
@@ -912,8 +953,8 @@ re_rhythmed_music:
          Lyric_combine_music * l = new Lyric_combine_music (SCM_EOL);
          l->set_mus_property ("music", $2->self_scm ());
          l->set_mus_property ("lyrics", $3->self_scm ());
-         scm_unprotect_object ($3->self_scm ());
-         scm_unprotect_object ($2->self_scm ());
+         scm_gc_unprotect_object ($3->self_scm ());
+         scm_gc_unprotect_object ($2->self_scm ());
          $$ = l;
        }
        ;
@@ -926,8 +967,8 @@ part_combined_music:
                p->set_mus_property ("one", $3->self_scm ());
                p->set_mus_property ("two", $4->self_scm ());  
 
-               scm_unprotect_object ($3->self_scm ());
-               scm_unprotect_object ($4->self_scm ());  
+               scm_gc_unprotect_object ($3->self_scm ());
+               scm_gc_unprotect_object ($4->self_scm ());  
 
 
                $$ = p;
@@ -954,7 +995,7 @@ property_def:
                Context_specced_music *csm = new Context_specced_music (SCM_EOL);
 
                csm->set_mus_property ("element", t->self_scm ());
-               scm_unprotect_object (t->self_scm ());
+               scm_gc_unprotect_object (t->self_scm ());
 
                $$ = csm;
                $$->set_spot (THIS->here_input ());
@@ -970,7 +1011,7 @@ property_def:
 
                Context_specced_music *csm = new Context_specced_music (SCM_EOL);
                csm->set_mus_property ("element", t->self_scm ());
-               scm_unprotect_object (t->self_scm ());
+               scm_gc_unprotect_object (t->self_scm ());
 
                $$ = csm;
                $$->set_spot (THIS->here_input ());
@@ -987,7 +1028,7 @@ property_def:
                t->set_mus_property ("grob-value", $8);
                Context_specced_music *csm = new Context_specced_music (SCM_EOL);
                csm->set_mus_property ("element", t->self_scm ());
-               scm_unprotect_object (t->self_scm ());
+               scm_gc_unprotect_object (t->self_scm ());
                $$ = csm;
                $$->set_spot (THIS->here_input ());
 
@@ -1002,7 +1043,7 @@ property_def:
                t->set_mus_property ("grob-value", $8);
                Context_specced_music *csm = new Context_specced_music (SCM_EOL);
                csm->set_mus_property ("element", t->self_scm ());
-               scm_unprotect_object (t->self_scm ());
+               scm_gc_unprotect_object (t->self_scm ());
 
                $$ = csm;
                $$->set_spot (THIS->here_input ());
@@ -1018,7 +1059,7 @@ property_def:
 
                Context_specced_music *csm = new Context_specced_music (SCM_EOL);
                csm->set_mus_property ("element", t->self_scm ());
-               scm_unprotect_object (t->self_scm ());
+               scm_gc_unprotect_object (t->self_scm ());
 
                $$ = csm;
                $$->set_spot (THIS->here_input ());
@@ -1063,7 +1104,7 @@ command_element:
 
                Context_specced_music *csm = new Context_specced_music (SCM_EOL);
                csm->set_mus_property ("element", t->self_scm ());
-               scm_unprotect_object (t->self_scm ());
+               scm_gc_unprotect_object (t->self_scm ());
 
                $$ = csm;
                $$->set_spot (THIS->here_input ());
@@ -1076,13 +1117,13 @@ command_element:
 
                Context_specced_music * sp = new Context_specced_music (SCM_EOL);
                sp->set_mus_property ("element", p->self_scm ());
-               scm_unprotect_object (p->self_scm ());
+               scm_gc_unprotect_object (p->self_scm ());
 
                $$ =sp ;
                sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
        }
        | CLEF STRING  {
-               SCM func = scm_eval2 (ly_symbol2scm ("clef-name-to-properties"), SCM_EOL);
+               SCM func = scm_primitive_eval (ly_symbol2scm ("clef-name-to-properties"));
                SCM result = gh_call1 (func, $2);
 
                SCM l = SCM_EOL;
@@ -1090,14 +1131,14 @@ command_element:
                        Music * p = new Music (SCM_EOL);
                        set_music_properties (p, gh_car (s));
                        l = gh_cons (p->self_scm (), l);
-                       scm_unprotect_object (p->self_scm ());
+                       scm_gc_unprotect_object (p->self_scm ());
                }
                Sequential_music * seq = new Sequential_music (SCM_EOL);
                seq->set_mus_property ("elements", l);
 
                Context_specced_music * sp = new Context_specced_music (SCM_EOL);
                sp->set_mus_property ("element", seq->self_scm ());
-               scm_unprotect_object (seq->self_scm ());
+               scm_gc_unprotect_object (seq->self_scm ());
 
                $$ =sp ;
                sp-> set_mus_property ("context-type", ly_str02scm ("Staff"));
@@ -1125,10 +1166,10 @@ command_element:
 
                
 
-               scm_unprotect_object (p3->self_scm ());
-               scm_unprotect_object (p2->self_scm ());
-               scm_unprotect_object (p1->self_scm ());
-               scm_unprotect_object (seq->self_scm ());
+               scm_gc_unprotect_object (p3->self_scm ());
+               scm_gc_unprotect_object (p2->self_scm ());
+               scm_gc_unprotect_object (p1->self_scm ());
+               scm_gc_unprotect_object (seq->self_scm ());
 
                $$ = sp;
 
@@ -1593,11 +1634,11 @@ multiplied_duration:
        steno_duration {
                $$ = $1;
        }
-       | steno_duration '*' bare_unsigned {
+       | multiplied_duration '*' bare_unsigned {
                $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
        }
-       | steno_duration '*' FRACTION {
-               Moment m (gh_scm2int (gh_car ($3)), gh_scm2int (gh_cdr ($3)));
+       | multiplied_duration '*' FRACTION {
+               Rational  m (gh_scm2int (gh_car ($3)), gh_scm2int (gh_cdr ($3)));
 
                $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
        }
@@ -1784,10 +1825,11 @@ chord_step:
                $$ = gh_cons ($1, SCM_EOL);
        }
        | CHORDMODIFIER_PITCH {
-               $$ = gh_cons ($1, SCM_EOL);
+               $$ = gh_cons (unsmob_pitch ($1)->smobbed_copy (), SCM_EOL);
        }
        | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
-               $$ = gh_list ($1, $2, SCM_UNDEFINED);
+               $$ = gh_list (unsmob_pitch ($1)->smobbed_copy (),
+                       $2, SCM_UNDEFINED);
        }
        ;
 
@@ -1918,7 +1960,7 @@ string:
                $$ = $1;
        }
        | string '+' string {
-               $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
+               $$ = scm_string_append (scm_list_n ($1, $3, SCM_UNDEFINED));
        }
        ;