From b2c05fb789b33eb7720aa5242e53d780f1745412 Mon Sep 17 00:00:00 2001 From: fred Date: Tue, 4 Mar 1997 22:12:59 +0000 Subject: [PATCH] lilypond-0.0.39 --- lily/include/parser.hh | 86 +++++ lily/lexer.l | 281 ++++++++++++++ lily/parser.y | 828 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1195 insertions(+) create mode 100644 lily/include/parser.hh create mode 100644 lily/lexer.l create mode 100644 lily/parser.y diff --git a/lily/include/parser.hh b/lily/include/parser.hh new file mode 100644 index 0000000000..3a3d4de3ef --- /dev/null +++ b/lily/include/parser.hh @@ -0,0 +1,86 @@ +typedef union { + Request * request; + Real real; + Identifier *id; + Voice *voice; + Voice_element *el; + String *string; + const char *consstr; + Paper_def *paper; + Midi_def* midi; + Input_music *music; + Music_general_chord *chord; + Music_voice *mvoice; + int i; + char c; + int ii[10]; + Moment *moment; + + Array * strvec; + Array *intvec; + Array *melreqvec; + Input_staff *staff; + Input_score *score; + Symtables * symtables; + Symtable * symtable; + Symbol * symbol; + Lookup*lookup; + Interval *interval; + Box *box; + Notename_tab *notename_tab; + Script_def * script; + Text_def * textdef; +} YYSTYPE; +#define VOICE 258 +#define STAFF 259 +#define SCORE 260 +#define TITLE 261 +#define BAR 262 +#define OUTPUT 263 +#define MULTIVOICE 264 +#define CM_T 265 +#define IN_T 266 +#define PT_T 267 +#define MM_T 268 +#define PAPER 269 +#define WIDTH 270 +#define METER 271 +#define UNITSPACE 272 +#define SKIP 273 +#define COMMANDS 274 +#define COMMAND 275 +#define GEOMETRIC 276 +#define START_T 277 +#define DURATIONCOMMAND 278 +#define OCTAVECOMMAND 279 +#define KEY 280 +#define CLEF 281 +#define TABLE 282 +#define VOICES 283 +#define STEM 284 +#define PARTIAL 285 +#define MUSIC 286 +#define GROUPING 287 +#define CADENZA 288 +#define END 289 +#define SYMBOLTABLES 290 +#define TEXID 291 +#define NOTENAMES 292 +#define SCRIPT 293 +#define TEXTSTYLE 294 +#define PLET 295 +#define GOTO 296 +#define MIDI 297 +#define TEMPO 298 +#define IDENTIFIER 299 +#define PITCHMOD 300 +#define DURATION 301 +#define RESTNAME 302 +#define NOTENAME 303 +#define REAL 304 +#define STRING 305 +#define DOTS 306 +#define INT 307 + + +extern YYSTYPE yylval; diff --git a/lily/lexer.l b/lily/lexer.l new file mode 100644 index 0000000000..6f5945a605 --- /dev/null +++ b/lily/lexer.l @@ -0,0 +1,281 @@ +%{ // -*-Fundamental-*- + +#include + +#include "string.hh" +#include "string-convert.hh" +#include "notename.hh" +#include "lexer.hh" +#include "varray.hh" +#include "parser.hh" +#include "debug.hh" +#include "input-score.hh" +#include "parseconstruct.hh" +#include "main.hh" + +%} + +%option c++ +%option noyywrap +%option nodefault +%option yylineno +%option debug +%option yyclass="My_flex_lexer" +%option stack + +%x notes +%x incl +%x quote +%x lyrics + + + +A [a-zA-Z] +AA {A}|_ +N [0-9] +AN {AA}|{N} +PUNCT [?!,.:;] +ACCENT [\\'"^] +NATIONAL [\241-\377] +TEX {AA}|-|{PUNCT}|{ACCENT}|{NATIONAL} + +WORD {A}{AN}* +ALPHAWORD {A}+ +INT -?{N}+ +REAL {INT}?(\.{N}*)? + +OPTSIGN !? +PITCHMOD ['`]*{OPTSIGN} +RESTNAME r|s|p +NOTECOMMAND \\{WORD} +NOTENAME [a-z]+ +UNOTENAME [A-Z][a-z]* +DOTS \.+ +LYRICS {TEX}+ +COMMENT [%#].*\n + +%% + +\$ { + yy_push_state(notes); +} + +\@ { + yy_push_state(lyrics); +} + +{RESTNAME} { + const char *s = YYText(); + yylval.string = new String (s); + mtor << "rest:"<< yylval.string; + return RESTNAME; +} +{UNOTENAME} { + int *p=yylval.ii; + return ret_notename(p, YYText(), -1); +} + +{NOTENAME} { + int *p=yylval.ii; + return ret_notename(p, YYText(), 0); +} + +{NOTECOMMAND} { + String c = YYText() +1; + mtor << "\\word: " << YYText()+1<{PITCHMOD} { + const char *s = YYText(); + mtor << "pitchmod:"<< YYText()<{DOTS} { + yylval.i = strlen(YYText()); + return DOTS; +} +{INT} { + yylval.i = String_convert::dec2_i( String( YYText() ) ); + return INT; +} +{COMMENT} { +} +[ \t\n]+ { + +} +\$ { + yy_pop_state(); +} +\"[^"]*\" { + String s (YYText()+1); + s = s.left_str(s.length_i()-1); + yylval.string = new String(s); + return STRING; +} +. { + return yylval.c = YYText()[0]; +} + +\" { + yy_push_state(quote); +} +[^"]* { + yylval.string = new String (YYText()); +} +\" { + mtor << "quoted string\n"; + yy_pop_state(); + return STRING; +} + +{DOTS} { + yylval.i = strlen(YYText()); + return DOTS; +} +{INT} { + yylval.i = String_convert::dec2_i( String( YYText() ) ); + return INT; +} +{NOTECOMMAND} { + String c = YYText() +1; + mtor << "\\word: " << YYText()+1<\"[^"]*\" { + String s (YYText()+1); + s = s.left_str(s.length_i()-1); + yylval.string = new String(s); + return STRING; +} +{LYRICS} { + String s (YYText()); + int i = 0; + while ((i=s.index_i("_")) != -1) // change word binding "_" to " " + *(s.ch_l() + i) = ' '; + if ((i=s.index_i("\\,")) != -1) // change "\," to TeX's "\c " + { + *(s.ch_l() + i + 1) = 'c'; + s = s.left_str(i+2) + " " + s.right_str(s.length_i()-i-2); + } + yylval.string = new String(s); + return STRING; +} +\| { + return YYText()[0]; +} +{COMMENT} { + +} +[{}] { + return YYText()[0]; +} +[()\[\]|/.^>_-] { + return yylval.c = YYText()[0]; +} +[ \t\n]+ { +} +@ { + yy_pop_state(); +} + +<> { + mtor << "<>"; + + if (! close_input()) + yyterminate(); // can't move this, since it actually rets a YY_NULL +} + + +include { + yy_push_state(incl); +} +[ \t]* { /* eat the whitespace */ } +\"[^"]*\"+ { /* got the include file name */ + String s (YYText()+1); + s = s.left_str(s.length_i()-1); + defined_ch_c_l = here_ch_c_l() - String( YYText() ).length_i() - 1; + new_input(s); + yy_pop_state(); +} + + +{WORD} { + mtor << "word: " << YYText()< + +#include "lookup.hh" +#include "misc.hh" +#include "lexer.hh" +#include "paper-def.hh" +#include "midi-def.hh" +#include "input-score.hh" +#include "main.hh" +#include "keyword.hh" +#include "debug.hh" +#include "parseconstruct.hh" +#include "dimen.hh" +#include "identifier.hh" +#include "commandrequest.hh" +#include "musicalrequest.hh" +#include "voice-element.hh" + +#ifndef NDEBUG +#define YYDEBUG 1 +#endif + +Array pre_reqs, post_reqs; +Array define_spots; +Paper_def*default_paper(); +char const* defined_ch_c_l; +char const* req_defined_ch_c_l; +int fatal_error_i = 0; + +%} + + +%union { + Request * request; + Real real; + Identifier *id; + Voice *voice; + Voice_element *el; + String *string; + const char *consstr; + Paper_def *paper; + Midi_def* midi; + Input_music *music; + Music_general_chord *chord; + Music_voice *mvoice; + int i; + char c; + int ii[10]; + Moment *moment; + + Array * strvec; + Array *intvec; + Array *melreqvec; + Input_staff *staff; + Input_score *score; + Symtables * symtables; + Symtable * symtable; + Symbol * symbol; + Lookup*lookup; + Interval *interval; + Box *box; + Notename_tab *notename_tab; + Script_def * script; + Text_def * textdef; +} + +%token VOICE STAFF SCORE TITLE BAR OUTPUT MULTIVOICE +%token CM_T IN_T PT_T MM_T PAPER WIDTH METER UNITSPACE SKIP COMMANDS COMMAND +%token GEOMETRIC START_T DURATIONCOMMAND OCTAVECOMMAND +%token KEY CLEF TABLE VOICES STEM +%token PARTIAL MUSIC GROUPING CADENZA +%token END SYMBOLTABLES TEXID TABLE NOTENAMES SCRIPT TEXTSTYLE PLET +%token GOTO +%token MIDI TEMPO + +%token IDENTIFIER +%token PITCHMOD DURATION RESTNAME +%token NOTENAME +%token REAL +%token STRING + +%token DOTS INT +%type unit +%type pitch_list +%type open_request_parens close_request_parens close_plet_parens +%type declaration +%type declarable_identifier +%type paper_block paper_body +%type midi_block midi_body +%type dim real +%type default_duration explicit_duration notemode_duration mudela_duration +%type notename +%type duration_length +%type voice_elt full_element lyrics_elt command_elt + +%type score_block score_body +%type staff_block staff_init staff_body +%type int +%type intastint_list +%type post_request pre_request command_req +%type pitchmod +%type music +%type music_chord music_chord_body + +%type music_voice_body music_voice + +%type dinterval +%type box +%type symtable symtable_body +%type symtables symtables_body +%type symboldef +%type notename_tab notename_tab_body +%type script_dir +%type