📄 mfcalc.cpp
字号:
/* A Bison parser, made from ../../rlplot/mfcalc.y by GNU Bison version 1.28 */#define YYBISON 1 /* Identify Bison output. */#define NUM 257#define STR 258#define ARR 259#define BLOCK 260#define PI 261#define E 262#define CLVAL 263#define PSEP 264#define IF 265#define ELSE 266#define VAR 267#define FNCT 268#define AFNCT 269#define SFNCT 270#define FUNC2 271#define TXT 272#define CLAUSE 273#define SER 274#define COLR 275#define COLC 276#define AND 277#define OR 278#define EQ 279#define NE 280#define GT 281#define GE 282#define LT 283#define LE 284#define NEG 285#define INC 286#define DEC 287#define PINC 288#define PDEC 289/* mfcalc.y, mfcalc.cpp, Copyright (c) 2004, 2005 R.Lackner parse string and simple math: based on the bison 'mfcalc' example This file is part of RLPlot. RLPlot 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. RLPlot 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 RLPlot; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#include <math.h>#include <stdlib.h>#include <ctype.h>#include <string.h>#include <stdio.h>#include "rlplot.h"class symrec {public: int type, row, col; unsigned int h_name; char *name, *text; double (*fnctptr)(...); symrec *next; double var; symrec(unsigned int h_n, int typ, symrec *nxt); ~symrec(); double GetValue(); void GetValue(void *res); double SetValue(double v); void SetValue(void* dest, void* src); void SetName(char *nam); void InitSS();private: bool isSSval;};// syntactical informationstruct syntax_info { int last_tok; //resolve ambiguous ':' double clval; //current value for where - clause int cl1, cl2; //limits of clause formula in buffer struct syntax_info *next; };static syntax_info *syntax_level = 0L;typedef struct{ double val; int type; symrec *tptr; double *a_data; char *text; int a_count;}YYSTYPE;static symrec *putsym (unsigned int h_name, int sym_type);static symrec *getsym (unsigned int h_name, char *sym_name = 0L);static int push(YYSTYPE *res, YYSTYPE *val);static void store_res(YYSTYPE *res);static char *PushString(char *text);static char *add_strings(char *st1, char *st2);static char *string_value(YYSTYPE *exp);static double eval(YYSTYPE *sr, YYSTYPE *dst);static int range_array(YYSTYPE * res, char *range);static void exec_clause(YYSTYPE *res);static YYSTYPE *proc_clause(YYSTYPE *res);static void yyerror(char *s);static int yylex(void);static double nop() {return 0.0;};static char res_txt[1000];static anyResult line_res = {ET_UNKNOWN, 0.0, res_txt};static DataObj *curr_data;static char *last_error = 0L; //error textstatic char *last_err_desc = 0L; //short error descriptionstatic char *buffer = 0L; //the current command bufferstatic int buff_pos = 0;static bool bRecent = false; //rearrange functionsstatic int parse_level = 0; //count reentrances into parser#define MAX_PARSE 20 //maximum number of reentances #include <stdio.h>#ifndef __cplusplus#ifndef __STDC__#define const#endif#endif#define YYFINAL 131#define YYFLAG -32768#define YYNTBASE 48#define YYTRANSLATE(x) ((unsigned)(x) <= 289 ? yytranslate[x] : 54)static const char yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 44, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 46, 47, 36, 35, 20, 34, 2, 37, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 45, 2, 19, 2, 25, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 43, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 21, 22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 38, 39, 40, 41, 42};#if YYDEBUG != 0static const short yyprhs[] = { 0, 0, 1, 4, 6, 8, 10, 13, 16, 19, 22, 25, 28, 30, 34, 38, 42, 44, 48, 50, 52, 56, 60, 62, 66, 68, 70, 72, 74, 76, 78, 80, 84, 88, 93, 98, 105, 114, 119, 124, 131, 140, 146, 154, 158, 162, 166, 170, 174, 178, 182, 186, 190, 194, 198, 202, 205, 208, 211, 214, 217, 221, 225, 231, 237, 243};static const short yyrhs[] = { -1, 48, 49, 0, 44, 0, 45, 0, 20, 0, 53, 44, 0, 53, 45, 0, 53, 20, 0, 50, 44, 0, 50, 45, 0, 1, 44, 0, 4, 0, 50, 35, 53, 0, 53, 35, 50, 0, 50, 35, 50, 0, 50, 0, 13, 23, 13, 0, 5, 0, 53, 0, 52, 20, 52, 0, 52, 21, 53, 0, 51, 0, 3, 22, 3, 0, 3, 0, 18, 0, 9, 0, 7, 0, 8, 0, 13, 0, 6, 0, 13, 19, 53, 0, 13, 19, 50, 0, 14, 46, 53, 47, 0, 15, 46, 52, 47, 0, 15, 46, 53, 10, 53, 47, 0, 15, 46, 53, 10, 53, 10, 53, 47, 0, 16, 46, 50, 47, 0, 16, 46, 53, 47, 0, 17, 46, 52, 10, 52, 47, 0, 17, 46, 52, 10, 52, 10, 51, 47, 0, 11, 46, 53, 47, 6, 0, 11, 46, 53, 47, 6, 12, 6, 0, 53, 26, 53, 0, 53, 27, 53, 0, 53, 28, 53, 0, 53, 29, 53, 0, 53, 30, 53, 0, 53, 31, 53, 0, 53, 32, 53, 0, 53, 33, 53, 0, 53, 35, 53, 0, 53, 34, 53, 0, 53, 36, 53, 0, 53, 37, 53, 0, 34, 53, 0, 13, 39, 0, 13, 40, 0, 39, 13, 0, 40, 13, 0, 53, 43, 53, 0, 46, 52, 47, 0, 53, 25, 53, 24, 53, 0, 53, 25, 4, 24, 4, 0, 53, 25, 4, 24, 53, 0, 53, 25, 53, 24, 4, 0};#endif#if YYDEBUG != 0static const short yyrline[] = { 0, 121, 122, 125, 125, 125, 126, 127, 128, 129, 130, 131, 134, 136, 137, 138, 141, 143, 146, 147, 148, 149, 150, 151, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198};#endif#if YYDEBUG != 0 || defined (YYERROR_VERBOSE)static const char * const yytname[] = { "$","error","$undefined.","NUM","STR","ARR","BLOCK","PI","E","CLVAL","PSEP","IF","ELSE","VAR","FNCT","AFNCT","SFNCT","FUNC2","TXT","'='","','","CLAUSE","SER","COLR","COLC","'?'","AND","OR","EQ","NE","GT","GE","LT","LE","'-'","'+'","'*'","'/'","NEG","INC","DEC","PINC","PDEC","'^'","'\\n'","';'","'('","')'","input","line","str_exp","range","arr","exp", NULL};#endifstatic const short yyr1[] = { 0, 48, 48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 50, 50, 50, 50, 51, 51, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53};static const short yyr2[] = { 0, 0, 2, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 3, 3, 3, 1, 3, 1, 1, 3, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 3, 4, 4, 6, 8, 4, 4, 6, 8, 5, 7, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 3, 3, 5, 5, 5, 5};static const short yydefact[] = { 1, 0, 0, 24, 12, 30, 27, 28, 26, 0, 29, 0, 0, 0, 0, 25, 5, 0, 0, 0, 3, 4, 0, 2, 0, 0, 11, 0, 0, 56, 57, 0, 0, 0, 0, 55, 58, 59, 24, 18, 29, 16, 22, 0, 19, 0, 9, 10, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 32, 31, 0, 0, 19, 0, 0, 0, 0, 0, 0, 0, 0, 61, 15, 13, 0, 0, 43, 44, 45, 46, 47, 48, 49, 50, 52, 14, 51, 53, 54, 60, 0, 33, 34, 0, 37, 38, 0, 51, 23, 17, 20, 21, 0, 0, 41, 0, 0, 63, 64, 65, 62, 0, 0, 35, 0, 39, 42, 0, 0, 0, 36, 40, 0, 0};static const short yydefgoto[] = { 1, 23, 41, 42, 43, 44};static const short yypact[] = {-32768, 88, -39,-32768,-32768,-32768,-32768,-32768,-32768, -33, 2, -26, -24, -18, -17,-32768,-32768, 378, 21, 24,-32768,-32768, 132,-32768, -27, 419,-32768, 378, 173,-32768,-32768, 378, 132, 173, 132, 3,-32768,-32768, 23,-32768, 0, 8,-32768, -14, 331, 173,-32768,-32768,-32768, 214, 378, 378, 378, 378, 378, 378, 378, 378, 378, 173, 378, 378, 378,-32768,-32768, 126, 8, 331, 167, -11, 400, -32, 208, 4, 378, 67, 58, 132, 378,-32768,-32768, 32, 52, 291, 456, 456, 29, 29, 29, 29, 29, 29, 32,-32768, 32, 3, 3, 3, 72,-32768,-32768, 378,-32768,-32768, 132, 32,-32768,-32768, 59, 440, 255, 296, 69, 372, -9,-32768, 440,-32768, 440, 76, 378,-32768, 337,-32768,-32768, 249, 36, 331,-32768,-32768, 84,-32768};static const short yypgoto[] = {-32768,-32768, 34, -37, -30, -1};#define YYLAST 499static const short yytable[] = { 25, 122, 69, 45, 73, 26, 77, 78, 45, 77, 78, 77, 78, 27, 104, 102, 35, 46, 47, 28, 31, 28, 32, 76, 77, 78, 65, 67, 33, 34, 68, 70, 72, 79, 36, 24, 100, 37, 123, 29, 30, 29, 30, 45, 81, 75, 62, 108, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 94, 95, 96, 97, 66, 58, 74, 60, 61, 71, 60, 61, 106, 107, 62, 105, 114, 62, 110, 109, 112, 80, 78, 119, 124, 129, 131, 126, 0, 0, 130, 2, 0, 3, 4, 93, 5, 6, 7, 8, 0, 9, 113, 10, 11, 12, 13, 14, 15, 0, 16, 116, 118, 0, 0, 0, 0, 0, 0, 0, 0, 125, 0, 127, 17, 0, 0, 0, 0, 18, 19, 0, 0, 0, 20, 21, 22, 38, 4, 39, 5, 6, 7, 8, 0, 9, 0, 40, 11, 12, 13, 14, 15, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 74, 60, 61, 0, 0, 17, 0, 0, 62, 0, 18, 19, 98, 0, 0, 3, 4, 22, 5, 6, 7, 8, 0, 9, 0, 10, 11, 12, 13, 14, 15, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 74, 60, 61, 0, 0, 17, 0, 0, 62, 0, 18, 19, 99, 0, 0, 3, 82, 22, 5, 6, 7, 8, 0, 9, 0, 10, 11, 12, 13, 14, 15, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 17, 0, 0, 62, 0, 18, 19, 103, 0, 0, 3, 115, 22, 5, 6, 7, 8, 0, 9, 0, 10, 11, 12, 13, 14, 15, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 74, 60, 61, 0, 0, 17, 0, 0, 62, 0, 18, 19, 128, 0, 0, 3, 117, 22, 5, 6, 7, 8, 0, 9, 0, 10, 11, 12, 13, 14, 15, 111, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 74, 60, 61, 0, 17, 0, 0, 0, 62, 18, 19, 0, 0, 0, 3, 4, 22, 5, 6, 7, 8, 0, 9, 0, 40, 11, 12, 13, 14, 15, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 17, 0, 0, 62, 0, 18, 19, 0, 0, 0, 3, 120, 22, 5, 6, 7, 8, 0, 9, 0, 10, 11, 12, 13, 14, 15, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 74, 60, 61, 101, 0, 17, 0, 0, 62, 0, 18, 19, 121, 0, 0, 0, 0, 22, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 48, 0, 0, 0, 62, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 62, 63, 64, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 74, 60, 61, 0, 0, 0, 0, 0, 62, 52, 53, 54, 55, 56, 57, 58, 74, 60, 61, 0, 0, 0, 0, 0, 62};static const short yycheck[] = { 1, 10, 32, 35, 34, 44, 20, 21, 35, 20, 21, 20, 21, 46, 10, 47, 17, 44, 45, 19, 46, 19, 46, 23, 20, 21, 27, 28, 46, 46, 31, 32, 33, 47, 13, 1, 47, 13, 47, 39, 40, 39, 40, 35, 45, 22, 43, 77, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 28, 34, 35, 36, 37, 33, 36, 37, 3, 13, 43, 74, 104, 43, 24, 78, 6, 45, 21, 12, 6, 47, 0, 122, -1, -1, 0, 1, -1, 3, 4, 59, 6, 7, 8, 9, -1, 11, 101, 13, 14, 15, 16, 17, 18, -1, 20, 110, 111, -1, -1, -1, -1, -1, -1, -1, -1, 120, -1, 122, 34, -1, -1, -1, -1, 39, 40, -1, -1, -1, 44, 45, 46, 3, 4, 5, 6, 7, 8, 9, -1, 11, -1, 13, 14, 15, 16, 17, 18, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, -1, -1, 34, -1, -1, 43, -1, 39, 40, 47, -1, -1, 3, 4, 46, 6, 7, 8, 9, -1, 11, -1, 13, 14, 15, 16, 17, 18, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, -1, -1, 34, -1, -1, 43, -1, 39, 40, 47, -1, -1, 3, 4, 46, 6, 7, 8, 9, -1, 11, -1, 13, 14, 15, 16, 17, 18, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, -1, -1, 34, -1, -1, 43, -1, 39, 40, 47, -1, -1, 3, 4, 46, 6, 7, 8, 9, -1, 11, -1, 13, 14, 15, 16, 17, 18, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, -1, -1, 34, -1, -1, 43, -1, 39, 40, 47, -1, -1, 3, 4, 46, 6, 7, 8, 9, -1, 11, -1, 13, 14, 15, 16, 17, 18, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, -1, 34, -1, -1, -1, 43, 39, 40, -1, -1, -1, 3, 4, 46, 6, 7, 8, 9, -1, 11, -1, 13, 14, 15, 16, 17, 18, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, -1, -1, 34, -1, -1, 43, -1, 39, 40, -1, -1, -1, 3, 10, 46, 6, 7, 8, 9, -1, 11, -1, 13, 14, 15, 16, 17, 18, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 10, -1, 34, -1, -1, 43, -1, 39, 40, 47, -1, -1, -1, -1, 46, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, -1, 20, -1, -1, -1, 43, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, -1, -1, -1, -1, -1, 43, 44, 45, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, -1, -1, -1, -1, -1, 43, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, -1, -1, -1, -1, -1, 43};/* -*-C-*- Note some compilers choke on comments on `#line' lines. *//* This file comes from bison-1.28. *//* Skeleton output parser for bison, Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc. 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, 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. *//* As a special exception, when this file is copied by Bison into a Bison output file, you may use that output file without restriction. This special exception was added by the Free Software Foundation in version 1.24 of Bison. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -