/* scivi - visualization plugin for XMMS * Copyright (C) 2003 Vitaly V. Bursov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ %{ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #ifdef HAVE_LOCALE_H #include #endif #include "common.h" #include "mathparse.tab.h" #include "mathcompile.h" math_expr_cont *math_lex_expr_cont; #define ERR scivi_complier_error #define WARN scivi_complier_warning %} %option noyywrap %option yylineno %% [[:digit:]]+"."[[:digit:]]* { char *stft; #ifdef HAVE_SETLOCALE char *old_locale = setlocale(LC_NUMERIC, "C"); #endif mathlval.d.line = mathlineno; mathlval.d.num = strtof(mathtext, &stft); if (*stft != '\0') WARN("%d: failed to convert '%s' to a number\n", mathlineno, mathtext); #ifdef HAVE_SETLOCALE setlocale(LC_NUMERIC, old_locale); #endif return NUM; } [[:digit:]]+ { char *stft; #ifdef HAVE_SETLOCALE char *old_locale = setlocale(LC_NUMERIC, "C"); #endif mathlval.d.line = mathlineno; mathlval.d.num = strtof(mathtext, &stft); if (*stft != '\0') WARN("%d: failed to convert '%s' to a number\n", mathlineno, mathtext); #ifdef HAVE_SETLOCALE setlocale(LC_NUMERIC, old_locale); #endif return NUM; } "if" mathlval.d.line = mathlineno; return KW_IF; "else" mathlval.d.line = mathlineno; return KW_ELSE; "for" mathlval.d.line = mathlineno; return KW_FOR; "do" mathlval.d.line = mathlineno; return KW_DO; "while" mathlval.d.line = mathlineno; return KW_WHILE; "break" mathlval.d.line = mathlineno; return KW_BREAK; "continue" mathlval.d.line = mathlineno; return KW_CONTINUE; "=" mathlval.d.line = mathlineno; return SY_ASSGIN; "+=" mathlval.d.line = mathlineno; return SY_ASSGIN_PLUS; "-=" mathlval.d.line = mathlineno; return SY_ASSGIN_MIN; "/=" mathlval.d.line = mathlineno; return SY_ASSGIN_DIV; "*=" mathlval.d.line = mathlineno; return SY_ASSGIN_MUL; "|" mathlval.d.line = mathlineno; return SY_OR; "~" mathlval.d.line = mathlineno; return SY_NOT; "!" mathlval.d.line = mathlineno; return SY_LNOT; "&" mathlval.d.line = mathlineno; return SY_AND; "^" mathlval.d.line = mathlineno; return SY_XOR; "%" mathlval.d.line = mathlineno; return SY_MOD; "||" mathlval.d.line = mathlineno; return SY_OROR; "&&" mathlval.d.line = mathlineno; return SY_ANDAND; ">" mathlval.d.line = mathlineno; return SY_GR; "<" mathlval.d.line = mathlineno; return SY_LS; ">=" mathlval.d.line = mathlineno; return SY_GE; "<=" mathlval.d.line = mathlineno; return SY_LE; "==" mathlval.d.line = mathlineno; return SY_EQ; "!=" mathlval.d.line = mathlineno; return SY_NEQ; [+\-*/(),{}\[\]] { mathlval.d.line = mathlineno; return mathtext[0]; } [[:alpha:]_]+[[:alnum:]_]* { int l = strlen(mathtext)+1; mathlval.d.line = mathlineno; mathlval.d.str = malloc(l); if (mathlval.d.str == NULL){ eprintf("Failed to allocate %d bytes\n", l); return EOS; } else memcpy(mathlval.d.str, mathtext, l); if (MATH(is_func_name)(math_lex_expr_cont, mathtext)) return FUNC; else return VAR; } [[:space:]] /* skip */ "#"[^\n]*"\n" /* skip */ "\n" /* skip */ ";" mathlval.d.line = mathlineno; return EOL; <> mathlval.d.line = mathlineno; return EOS; [^;[:space:][:alnum:]_+\-*/(),{}\[\]=<>!|*&^%\n]+ { ERR("%d: Invalid token '%s'\n", mathlineno, mathtext); } %%