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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
%{
/*
csound_sco.lex:
Copyright (C) 2013 March
John ffitch
This file is part of Csound.
The Csound Library is free software; you can redistribute it
and/or modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Csound is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with Csound; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "csoundCore.h"
#include "score_param.h"
#include "csound_scoparse.h"
#define YYSTYPE MYFLT
#define YYLTYPE SCOTOKEN
#define YY_DECL int yylex (YYLTYPE *lvalp, CSOUND *csound, yyscan_t yyscanner)
#include "corfile.h"
YYLTYPE *yylval_param;
YYLTYPE *yylloc_param;
static SCOTOKEN *make_string(CSOUND *, char *);
static SCOTOKEN *make_int(CSOUND *, int);
static SCOTOKEN *make_num(CSOUND *, double);
extern void *fopen_path(CSOUND *, FILE **, char *, char *, char *, int);
#define YY_EXTRA_TYPE SCORE_PARM *
#define PARM yyget_extra(yyscanner)
#define YY_USER_INIT
struct yyguts_t;
static SCOTOKEN *do_at(CSOUND *, int, struct yyguts_t*);
%}
%option reentrant
%option bison-bridge
%option bison-locations
%option prefix="csound_sco"
%option outfile="Engine/csound_scolex.c"
%option stdout
STRCONST \"(\\.|[^\"])*\"
STRCONSTe \"(\\.|[^\"])*$
INTGR -?[0-9]+
NUMBER -?[0-9]+\.?[0-9]*([eE][-+]?[0-9]+)?|\.[0-9]+([eE][-+]?[0-9]+)?|0[xX][0-9a-fA-F]+
WHITE [ \t]+
OPTWHITE [ \t]*
CONT \\[ \t]*(;.*)?\n
LINE "#line"
FILE "#source"
EXIT "#exit"
FNAME [a-zA-Z0-9/:.+-_]+
NPX "np^"${INTGR}
PPX "pp^"${INTGR}
CNPX "NP^"${INTGR}
CPPX "PP^"${INTGR}
%x line
%x src
%%
"\r" { } /* EATUP THIS PART OF WINDOWS NEWLINE */
{CONT} { csound_scoset_lineno(1+csound_scoget_lineno(yyscanner),
yyscanner);
}
"\n" { int n = csound_scoget_lineno(yyscanner)+1;
csound_scoset_lineno(n, yyscanner);
return NEWLINE; }
${NPX} { return T_NP; }
${PPX} { return T_PP; }
${CNPX} { return T_CNP; }
${CPPX} { return T_CPP; }
"a" { return yytext[0];}
"b" { return yytext[0];}
"e" { return yytext[0];}
"f" { return yytext[0];}
"i" { return yytext[0];}
"m" { return yytext[0];}
"n" { return yytext[0];}
"q" { return yytext[0];}
"r" { return yytext[0];}
"s" { return yytext[0];}
"t" { return yytext[0];}
"v" { return yytext[0];}
"w" { return yytext[0];}
"x" { return yytext[0];}
"y" { return yytext[0];}
"z" { return yytext[0];}
"(" { return '('; }
")" { return ')'; }
"[" { return '['; }
"]" { return ']'; }
"{" { return '}'; }
"}" { return '}'; }
"+" { return '+'; }
"-" { return '-'; }
"*" { return '*'; }
"/" { return '/'; }
"%" { return '%'; }
"\^" { return '^'; }
"!" { return '!'; }
">" { return '>'; }
"<" { return '<'; }
"|" { return '|'; }
"&" { return '&'; }
"#" { return '#'; }
"~" { return '~'; }
"." { return '.'; }
"@@"{OPTWHITE}{INTGR} { lvalp = do_at(csound, 1, yyg);
return INTEGER_TOKEN; }
"@"{OPTWHITE}{INTGR} { lvalp = do_at(csound, 0, yyg);
return INTEGER_TOKEN; }
{STRCONST} { lvalp = make_string(csound, yytext);
return (STRING_TOKEN); }
{STRCONSTe} { lvalp = make_string(csound, yytext);
csound->Message(csound,
Str("unterminated string found on line %d >>%s<<\n"),
csound_scoget_lineno(yyscanner),
yytext);
return (STRING_TOKEN); }
{INTGR} {
lvalp = make_int(csound, atoi(yytext)); return (INTEGER_TOKEN);
}
{NUMBER} { lvalp = make_num(csound, atof(yytext)); return (NUMBER_TOKEN); }
{WHITE} { }
{LINE} { BEGIN(line); }
<line>[ \t]* /* eat the whitespace */
<line>{INTGR} { csound_scoset_lineno(atoi(yytext), yyscanner);
printf("set line to %d (%s)\n", csound_scoget_lineno(yyscanner), yytext); }
<line>"\n" {BEGIN(INITIAL);}
{FILE} { BEGIN(src); }
<src>[ \t]* /* eat the whitespace */
<src>{FNAME} { PARM->locn = atoi(yytext); }
<src>"\n" { BEGIN(INITIAL); }
{EXIT} { yyterminate(); }
<<EOF>> {
yyterminate();
}
. { fprintf(stderr, "unknown character %c(%.2x)\n",
yytext[0], yytext[0]);
}
%%
static SCOTOKEN *make_string(CSOUND *csound, char *s)
{
SCOTOKEN *ans = (SCOTOKEN*)mcalloc(csound, sizeof(SCOTOKEN));
ans->type = STRING_TOKEN;
ans->strbuff = strdup(s);
return ans;
}
static SCOTOKEN *make_int(CSOUND *csound, int i)
{
SCOTOKEN *ans = (SCOTOKEN*)mcalloc(csound, sizeof(SCOTOKEN));
ans->type = INTEGER_TOKEN;
ans->ival = i;
return ans;
}
static SCOTOKEN *make_num(CSOUND *csound, double f)
{
SCOTOKEN *ans = (SCOTOKEN*)mcalloc(csound, sizeof(SCOTOKEN));
ans->type = NUMBER_TOKEN;
ans->fval = (MYFLT)f;
return ans;
}
static SCOTOKEN *do_at(CSOUND *csound, int k, struct yyguts_t *yyg)
{
SCOTOKEN *ans = (SCOTOKEN*)mcalloc(csound, sizeof(SCOTOKEN));
int n, i = 1;
char *s = yytext;
while (*s=='@') s++;
n = atoi(s);
while (i<=n-k && i< 0x4000000) i <<= 1;
ans->type = INTEGER_TOKEN;
ans->ival = i;
return ans;
}
char *csound_scoget_current_pointer(void *yyscanner)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
return yyg->yy_c_buf_p;
}
int csound_scoget_locn(void *yyscanner)
{
// struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
return PARM->locn;
}
|