#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
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; }
};
/**
*/
+/// 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
#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
%{ // -*-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++
%option nodefault
%option yylineno
%option debug
+%option yyclass="My_flex_lexer"
%x notes
%x incl
%x quote
<<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
}
%%
-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;
-}