From 7110e84f08f32c1b157e589f1404c86553bee9c7 Mon Sep 17 00:00:00 2001 From: fred Date: Sun, 24 Mar 2002 19:26:42 +0000 Subject: [PATCH] lilypond-0.0.17 --- src/mylexer.cc | 129 ++++++++++++++++++++++++++++++++++++++++++++++++ src/notename.cc | 35 +++++++------ 2 files changed, 146 insertions(+), 18 deletions(-) create mode 100644 src/mylexer.cc diff --git a/src/mylexer.cc b/src/mylexer.cc new file mode 100644 index 0000000000..0a912e3389 --- /dev/null +++ b/src/mylexer.cc @@ -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; + 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 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; +} diff --git a/src/notename.cc b/src/notename.cc index dec6d47701..f22f44d7b9 100644 --- a/src/notename.cc +++ b/src/notename.cc @@ -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); +} -- 2.39.5