#ifndef lint
static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
#endif
#define YYBYACC 1
#define YYMAJOR 1
#define YYMINOR 9
#define yyclearin (yychar=(-1))
#define yyerrok (yyerrflag=0)
#define YYRECOVERING (yyerrflag!=0)
#define yyparse fml_parse
#define yylex fml_lex
#define yyerror fml_error
#define yychar fml_char
#define yyval fml_val
#define yylval fml_lval
#define yydebug fml_debug
#define yynerrs fml_nerrs
#define yyerrflag fml_errflag
#define yyss fml_ss
#define yyssp fml_ssp
#define yyvs fml_vs
#define yyvsp fml_vsp
#define yylhs fml_lhs
#define yylen fml_len
#define yydefred fml_defred
#define yydgoto fml_dgoto
#define yysindex fml_sindex
#define yyrindex fml_rindex
#define yygindex fml_gindex
#define yytable fml_table
#define yycheck fml_check
#define yyname fml_name
#define yyrule fml_rule
#define YYPREFIX "fml_"
#line 8 "capaFormula.y"
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
#include "capaParser.h" /* _symbol structure def */
#include "capaCommon.h"
#include "capaFunction.h"
#include "capaToken.h"
#ifdef __hpux
#include <stdlib.h>
#include <alloca.h>
#endif
#ifdef FML_DBUG
#define FMLDBUG_PR1(xx) { printf(xx); fflush(stdout); }
#define FMLDBUG_PR2(xx,yy) { printf(xx,yy); fflush(stdout); }
#define FMLDBUG_PR3(xx,yy,zz) { printf(xx,yy,zz); fflush(stdout); }
#else
#define FMLDBUG_PR1(xx) { }
#define FMLDBUG_PR2(xx,yy) { }
#define FMLDBUG_PR3(xx,yy,zz) { }
#endif
#define ADD_op 1
#define SUB_op 2
#define MUL_op 3
#define DIV_op 4
#define IDIV_op 5
#define NOT_DEFINED_op 9
#ifdef YYSTYPE
#undef YYSTYPE
#endif
#define YYSTYPE Symbol_p
/* =============================================================== */
extern int Func_idx;
extern Symbol FuncStack[MAX_FUNC_NEST];
double FormulaVal;
int FormulaParseOK=1;
#line 81 "fma.tab.c"
#define F_NUMBER 257
#define V_ID 258
#define F_ID 259
#define EoI 260
#define F_ERROR 261
#define F_PLUS 262
#define F_MINUS 263
#define F_MULT 264
#define F_DIV 265
#define F_MOD 266
#define F_POW 267
#define F_LPAR 268
#define F_RPAR 269
#define F_COMMA 270
#define YYERRCODE 256
short fml_lhs[] = { -1,
0, 1, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 5, 5, 4, 4, 4, 4, 4, 4,
4,
};
short fml_len[] = { 2,
1, 3, 3, 1, 1, 1, 3, 3, 3, 1,
3, 1, 3, 1, 3, 4, 1, 2, 2, 1,
3,
};
short fml_defred[] = { 0,
6, 20, 17, 0, 5, 0, 0, 0, 0, 0,
0, 0, 12, 0, 19, 18, 0, 0, 0, 0,
0, 0, 0, 15, 0, 0, 21, 0, 0, 0,
0, 0, 11, 16, 0, 0,
};
short fml_dgoto[] = { 9,
10, 11, 12, 13, 26,
};
short fml_sindex[] = { -227,
0, 0, 0, -266, 0, -219, -219, -227, 0, -241,
-218, -262, 0, -245, 0, 0, -254, -219, -219, -219,
-219, -219, -219, 0, -241, -244, 0, -218, -218, -262,
-262, -262, 0, 0, -227, -241,
};
short fml_rindex[] = { 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 7,
33, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, -216, 0, 0, 37, 42, 10,
19, 28, 0, 0, 0, -214,
};
short fml_gindex[] = { 0,
-8, 39, 30, -3, 0,
};
#define YYTABLESIZE 312
short fml_table[] = { 17,
10, 14, 15, 16, 23, 25, 1, 18, 19, 7,
1, 2, 3, 4, 27, 5, 6, 7, 8, 33,
18, 19, 8, 24, 34, 35, 36, 9, 1, 2,
3, 4, 4, 5, 6, 7, 2, 2, 3, 4,
8, 3, 6, 7, 0, 20, 21, 22, 8, 30,
31, 32, 14, 14, 13, 13, 28, 29, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 10, 10, 10, 10, 10, 0, 0, 10,
10, 7, 7, 7, 7, 7, 0, 0, 7, 7,
8, 8, 8, 8, 8, 0, 0, 8, 8, 9,
9, 9, 9, 9, 4, 4, 9, 9, 2, 2,
0, 4, 4, 3, 3, 2, 2, 0, 0, 0,
3, 3,
};
short fml_check[] = { 8,
0, 268, 6, 7, 267, 14, 0, 262, 263, 0,
256, 257, 258, 259, 269, 261, 262, 263, 0, 23,
262, 263, 268, 269, 269, 270, 35, 0, 256, 257,
258, 259, 0, 261, 262, 263, 0, 257, 258, 259,
268, 0, 262, 263, -1, 264, 265, 266, 268, 20,
21, 22, 269, 270, 269, 270, 18, 19, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, 262, 263, 264, 265, 266, -1, -1, 269,
270, 262, 263, 264, 265, 266, -1, -1, 269, 270,
262, 263, 264, 265, 266, -1, -1, 269, 270, 262,
263, 264, 265, 266, 262, 263, 269, 270, 262, 263,
-1, 269, 270, 262, 263, 269, 270, -1, -1, -1,
269, 270,
};
#define YYFINAL 9
#ifndef YYDEBUG
#define YYDEBUG 0
#endif
#define YYMAXTOKEN 270
#if YYDEBUG
char *fml_name[] = {
"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"F_NUMBER","V_ID","F_ID","EoI",
"F_ERROR","F_PLUS","F_MINUS","F_MULT","F_DIV","F_MOD","F_POW","F_LPAR","F_RPAR",
"F_COMMA",
};
char *fml_rule[] = {
"$accept : f_expr",
"f_expr : block",
"block : block F_PLUS term",
"block : block F_MINUS term",
"block : term",
"block : F_ERROR",
"block : error",
"term : term F_MULT basic_constr",
"term : term F_DIV basic_constr",
"term : term F_MOD basic_constr",
"term : basic_constr",
"basic_constr : basic_constr F_POW basic_item",
"basic_constr : basic_item",
"arg_list : arg_list F_COMMA block",
"arg_list : block",
"basic_item : F_ID F_LPAR F_RPAR",
"basic_item : F_ID F_LPAR arg_list F_RPAR",
"basic_item : V_ID",
"basic_item : F_MINUS basic_item",
"basic_item : F_PLUS basic_item",
"basic_item : F_NUMBER",
"basic_item : F_LPAR block F_RPAR",
};
#endif
#ifndef YYSTYPE
typedef int YYSTYPE;
#endif
#ifdef YYSTACKSIZE
#undef YYMAXDEPTH
#define YYMAXDEPTH YYSTACKSIZE
#else
#ifdef YYMAXDEPTH
#define YYSTACKSIZE YYMAXDEPTH
#else
#define YYSTACKSIZE 500
#define YYMAXDEPTH 500
#endif
#endif
int yydebug;
int yynerrs;
int yyerrflag;
int yychar;
short *yyssp;
YYSTYPE *yyvsp;
YYSTYPE yyval;
YYSTYPE yylval;
short yyss[YYSTACKSIZE];
YYSTYPE yyvs[YYSTACKSIZE];
#define yystacksize YYSTACKSIZE
#line 155 "capaFormula.y"
void
fml_error(char *msg)
{
FormulaParseOK=0;
printf("Error Parsing: %s\n",msg);
}
/* ---------------------------------------------------- */
Symbol *
f_symbol_pow(ap,bp) Symbol *ap; Symbol *bp;
{
Symbol *cp;
double a, b;
int error = 0;
cp = NULL;
switch(ap->s_type) {
case I_VAR: a = (double)(ap->s_int);
break;
case I_CONSTANT: a = (double)(ap->s_int); capa_mfree((char *)ap);
break;
case R_VAR: a = ap->s_real;
break;
case R_CONSTANT: a = ap->s_real; capa_mfree((char *)ap);
break;
case S_VAR:
case S_CONSTANT:
default: error = 1; break;
}
switch(bp->s_type) {
case I_VAR: b = (double)(bp->s_int);
break;
case I_CONSTANT: b = (double)(bp->s_int); capa_mfree((char *)bp);
break;
case R_VAR: b = bp->s_real;
break;
case R_CONSTANT: b = bp->s_real; capa_mfree((char *)bp);
break;
case S_VAR:
case S_CONSTANT:
default: error = 1; break;
}
if (!error) {
cp = (Symbol *)capa_malloc(sizeof(Symbol),1);
cp->s_type = R_CONSTANT;
cp->s_real = pow(a,b);
}
return (cp);
}
/* ============================================================================= */
#line 320 "fma.tab.c"
#define YYABORT goto yyabort
#define YYREJECT goto yyabort
#define YYACCEPT goto yyaccept
#define YYERROR goto yyerrlab
int
yyparse()
{
register int yym, yyn, yystate;
#if YYDEBUG
register char *yys;
extern char *getenv();
if (yys = getenv("YYDEBUG"))
{
yyn = *yys;
if (yyn >= '0' && yyn <= '9')
yydebug = yyn - '0';
}
#endif
yynerrs = 0;
yyerrflag = 0;
yychar = (-1);
yyssp = yyss;
yyvsp = yyvs;
*yyssp = yystate = 0;
yyloop:
if (yyn = yydefred[yystate]) goto yyreduce;
if (yychar < 0)
{
if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("%sdebug: state %d, reading %d (%s)\n",
YYPREFIX, yystate, yychar, yys);
}
#endif
}
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: state %d, shifting to state %d\n",
YYPREFIX, yystate, yytable[yyn]);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate = yytable[yyn];
*++yyvsp = yylval;
yychar = (-1);
if (yyerrflag > 0) --yyerrflag;
goto yyloop;
}
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{
yyn = yytable[yyn];
goto yyreduce;
}
if (yyerrflag) goto yyinrecovery;
#ifdef lint
goto yynewerror;
#endif
yynewerror:
yyerror("syntax error");
#ifdef lint
goto yyerrlab;
#endif
yyerrlab:
++yynerrs;
yyinrecovery:
if (yyerrflag < 3)
{
yyerrflag = 3;
for (;;)
{
if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: state %d, error recovery shifting\
to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate = yytable[yyn];
*++yyvsp = yylval;
goto yyloop;
}
else
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: error recovery discarding state %d\n",
YYPREFIX, *yyssp);
#endif
if (yyssp <= yyss) goto yyabort;
--yyssp;
--yyvsp;
}
}
}
else
{
if (yychar == 0) goto yyabort;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
YYPREFIX, yystate, yychar, yys);
}
#endif
yychar = (-1);
goto yyloop;
}
yyreduce:
#if YYDEBUG
if (yydebug)
printf("%sdebug: state %d, reducing by rule %d (%s)\n",
YYPREFIX, yystate, yyn, yyrule[yyn]);
#endif
yym = yylen[yyn];
yyval = yyvsp[1-yym];
switch (yyn)
{
case 1:
#line 66 "capaFormula.y"
{ switch(yyvsp[0]->s_type) {
case I_VAR:
case I_CONSTANT: FormulaVal = (double)(yyvsp[0]->s_int);
break;
case R_VAR:
case R_CONSTANT: FormulaVal = yyvsp[0]->s_real;
break;
case S_VAR:
case S_CONSTANT: FormulaParseOK = 0;
break;
default: FormulaParseOK = 0;
break;
}
capa_mfree((char *)yyvsp[0]);
FMLDBUG_PR1("[f_expr <= block ]\n");
}
break;
case 2:
#line 84 "capaFormula.y"
{ yyval = symbols_op(yyvsp[-2], yyvsp[0], ADD_op); }
break;
case 3:
#line 85 "capaFormula.y"
{ yyval = symbols_op(yyvsp[-2], yyvsp[0], SUB_op); }
break;
case 4:
#line 86 "capaFormula.y"
{ yyval = yyvsp[0]; }
break;
case 5:
#line 87 "capaFormula.y"
{ FormulaParseOK = 0; FMLDBUG_PR1("[F_ERROR]\n"); return 0;}
break;
case 6:
#line 88 "capaFormula.y"
{ FormulaParseOK = 0; FMLDBUG_PR1("[ERROR]\n"); return 0; }
break;
case 7:
#line 91 "capaFormula.y"
{ yyval = symbols_op(yyvsp[-2], yyvsp[0], MUL_op); }
break;
case 8:
#line 92 "capaFormula.y"
{ yyval = symbols_op(yyvsp[-2], yyvsp[0], DIV_op); }
break;
case 9:
#line 93 "capaFormula.y"
{ yyval = symbols_op(yyvsp[-2], yyvsp[0], IDIV_op); }
break;
case 10:
#line 94 "capaFormula.y"
{ yyval = yyvsp[0]; }
break;
case 11:
#line 97 "capaFormula.y"
{ yyval = f_symbol_pow(yyvsp[-2],yyvsp[0]);
FMLDBUG_PR3("[%.16g ^ %.16g] ",yyvsp[-2]->s_real,yyvsp[0]->s_real); }
break;
case 12:
#line 99 "capaFormula.y"
{ yyval = yyvsp[0]; }
break;
case 13:
#line 102 "capaFormula.y"
{ yyval = yyvsp[-2];
yyval->s_argc++;
yyval->s_argp = addto_arglist(yyvsp[-2]->s_argp, yyvsp[0]);
}
break;
case 14:
#line 106 "capaFormula.y"
{ yyval = yyvsp[0];
yyval->s_argc = 1;
yyval->s_argp = new_arglist(yyvsp[0]);
}
break;
case 15:
#line 112 "capaFormula.y"
{ int tmp;
Func_idx--;
if(Func_idx >= 0 ) {
tmp = match_function(FuncStack[Func_idx].s_name,0);
yyval = do_function(tmp, 0, NULL );
capa_mfree(FuncStack[Func_idx].s_name);
}
}
break;
case 16:
#line 121 "capaFormula.y"
{ int tmp;
Func_idx--;
if(Func_idx >= 0 ) {
tmp = match_function(FuncStack[Func_idx].s_name,yyvsp[-1]->s_argc);
yyval = do_function(tmp, yyvsp[-1]->s_argc, yyvsp[-1]->s_argp);
capa_mfree(FuncStack[Func_idx].s_name);
free_arglist(yyvsp[-1]->s_argp);
}
}
break;
case 17:
#line 131 "capaFormula.y"
{ FMLDBUG_PR3("[V %s = %.16g] ",yyvsp[0]->s_name, yyvsp[0]->s_real);
yyval = yyvsp[0];
}
break;
case 18:
#line 134 "capaFormula.y"
{ yyval = yyvsp[0];
switch(yyvsp[0]->s_type) {
case I_VAR: yyval = (Symbol *)capa_malloc(sizeof(Symbol),1);
yyval->s_type = I_CONSTANT;
case I_CONSTANT: yyval->s_int = - yyvsp[0]->s_int; break;
case R_VAR: yyval = (Symbol *)capa_malloc(sizeof(Symbol),1);
yyval->s_type = R_CONSTANT;
case R_CONSTANT: yyval->s_real = (-1.0)*(yyvsp[0]->s_real);
break;
case S_VAR:
case S_CONSTANT: break;
default: break;
}
}
break;
case 19:
#line 148 "capaFormula.y"
{ yyval = yyvsp[0]; }
break;
case 20:
#line 149 "capaFormula.y"
{ FMLDBUG_PR2("[F %.16g] ",yyvsp[0]->s_real);
yyval = yyvsp[0];
}
break;
case 21:
#line 152 "capaFormula.y"
{ yyval = yyvsp[-1]; }
break;
#line 601 "fma.tab.c"
}
yyssp -= yym;
yystate = *yyssp;
yyvsp -= yym;
yym = yylhs[yyn];
if (yystate == 0 && yym == 0)
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: after reduction, shifting from state 0 to\
state %d\n", YYPREFIX, YYFINAL);
#endif
yystate = YYFINAL;
*++yyssp = YYFINAL;
*++yyvsp = yyval;
if (yychar < 0)
{
if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("%sdebug: state %d, reading %d (%s)\n",
YYPREFIX, YYFINAL, yychar, yys);
}
#endif
}
if (yychar == 0) goto yyaccept;
goto yyloop;
}
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
yystate = yytable[yyn];
else
yystate = yydgoto[yym];
#if YYDEBUG
if (yydebug)
printf("%sdebug: after reduction, shifting from state %d \
to state %d\n", YYPREFIX, *yyssp, yystate);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate;
*++yyvsp = yyval;
goto yyloop;
yyoverflow:
yyerror("yacc stack overflow");
yyabort:
return (1);
yyaccept:
return (0);
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>