]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.17
authorfred <fred>
Tue, 17 Dec 1996 01:04:45 +0000 (01:04 +0000)
committerfred <fred>
Tue, 17 Dec 1996 01:04:45 +0000 (01:04 +0000)
hdr/inputmusic.hh
hdr/lexer.hh
src/lexer.l
src/lexerinit.cc [new file with mode: 0644]

index 57ddf79443f0960b6ac8f3e0418c46bf19480c50..d3286135f8c2774073edbe86e70afdce0d21e14f 100644 (file)
@@ -9,11 +9,10 @@
 
 #include "plist.hh"
 #include "proto.hh"
+#include "voice.hh"
 
 struct Voice_list : public PointerList<Voice*> {
     void translate_time(Real dt);
-    /// delete stuff; not in destructor!
-    void junk();
 };
 
 /// ABC for input structures
@@ -21,9 +20,13 @@ struct Input_music {
     virtual Voice_list convert()=0;
     virtual Real length()=0;
     virtual void translate_time(Real dt)=0;
-    virtual ~Input_music();
+    virtual ~Input_music(){}
     virtual void print() const =0;
     // virtual void transpose(...) const =0;
+    
+    
+    virtual Input_music *clone() const = 0;
+    virtual Simple_music *simple() { return 0; }
 };
 /**
 
@@ -37,96 +40,80 @@ struct Input_music {
   */
 
 
+/// Simple music consists of one voice
+struct Simple_music : Input_music {
+    Voice voice_;
 
-/// 
-struct Vertical_music : Input_music {
-    virtual Vertical_music *clone() const = 0;
-
-    /// check if it is a simple voice
-    virtual Vertical_simple *simple() { return 0;}
-};
-/**
-  chord like :
-
-  - different music forms which start at the same time ( stacked "vertically" )
-
-  This class really doesn't do very much, but it enables you to say
-
-  a Music_voice is a List<Vertical_music>
-  
-  */
-
-///
-struct Horizontal_music : Input_music {
-    virtual Voice_list convert()=0;
-    virtual Horizontal_music *clone() const = 0;
-};
-/**
-  voice like.
-
-  different music forms which start after each other ( concatenated,
-  stacked "horizontally )
-
-  This class really doesn't do very much, but it enables you to say
-
-  a Chord is a List<Horizontal_music>
- */
-
-/// the most basic element of a chord: a simple voice
-struct Vertical_simple : Vertical_music {
-    Voice * voice_;            // should be a  real member
-    
-    /****************/
-    Vertical_simple(Vertical_simple const&);
-    Vertical_simple();
-    ~Vertical_simple();
+    /****/
+    virtual Simple_music*simple() { return this; }  
     void add(Voice_element*);
-    virtual Vertical_simple*simple() { return this; }
     virtual Real length();
     virtual Voice_list convert();
     virtual void translate_time(Real dt);
-    virtual Vertical_music *clone() const {
-       return new Vertical_simple(*this);
+    virtual void print() const;
+    virtual Input_music *clone() const {
+       return new Simple_music(*this);
     }
+
+};
+
+/// Complex_music consists of multiple voices
+struct Complex_music : Input_music {
+    IPointerList<Input_music*> elts;
+
+    void add(Input_music*);
+    Complex_music();
+    Complex_music(Complex_music const &);
     virtual void print() const ;
+    void concatenate(Complex_music*);
 };
 
-/// the only child of Horizontal_music
-struct Music_voice : Horizontal_music {
-    IPointerList<Vertical_music*> voice_ ;
+/// multiple stuff  after each other
+struct Music_voice : Complex_music {
     
     /****************/
-    Music_voice() {}
-    Music_voice(Music_voice const&);
     Real length();
-    void add(Vertical_music*);
-    void add(Voice_element*);
-    virtual Voice_list convert();
     virtual void translate_time(Real dt);
-    virtual Horizontal_music *clone() const {
+    virtual Voice_list convert();
+    void add_elt(Voice_element*);
+    virtual Input_music *clone() const {
        return new Music_voice(*this);
     }
-    void concatenate(Music_voice*);
     virtual void print() const ;
 };
-///
-struct Music_general_chord : Vertical_music {
-    IPointerList<Horizontal_music*> chord_;
+/**
+  voice like.
+
+  different music forms which start after each other ( concatenated,
+  stacked "horizontally )
+ */
+
+/// Multiple musicstuff stacked on top of each other
+struct Music_general_chord : Complex_music {
+    IPointerList<Input_music*> chord_;
 
     /****************/
-    Music_general_chord() {}
-    Music_general_chord(Music_general_chord const&s);
-    void add(Horizontal_music*);
+
     virtual Real length();
     virtual Voice_list convert();
     virtual void translate_time(Real dt);
-    virtual Vertical_music *clone() const {
+    void add_elt(Voice_element*);
+    virtual Input_music *clone() const {
        return new Music_general_chord(*this);
     }
-    void concatenate(Music_general_chord*);
+    
     virtual void print() const ;
 };
+/**
+  chord like :
+
+  - different music forms which start at the same time ( stacked "vertically" )
+  
+  */
+
 
 
 #endif // INPUTMUSIC_HH
index 7284dd40eb2f54487383ad7fbb1a6bc83e8fe490..239b7bbe0b979c36bfdb036efaaa99b86ea0298e 100644 (file)
@@ -1,17 +1,50 @@
 #ifndef LEXER_HH
 #define LEXER_HH
-
+#include <FlexLexer.h>
 #include "proto.hh"
-
-void new_input(String s);
+#include "fproto.hh"
+#include "sstack.hh"
+#include "string.hh"
 
 int yylex();
 void yyerror(const char *s);
 bool busy_parsing();
-int lookup_keyword(String s);
-
-Identifier* lookup_identifier(String s);
-void add_identifier(Identifier*i);
-void delete_identifiers();
 void kill_lexer();
+void set_lexer();
+
+struct Input_file {
+       istream*is;
+       int line;
+       String name;
+
+       Input_file(String);
+       ~Input_file();
+};
+
+
+/// lexer with provisions for include files.
+struct My_flex_lexer : yyFlexLexer {
+
+    sstack<Input_file*> include_stack;
+    Assoc<String, Identifier*> *the_id_tab;
+    Keyword_table * keytable;
+    Notename_tab * defaulttab;
+
+    /****************/
+    
+    void set(Notename_tab *n);
+    int     lookup_keyword(String);
+    void lookup_notename(int &large, int &small, String s);
+    void LexerError(const char *);
+    Identifier*lookup_identifier(String s);
+    My_flex_lexer();
+    void add_identifier(Identifier*i);
+    ~My_flex_lexer();
+    void new_input(String s);
+    bool  close_input();
+    int yylex();
+};
+
+extern My_flex_lexer *lexer;
+
 #endif
index c5c51f70b69b1e519ade8cc5c0460c99bb7a495d..0b17abac663d3a0bdd3aef64337e24c9b83c0f57 100644 (file)
@@ -1,37 +1,14 @@
 %{ // -*-Fundamental-*-
 
-#include <fstream.h>
 #include <stdio.h>
-#include "glob.hh"
+
 #include "string.hh"
 #include "notename.hh"
 #include "lexer.hh"
-#include "keyword.hh"
 #include "vray.hh"
 #include "parser.hh"
 #include "debug.hh"
-#include "sstack.hh"
-
-struct Input_file {
-       istream*is;
-       int line;
-       String name;
-
-       Input_file(String);
-       ~Input_file();
-};
-
-/// lexer with provisions for include files.
-struct My_flex_lexer : yyFlexLexer {
-    sstack<Input_file*> include_stack;
-    void new_input(String s);
-    bool  close_input();
-};
 
-My_flex_lexer *lexer=0;
-
-static int last_print;
-const int DOTPRINT=50; // every 50 lines dots
 %}
 
 %option c++
@@ -39,6 +16,7 @@ const int DOTPRINT=50; // every 50 lines dots
 %option nodefault
 %option yylineno
 %option debug
+%option yyclass="My_flex_lexer"
 %x notes
 %x incl
 %x quote
@@ -162,7 +140,7 @@ DOTS                \.+
 <<EOF>> {
        mtor << "<<EOF>>";
 
-       if (! ((My_flex_lexer*) this)->close_input())
+       if (! close_input())
          yyterminate(); // can't move this, since it actually rets a YY_NULL
 }
 
@@ -217,102 +195,3 @@ DOTS              \.+
 
 %%
 
-int
-yylex() {
-       return lexer->yylex();
-}
-
-void
-yyerror(const char *s)
-{
-    String e;
-    if (lexer->include_stack.empty()) {
-       *mlog << "error at EOF" << s;
-    }else 
-       *mlog << lexer->include_stack.top()->name <<  ": " <<
-        lexer->lineno() <<  ": error:" << s << '\n';
-  exit(1);
-}
-
-
-bool
-busy_parsing()
-{
-    return lexer;      
-}
-
-void
-kill_lexer()
-{
-       delete lexer;
-       lexer = 0;
-}
-
-void
-new_input(String s)
-{
-    if (!lexer) {
-       lexer = new My_flex_lexer;
-       lexer->set_debug( !monitor.silence("Lexer") && check_debug);
-   }           
-   lexer->new_input(s);
-}
-
-/****************/
-
-Input_file::Input_file(String s)
-{
-    name = s;
-    line = 1;
-    if (s=="")
-       is = &cin;
-    else
-       is = new ifstream( s ); //
-    
-   if ( ! *is) {
-       String e("cant open "  + s);
-       if (lexer)
-             yyerror(e);
-       else
-             error(e);
-   }
-   cout << "["<<s<<flush;
-}
-
-Input_file::~Input_file()
-{
-  if (is != &cin)
-      delete is;
-  cout << "]" << flush;  
-}
-/****************/
-
-// set the  new input to s, remember old file.
-void
-My_flex_lexer::new_input(String s)
-{    
-   if (!include_stack.empty())
-       include_stack.top()->line = lineno();
-
-   Input_file *newin = new Input_file(s);
-   include_stack.push(newin);
-   switch_streams(newin->is);
-   yylineno = 1;
-}
-
-// pop the inputstack.
-bool
-My_flex_lexer::close_input()
-{
-    Input_file *old = include_stack.pop();
-     bool ok =         true;
-    if (include_stack.empty()) {
-       ok = false;
-    } else {
-       Input_file *i = include_stack.top();
-       switch_streams(i->is);
-       yylineno = i->line;     
-    }
-    delete old;
-    return ok;
-}
diff --git a/src/lexerinit.cc b/src/lexerinit.cc
new file mode 100644 (file)
index 0000000..3bc0d31
--- /dev/null
@@ -0,0 +1,61 @@
+#include <fstream.h>
+#include "lexer.hh"
+#include "debug.hh"
+
+My_flex_lexer *lexer=0;
+
+int
+yylex() {
+       return lexer->yylex();
+}
+
+void
+yyerror(const char *s)
+{
+       lexer->LexerError(s);
+}
+
+bool
+busy_parsing()
+{
+    return lexer;      
+}
+
+void
+kill_lexer()
+{
+       delete lexer;
+       lexer = 0;
+}
+
+void
+set_lexer()
+{
+    if (!lexer) {
+       lexer = new My_flex_lexer;
+       lexer->set_debug( !monitor.silence("Lexer") && check_debug);
+   }           
+}
+
+Input_file::Input_file(String s)
+{
+    name = s;
+    line = 1;
+    if (s=="")
+       is = &cin;
+    else
+       is = new ifstream( s );
+    
+   if ( ! *is) {
+       String e("cant open "  + s);
+      error(e);
+   }
+   cout << "["<<s<<flush;
+}
+
+Input_file::~Input_file()
+{
+  if (is != &cin)
+      delete is;
+  cout << "]" << flush;  
+}