From: fred Date: Tue, 17 Dec 1996 01:04:45 +0000 (+0000) Subject: lilypond-0.0.17 X-Git-Tag: release/1.5.59~6573 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=0e3b4ac742a720ac7663ed1a8726256882ce6b85;p=lilypond.git lilypond-0.0.17 --- diff --git a/hdr/inputmusic.hh b/hdr/inputmusic.hh index 57ddf79443..d3286135f8 100644 --- a/hdr/inputmusic.hh +++ b/hdr/inputmusic.hh @@ -9,11 +9,10 @@ #include "plist.hh" #include "proto.hh" +#include "voice.hh" struct Voice_list : public PointerList { 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 - - */ - -/// -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 - - */ - -/// 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 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 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 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 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 diff --git a/hdr/lexer.hh b/hdr/lexer.hh index 7284dd40eb..239b7bbe0b 100644 --- a/hdr/lexer.hh +++ b/hdr/lexer.hh @@ -1,17 +1,50 @@ #ifndef LEXER_HH #define LEXER_HH - +#include #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 include_stack; + Assoc *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 diff --git a/src/lexer.l b/src/lexer.l index c5c51f70b6..0b17abac66 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -1,37 +1,14 @@ %{ // -*-Fundamental-*- -#include #include -#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 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 \.+ <> { mtor << "<>"; - 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 << "["<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 index 0000000000..3bc0d31aed --- /dev/null +++ b/src/lexerinit.cc @@ -0,0 +1,61 @@ +#include +#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 << "["<