mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2024-11-10 08:55:37 +00:00
76 lines
2.0 KiB
Plaintext
76 lines
2.0 KiB
Plaintext
|
%option reentrant
|
||
|
%option prefix="_Math_"
|
||
|
%option bison-bridge
|
||
|
%option bison-locations
|
||
|
%option noyywrap
|
||
|
%option yylineno
|
||
|
|
||
|
%{
|
||
|
#include <iostream>
|
||
|
#include <latan/MathCompiler.hpp>
|
||
|
#include <latan/MathParser.hpp>
|
||
|
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||
|
#pragma GCC diagnostic ignored "-Wunused-function"
|
||
|
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||
|
|
||
|
using namespace std;
|
||
|
using namespace Latan;
|
||
|
|
||
|
#define YY_EXTRA_TYPE MathParserState*
|
||
|
#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;
|
||
|
|
||
|
#define YY_INPUT(buf,result,max_size) \
|
||
|
{ \
|
||
|
(*yyextra->stream).read(buf,max_size);\
|
||
|
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}+)?
|
||
|
OP [+\-*/^]
|
||
|
PAR [()]
|
||
|
BLANK [ \t]
|
||
|
|
||
|
%%
|
||
|
|
||
|
{FLOAT} {
|
||
|
strncpy(yylval->val_str,yytext,MAXIDLENGTH);
|
||
|
RETTOK(FLOAT);
|
||
|
}
|
||
|
{OP} {RET(*yytext);}
|
||
|
{PAR} {RET(*yytext);}
|
||
|
{ALPHA}({ALPHA}|{DIGIT})* {
|
||
|
strncpy(yylval->val_str,yytext,MAXIDLENGTH);
|
||
|
RETTOK(ID);
|
||
|
}
|
||
|
<*>\n {yylloc->last_column = 0;}
|
||
|
<*>{BLANK}
|
||
|
<*>. {yylval->val_char = yytext[0]; RETTOK(ERR);}
|
||
|
|
||
|
%%
|
||
|
|
||
|
void MathParserState::init_scanner()
|
||
|
{
|
||
|
yylex_init(&scanner);
|
||
|
yyset_extra(this, scanner);
|
||
|
}
|
||
|
|
||
|
void MathParserState::destroy_scanner()
|
||
|
{
|
||
|
yylex_destroy(scanner);
|
||
|
}
|