]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.3
authorfred <fred>
Fri, 11 Oct 1996 19:55:49 +0000 (19:55 +0000)
committerfred <fred>
Fri, 11 Oct 1996 19:55:49 +0000 (19:55 +0000)
identifier.cc [new file with mode: 0644]
keyword.hh
symtable.cc
table.cc

diff --git a/identifier.cc b/identifier.cc
new file mode 100644 (file)
index 0000000..9eab42e
--- /dev/null
@@ -0,0 +1,22 @@
+#include <assert.h>
+#include "keyword.hh"
+#include "lexer.hh"
+#include "parser.hh"
+
+Identifier::Identifier()
+{
+    data = 0;
+    type = IDENTIFIER;
+}
+
+
+Identifier::~Identifier()
+{
+    if (!data)
+       return;
+    switch (type) {
+    case IDENTIFIER:
+    default:
+       assert(false);
+    }
+}
index aa87a8dc1af7591d595219c9ed722753142dd3ef..42267ef57a5cb29167ffc12eed102022590763bf 100644 (file)
@@ -13,5 +13,11 @@ struct Keyword_table
     int     lookup(const char *s) const;
 };
 
-struct Identifier{
+struct Identifier
+{
+    void *data;
+    int type;
+
+    Identifier();
+    ~Identifier();
 };
index 8b87e2fc99a893130426f1075878963f2efbdce5..5d295d0be5aafacf5eb41d5f015b2385198e8d39 100644 (file)
@@ -6,6 +6,20 @@
 #include "symtable.hh"
 #include "const.hh"
 
+static Symbol unknown;
+
+
+// scary! What if Symtable resizes on the fly...?
+const Symbol *
+Symtable::lookup(String s) const
+{
+    if (elt_query(s))
+       return &(*this)[s];
+    else {
+       WARN<<"Unknown symbol " << s <<'\n';
+       return &unknown;
+    }
+}
 
 Symtable* 
 Symtables::operator()(String s) 
@@ -53,25 +67,22 @@ Symtables the_sym_tables("symbol.ini");
 
 
 const Symbol*
-Symbol::find_ball(int i)
+Symbol::find_ball(int j)
 {
-    int j = intlog2(i)+1;
     if (j > 4) j = 4;
     Symtable * st = the_sym_tables("balls");
-    return &(*st)[String(j)];
-
+    return st->lookup(String(j));
 }
 
 const Symbol*
-Symbol::find_rest(int i)
+Symbol::find_rest(int j)
 {
-    int j = intlog2(i)+1;
-    return &(*the_sym_tables("rests"))[String(j)];
+    return the_sym_tables("rests")->lookup(String(j));
 }
 const Symbol*
 Symbol::find_bar(String s)
 {
-    return &(*the_sym_tables("bars"))[s];  
+    return the_sym_tables("bars")->lookup(s);
 }
 /****************************************************************/
 // bare bones.
index 45e6f4a0e476887a5e11312ef44cdb83c2be2f8a..b06e2ee92f933057cc8787157c00abf701d5ebe8 100644 (file)
--- a/table.cc
+++ b/table.cc
@@ -1,4 +1,5 @@
 #include "glob.hh"
+#include "debug.hh"
 #include "string.hh"
 #include "keyword.hh"
 #include "parser.hh"
@@ -8,6 +9,7 @@ static Keyword_ent  the_key_tab[]={
     "rhythmstaff", RHYTHMSTAFF,
     "score", SCORE,
     "bar", BAR,
+    "output", OUTPUT,
     0,0
 } ;
 
@@ -19,9 +21,13 @@ lookup_keyword(String s)
     return table.lookup(s);
 }
 
+Assoc<String, Identifier*> the_id_tab;
+
 Identifier*
 lookup_identifier(String s)
 {
-    assert(false);
-    return 0;
+    if (!the_id_tab.elt_query(s))
+        the_id_tab[s]= new Identifier;
+    
+    return the_id_tab[s];
 }