]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.17
authorfred <fred>
Sun, 24 Mar 2002 19:26:42 +0000 (19:26 +0000)
committerfred <fred>
Sun, 24 Mar 2002 19:26:42 +0000 (19:26 +0000)
src/mylexer.cc [new file with mode: 0644]
src/notename.cc

diff --git a/src/mylexer.cc b/src/mylexer.cc
new file mode 100644 (file)
index 0000000..0a912e3
--- /dev/null
@@ -0,0 +1,129 @@
+#include "identparent.hh"
+#include "associter.hh"
+#include "lexer.hh"
+#include "parser.hh"
+#include "keyword.hh"
+#include "assoc.hh"
+#include "lexer.hh"
+#include "sstack.hh"
+#include "debug.hh"
+#include "notename.hh"
+
+static Keyword_ent the_key_tab[]={
+    "bar", BAR,
+    "bass", BASS,
+    "clef", CLEF,
+    "cm", CM,
+    "commands", COMMANDS,
+    "duration", DURATIONCOMMAND,
+    "geometric", GEOMETRIC,
+    "in", IN,
+    "key", KEY, 
+    "melodic", MELODIC,
+    "meter", METER,
+    "mm", MM,
+    "octave", OCTAVECOMMAND,
+    "output", OUTPUT,
+    "partial", PARTIAL,
+    "paper", PAPER,
+    "pt", PT,
+    "rhythmic", RHYTHMIC,
+    "score", SCORE,
+    "skip", SKIP,
+    "staff", STAFF,
+    "start", START_T,
+    "table", TABLE,
+    "symboltables", SYMBOLTABLES,
+    "notenames", NOTENAMES,
+    "texid", TEXID,
+    "chord", CHORD,
+    "multi", MULTI,
+    "unitspace", UNITSPACE,
+    "violin", VIOLIN,
+    "voice", VOICE,
+    "voices", VOICES,
+    "width", WIDTH,
+    "music", MUSIC,
+    "grouping", GROUPING,
+    0,0
+};
+
+My_flex_lexer::My_flex_lexer()
+{
+    keytable = new Keyword_table(the_key_tab);
+    the_id_tab = new Assoc<String, Identifier*>;
+    defaulttab = 0;
+}
+
+int
+My_flex_lexer::lookup_keyword(String s)
+{
+    return keytable->lookup(s);
+}
+
+Identifier*
+My_flex_lexer::lookup_identifier(String s)
+{
+    if (!the_id_tab->elt_query(s))
+       return 0;
+    
+    return (*the_id_tab)[s];
+}
+
+void
+My_flex_lexer::add_identifier(Identifier*i)
+{
+    delete lookup_identifier(i->name);
+    (*the_id_tab)[i->name] = i;
+}
+
+My_flex_lexer::~My_flex_lexer()
+{
+    delete keytable;
+    delete defaulttab;
+    for (Assoc_iter<String,Identifier*> ai(*the_id_tab); ai.ok(); ai++) {
+       mtor << "deleting: " << ai.key()<<'\n';
+       delete ai.val();
+    }
+    delete the_id_tab;
+}
+
+void
+My_flex_lexer::LexerError(const char *s)
+{
+    if (lexer->include_stack.empty()) {
+       *mlog << "error at EOF" << s;
+    }else 
+       *mlog << lexer->include_stack.top()->name <<  ": " <<
+        lexer->lineno() <<  ": error:" << s << '\n';
+     exit(1);
+}
+// 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;
+}
index dec6d47701c222d1f5143266674fab14f510b2dd..f22f44d7b9ab957b12f15b7c3b6b481bfd4d070a 100644 (file)
@@ -4,24 +4,6 @@
 #include "lexer.hh"
 #include "identifier.hh"
 
-static Notename_tab * defaulttab = 0;
-
-void
-set_notename_tab(Notename_tab*n)
-{
-    delete defaulttab;
-    defaulttab = n;
-}
-
-void
-lookup_notename(int &large, int &small, String s)
-{
-    if (!defaulttab)
-       set_notename_tab(lookup_identifier("default_table")->
-                        notename_tab(true));
-    
-    defaulttab->lookup(large, small, s);
-}
     
 
 void
@@ -46,3 +28,20 @@ Notename_tab::set(int l, int s, String n)
     assert(l < 8 && s <= 2 && s >= -2 && l >=0);
     notetab[l * 5 + s +2] = n;
 }
+/****************/
+void
+My_flex_lexer::set(Notename_tab *n)
+{
+    delete defaulttab;
+    defaulttab = n;
+}
+
+void
+My_flex_lexer::lookup_notename(int &large, int &small, String s)
+{
+    if (!defaulttab)
+       set(lookup_identifier("default_table")->
+           notename_tab(true));
+    
+    defaulttab->lookup(large, small, s);
+}