]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/parser.yy
release: 1.0.10
[lilypond.git] / lily / parser.yy
index 86b67fb02d904679674127a96b16f3e5e681ac62..067eed8e65b4504944083769ac156ad5d8243deb 100644 (file)
@@ -10,7 +10,7 @@
 */
 
 #include <iostream.h>
-
+#include "notename-table.hh"
 #include "scalar.hh"
 #include "translation-property.hh"
 #include "script-def.hh"
@@ -44,8 +44,8 @@
 
 
 // mmm
-Mudela_version oldest_version ("1.0.1");
-Mudela_version version ("1.0.1");
+Mudela_version oldest_version ("1.0.3");
+Mudela_version version ("1.0.4");
 
 
 // needed for bison.simple's malloc() and free()
@@ -74,6 +74,8 @@ Paper_def* current_paper = 0;
 #define THIS ((My_lily_parser *) my_lily_parser_l)
 
 #define yyerror THIS->parser_error
+#define ARRAY_SIZE(a,s)   if (a.size () != s) THIS->parser_error (_f("expecting %d arguments", s))
+
 
 %}
 
@@ -84,12 +86,12 @@ Paper_def* current_paper = 0;
     Array<String> * strvec;
     Array<int> *intvec;
     Box *box;
-    Chord * chord;
+    Simultaneous_music *chord;
     Duration *duration;
     Identifier *id;
     Translator* trans;
     Music *music;
-    Music_list *musiclist;
+    Music_list *music_list;
     Score *score;
     Header *header;
     Interval *interval;
@@ -101,6 +103,7 @@ Paper_def* current_paper = 0;
     Midi_def* midi;
     Moment *moment;
     Note_req *notereq;
+    Notename_table *notenametab;
     Paper_def *paper;
     Real real;
     Request * request;
@@ -137,61 +140,54 @@ yylex (YYSTYPE *s,  void * v_l)
 
 /* tokens which are not keywords */
 
-%token ALIAS
+%token ABSDYNAMIC
+%token ACCEPTS
 %token BAR
 %token BEAMPLET
-%token MAEBTELP
-%token PENALTY
 %token CADENZA
-%token CLEAR
 %token CLEF
-%token CONTAINS
-%token RELATIVE
-%token CONSISTS
-%token ACCEPTS
 %token CM_T
+%token CONSISTS
 %token DURATION
-%token ABSDYNAMIC
 %token END
+%token FONT
 %token GROUPING
-%token TRANSLATOR
 %token HEADER
 %token IN_T
-%token LYRIC
 %token KEY
 %token KEYSIGNATURE
+%token LYRIC
+%token MAEBTELP
 %token MARK
-%token MUSIC
-%token MUSICAL_PITCH
-%token MELODIC
+%token MEASURES
 %token MIDI
-%token TIME_T
 %token MM_T
-%token MULTI
+%token MUSIC
+%token MUSICAL_PITCH
 %token NOTENAMES
+%token NOTES
 %token OCTAVE
 %token OUTPUT
 %token PAPER
 %token PARTIAL
+%token PENALTY
 %token PLET
-%token TELP
+%token PROPERTY
 %token PT_T
+%token RELATIVE
 %token SCORE
 %token SCRIPT
 %token SHAPE
 %token SKIP
 %token SPANDYNAMIC
-%token STAFF
-%token START_T
 %token SYMBOLTABLES
 %token TABLE
-%token TRANSPOSE
+%token TELP
 %token TEMPO
+%token TIME_T
+%token TRANSLATOR
+%token TRANSPOSE
 %token TYPE
-%token FONT
-%token MEASURES
-%token TITLE
-%token PROPERTY
 %token VERSION
 
 /* escaped */
@@ -202,9 +198,8 @@ yylex (YYSTYPE *s,  void * v_l)
 %token <pitch> NOTENAME_PITCH
 %token <id>    DURATION_IDENTIFIER
 %token <id>    IDENTIFIER
-
+%token <id>    NOTENAME_TABLE_IDENTIFIER
 %token <id>    MUSIC_IDENTIFIER
-%token <id>    VOICE_IDENTIFIER
 %token <id>    POST_REQUEST_IDENTIFIER
 %token <id>    SCRIPT_IDENTIFIER
 %token <id>    COMMAND_IDENTIFIER
@@ -237,7 +232,7 @@ yylex (YYSTYPE *s,  void * v_l)
 %type <duration> steno_duration notemode_duration
 %type <duration> entered_notemode_duration explicit_duration
 %type <interval>       dinterval
-%type <intvec> intastint_list
+%type <intvec> intastint_list int_list
 %type <lookup> symtables symtables_body
 
 %type <pitch>   explicit_musical_pitch steno_musical_pitch musical_pitch absolute_musical_pitch
@@ -247,10 +242,9 @@ yylex (YYSTYPE *s,  void * v_l)
 %type <duration>       duration_length
 
 %type <scalar>  scalar
-%type <music>  Music transposed_music relative_music
+%type <music>  Music  relative_music Sequential_music Simultaneous_music
 %type <music>  property_def translator_change
-%type <musiclist> Voice Voice_body
-%type <chord>  Chord Chord_body
+%type <music_list> Music_list
 %type <paper>  paper_block paper_body
 %type <real>   dim real
 %type <real>   real_mult_expression real_primary
@@ -271,25 +265,40 @@ yylex (YYSTYPE *s,  void * v_l)
 %type <symtable>       symtable symtable_body
 %type <trans>  translator_spec translator_spec_body
 %type <tempo>  tempo_request
-%type <string> concat_strings
-
+%type <notenametab> notenames_body notenames_block
 %expect 1
 
 
 %%
 
 mudela:        /* empty */
-       | mudela mudela_header {
-               delete header_global_p;
-               header_global_p = $2;
-       }
-       | mudela score_block {
-               score_global_array.push ($2);
-       }
+       | mudela toplevel_expression {}
        | mudela add_declaration { }
        | mudela error
        | mudela check_version { }
-       | mudela add_notenames { }
+       ;
+
+toplevel_expression:
+       notenames_block                 {
+               THIS->lexer_p_->set_notename_table ($1);
+       }
+       | mudela_header {
+               delete header_global_p;
+               header_global_p = $1;
+       }
+       | score_block {
+               score_global_array.push ($1);
+       }
+       | paper_block {
+               Identifier * id = new
+                       Paper_def_identifier ($1, PAPER_IDENTIFIER);
+               THIS->lexer_p_->set_identifier ("$defaultpaper", id)
+       }
+       | midi_block {
+               Identifier * id = new
+                       Midi_def_identifier ($1, MIDI_IDENTIFIER);
+               THIS->lexer_p_->set_identifier ("$defaultmidi", id)
+       }
        ;
 
 check_version:
@@ -306,17 +315,23 @@ check_version:
        }
        ;
 
-add_notenames:
-       NOTENAMES '{' notenames_body '}'
+
+notenames_block:
+       NOTENAMES '{' notenames_body '}'  {  $$ = $3; }
        ;
+
+
+
 notenames_body:
        /**/    {
+               $$ = new Notename_table;
        }
-       | notenames_body CLEAR  {
-               THIS->clear_notenames ();
+       | NOTENAME_TABLE_IDENTIFIER     {
+               $$ = $1-> access_Notename_table();
        }
        | notenames_body STRING '=' explicit_musical_pitch {
-               THIS->add_notename (*$2, *$4);
+               (*$$)[*$2] = *$4;
+
                delete $4;
                delete $2;
        }
@@ -326,7 +341,7 @@ mudela_header_body:
                {
                $$ = new Header;
        }
-       | mudela_header_body STRING '=' concat_strings ';' {
+       | mudela_header_body STRING '=' string ';' {
                (*$$)[*$2] = *$4;
                delete $2;
                delete $4;
@@ -340,19 +355,9 @@ mudela_header:
        ;
 
 
-concat_strings:
-               {
-               $$ = new String;
-       }
-       | concat_strings STRING {
-               *$$ += *$2;
-       }
-
-
 /*
        DECLARATIONS
 */
-
 add_declaration:
        STRING {
                THIS->remember_spot ();
@@ -369,6 +374,9 @@ identifier_init:
                $$ = new Score_identifier ($1, SCORE_IDENTIFIER);
 
        }
+       | notenames_block {
+               $$ = new Notename_table_identifier ($1, NOTENAME_TABLE_IDENTIFIER);
+       }
        | paper_block {
                $$ = new Paper_def_identifier ($1, PAPER_IDENTIFIER);
        }
@@ -429,10 +437,21 @@ translator_spec_body:
                $$ = t;
                delete $2;
        }
-       | translator_spec_body STRING '=' scalar ';'    { 
-               $$-> set_property (*$2, *$4);
-               delete $2;
+       | translator_spec_body STRING '=' simple_identifier_init ';'    { 
+               Identifier* id = $4;
+               String_identifier *s = id->access_String_identifier ();
+               Real_identifier *r= id->access_Real_identifier ();
+               int_identifier *i = id->access_int_identifier ();
+       
+               String str;
+               if (s) str = *s->access_String (false); 
+               if (i) str = to_str (*i->access_int (false));
+               if (r) str = to_str (*r->access_Real (false));
+               if (!s && !i && !r)
+                       THIS->parser_error (_("Wrong type for property value"));
+
                delete $4;
+               $$->set_property (*$2, str);
        }
        | translator_spec_body CONSISTS STRING ';' {
                $$->group_l ()->consists_str_arr_.push (*$3);
@@ -499,7 +518,10 @@ intastint_list:
        | intastint_list int '*' int    {
                $$->push ($2); $$->push ($4);
        }
-       ;
+       | intastint_list int    {
+               $$->push ($2); $$->push (1);
+       }
+       ;       
 
 
 /*
@@ -612,6 +634,9 @@ midi_block:
 midi_body: /* empty */                 {
                $$ = THIS->default_midi_p ();
        }
+       | MIDI_IDENTIFIER       {
+               $$ = $1-> access_Midi_def ();           
+       }
        | midi_body STRING '=' translator_spec  {
                $$-> assign_translator (*$2, $4);
                delete $2;
@@ -638,25 +663,26 @@ tempo_request:
        }
        ;
 
-Voice:
-       '{' Voice_body '}'      {
-               $$ = $2;
+Music_list: /* empty */ {
+               $$ = new Music_list;
        }
-       ;
-
-Voice_body:
-       /**/            {
-               $$ = new Voice;
-               $$->set_spot (THIS->here_input ());
+       | Music_list Music {
+               $$->add_music ($2);
        }
-       | Voice_body Music      {
-               $$->add ($2);
+       | Music_list error {
        }
-       | Voice_body error                      {
-               $$ = new Music_list;
+       ;
+
+
+Sequential_music: '{' Music_list '}'           {
+               $$ = new Sequential_music ($2);
        }
        ;
 
+Simultaneous_music: '<' Music_list '>' {
+               $$ = new Simultaneous_music ($2);
+       }
+       ;
 Music:
        request_chord           { $$ = $1; }
        | TYPE STRING Music     {
@@ -671,11 +697,15 @@ Music:
                delete $2;
                delete $4;
        }
-       | Voice         { $$ = $1; }
-       | Chord                 { $$ = $1; }
-       | transposed_music      { $$ = $1; }
+       | Simultaneous_music            { $$ = $1; }
+       | Sequential_music              { $$ = $1; }
+       | TRANSPOSE musical_pitch Music {
+               $$ = $3;
+               $$ -> transpose (*$2);
+               delete $2;
+       }
        | MUSIC_IDENTIFIER { $$ = $1->access_Music (); }
-       | MELODIC
+       | NOTES
                { THIS->lexer_p_->push_note_state (); }
        Music
                { $$ = $3;
@@ -734,39 +764,10 @@ scalar:
        ;
 
 
-Chord:
-       '<' Chord_body '>'      { $$  = $2; }
-       ;
-
-Chord_body:
-       /**/    {
-               $$ = new Chord;
-               $$-> multi_level_i_ = 0;
-               $$->set_spot (THIS->here_input ());
-       }
-       | Chord_body Music {
-               $$->add ($2);
-       }
-       | Chord_body error {
-               $$ = new Chord;
-       }
-       ;
-
-transposed_music:
-       TRANSPOSE musical_pitch Music {
-               $$ = $3;
-               $$ -> transpose (*$2);
-               delete $2;
-       }
-       ;
-
 
-/*
-       VOICE ELEMENTS
-*/
 request_chord:
        pre_requests simple_element post_requests       {
-               THIS->add_requests ((Chord*)$2);//ugh
+               THIS->add_requests ((Simultaneous_music*)$2);//ugh
                $$ = $2;
        }
        | command_element
@@ -780,7 +781,7 @@ command_element:
                $$ = new Request_chord;
                $$-> set_spot (THIS->here_input ());
                $1-> set_spot (THIS->here_input ());
-               ((Chord*)$$) ->add ($1);//ugh
+               ((Simultaneous_music*)$$) ->add_music ($1);//ugh
 
        }
        ;
@@ -897,13 +898,9 @@ post_request:
                $$ = $1;
        }
        | abbrev_type   {
-#if 1 // re-instating
                Abbreviation_req* a = new Abbreviation_req;
                a->type_i_ = $1;
                $$ = a;
-#else // and disabling just created ugly sticky abbrev_req
-               THIS->default_abbrev_i_ = $1;
-#endif
        }
        ;
 
@@ -927,28 +924,29 @@ sub_quotes:
 steno_musical_pitch:
        NOTENAME_PITCH  {
                $$ = $1;
-               // $$->octave_i_ += THIS->default_octave_i_;
        }
        | NOTENAME_PITCH sup_quotes     {
                $$ = $1;
-               // $$->octave_i_ += THIS->default_octave_i_ + $2;
                $$->octave_i_ +=  $2;
        }
        | NOTENAME_PITCH sub_quotes      {
                $$ = $1;
                $$->octave_i_ += - $2;
-               // $$->octave_i_ += THIS->default_octave_i_ - $2;
        }
        ;
 
 explicit_musical_pitch:
-       MUSICAL_PITCH '{' int int int '}'       {/* ugh */
+       MUSICAL_PITCH '{' int_list '}'  {/* ugh */
+               Array<int> &a = *$3;
+               ARRAY_SIZE(a,3);
                $$ = new Musical_pitch;
-               $$->octave_i_ = $3;
-               $$->notename_i_ = $4;
-               $$->accidental_i_ = $5;
+               $$->octave_i_ = a[0];
+               $$->notename_i_ = a[1];
+               $$->accidental_i_ = a[2];
+               delete &a;
        }
        ;
+
 musical_pitch:
        steno_musical_pitch
        | explicit_musical_pitch
@@ -968,10 +966,15 @@ steno_notepitch:
 
 
 explicit_duration:
-       DURATION '{' int unsigned '}'   {
+       DURATION '{' int_list '}'       {
                $$ = new Duration;
-               $$-> durlog_i_ = $3;
-               $$-> dots_i_ = $4;
+               Array<int> &a = *$3;
+               ARRAY_SIZE(a,2);
+                       
+               $$-> durlog_i_ = a[0];
+               $$-> dots_i_ = a[1];
+
+               delete &a;              
        }
        ;
 
@@ -1186,7 +1189,6 @@ pre_requests:
 absolute_musical_pitch:
        steno_musical_pitch     {
                $$ = $1;
-               // $$->octave_i_ -=  THIS->default_octave_i_;
        }
        ;
 
@@ -1277,9 +1279,9 @@ simple_element:
                m->duration_ = *$2;
                delete $2;
 
-               Chord*velt_p = new Request_chord;
+               Simultaneous_music*velt_p = new Request_chord;
                velt_p->set_spot (THIS->here_input ());
-               velt_p->add (m);
+               velt_p->add_music (m);
                $$ = velt_p;
 
        }
@@ -1304,6 +1306,16 @@ pitch_list:                      {
        }
        ;
 
+
+int_list:
+       /**/                    {
+               $$ = new Array<int>
+       }
+       | int_list int          {
+               $$->push ($2);          
+       }
+       ;
+
 unsigned:
        UNSIGNED        {
                $$ = $1;