From 435315f25e47a85184e0a1fac65d0abf81c8ea2e Mon Sep 17 00:00:00 2001 From: emc-re-ds Date: Wed, 14 Jul 2021 11:31:59 +0200 Subject: [PATCH] simplified yacc file --- src/SRCompiler.l | 77 ++++--- src/SRCompiler.y | 535 ++++++++++------------------------------------- 2 files changed, 142 insertions(+), 470 deletions(-) diff --git a/src/SRCompiler.l b/src/SRCompiler.l index 9487025..fb86dbb 100644 --- a/src/SRCompiler.l +++ b/src/SRCompiler.l @@ -1,16 +1,13 @@ /* This file is part of SRCompiler. - SRCompiler 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. - SRCompiler 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 SRCompiler. If not, see . */ @@ -86,14 +83,14 @@ LD [0-9a-zA-Z_] /* Builtins (AKA functions) */ %} "GRAPH" {return ret(tkGraph);} +"INIT" {return ret(tkInit);} %{ /* Data Builtins */ %} -"INIT" {return ret(tkInit);} -"ENDVAL" {return ret(tkEndval);} -"HISTORY" {return ret(tkHistory);} -"PREVIOUS" {return ret(tkPrevious);} +"ENDVAL" {return ret(tkBuiltin);} +"HISTORY" {return ret(tkBuiltin);} +"PREVIOUS" {return ret(tkBuiltin);} %{ /* Logical Builtins */ @@ -108,55 +105,55 @@ LD [0-9a-zA-Z_] %{ /* Statistical Builtins */ %} -"RANDOM" {return ret(tkRandom);} -"NORMAL" {return ret(tkNormal);} -"POISSON" {return ret(tkPoisson);} -"LOGNORMAL" {return ret(tkLognormal);} -"EXPRAND" {return ret(tkExprand);} +"RANDOM" {return ret(tkBuiltin);} +"NORMAL" {return ret(tkBuiltin);} +"POISSON" {return ret(tkBuiltin);} +"LOGNORMAL" {return ret(tkBuiltin);} +"EXPRAND" {return ret(tkBuiltin);} %{ /* Miscellaneous Builtins */ %} -"COUNTER" {return ret(tkCter);} -"TREND" {return ret(tkTrend);} +"COUNTER" {return ret(tkBuiltin);} +"TREND" {return ret(tkBuiltin);} %{ /* Simulation Builtins */ %} -"TIME" {return ret(tkTime);} -"DT" {return ret(tkDiT);} -"STARTTIME" {return ret(tkStartTime);} -"STOPTIME" {return ret(tkStopTime);} +"TIME" {return ret(tkBuiltin);} +"DT" {return ret(tkBuiltin);} +"STARTTIME" {return ret(tkBuiltin);} +"STOPTIME" {return ret(tkBuiltin);} %{ /* Mathematical Builtins */ %} -"MAX" {return ret(tkMax);} -"MIN" {return ret(tkMin);} -"EXP" {return ret(tkExp);} -"ABS" {return ret(tkAbs);} -"LN" {return ret(tkLn);} -"INT" {return ret(tkInt);} -"LOG10" {return ret(tkLog);} -"MOD" {return ret(tkMod);} -"PERCENT" {return ret(tkPer);} -"PI" {return ret(tkPi);} -"ROOTN" {return ret(tkRtn);} -"ROUND" {return ret(tkRond);} -"SAFEDIV" {return ret(tkSfDiv);} -"SQRT" {return ret(tkSqrt);} +"MAX" {return ret(tkBuiltin);} +"MIN" {return ret(tkBuiltin);} +"EXP" {return ret(tkBuiltin);} +"ABS" {return ret(tkBuiltin);} +"LN" {return ret(tkBuiltin);} +"INT" {return ret(tkBuiltin);} +"LOG10" {return ret(tkBuiltin);} +"MOD" {return ret(tkBuiltin);} +"PERCENT" {return ret(tkBuiltin);} +"PI" {return ret(tkBuiltin);} +"ROOTN" {return ret(tkBuiltin);} +"ROUND" {return ret(tkBuiltin);} +"SAFEDIV" {return ret(tkBuiltin);} +"SQRT" {return ret(tkBuiltin);} %{ /* Trigonometric Builtins */ %} -"ARCCOS" {return ret(tkArccos);} -"ARCSIN" {return ret(tkArcsin);} -"ARCTAN" {return ret(tkArctan);} -"COS" {return ret(tkCos);} -"COSWAVE" {return ret(tkCoswave);} -"SIN" {return ret(tkSin);} -"SINWAVE" {return ret(tkSinwave);} -"TAN" {return ret(tkTan);} +"ARCCOS" {return ret(tkBuiltin);} +"ARCSIN" {return ret(tkBuiltin);} +"ARCTAN" {return ret(tkBuiltin);} +"COS" {return ret(tkBuiltin);} +"COSWAVE" {return ret(tkBuiltin);} +"SIN" {return ret(tkBuiltin);} +"SINWAVE" {return ret(tkBuiltin);} +"TAN" {return ret(tkBuiltin);} {L}({LD})* {return ret(id);} {D}+ {return ret(numentero);} diff --git a/src/SRCompiler.y b/src/SRCompiler.y index 6840363..43e8f05 100644 --- a/src/SRCompiler.y +++ b/src/SRCompiler.y @@ -15,16 +15,11 @@ along with SRCompiler. If not, see . */ -%token tkTimePar tkDT tkComa +%token tkTimePar tkDT tkComa tkGraph %token tkTime tkDiT tkStartTime tkStopTime %token tkIf tkElse tkNot tkOr tkThen tkAnd %token tkInit tkT -%token tkGraph -%token tkCter tkTrend -%token tkRandom tkNormal tkPoisson tkLognormal tkExprand -%token tkEndval tkHistory tkPrevious -%token tkArccos tkArcsin tkArctan tkCos tkCoswave tkSin tkSinwave tkTan -%token tkMax tkMin tkExp tkAbs tkInt tkLn tkLog tkMod tkPer tkPi tkRtn tkRond tkSfDiv tkSqrt +%token tkBuiltin %token id %token opas opmul oprel opExp @@ -139,439 +134,119 @@ A : id { YValues.push_back($1.lexema); } pari tkT pard asig id pari tkT opas t | {}; - -OpEndval : tkEndval pari Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - }; - -OpHistory : tkHistory pari Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - }; - | tkHistory pari Op tkComa Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - $$.lexema = strcat($$.lexema, $7.lexema); - $$.lexema = strcat($$.lexema, $8.lexema); - }; - -OpPrevious : tkPrevious pari Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - }; - -// Logical Builtins -OpIf : tkIf Op oprel Op tkThen Op tkElse Op { - $$.lexema = strcat($$.lexema, "ELSE("); - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, ","); - $$.lexema = strcat($$.lexema, $6.lexema); - $$.lexema = strcat($$.lexema, ","); - $$.lexema = strcat($$.lexema, $8.lexema); - $$.lexema = strcat($$.lexema, ")"); - }; - | tkIf oprel pari Op oprel Op pard tkThen Op tkElse Op { - $$.lexema = strcat($$.lexema, "ELSE("); - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - $$.lexema = strcat($$.lexema, $7.lexema); - $$.lexema = strcat($$.lexema, ","); - $$.lexema = strcat($$.lexema, $9.lexema); - $$.lexema = strcat($$.lexema, ","); - $$.lexema = strcat($$.lexema, $11.lexema); - $$.lexema = strcat($$.lexema, ")"); - }; - | tkIf pari Op oprel Op pard oprel pari Op oprel Op pard tkThen Op tkElse Op { - $$.lexema = strcat($$.lexema, "ELSE("); - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - $$.lexema = strcat($$.lexema, $7.lexema); - $$.lexema = strcat($$.lexema, $8.lexema); - $$.lexema = strcat($$.lexema, $9.lexema); - $$.lexema = strcat($$.lexema, $10.lexema); - $$.lexema = strcat($$.lexema, $11.lexema); - $$.lexema = strcat($$.lexema, $12.lexema); - $$.lexema = strcat($$.lexema, ","); - $$.lexema = strcat($$.lexema, $14.lexema); - $$.lexema = strcat($$.lexema, ","); - $$.lexema = strcat($$.lexema, $16.lexema); - $$.lexema = strcat($$.lexema, ")"); +// Builtin input parameters +OpFparams : Op { $$.lexema = $1.lexema; }; + | Op tkComa OpFparams { + std::stringstream ss; + ss << $1.lexema << " " << $2.lexema << " " << $3.lexema; + $$.lexema = strdup(ss.str().c_str()); + }; + | Op pyc OpFparams { + std::stringstream ss; + ss << $1.lexema << " " << $2.lexema << " " << $3.lexema; + $$.lexema = strdup(ss.str().c_str()); }; -// Statistical Builtins -OpRandom : tkRandom pari Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - }; - | tkRandom pari Op tkComa Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - $$.lexema = strcat($$.lexema, $7.lexema); - $$.lexema = strcat($$.lexema, $8.lexema); - }; - -OpNormal : tkNormal pari Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - }; - | tkNormal pari Op tkComa Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - $$.lexema = strcat($$.lexema, $7.lexema); - $$.lexema = strcat($$.lexema, $8.lexema); - }; - -OpPoisson : tkPoisson pari Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - }; - | tkPoisson pari Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - }; - -OpLognormal : tkLognormal pari Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - }; - | tkLognormal pari Op tkComa Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - $$.lexema = strcat($$.lexema, $7.lexema); - $$.lexema = strcat($$.lexema, $8.lexema); - }; - -OpExprand : tkExprand pari Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - }; - | tkExprand pari Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - }; - -// Miscellaneous Builtins -OpCter : tkCter pari Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - }; -OpTren : tkTrend pari Op tkComa Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - $$.lexema = strcat($$.lexema, $7.lexema); - $$.lexema = strcat($$.lexema, $8.lexema); - }; - -// Simulation Builtins -OpTime : tkTime { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, "("); - $$.lexema = strcat($$.lexema, ")"); - } - -// Mathematical Builtins -OpMax : tkMax pari Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - }; - | tkMax pari Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - }; - -OpMin : tkMin pari Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - }; - -OpExp : tkExp pari Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - }; - -OpAbs : tkAbs pari Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - }; - -OpInt : tkInt pari Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - }; - -OpLn : tkLn pari Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - }; - -OpLog : tkLog pari Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - }; - -OpMod : tkMod pari Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - }; - -OpPer : tkPer pari Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - }; - -OpPi : tkPi pari pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - }; - -OpRtn : tkRtn pari Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - }; - -OpRond : tkRond pari Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - }; - -OpSfDiv : tkSfDiv pari Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - }; - -OpSqrt : tkSqrt pari Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - }; - - -// Trigonometric Builtins -OpACos : tkArccos pari Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - }; - -OpASin : tkArcsin pari Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - }; - -OpATan : tkArctan pari Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - }; - -OpCos : tkCos pari Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - }; - -OpCW : tkCoswave pari Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - }; - -OpSin : tkSin pari Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - }; - -OpSW : tkSinwave pari Op tkComa Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - $$.lexema = strcat($$.lexema, $5.lexema); - $$.lexema = strcat($$.lexema, $6.lexema); - }; - -OpTan : tkTan pari Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema); - $$.lexema = strcat($$.lexema, $4.lexema); - }; - -Op : F opas Op { +OpFpars : pari OpFparams pard { std::stringstream ss; ss << $1.lexema << " " << $2.lexema << " " << $3.lexema; + $$.lexema = strdup(ss.str().c_str()); + }; + +OpBuiltin : tkBuiltin OpBuiltin { + std::stringstream ss; + ss << $1.lexema << " " << $2.lexema; + $$.lexema = strdup(ss.str().c_str()); + }; + | tkBuiltin OpFpars { + std::stringstream ss; + ss << $1.lexema << " " << $2.lexema; + $$.lexema = strdup(ss.str().c_str()); + }; + | tkBuiltin { + std::stringstream ss; + ss << $1.lexema << "()"; $$.lexema = strdup(ss.str().c_str()); }; - | OpMul{ $$.tipo = $1.tipo; }; -OpMul : F opmul Op { +// Logical builtin +OpIfparams1 : pari Op oprel OpIfparams1 { + std::stringstream ss; + ss << $1.lexema << " " << $2.lexema << " " << $3.lexema << " " << $4.lexema; + $$.lexema = strdup(ss.str().c_str()); + }; + | Op pard oprel OpIfparams1 { + std::stringstream ss; + ss << $1.lexema << " " << $2.lexema << " " << $3.lexema << " " << $4.lexema; + $$.lexema = strdup(ss.str().c_str()); + }; + | Op pard OpIfparams2 { std::stringstream ss; ss << $1.lexema << " " << $2.lexema << " " << $3.lexema; - $$.lexema = strdup(ss.str().c_str()); - }; - | OpExpo { - $$.tipo = $1.tipo; - }; - -OpExpo : F opExp Op { + $$.lexema = strdup(ss.str().c_str()); + }; + | Op oprel OpIfparams1 { std::stringstream ss; ss << $1.lexema << " " << $2.lexema << " " << $3.lexema; - $$.lexema = strdup(ss.str().c_str()); }; - | F{ $$.tipo = $1.tipo; }; - -F : numentero { $$.tipo = ENTERO; }; - | numreal { $$.tipo = REAL; }; - | opas F { $$.lexema = $1.lexema; }; - | OpEndval { $$.lexema = $1.lexema; }; - | OpHistory { $$.lexema = $1.lexema; }; - | OpPrevious{ $$.lexema = $1.lexema; }; - | OpRandom { $$.lexema = $1.lexema; }; - | OpMax { $$.lexema = $1.lexema; }; - | OpMin { $$.lexema = $1.lexema; }; - | OpExp { $$.lexema = $1.lexema; }; - | OpAbs { $$.lexema = $1.lexema; }; - | OpInt { $$.lexema = $1.lexema; }; - | OpLn { $$.lexema = $1.lexema; }; - | OpLog { $$.lexema = $1.lexema; }; - | OpMod { $$.lexema = $1.lexema; }; - | OpPer { $$.lexema = $1.lexema; }; - | OpPi { $$.lexema = $1.lexema; }; - | OpRtn { $$.lexema = $1.lexema; }; - | OpRond { $$.lexema = $1.lexema; }; - | OpSfDiv { $$.lexema = $1.lexema; }; - | OpSqrt { $$.lexema = $1.lexema; }; - | OpACos { $$.lexema = $1.lexema; }; - | OpASin { $$.lexema = $1.lexema; }; - | OpATan { $$.lexema = $1.lexema; }; - | OpCos { $$.lexema = $1.lexema; }; - | OpCW { $$.lexema = $1.lexema; }; - | OpSin { $$.lexema = $1.lexema; }; - | OpSW { $$.lexema = $1.lexema; }; - | OpTan { $$.lexema = $1.lexema; }; - | OpCter { $$.lexema = $1.lexema; }; - | OpIf { $$.lexema = $1.lexema; }; - | OpTime { $$.lexema = $1.lexema; }; - | id { $$.lexema = $1.lexema; }; - | pari Op pard { - $$.lexema = $1.lexema; - $$.lexema = strcat($$.lexema, $2.lexema); - $$.lexema = strcat($$.lexema, $3.lexema);}; + $$.lexema = strdup(ss.str().c_str()); + }; + | Op OpIfparams2 { + std::stringstream ss; + ss << $1.lexema << " " << $2.lexema; + $$.lexema = strdup(ss.str().c_str()); + }; + +OpIfparams2 : tkThen Op tkElse Op { + std::stringstream ss; + ss << "," << $2.lexema << "," << $4.lexema << ")"; + $$.lexema = strdup(ss.str().c_str()); + }; + +OpIf : tkIf OpIfparams1 { + std::stringstream ss; + ss << "IFELSE" << $2.lexema; + $$.lexema = strdup(ss.str().c_str()); + }; + +// Operations +Op : pari Op pard Arith { + std::stringstream ss; + ss << $1.lexema << " " << $2.lexema << " " << $3.lexema << " " << $4.lexema; + $$.lexema = strdup(ss.str().c_str()); + }; + | F Arith { + std::stringstream ss; + ss << $1.lexema << " " << $2.lexema; + $$.lexema = strdup(ss.str().c_str()); + }; + | F { $$.lexema = $1.lexema; }; + +Arith : opas Op { + std::stringstream ss; + ss << $1.lexema << " " << $2.lexema; + $$.lexema = strdup(ss.str().c_str()); + }; + | opmul Op { + std::stringstream ss; + ss << $1.lexema << " " << $2.lexema; + $$.lexema = strdup(ss.str().c_str()); + }; + | OpExpo { $$.lexema = $1.lexema; }; + | {}; + +OpExpo : opExp Op { + std::stringstream ss; + ss << $1.lexema << " " << $2.lexema; + $$.lexema = strdup(ss.str().c_str()); + }; + | opExp { $$.lexema = $1.lexema; }; + +// ... + F : numentero { $$.tipo = ENTERO; }; + | numreal { $$.tipo = REAL; }; + | Arith { $$.lexema = $1.lexema; }; + | OpBuiltin { $$.lexema = $1.lexema; }; + | OpIf { $$.lexema = $1.lexema; }; + | id { $$.lexema = $1.lexema; }; %%