]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.27
authorfred <fred>
Sun, 24 Mar 2002 19:30:19 +0000 (19:30 +0000)
committerfred <fred>
Sun, 24 Mar 2002 19:30:19 +0000 (19:30 +0000)
hdr/lexer.hh
src/lexer.l
src/lexerinit.cc
src/note.cc
src/parser.y
src/scores.cc

index 7cbbbe37475397003f976c3c75efe68f3637f80b..0617b9742cf6547ffbd31339801b0daf858a8865 100644 (file)
@@ -13,7 +13,8 @@ void kill_lexer();
 void set_lexer();
 
 struct Input_file {
-       istream*is;
+       istream* is;
+       Source_file* sourcefile_l_;
        int line;
        String name;
 
@@ -29,9 +30,11 @@ struct My_flex_lexer : yyFlexLexer {
     Assoc<String, Identifier*> *the_id_tab;
     Keyword_table * keytable;
     Notename_tab * defaulttab;
-
+    char const* data_ch_c_l_m;
+    int errorlevel_i_;
     /****************/
-    
+    int ret_notename(int *p, String text, int octave_mod);    
+    char const* here_ch_c_l();
     void set(Notename_tab *n);
     int lookup_keyword(String);
     void lookup_notename(int &large, int &small, String s);
index 4446661d8ef426de46d9b525b50f34c33050038a..00b4c70c159e012edeec94402bc9c4eb25329663 100644 (file)
@@ -8,6 +8,8 @@
 #include "varray.hh"
 #include "parser.hh"
 #include "debug.hh"
+#include "inputscore.hh"
+#include "main.hh"
 
 %}
 
@@ -44,7 +46,8 @@ OPTSIGN               !?
 PITCHMOD       ['`]*{OPTSIGN}
 RESTNAME       r|s|p
 NOTECOMMAND    \\{WORD}
-NOTENAME       {ALPHAWORD}
+NOTENAME       [a-z]+
+UNOTENAME      [A-Z][a-z]*
 DOTS           \.+
 LYRICS         {TEX}+
 COMMENT                [%#].*\n
@@ -65,16 +68,14 @@ COMMENT             [%#].*\n
        mtor << "rest:"<< yylval.string;
        return RESTNAME;
 }
+<notes>{UNOTENAME}     {
+       int *p=yylval.ii;
+       return ret_notename(p, YYText(), -1);
+}
 
 <notes>{NOTENAME}      {
        int *p=yylval.ii;
-       lookup_notename(p[0], p[1], YYText());
-       mtor << "notename: "<< YYText()<<eol;
-       if (p[0] < 0) {
-               String e("notename does not exist: ");
-               error(e + YYText());
-       }
-       return NOTENAME;
+       return ret_notename(p, YYText(), 0);
 }
 
 <notes>{NOTECOMMAND}   {
@@ -269,8 +270,9 @@ include           {
        //ignore
 }
 .              {
-       error("lexer error: illegal character '"+String(YYText()[0])+
-         "' encountered");
+//     error( "lexer error: illegal character '"+String(YYText()[0])+ "' encountered");
+       error( String( "illegal character: " ) + String( YYText()[0] ) + ": ",
+               here_ch_c_l() );
        return YYText()[0];
 }
 
index cc69a4a6bbf484f539593db84c41efbe3322f6b4..508c61e30d993ace379110598d5e9bb1aedf8bb6 100644 (file)
@@ -1,7 +1,12 @@
-#include <fstream.h>
+#include <iostream.h>
+#include <strstream.h>
+#include "proto.hh"
+#include "plist.hh"
 #include "lexer.hh"
 #include "debug.hh"
 #include "main.hh"
+#include "sourcefile.hh"
+#include "source.hh"
 
 My_flex_lexer *lexer=0;
 
@@ -27,22 +32,20 @@ Input_file::Input_file(String s)
     name = s;
     line = 1;
     String pf(s);
-    if (pf=="")
+    if (pf=="") {
        is = &cin;
+        sourcefile_l_ = 0;
+    }
     else {
-       pf =find_file(pf);
-       if (pf=="") {
-           String e("can\'t open `"  + s+"\'");
-           error(e);
-       }
-       is = new ifstream(  pf);
+       Source_file* sourcefile_p = new Source_file( pf );
+       source_l->add( sourcefile_p );
+       sourcefile_l_ = sourcefile_p;
+       is = sourcefile_l_->istream_l();
     }
     cout << "["<<pf<<flush;
 }
 
 Input_file::~Input_file()
 {
-  if (is != &cin)
-      delete is;
   cout << "]" << flush;  
 }
index f53b002d864b29ddb9673ffea998917ed8765597..9519371175ecbd335519fe1dfd1b436a6a67ceb2 100644 (file)
@@ -1,4 +1,7 @@
-#include <ctype.h>
+/*
+  could use cleanup
+ */
+  #include <ctype.h>
 #include "lexer.hh"
 #include "string.hh"
 #include "real.hh"
 #include "identparent.hh"
 #include "varray.hh"
 #include "textdef.hh"
-
+#include "parseconstruct.hh"
 
 int default_duration = 4, default_dots=0, default_octave=0;
 int default_plet_type = 1, default_plet_dur = 1;
 String textstyle="roman";              // in lexer?
 
+bool last_duration_mode = false;
+
+void
+set_duration_mode(String s)
+{
+    s.upper();
+    last_duration_mode = (s== "LAST");
+}
+
+void
+last_duration(int n)
+{
+    if (last_duration_mode)
+       default_duration = n;
+}
+
 /* triplet is '2/3' */
 void set_plet(int num,int den)
 {
@@ -29,6 +48,7 @@ get_text(String s) return t;
     t= new Text_def;
     t->text_str_= s;
     t->style_str_ = textstyle;
+    t->defined_ch_c_l_m = defined_ch_c_l;
     return t;
 }
 
@@ -89,6 +109,9 @@ get_note_element(String pitch, int * notename, int * duration )
        v->add(st);
     }
     
+    if ( !defined_ch_c_l )
+        defined_ch_c_l = lexer->here_ch_c_l();
+
     Note_req * rq = new Note_req;
     
     int oct;
@@ -101,9 +124,11 @@ get_note_element(String pitch, int * notename, int * duration )
     rq->balltype = dur;
     rq->dots = dots;
     rq->plet_factor = Moment(default_plet_dur, default_plet_type);
+    rq->defined_ch_c_l_m = defined_ch_c_l;
     rq->print();
 
     v->add(rq);
+    v->defined_ch_c_l_m = defined_ch_c_l;
 
     return v;
 }
@@ -117,6 +142,13 @@ get_word_element(Text_def* tdef_p, int* duration)
     int dur = duration[0];
     int dots=duration[1];
     
+    tdef_p->defined_ch_c_l_m = defined_ch_c_l;
+#if 0
+    char buf[ 21 ];
+    strncpy( buf, tdef_p->defined_ch_c_l_m, 20 );
+    buf[ 20 ] = 0;
+    cout << hex << (void*)tdef_p->defined_ch_c_l_m << dec << buf << endl;
+#endif
     Lyric_req* lreq_p = new Lyric_req(tdef_p);
 
     lreq_p->balltype = dur;
@@ -147,7 +179,7 @@ get_rest_element(String,  int * duration )
 void
 get_default_duration(int *p)
 {
-   *p++ = default_duration;
+    *p++ = default_duration;
     *p = default_dots;
 }
 
@@ -170,10 +202,10 @@ set_default_octave(String d)
 Request*
 get_request(char c)
 {
-    Request* ret=0;
+    Request* req_p=0;
     switch (c) {
     case '|':
-       ret = new Barcheck_req;
+       req_p = new Barcheck_req;
        break;
 
     case '[':
@@ -182,14 +214,14 @@ get_request(char c)
        Beam_req*b = new Beam_req;
        if (default_plet_type != 1)
            b->nplet = default_plet_type;
-       ret = b;
+       req_p = b;
     }
        break;
 
 
     case ')':
     case '(':
-       ret = new Slur_req;
+       req_p = new Slur_req;
        break;
     default:
        assert(false);
@@ -199,18 +231,19 @@ get_request(char c)
     switch (c) {
     case '(':
     case '[':
-       ret->span()->spantype = Span_req::START;
+       req_p->span()->spantype = Span_req::START;
        break;
     case ')':
     case ']':
-       ret->span()->spantype = Span_req::STOP;
+       req_p->span()->spantype = Span_req::STOP;
        break;
        
     default:
        break;
     }
 
-    return ret;
+    req_p->defined_ch_c_l_m = req_defined_ch_c_l;
+    return req_p;
 }
 
 void
@@ -282,3 +315,13 @@ get_barcheck_element()
     
     return v_p;
 }
+
+Voice_element*
+get_stemdir_element(int d)
+{
+    Voice_element*v_p = new Voice_element;
+    Group_feature_req * gfreq_p = new Group_feature_req;
+    gfreq_p->stemdir_i_ =d; 
+    v_p->add(gfreq_p);
+    return v_p;
+}
index f36d153113cfa3272f815382ab9c3c3fe1f34dc2..8d6ac75f0c2cdbe32816f3b0896e6fbc0cda5db0 100644 (file)
@@ -20,8 +20,9 @@
 
 Array<Request*> pre_reqs, post_reqs;
 sstack<String> define_spots;
-extern bool want_beam;
 Paperdef*default_paper();
+char const* defined_ch_c_l;
+char const* req_defined_ch_c_l;
 
 %}
 
@@ -61,10 +62,10 @@ Paperdef*default_paper();
     Text_def * textdef;
 }
 
-%token VOICE STAFF SCORE TITLE  BAR NOTENAME OUTPUT
+%token VOICE STAFF SCORE TITLE  BAR  OUTPUT MULTIVOICE
 %token CM IN PT MM PAPER WIDTH METER UNITSPACE SKIP COMMANDS COMMAND
 %token GEOMETRIC START_T DURATIONCOMMAND OCTAVECOMMAND
-%token KEY CLEF MULTI TABLE CHORD VOICES
+%token KEY CLEF  TABLE  VOICES STEM
 %token PARTIAL MUSIC GROUPING CADENZA
 %token END SYMBOLTABLES TEXID TABLE NOTENAMES SCRIPT TEXTSTYLE PLET
 %token MARK GOTO
@@ -72,25 +73,26 @@ Paperdef*default_paper();
 %token <id>  IDENTIFIER
 %token <string> PITCHMOD DURATION RESTNAME
 %token <ii> NOTENAME 
-%token <real> REAL
+%token <real> REAL 
 %token <string> STRING
 
 %token <i> DOTS INT
 %type <consstr> unit
-%type <intvec> pitch_list
+%type <intvec> pitch_list 
 %type <c> open_request_parens close_request_parens
 %type <id> declaration
 %type <string> declarable_identifier
 %type <paper> paper_block paper_body
-%type <real> dim
-%type <ii> duration
+%type <real> dim real
+%type <ii>  default_duration explicit_duration notemode_duration mudela_duration
+%type <ii> notename
 %type <moment> duration_length
 %type <el> voice_elt full_element lyrics_elt
 %type <command> score_command staff_command position_command
 %type <score> score_block score_body
 %type <staff> staff_block staff_init staff_body
 %type <i> int
-%type <intvec> int_list
+%type <intvec> int_list intastint_list
 %type <commandvec> score_commands_block score_commands_body
 %type <commandvec> staff_commands_block staff_commands_body
 %type <request> post_request pre_request 
@@ -115,8 +117,8 @@ Paperdef*default_paper();
 %%
 
 mudela:        /* empty */
-       | mudela score_block { 
-               add_score($2);
+       | mudela score_block {
+               add_score($2);          
        }
        | mudela add_declaration { }
        | mudela mudela_command  {}
@@ -164,6 +166,13 @@ declaration:
                $$ = new Notetab_id(*$1, $3);
                delete $1;
        }
+       | declarable_identifier '=' real        {
+               $$ = new Real_id(*$1, new Real($3));
+               delete $1;
+       }
+       | declarable_identifier error '}' {
+               warning( "parse error", lexer->here_ch_c_l() );
+       }
        ;
 
 notename_tab:
@@ -192,10 +201,16 @@ score_block: SCORE
                $$->define_spot_str_ = define_spots.pop();
                if (!$$->paper_)
                        $$->paper_ = default_paper();
+
+               /* handle error levels. */
+               $$->errorlevel_i_ = lexer->errorlevel_i_;
+               lexer->errorlevel_i_ = 0;
        }
        ;
 
-score_body:            { $$ = new Input_score; }
+score_body:            { 
+               $$ = new Input_score; 
+       }
        | score_body staff_block        { $$->add($2); }
        | score_body score_commands_block       {
                $$->add(*$2);
@@ -208,6 +223,9 @@ score_body:         { $$ = new Input_score; }
 */
 score_commands_block:
        COMMANDS '{' score_commands_body '}' { $$ =$3;}
+       | COMMANDS '{' error '}' {
+               warning( "parse error", lexer->here_ch_c_l() );
+       }
        ;
 
 score_commands_body:                   { $$ = new Array<Input_command*>; }
@@ -244,15 +262,6 @@ staff_command:
        }
        ;
 
-duration_length:       
-       duration                {
-               $$ = new Moment(wholes($1[0], $1[1]));
-       }
-       |int '*' duration       {
-               $$ = new Moment($1 * wholes($3[0], $3[1]));
-       }
-       ;
-
 position_command:
        SKIP int ':' duration_length            {
                $$ = get_skip_command($2, *$4);
@@ -264,6 +273,14 @@ position_command:
        }
        ;
 
+
+intastint_list:
+       /* */   { $$ =new Array<int>; }
+       | intastint_list int '*' int    {
+               $$->push($2); $$->push($4);
+       }
+       ;
+
 score_command:
        BAR STRING                      {
                $$ = get_bar_command(*$2);
@@ -276,7 +293,7 @@ score_command:
                $$ = get_partial_command(*$2);
                delete $2;
        }
-       | GROUPING int_list             {
+       | GROUPING intastint_list               {
                $$ = get_grouping_command(*$2);
                delete $2;
        }
@@ -307,6 +324,9 @@ paper_body:
        | paper_body symtables          { $$->set($2); }
        | paper_body UNITSPACE dim      { $$->whole_width = $3; }
        | paper_body GEOMETRIC REAL     { $$->geometric_ = $3; }
+       | paper_body error {
+               warning( "parse error", lexer->here_ch_c_l() );
+       }
        ;
 
 /*
@@ -333,12 +353,16 @@ staff_init:
 staff_body:
        staff_init
        | staff_body music      {
+               $2->set_default_group( "staff_music" + String($$->music_.size()));
                $$->add($2);
        }
        | staff_body staff_commands_block {
                $$->add(*$2);
                delete $2;
        }
+       | staff_body error {
+               warning( "parse error", lexer->here_ch_c_l() );
+       }
        ;
 
 /*
@@ -352,11 +376,12 @@ music:
 music_voice:  MUSIC '{' music_voice_body '}'   { $$ = $3; }
        ;
 
-music_voice_body:                      {
+music_voice_body:
+       /* */   {
                $$ = new Music_voice;
        }
        | music_voice_body IDENTIFIER {
-               $$->concatenate($2->mvoice());
+               $$->concatenate($2->mvoice(true));
        }
        | music_voice_body full_element {
                $$->add_elt($2);
@@ -366,16 +391,23 @@ music_voice_body:                 {
        | music_voice_body music        {
                $$->add($2);
        }
+       | music_voice_body error {
+               warning( "parse error", lexer->here_ch_c_l() );
+       }
        ;
 
 music_chord:  '{' music_chord_body '}' { $$ = $2; }
        ;
 
-music_chord_body:              {
-               $$ = new Music_general_chord;
+music_chord_body:
+       /* */   {
+               $$ = new Voice_group_chord;
+       }
+       | MULTIVOICE {
+               $$ = new Multi_voice_chord;
        }
        | music_chord_body IDENTIFIER {
-               $$->concatenate($2->mchord());
+               $$->concatenate($2->mchord(true));
        }
        | music_chord_body music {
                $$ -> add($2);
@@ -383,6 +415,9 @@ music_chord_body:           {
        | music_chord_body full_element {
                $$ ->add_elt($2);
        }
+       | music_chord_body error {
+               warning( "parse error", lexer->here_ch_c_l() );
+       }
        ;
 
 
@@ -402,7 +437,15 @@ full_element:      pre_requests voice_elt post_requests {
        | COMMAND '{' staff_command '}' { $$=get_command_element($3); }
        | COMMAND '{' score_command '}' { $$=get_command_element($3); }
        | '|'                           { $$ = get_barcheck_element(); }
+       | STEM '{' int '}'              {
+               $$ = get_stemdir_element($3);
+       }
        | lyrics_elt
+/*
++      | pre_requests voice_elt post_requests error '|' { 
++              warning( "parse error", lexer->here_ch_c_l() );
++      }
++ */
        ;
                
 post_requests:
@@ -415,19 +458,34 @@ post_requests:
        ;
 
 post_request:
-       close_request_parens            { $$ = get_request($1); }
+       close_request_parens    { 
+               $$ = get_request($1); 
+               req_defined_ch_c_l = lexer->here_ch_c_l();
+       }
        | script_req
        | textscript_req
        ;
 
 close_request_parens:
-       '('     { $$='('; }
-       |']'    { $$=']'; }
+       '('     { 
+               $$='(';
+               req_defined_ch_c_l = lexer->here_ch_c_l();
+       }
+       | ']'   { 
+               $$ = ']';
+               req_defined_ch_c_l = lexer->here_ch_c_l();
+       }
        ;
-
+  
 open_request_parens:
-       ')'     { $$=')'; }
-       |'['    { $$='['; }
+       ')'     { 
+               $$=')';
+               req_defined_ch_c_l = lexer->here_ch_c_l();
+       }
+       | '['   {
+               $$='[';
+               req_defined_ch_c_l = lexer->here_ch_c_l();
+       }
        ;
 
 script_definition:
@@ -446,7 +504,11 @@ textscript_req:
        ;
 
 mudela_text:
-       STRING                  { $$ = get_text(*$1); delete $1; }
+       STRING                  { 
+               $$ = get_text(*$1); 
+               delete $1;
+               defined_ch_c_l = lexer->here_ch_c_l();
+       }
        ;
 
 script_req:
@@ -464,7 +526,8 @@ mudela_script:
        | '>'           { $$ = get_scriptdef('>'); }
        | '.'           { $$ = get_scriptdef('.'); }
        | DOTS          {
-               if ($1>1) error("too many staccato reqs");
+               if ( $1 > 1 ) 
+                   warning( "too many staccato dots", lexer->here_ch_c_l() );
                $$ = get_scriptdef('.');
        }
        ;
@@ -482,16 +545,21 @@ pre_requests:
        ;
 
 pre_request: 
-       open_request_parens             { $$ = get_request($1); }
+       open_request_parens     { 
+               $$ = get_request($1); 
+               defined_ch_c_l = lexer->here_ch_c_l();
+       }
        ;
 
-
-
 voice_command:
        PLET    '{' INT '/' INT '}'             {
                set_plet($3,$5);
        }
-       | DURATIONCOMMAND '{' duration '}'      {
+       | DURATIONCOMMAND '{' STRING '}'        {
+               set_duration_mode(*$3);
+               delete $3;
+       }
+       | DURATIONCOMMAND '{' notemode_duration '}'     {
                set_default_duration($3);
        }
        | OCTAVECOMMAND '{' pitchmod '}'        {
@@ -504,11 +572,22 @@ voice_command:
        }
        ;
 
-duration:              {
-               get_default_duration($$);
+duration_length:       
+       mudela_duration         {
+               $$ = new Moment(wholes($1[0], $1[1]));
        }
-       | int           {
-               get_default_duration($$);
+       |int '*' mudela_duration        {
+               $$ = new Moment(Rational($1) * wholes($3[0], $3[1]));
+       }
+       ;
+
+notemode_duration:
+       explicit_duration
+       | default_duration
+       ;
+
+mudela_duration:
+       int             {
                $$[0] = $1;
                $$[1] = 0;
        }
@@ -516,22 +595,52 @@ duration:         {
                $$[0] = $1;
                $$[1] = $2;
        }
+       ;
+
+
+explicit_duration:
+       INT             {
+               last_duration($1);
+               $$[0] = $1;
+               $$[1] = 0;
+       }
+       | INT DOTS      {
+               last_duration($1);
+               $$[0] = $1;
+               $$[1] = $2;
+       }
        | DOTS  {
                 get_default_duration($$);
                 $$[1] = $1;
        }
        ;
 
-pitchmod:              { $$ = new String; }
-       |PITCHMOD       
+default_duration:
+       {
+               get_default_duration($$);
+       }
+       ;
+
+pitchmod:              { 
+               $$ = new String; 
+               defined_ch_c_l = lexer->here_ch_c_l();
+       }
+       | PITCHMOD      { 
+               $$ = $1;
+               defined_ch_c_l = lexer->here_ch_c_l();
+       }
+       ;
+
+notename:
+       NOTENAME
        ;
 
 voice_elt:
-       pitchmod NOTENAME duration                      {
+       pitchmod notename notemode_duration                     {
                $$ = get_note_element(*$1, $2, $3);
                delete $1;
        }
-       | RESTNAME duration             {
+       | RESTNAME notemode_duration            {
                $$ = get_rest_element(*$1, $2);
                delete $1;
 
@@ -539,7 +648,7 @@ voice_elt:
        ;
 
 lyrics_elt:
-       mudela_text duration                    {
+       mudela_text notemode_duration                   {
                $$ = get_word_element($1, $2);
        };
 
@@ -556,16 +665,27 @@ pitch_list:                       {
        ;
 
 int:
-       REAL                    {
+       real                    {
                $$ = int($1);
                if ( distance($1,Real(int($$)) ) > 1e-8)
-                       error("expecting integer number");
+                       error( "integer expected", lexer->here_ch_c_l() );
        }
-       | INT
        ;
 
-int_list:
-       /* */           {
+real:
+       INT                     {
+               $$ = Real($1);
+       }
+       | REAL          {
+               $$ = $1;
+       }
+       | IDENTIFIER            {
+               $$ = * $1->real(0);             
+       }
+       ;
+       
+
+int_list:              {
                $$ = new Array<int>;
        }
        | int_list int          {
@@ -573,8 +693,9 @@ int_list:
        }
        ;
 
+
 dim:
-       REAL unit       { $$ = convert_dimen($1,$2); }
+       real unit       { $$ = convert_dimen($1,$2); }
        ;
 
 
@@ -650,7 +771,7 @@ dinterval: dim      dim             {
 %%
 
 void
-parse_file(String s)
+parse_file(String init, String s)
 {
    *mlog << "Parsing ... ";
    lexer = new My_flex_lexer;
@@ -660,7 +781,7 @@ parse_file(String s)
    lexer->set_debug( !monitor.silence("InitLexer") && check_debug);
 #endif
 
-   lexer->new_input("symbol.ini");
+   lexer->new_input(init);
    yyparse();
 
 #ifdef YYDEBUG
index 6ebbf18a171e986804d9b06ff8d33c6e103c49fe..06a401fd82d3d26751f263afd6268d8dd2fcf4e6 100644 (file)
@@ -28,6 +28,16 @@ add_score(Input_score * s)
     score_array_global.push(s);
 }
 
+#if 0
+Input_score*
+current_iscore_l()
+{
+    if ( score_array_global.size() )
+       return score_array_global.last(); // UGH
+    else
+       return 0;
+}
+#endif
 
 void
 set_default_output(String s)