From: fred Date: Thu, 12 Dec 1996 11:46:04 +0000 (+0000) Subject: lilypond-0.0.16 X-Git-Tag: release/1.5.59~6602 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=c270fdad74b5b7049745bef593046fc50dad349f;p=lilypond.git lilypond-0.0.16 --- diff --git a/.dstreamrc b/.dstreamrc index a449d3f574..2a2dc43002 100644 --- a/.dstreamrc +++ b/.dstreamrc @@ -1,6 +1,7 @@ #class name silence? -yyFlexLexer 1 +My_flex_lexer 0 +yyFlexLexer 0 PCol 0 Score_column 1 Ineq_constrained_qp 1 @@ -8,8 +9,13 @@ Spacing_problem 1 Colinfo 1 Mixed_qp 1 PScore 1 -Parser 0 -Lexer 1 + +# yydebug +Parser 1 + +# FlexLexer debug +Lexer 0 + parse_duration 1 parse_pitch 1 Col_configuration 1 diff --git a/lilyponddefs.tex b/lilyponddefs.tex index fe056efa23..5f42c07c51 100644 --- a/lilyponddefs.tex +++ b/lilyponddefs.tex @@ -12,6 +12,7 @@ \newdimen\interstaffrule \def\musixtwentydefs{ + \font\textfont=cmr10 \font\slurufont=xslu20 \font\slurdfont=xsld20 \font\slurhfont=xslz20 @@ -25,6 +26,7 @@ \musixcalc } \def\musixsixteendefs{ + \font\textfont=cmr8 \font\slurufont=xslu16 \font\slurdfont=xsld16 \font\slurhfont=xslz20 % sigh @@ -89,7 +91,7 @@ \def\maatstreep{\vrule height\balkhoog} \def\finishbar{\vrule height\balkhoog width 1pt} -\def\generalmeter#1#2{\vbox to 0pt{\vss\rm\hbox{#1}\hbox{#2}}} +\def\generalmeter#1#2{\vbox to 0pt{\vss\textfont\hbox{#1}\hbox{#2}}} \def\lineseparator{\vbox{\mussepline\vskip -5pt\mussepline}} \def\beauty{% diff --git a/src/lexer.l b/src/lexer.l index f83cf144df..c5c51f70b6 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -4,14 +4,32 @@ #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; -sstack include_stack; static int last_print; const int DOTPRINT=50; // every 50 lines dots %} @@ -26,20 +44,23 @@ const int DOTPRINT=50; // every 50 lines dots %x quote -NOTECOMMAND \\{WORD} + +A [a-zA-Z] +AA {A}|_ +N [0-9] +AN {AA}|{N} + +WORD {A}{AN}* +ALPHAWORD {A}+ +INT -?{N}+ +REAL {INT}(\.{N}*)? + OPTSIGN !? -NOTENAMEI A|B|C|D|E|F|G|As|Bes|Ces|Des|Es|Fes|Ges|Ais|Bis|Cis|Dis|Eis|Fis|Gis -NOTENAMEII a|b|c|d|e|f|g|as|bes|ces|des|es|fes|ges|ais|bis|cis|dis|eis|fis|gis -NOTENAMEIII Ases|Beses|Ceses|Deses|Eses|Feses|Geses|Aisis|Bisis|Cisis|Disis|Eisis|Fisis|Gisis -NOTENAMEIIII ases|beses|ceses|deses|eses|feses|geses|aisis|bisis|cisis|disis|eisis|fisis|gisis -RESTNAME r|s -NOTENAME {NOTENAMEI}|{NOTENAMEII}|{NOTENAMEIII}|{NOTENAMEIIII} -PITCH ['`]*{OPTSIGN}{NOTENAME} -DURNAME 1|2|4|8|16|32 -DURATION {DURNAME}\.* -FULLNOTE {PITCH}{DURATION}? -WORD [a-zA-Z][a-zA-Z0-9_]+ -REAL -?[0-9]+(\.[0-9]*)? +PITCHMOD ['`]*{OPTSIGN} +RESTNAME r|s|p +NOTECOMMAND \\{WORD} +NOTENAME {ALPHAWORD} +DOTS \.+ %% @@ -47,9 +68,27 @@ REAL -?[0-9]+(\.[0-9]*)? BEGIN(notes); } +{RESTNAME} { + const char *s = YYText(); + yylval.string = new String (s); + mtor << "rest:"<< yylval.string; + return RESTNAME; +} + +{NOTENAME} { + int *p=yylval.ii; + lookup_notename(p[0], p[1], YYText()); + mtor << "notename: "<< YYText()<{NOTECOMMAND} { String c = YYText() +1; - + mtor << "\\word: " << YYText()+1<{RESTNAME} { - const char *s = YYText(); - yylval.string = new String (s); - mtor << "rest:"<< yylval.string; - return RESTNAME; -} -{PITCH} { +{PITCHMOD} { const char *s = YYText(); + mtor << "pitchmod:"<< YYText()<{DURATION} { - yylval.string = new String (YYText()); - return DURATION; +{DOTS} { + yylval.i = strlen(YYText()); + return DOTS; +} +{INT} { + yylval.i = String(YYText()).value(); + return INT; } \| { } [:space:]+ { } -[ \t\n]+ { +[%#].*\n { + } -[%#].*$ { +[ \t\n]+ { } \$ { @@ -122,10 +160,14 @@ REAL -?[0-9]+(\.[0-9]*)? } <> { - if(!close_input()) - yyterminate(); + mtor << "<>"; + + if (! ((My_flex_lexer*) this)->close_input()) + yyterminate(); // can't move this, since it actually rets a YY_NULL } + {WORD} { + mtor << "word: " << YYText()<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() @@ -183,65 +241,78 @@ busy_parsing() return lexer; } -// set the new input to s, remember old file. void -new_input(String s) -{ - istream *newin ; - - if (s=="") - newin = &cin; - else - newin = new ifstream( s ); // - - if ( ! *newin) - error("cant open " + s); - cout << "["<set_debug( !monitor.silence("Lexer")); +void +new_input(String s) +{ + if (!lexer) { + lexer = new My_flex_lexer; + lexer->set_debug( !monitor.silence("Lexer") && check_debug); } - - lexer->switch_streams(newin); + lexer->new_input(s); } +/****************/ -// pop the inputstack. -bool -close_input() +Input_file::Input_file(String s) { - - istream *closing= include_stack.pop(); - if (closing != &cin) - delete closing; - - cout << "]" << flush; - - if (include_stack.empty()) { - return false ; - } else - lexer->switch_streams(include_stack.top()); - return true; + 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 << "["<yylex(); +Input_file::~Input_file() +{ + if (is != &cin) + delete is; + cout << "]" << flush; } +/****************/ +// set the new input to s, remember old file. void -yyerror(const char *s) -{ - *mlog << "error in line " << lexer->lineno() << ": " << s << '\n'; - exit(1); +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; } -void -kill_lexer() +// pop the inputstack. +bool +My_flex_lexer::close_input() { - delete lexer; - lexer = 0; + 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/note.cc b/src/note.cc index f5911c0eda..fe269792eb 100644 --- a/src/note.cc +++ b/src/note.cc @@ -10,30 +10,6 @@ int default_duration = 4, default_dots=0, default_octave=0; -void -parse_duration(const char *a, int &j, int &intdur, int &dots) -{ - String durstr; - while (isdigit(a[j])) - { - durstr += a[j++]; - } - - dots=default_dots; - - while (a[j] == '.') - { - j++; - dots++; - } - - intdur = (durstr.len()) ? - durstr.value():default_duration; - - mtor << "dur " << intdur << "dots " << dots<= 2) { @@ -105,13 +62,12 @@ get_note_element(String pitch, String durstr) v->add(st); } - int oct, pit, acc; + int oct; bool forceacc; - parse_pitch(pitch, i, oct, forceacc, pit, acc); - rq->name =pit; - + parse_pitchmod(pitch, i, oct, forceacc); + rq->name =notename[0]; + rq->accidental = notename[1]; rq->octave = oct; - rq->accidental = acc; rq->forceacc = forceacc; rq->balltype = dur; rq->dots = dots; @@ -124,19 +80,14 @@ get_note_element(String pitch, String durstr) } Voice_element * -get_rest_element(String, String durstr) +get_rest_element(String, int * duration ) { Voice_element*v = new Voice_element; - int i=0; - - int dur, dots; - parse_duration(durstr, i, dur, dots); - i=0; Rest_req * rq = new Rest_req; - rq->balltype = dur; - rq->dots = dots; + rq->balltype = duration[0]; + rq->dots = duration[1]; rq->print(); v->add(rq); @@ -144,15 +95,22 @@ get_rest_element(String, String durstr) } void -set_default_duration(String d) +get_default_duration(int *p) { - int i=0; - parse_duration(d, i, default_duration, default_dots); + *p++ = default_duration; + *p = default_dots; +} + +void +set_default_duration(int *p) +{ + default_duration = *p++; + default_dots = *p++; } void -set_default_pitch(String d) +set_default_octave(String d) { int i=0; default_octave=0;