-
Notifications
You must be signed in to change notification settings - Fork 16
/
t2mf.fl
98 lines (79 loc) · 1.91 KB
/
t2mf.fl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* $Id: t2mf.fl,v 1.3 1991/11/15 19:31:00 piet Rel $ */
%{
#include "t2mf.h"
#ifdef NO_YYLENG_VAR
int yylength;
#define YY_USER_ACTION yylength = yyleng
#endif
int do_hex = 0;
int eol_seen = 0;
int lineno = 1;
long yyval;
long bankno();
%}
Hex [0-9a-f]
%x QUOTE
%x HEX
%%
if (do_hex) {
BEGIN(HEX);
do_hex = 0;
}
eol_seen = 0;
<INITIAL,HEX>[ \t\r] /* skip whitespace */;
<INITIAL,HEX>"#".*\n /* skip comment */ lineno++;
MFile return MTHD;
MTrk return MTRK;
TrkEnd return TRKEND;
On return ON;
Off return OFF;
Po(ly)?Pr return POPR;
Par(am)? return PAR;
Pb return PB;
Pr(og)?Ch return PRCH;
Ch(an)?Pr return CHPR;
SysEx return SYSEX;
Meta return META;
SeqSpec return SEQSPEC;
Text return TEXT;
Copyright return COPYRIGHT;
TrkName|SeqName return SEQNAME;
InstrName return INSTRNAME;
Lyric return LYRIC;
Marker return MARKER;
Cue return CUE;
SeqNr return SEQNR;
KeySig return KEYSIG;
Tempo return TEMPO;
TimeSig return TIMESIG;
SMPTE return SMPTE;
Arb return ARB;
[:/] return '/';
minor return MINOR;
major return MAJOR;
ch= return CH;
n(ote)?= return NOTE;
v([oa]l)?= return VAL;
c(on)?= return CON;
p(rog)?= return PROG;
[-+]?[0-9]+ sscanf (yytext, "%ld", &yyval); return INT;
0x{Hex}+ sscanf (yytext+2, "%lx", &yyval); return INT;
\$[A-H1-8]+ yyval = bankno (yytext+1, yyleng-1); return INT;
<HEX>{Hex}{Hex}? sscanf (yytext, "%lx", &yyval); return INT;
[a-g][#b+-]?[0-9]+ return NOTEVAL;
<INITIAL,HEX>\" BEGIN (QUOTE);
<QUOTE>[^\\"\n]* yymore();
<QUOTE>\" BEGIN (0); return STRING;
<QUOTE>\\(.|\n) yymore();
<QUOTE>\n { error ("unterminated string");
lineno++; eol_seen++; BEGIN(0); return EOL;
}
<QUOTE><<EOF>> error ("EOF in string"); return EOF;
<INITIAL,HEX>\\[ \t\r]*\n lineno++;
<INITIAL,HEX>\n lineno++; eol_seen++; BEGIN(0); return EOL;
<HEX>[g-z][a-z]+ BEGIN (0); return ERR;
<HEX>. BEGIN (0); return ERR;
[a-z]+ return ERR;
. return ERR;
<<EOF>> return EOF;
%%