2014-02-06 18:52:13 +00:00
|
|
|
/*
|
|
|
|
* MathLexer.lpp, part of LatAnalyze 3
|
|
|
|
*
|
2015-06-11 14:04:54 +01:00
|
|
|
* Copyright (C) 2013 - 2015 Antonin Portelli
|
2014-02-06 18:52:13 +00:00
|
|
|
*
|
|
|
|
* LatAnalyze 3 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* LatAnalyze 3 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 LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-09-15 18:39:22 +01:00
|
|
|
%option reentrant
|
2014-01-22 15:57:47 +00:00
|
|
|
%option prefix="_math_"
|
2013-09-15 18:39:22 +01:00
|
|
|
%option bison-bridge
|
|
|
|
%option bison-locations
|
|
|
|
%option noyywrap
|
|
|
|
%option yylineno
|
|
|
|
|
|
|
|
%{
|
|
|
|
#include <iostream>
|
2014-03-13 18:51:01 +00:00
|
|
|
#include <LatAnalyze/MathInterpreter.hpp>
|
2014-03-14 11:05:25 +00:00
|
|
|
#include "MathParser.hpp"
|
2015-05-23 14:44:43 +01:00
|
|
|
|
|
|
|
#if (defined __INTEL_COMPILER)
|
|
|
|
#pragma warning disable 1682 2259
|
|
|
|
#elif (defined __GNUC__)||(defined __clang__)
|
2015-02-24 16:59:22 +00:00
|
|
|
#pragma GCC diagnostic ignored "-Wconversion"
|
|
|
|
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
2013-09-15 18:39:22 +01:00
|
|
|
#pragma GCC diagnostic ignored "-Wsign-compare"
|
|
|
|
#pragma GCC diagnostic ignored "-Wunused-function"
|
|
|
|
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
2015-05-23 14:44:43 +01:00
|
|
|
#endif
|
2013-09-15 18:39:22 +01:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Latan;
|
|
|
|
|
2014-02-06 18:07:27 +00:00
|
|
|
#define YY_EXTRA_TYPE MathInterpreter::MathParserState *
|
2013-09-15 18:39:22 +01:00
|
|
|
#define YY_USER_ACTION \
|
|
|
|
yylloc->first_line = yylloc->last_line = yylineno;\
|
|
|
|
yylloc->first_column = yylloc->last_column + 1;\
|
|
|
|
yylloc->last_column = yylloc->first_column + yyleng - 1;
|
|
|
|
|
2014-01-23 14:08:18 +00:00
|
|
|
#define YY_INPUT(buf, result, max_size) \
|
2013-09-15 18:39:22 +01:00
|
|
|
{ \
|
2014-01-23 14:08:18 +00:00
|
|
|
(*yyextra->stream).read(buf, max_size);\
|
2013-09-15 18:39:22 +01:00
|
|
|
result = (*yyextra->stream).gcount();\
|
|
|
|
}
|
|
|
|
|
|
|
|
#define YY_DEBUG 0
|
|
|
|
#if (YY_DEBUG == 1)
|
|
|
|
#define RET(var) cout << (var) << "(" << yytext << ")" << endl; return (var)
|
|
|
|
#define RETTOK(tok) cout << #tok << "(" << yytext << ")" << endl; return tok
|
|
|
|
#else
|
|
|
|
#define RET(var) return (var)
|
|
|
|
#define RETTOK(tok) return tok
|
|
|
|
#endif
|
|
|
|
%}
|
|
|
|
|
|
|
|
DIGIT [0-9]
|
|
|
|
ALPHA [a-zA-Z_]
|
|
|
|
FLOAT (({DIGIT}+(\.{DIGIT}*)?)|({DIGIT}*\.{DIGIT}+))([eE][+-]?{DIGIT}+)?
|
2014-02-04 17:33:58 +00:00
|
|
|
SPECIAL [;,()+\-*/^={}]
|
2013-09-15 18:39:22 +01:00
|
|
|
BLANK [ \t]
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
{FLOAT} {
|
|
|
|
strncpy(yylval->val_str,yytext,MAXIDLENGTH);
|
|
|
|
RETTOK(FLOAT);
|
|
|
|
}
|
2014-02-04 17:33:58 +00:00
|
|
|
{SPECIAL} {RET(*yytext);}
|
|
|
|
return {RETTOK(RETURN);}
|
2013-09-15 18:39:22 +01:00
|
|
|
{ALPHA}({ALPHA}|{DIGIT})* {
|
|
|
|
strncpy(yylval->val_str,yytext,MAXIDLENGTH);
|
|
|
|
RETTOK(ID);
|
|
|
|
}
|
|
|
|
<*>\n {yylloc->last_column = 0;}
|
|
|
|
<*>{BLANK}
|
|
|
|
<*>. {yylval->val_char = yytext[0]; RETTOK(ERR);}
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2014-02-06 18:07:27 +00:00
|
|
|
void MathInterpreter::MathParserState::initScanner()
|
2013-09-15 18:39:22 +01:00
|
|
|
{
|
|
|
|
yylex_init(&scanner);
|
|
|
|
yyset_extra(this, scanner);
|
|
|
|
}
|
|
|
|
|
2014-02-06 18:07:27 +00:00
|
|
|
void MathInterpreter::MathParserState::destroyScanner()
|
2013-09-15 18:39:22 +01:00
|
|
|
{
|
|
|
|
yylex_destroy(scanner);
|
|
|
|
}
|