[WIP] Add nodes.h and start defining types/union
Co-authored-by: Ezequiel Bellver <ebellver@itba.edu.ar> Co-authored-by: Juan Barmasch <jbarmasch@itba.edu.ar>
This commit is contained in:
parent
18ef547882
commit
61e08f994c
|
@ -7,6 +7,8 @@ cache/
|
||||||
log/
|
log/
|
||||||
obj/
|
obj/
|
||||||
node_modules/
|
node_modules/
|
||||||
|
.idea/
|
||||||
|
cmake-build-debug/
|
||||||
|
|
||||||
# Files:
|
# Files:
|
||||||
*.csproj.user
|
*.csproj.user
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
#include "calculator.h"
|
#include "calculator.h"
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementación de "calculator.h".
|
|
||||||
*/
|
|
||||||
|
|
||||||
double Add(const double leftAddend, const double rightAddend) {
|
double Add(const double leftAddend, const double rightAddend) {
|
||||||
return leftAddend + rightAddend;
|
return leftAddend + rightAddend;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +23,3 @@ double Power(const double base, const double exponent) {
|
||||||
return pow(base, exponent);
|
return pow(base, exponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// double (* function) (double) declareFunction(char * expression) {
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
|
@ -0,0 +1,165 @@
|
||||||
|
#ifndef NODES_H
|
||||||
|
#define NODES_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
typedef struct variable_t {
|
||||||
|
char * name;
|
||||||
|
struct expression_t * value;
|
||||||
|
} variable_t;
|
||||||
|
|
||||||
|
typedef struct while_t {
|
||||||
|
struct boolean_t * boolean;
|
||||||
|
struct block_t * block;
|
||||||
|
} while_t;
|
||||||
|
|
||||||
|
typedef struct expression_t {
|
||||||
|
struct algebraic_op_t * algebraic_op;
|
||||||
|
double * number;
|
||||||
|
struct variable_t * variable;
|
||||||
|
struct derivative_t * derivative;
|
||||||
|
struct integrate_t * integrate;
|
||||||
|
struct evaluate_t * evaluate;
|
||||||
|
struct negative_t * negative;
|
||||||
|
struct parenthesis_exp_t * parenthesis_exp;
|
||||||
|
|
||||||
|
struct expression_t * next;
|
||||||
|
} expression_t;
|
||||||
|
|
||||||
|
typedef struct function_t {
|
||||||
|
char * name;
|
||||||
|
expression_t * expression;
|
||||||
|
struct domain_t * domain;
|
||||||
|
struct taylor_t * taylor;
|
||||||
|
struct composite_t * composite;
|
||||||
|
|
||||||
|
struct function_t * next;
|
||||||
|
} function_t;
|
||||||
|
|
||||||
|
typedef struct statement_t {
|
||||||
|
struct while_t * while_st;
|
||||||
|
struct print_t * print;
|
||||||
|
struct for_t * for_st;
|
||||||
|
struct if_t * if_st;
|
||||||
|
struct integrate_t * integrate;
|
||||||
|
struct derivative_t * derivative;
|
||||||
|
struct evaluate_t * evaluate;
|
||||||
|
struct variable_t * variable;
|
||||||
|
|
||||||
|
struct statement_t * next;
|
||||||
|
} statement_t;
|
||||||
|
|
||||||
|
typedef struct block_t {
|
||||||
|
statement_t * statement;
|
||||||
|
} block_t;
|
||||||
|
|
||||||
|
typedef struct print_t {
|
||||||
|
expression_t * exp;
|
||||||
|
char * string;
|
||||||
|
} print_t;
|
||||||
|
|
||||||
|
typedef struct for_t {
|
||||||
|
variable_t * variable_t;
|
||||||
|
struct boolean_t * boolean;
|
||||||
|
block_t * block;
|
||||||
|
} for_t;
|
||||||
|
|
||||||
|
typedef struct if_t {
|
||||||
|
struct boolean_t * boolean;
|
||||||
|
block_t * block;
|
||||||
|
block_t * else_block;
|
||||||
|
} if_t;
|
||||||
|
|
||||||
|
typedef struct boolean_t {
|
||||||
|
struct domain_t * domain;
|
||||||
|
struct not_bool_t * not_bool;
|
||||||
|
struct bool_op_t * bool_op;
|
||||||
|
} boolean_t;
|
||||||
|
|
||||||
|
typedef struct bool_op_t {
|
||||||
|
boolean_t * left;
|
||||||
|
boolean_t * right;
|
||||||
|
int op;
|
||||||
|
} bool_op_t;
|
||||||
|
|
||||||
|
typedef struct not_bool_t {
|
||||||
|
boolean_t * boolean;
|
||||||
|
} not_bool_t;
|
||||||
|
|
||||||
|
typedef struct domain_one_op_t {
|
||||||
|
expression_t * left;
|
||||||
|
expression_t * right;
|
||||||
|
int oper;
|
||||||
|
} domain_one_op_t;
|
||||||
|
|
||||||
|
typedef struct domain_two_op_t {
|
||||||
|
expression_t * left;
|
||||||
|
expression_t * mid;
|
||||||
|
expression_t * right;
|
||||||
|
int oper1;
|
||||||
|
int oper2;
|
||||||
|
} domain_two_op_t;
|
||||||
|
|
||||||
|
typedef struct domain_t {
|
||||||
|
domain_one_op_t * domain_one;
|
||||||
|
domain_two_op_t * domain_two;
|
||||||
|
} domain_t;
|
||||||
|
|
||||||
|
typedef struct parenthesis_exp_t {
|
||||||
|
expression_t * expression;
|
||||||
|
} parenthesis_exp_t;
|
||||||
|
|
||||||
|
typedef struct negative_t {
|
||||||
|
expression_t * expression;
|
||||||
|
} negative_t;
|
||||||
|
|
||||||
|
typedef struct derivative_t {
|
||||||
|
function_t * function;
|
||||||
|
double * value;
|
||||||
|
double * error;
|
||||||
|
} derivative_t;
|
||||||
|
|
||||||
|
typedef struct evaluate_t {
|
||||||
|
function_t * function;
|
||||||
|
double * value;
|
||||||
|
} evaluate_t;
|
||||||
|
|
||||||
|
typedef struct integrate_t {
|
||||||
|
function_t * function;
|
||||||
|
double * value;
|
||||||
|
double * error;
|
||||||
|
|
||||||
|
expression_t * lvalue;
|
||||||
|
expression_t * rvalue;
|
||||||
|
} integrate_t;
|
||||||
|
|
||||||
|
typedef struct algebraic_op_t {
|
||||||
|
expression_t * left;
|
||||||
|
expression_t * right;
|
||||||
|
int op;
|
||||||
|
} algebraic_op_t;
|
||||||
|
|
||||||
|
typedef struct composite_t {
|
||||||
|
function_t * outter_funct;
|
||||||
|
function_t * inner_funct;
|
||||||
|
} composite_t;
|
||||||
|
|
||||||
|
typedef struct numArray_t {
|
||||||
|
expression_t * expressions;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
struct numArray_t * next;
|
||||||
|
} numArray_t;
|
||||||
|
|
||||||
|
typedef struct taylor_t {
|
||||||
|
int num;
|
||||||
|
function_t * function;
|
||||||
|
} taylor_t;
|
||||||
|
|
||||||
|
typedef struct id_t {
|
||||||
|
variable_t * variable;
|
||||||
|
function_t * function;
|
||||||
|
} id_t;
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,67 +1,537 @@
|
||||||
#include "../../backend/domain-specific/calculator.h"
|
#include "../../backend/domain-specific/calculator.h"
|
||||||
#include "../../backend/support/logger.h"
|
#include "../../backend/support/logger.h"
|
||||||
|
#include "../../backend/support/nodes.h"
|
||||||
#include "bison-actions.h"
|
#include "bison-actions.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementación de "bison-grammar.h".
|
|
||||||
*/
|
|
||||||
|
|
||||||
void yyerror(const char * string) {
|
void yyerror(const char * string) {
|
||||||
LogError("Mensaje: '%s' debido a '%s' (linea %d).", string, yytext, yylineno);
|
LogError("Mensaje: '%s' debido a '%s' (linea %d).", string, yytext, yylineno);
|
||||||
// LogError("En ASCII es:");
|
|
||||||
// LogErrorRaw("\t");
|
|
||||||
// const int length = strlen(yytext);
|
|
||||||
// for (int i = 0; i < length; ++i) {
|
|
||||||
// LogErrorRaw("[%d]", yytext[i]);
|
|
||||||
// }
|
|
||||||
// LogErrorRaw("\n\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ProgramGrammarAction(const int value) {
|
int ProgramGrammarAction(const int value) {
|
||||||
// LogDebug("ProgramGrammarAction(%d)", value);
|
|
||||||
state.succeed = true;
|
state.succeed = true;
|
||||||
state.result = value;
|
state.result = value;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AdditionExpressionGrammarAction(const int leftValue, const int rightValue) {
|
statement_t * EvaluateGrammarAction(evaluate_t * evaluate) {
|
||||||
LogDebug("AdditionExpressionGrammarAction(%d, %d)", leftValue, rightValue);
|
statement_t * statement = malloc(sizeof(statement_t));
|
||||||
return Add(leftValue, rightValue);
|
evaluate_t * evalAux = malloc(sizeof(evaluate_t));
|
||||||
|
evalAux->function = evaluate->function;
|
||||||
|
evalAux->value = evaluate->value;
|
||||||
|
statement->evaluate = evalAux;
|
||||||
|
statement->next = NULL;
|
||||||
|
return statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SubtractionExpressionGrammarAction(const int leftValue, const int rightValue) {
|
statement_t * IntegrateGrammarAction(integrate_t * integrate) {
|
||||||
LogDebug("SubtractionExpressionGrammarAction(%d, %d)", leftValue, rightValue);
|
statement_t * statement = malloc(sizeof(statement_t));
|
||||||
return Subtract(leftValue, rightValue);
|
integrate_t * intAux = malloc(sizeof(integrate_t));
|
||||||
|
intAux->function = integrate->function;
|
||||||
|
intAux->error = integrate->error;
|
||||||
|
intAux->lvalue = integrate->lvalue;
|
||||||
|
intAux->rvalue = integrate->rvalue;
|
||||||
|
statement->integrate = intAux;
|
||||||
|
statement->next = NULL;
|
||||||
|
return statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MultiplicationExpressionGrammarAction(const int leftValue, const int rightValue) {
|
statement_t * DerivativeGrammarAction(derivative_t * derivative) {
|
||||||
LogDebug("MultiplicationExpressionGrammarAction(%d, %d)", leftValue, rightValue);
|
statement_t * statement = malloc(sizeof(statement_t));
|
||||||
return Multiply(leftValue, rightValue);
|
derivative_t * derAux = malloc(sizeof(derivative_t));
|
||||||
|
derAux->function = derivative->function;
|
||||||
|
derAux->error = derivative->error;
|
||||||
|
derAux->value = derivative->value;
|
||||||
|
statement->derivative = derAux;
|
||||||
|
statement->next = NULL;
|
||||||
|
return statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DivisionExpressionGrammarAction(const int leftValue, const int rightValue) {
|
statement_t * StatementDeclareFunctionGrammarAction(function_t * function) {
|
||||||
LogDebug("DivisionExpressionGrammarAction(%d, %d)", leftValue, rightValue);
|
statement_t * statement = malloc(sizeof(statement_t));
|
||||||
return Divide(leftValue, rightValue);
|
function_t * funAux = malloc(sizeof(function_t));
|
||||||
|
funAux->name = funAux->name;
|
||||||
|
funAux->expression = funAux->expression;
|
||||||
|
funAux->domain = funAux->domain;
|
||||||
|
funAux->taylor = funAux->taylor;
|
||||||
|
funAux->composite = funAux->composite;
|
||||||
|
funAux->next = NULL;
|
||||||
|
statement->evaluate = funAux;
|
||||||
|
statement->next = NULL;
|
||||||
|
return statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FactorExpressionGrammarAction(const int value) {
|
statement_t * IfGrammarAction(if_t * if_st) {
|
||||||
LogDebug("FactorExpressionGrammarAction(%d)", value);
|
statement_t * statement = malloc(sizeof(statement_t));
|
||||||
return value;
|
if_t * ifAux = malloc(sizeof(if_t));
|
||||||
|
ifAux->block = if_st->block;
|
||||||
|
ifAux->boolean = if_st->boolean;
|
||||||
|
statement->if_st = ifAux;
|
||||||
|
statement->next = NULL;
|
||||||
|
return statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ExpressionFactorGrammarAction(const int value) {
|
statement_t * ForGrammarAction(for_t * for_st) {
|
||||||
LogDebug("ExpressionFactorGrammarAction(%d)", value);
|
statement_t * statement = malloc(sizeof(statement_t));
|
||||||
return value;
|
for_t * forAux = malloc(sizeof(for_t));
|
||||||
|
forAux->block = for_st->block;
|
||||||
|
forAux->boolean = for_st->boolean;
|
||||||
|
forAux->variable_t = for_st->variable_t;
|
||||||
|
statement->for_st = forAux;
|
||||||
|
statement->next = NULL;
|
||||||
|
return statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConstantFactorGrammarAction(const int value) {
|
statement_t * WhileGrammarAction(while_t * while_st) {
|
||||||
LogDebug("ConstantFactorGrammarAction(%d)", value);
|
statement_t * statement = malloc(sizeof(statement_t));
|
||||||
return value;
|
while_t * whileAux = malloc(sizeof(while_t));
|
||||||
|
whileAux->block = while_st->block;
|
||||||
|
whileAux->boolean = while_st->boolean;
|
||||||
|
statement->while_st = whileAux;
|
||||||
|
statement->next = NULL;
|
||||||
|
return statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
int IntegerConstantGrammarAction(const int value) {
|
statement_t * PrintGrammarAction(print_t * print) {
|
||||||
LogDebug("IntegerConstantGrammarAction(%d)", value);
|
statement_t * statement = malloc(sizeof(statement_t));
|
||||||
return value;
|
print_t * printAux = malloc(sizeof(print_t));
|
||||||
|
printAux->exp = print->exp;
|
||||||
|
printAux->string = print->string;
|
||||||
|
statement->print = printAux;
|
||||||
|
statement->next = NULL;
|
||||||
|
return statement;
|
||||||
|
}
|
||||||
|
|
||||||
|
void expressionShallowCopy(expression_t * src, expression_t * dest) {
|
||||||
|
dest->algebraic_op = src->algebraic_op;
|
||||||
|
dest->variable = src->variable;
|
||||||
|
dest->derivative = src->derivative;
|
||||||
|
dest->integrate = src->integrate;
|
||||||
|
dest->evaluate = src->evaluate;
|
||||||
|
dest->negative = src->negative;
|
||||||
|
dest->parenthesis_exp = src->parenthesis_exp;
|
||||||
|
dest->number = src->number;
|
||||||
|
dest->next = src->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
void statementShallowCopy(statement_t * src, statement_t * dest) {
|
||||||
|
dest->while_st = src->while_st;
|
||||||
|
dest->print = src->print;
|
||||||
|
dest->for_st = src->for_st;
|
||||||
|
dest->if_st = src->if_st;
|
||||||
|
dest->integrate = src->integrate;
|
||||||
|
dest->derivative = src->derivative;
|
||||||
|
dest->evaluate = src->evaluate;
|
||||||
|
dest->variable = src->variable;
|
||||||
|
|
||||||
|
dest->next = src->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
void compositeShallowCopy(composite_t * src, composite_t * dest) {
|
||||||
|
dest->outter_funct = src->outter_funct;
|
||||||
|
dest->inner_funct = src->inner_funct;
|
||||||
|
}
|
||||||
|
|
||||||
|
expression_t * ExpressionOperatorGrammarAction(expression_t * firstExpression, int token, expression_t * secondExpression) {
|
||||||
|
expression_t * expression = malloc(sizeof(expression_t));
|
||||||
|
expression_t * firstExpressionAux = malloc(sizeof(expression_t));
|
||||||
|
expression_t * secondExpressionAux = malloc(sizeof(expression_t));
|
||||||
|
|
||||||
|
expressionShallowCopy(firstExpression, firstExpressionAux);
|
||||||
|
expressionShallowCopy(secondExpression, secondExpressionAux);
|
||||||
|
|
||||||
|
expression->algebraic_op->op = token;
|
||||||
|
expression->algebraic_op->left = firstExpressionAux;
|
||||||
|
expression->algebraic_op->right = secondExpressionAux;
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
expression_t * AlgebraicExpressionGrammarAction(algebraic_op_t * algebraicOp) {
|
||||||
|
expression_t * expression = malloc(sizeof(expression_t));
|
||||||
|
algebraic_op_t * algebraicAux = malloc(sizeof(algebraic_op_t));
|
||||||
|
algebraicAux->left = algebraicOp->left;
|
||||||
|
algebraicAux->right = algebraicOp->right;
|
||||||
|
algebraicAux->op = algebraicOp->op;
|
||||||
|
expression->algebraic_op = algebraicAux;
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
expression_t * EvaluateExpressionGrammarAction(evaluate_t * evaluate) {
|
||||||
|
expression_t * expression = malloc(sizeof(expression_t));
|
||||||
|
evaluate_t * evalAux = malloc(sizeof(evaluate_t));
|
||||||
|
evalAux->function = evaluate->function;
|
||||||
|
evalAux->value = evaluate->value;
|
||||||
|
expression->evaluate = evalAux;
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
expression_t * DerivativeExpressionGrammarAction(derivative_t * derivative) {
|
||||||
|
expression_t * expression = malloc(sizeof(expression_t));
|
||||||
|
derivative_t * derAux = malloc(sizeof(derivative_t));
|
||||||
|
derAux->function = derivative->function;
|
||||||
|
derAux->value = derivative->value;
|
||||||
|
derAux->error = derivative->error;
|
||||||
|
expression->derivative = derAux;
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
expression_t * IntegrateExpressionGrammarAction(integrate_t * integrate) {
|
||||||
|
expression_t * expression = malloc(sizeof(expression_t));
|
||||||
|
integrate_t * intAux = malloc(sizeof(integrate_t));
|
||||||
|
intAux->function = integrate->function;
|
||||||
|
intAux->lvalue = integrate->lvalue;
|
||||||
|
intAux->rvalue = integrate->rvalue;
|
||||||
|
intAux->error = integrate->error;
|
||||||
|
expression->integrate = intAux;
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
expression_t * NegativeExpressionGrammarAction(expression_t * negative) {
|
||||||
|
expression_t * expression = malloc(sizeof(expression_t));
|
||||||
|
negative_t * negAux = malloc(sizeof(negative_t));
|
||||||
|
negAux->expression = negative;
|
||||||
|
expression->negative = negAux;
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
expression_t * ParenthesisExpressionGrammarAction(expression_t * exp) {
|
||||||
|
expression_t * expression = malloc(sizeof(expression_t));
|
||||||
|
parenthesis_exp_t * parAux = malloc(sizeof(parenthesis_exp_t));
|
||||||
|
parAux->expression = exp;
|
||||||
|
expression->parenthesis_exp = parAux;
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
expression_t * VariableExpressionGrammarAction(variable_t * variable) {
|
||||||
|
expression_t * expression = malloc(sizeof(expression_t));
|
||||||
|
variable_t * varAux = malloc(sizeof(variable_t));
|
||||||
|
varAux->value = variable->value;
|
||||||
|
varAux->name = variable->name;
|
||||||
|
expression->variable = varAux;
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
statement_t * VariableStatementGrammarAction(variable_t * variable) {
|
||||||
|
statement_t * statement = malloc(sizeof(statement_t));
|
||||||
|
variable_t * varAux = malloc(sizeof(variable_t));
|
||||||
|
varAux->name = variable->name;
|
||||||
|
varAux->value = variable->value;
|
||||||
|
statement->variable = varAux;
|
||||||
|
return statement;
|
||||||
|
}
|
||||||
|
|
||||||
|
variable_t * VariableGrammarAction(char * name, expression_t * expression) {
|
||||||
|
variable_t * variable = malloc(sizeof(variable_t));
|
||||||
|
expression_t * expAux = malloc(sizeof(expression_t));
|
||||||
|
size_t size = strlen(name);
|
||||||
|
char * nameAux = malloc(size + 1);
|
||||||
|
|
||||||
|
expressionShallowCopy(expression, expAux);
|
||||||
|
strcpy(nameAux, name);
|
||||||
|
|
||||||
|
variable->value = expAux;
|
||||||
|
variable->name = nameAux;
|
||||||
|
return variable;
|
||||||
|
}
|
||||||
|
|
||||||
|
function_t * TaylorFunctionGrammarAction(taylor_t * taylor) {
|
||||||
|
function_t * function = malloc(sizeof(function_t));
|
||||||
|
taylor_t * taylorAux = malloc(sizeof(taylor_t));
|
||||||
|
taylorAux->function = taylor->function;
|
||||||
|
taylorAux->num = taylor->num;
|
||||||
|
function->taylor = taylorAux;
|
||||||
|
return function;
|
||||||
|
}
|
||||||
|
|
||||||
|
void functionShallowCopy(function_t * src, function_t * dest) {
|
||||||
|
dest->taylor = src->taylor;
|
||||||
|
dest->expression = src->expression;
|
||||||
|
dest->name = src->name;
|
||||||
|
dest->composite = src->composite;
|
||||||
|
dest->domain = src->domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
composite_t * CompositeIdGrammarAction(id_t * id1, id_t * id2) {
|
||||||
|
composite_t * composite = malloc(sizeof(composite_t));
|
||||||
|
function_t * funAux1 = malloc(sizeof(function_t));
|
||||||
|
function_t * funAux2 = malloc(sizeof(function_t));
|
||||||
|
|
||||||
|
funAux1 = id1->function;
|
||||||
|
funAux2 = id2->function;
|
||||||
|
|
||||||
|
composite->inner_funct = funAux1;
|
||||||
|
composite->outter_funct = funAux2;
|
||||||
|
return composite;
|
||||||
|
}
|
||||||
|
|
||||||
|
composite_t * CompositeCompGrammarAction(composite_t * composite, id_t * id) {
|
||||||
|
composite_t * compAux = malloc(sizeof(composite_t));
|
||||||
|
function_t * funAux1 = malloc(sizeof(function_t));
|
||||||
|
function_t * funAux2 = malloc(sizeof(function_t));
|
||||||
|
|
||||||
|
compositeShallowCopy(composite, compAux);
|
||||||
|
|
||||||
|
funAux1->composite = composite;
|
||||||
|
funAux2 = id->function;
|
||||||
|
|
||||||
|
composite->inner_funct = funAux1;
|
||||||
|
composite->outter_funct = funAux2;
|
||||||
|
return composite;
|
||||||
|
}
|
||||||
|
|
||||||
|
domain_t * DomainOneOptOperatorGrammarAction(expression_t * firstExpression, int token, expression_t * secondExpression) {
|
||||||
|
domain_t * domain = malloc(sizeof(expression_t));
|
||||||
|
expression_t * firstExpressionAux = malloc(sizeof(expression_t));
|
||||||
|
expression_t * secondExpressionAux = malloc(sizeof(expression_t));
|
||||||
|
|
||||||
|
expressionShallowCopy(firstExpression, firstExpressionAux);
|
||||||
|
expressionShallowCopy(secondExpression, secondExpressionAux);
|
||||||
|
|
||||||
|
domain->domain_one->left = firstExpressionAux;
|
||||||
|
domain->domain_one->right = secondExpressionAux;
|
||||||
|
domain->domain_one->oper = token;
|
||||||
|
|
||||||
|
return domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
domain_t * DomainTwoOptOperatorGrammarAction(expression_t * firstExpression, int token1, expression_t * secondExpression, int token2, expression_t * thirdExpression) {
|
||||||
|
domain_t * domain = malloc(sizeof(expression_t));
|
||||||
|
expression_t * firstExpressionAux = malloc(sizeof(expression_t));
|
||||||
|
expression_t * secondExpressionAux = malloc(sizeof(expression_t));
|
||||||
|
expression_t * thirdExpressionAux = malloc(sizeof(expression_t));
|
||||||
|
|
||||||
|
expressionShallowCopy(firstExpression, firstExpressionAux);
|
||||||
|
expressionShallowCopy(secondExpression, secondExpressionAux);
|
||||||
|
expressionShallowCopy(thirdExpression, thirdExpressionAux);
|
||||||
|
|
||||||
|
domain->domain_two->left = firstExpressionAux;
|
||||||
|
domain->domain_two->mid = secondExpressionAux;
|
||||||
|
domain->domain_two->right = thirdExpression;
|
||||||
|
domain->domain_two->oper1 = token1;
|
||||||
|
domain->domain_two->oper2 = token2;
|
||||||
|
|
||||||
|
return domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean_t * DomainGrammarAction(domain_t * domain) {
|
||||||
|
boolean_t * boolean = malloc(sizeof(boolean_t));
|
||||||
|
domain_t * domainAux = malloc(sizeof(domain_t));
|
||||||
|
|
||||||
|
domainAux->domain_one = domain->domain_one;
|
||||||
|
domainAux->domain_two = domain->domain_two;
|
||||||
|
|
||||||
|
boolean->domain = domainAux;
|
||||||
|
|
||||||
|
return boolean;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void booleanShallowCopy(boolean_t * source, boolean_t * dest) {
|
||||||
|
dest->domain = source->domain;
|
||||||
|
dest->bool_op = source->bool_op;
|
||||||
|
dest->not_bool = source->not_bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean_t * BooleanOperatorGrammarAction(boolean_t * left, int token, boolean_t * right) {
|
||||||
|
boolean_t * boolean = malloc(sizeof(boolean_t));
|
||||||
|
boolean_t * leftAux = malloc(sizeof(boolean_t));
|
||||||
|
boolean_t * rightAux = malloc(sizeof(boolean_t));
|
||||||
|
|
||||||
|
booleanShallowCopy(left, leftAux);
|
||||||
|
booleanShallowCopy(right, rightAux);
|
||||||
|
|
||||||
|
boolean->bool_op->left = leftAux;
|
||||||
|
boolean->bool_op->right = rightAux;
|
||||||
|
boolean->bool_op->op = token;
|
||||||
|
|
||||||
|
return boolean;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean_t * NotBooleanAction(boolean_t * notBoolean) {
|
||||||
|
boolean_t * boolean = malloc(sizeof(boolean_t));
|
||||||
|
not_bool_t * notBooleanAux = malloc(sizeof(not_bool_t));
|
||||||
|
|
||||||
|
booleanShallowCopy(notBoolean, notBooleanAux->boolean);
|
||||||
|
|
||||||
|
boolean->not_bool = notBooleanAux;
|
||||||
|
|
||||||
|
return boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
function_t * DeclareFunctionGrammarAction(id_t * id, function_t * func) {
|
||||||
|
function_t * function = malloc(sizeof(function_t));
|
||||||
|
function_t * funcAux = malloc(sizeof(function_t));
|
||||||
|
|
||||||
|
functionShallowCopy(func, function);
|
||||||
|
|
||||||
|
function->name = id;
|
||||||
|
|
||||||
|
return function;
|
||||||
|
}
|
||||||
|
|
||||||
|
function_t * DeclareFunctionListGrammarAction(id_t * id, function_t * func) {
|
||||||
|
function_t * function = malloc(sizeof(function_t));
|
||||||
|
|
||||||
|
functionShallowCopy(func, function);
|
||||||
|
|
||||||
|
function->name = id;
|
||||||
|
|
||||||
|
return function;
|
||||||
|
}
|
||||||
|
|
||||||
|
function_t * FunctionsGrammarAction(function_t * func1, function_t * func2) {
|
||||||
|
function_t * funcFinal = malloc(sizeof(function_t));
|
||||||
|
function_t * funcAux = malloc(sizeof(function_t));
|
||||||
|
|
||||||
|
functionShallowCopy(func1, funcFinal);
|
||||||
|
functionShallowCopy(func2, funcAux);
|
||||||
|
|
||||||
|
funcFinal->next = funcAux;
|
||||||
|
return funcFinal;
|
||||||
|
}
|
||||||
|
|
||||||
|
function_t * CompositeFunctionGrammarAction(composite_t * composite) {
|
||||||
|
function_t * function = malloc(sizeof(function_t));
|
||||||
|
composite_t * compAux = malloc(sizeof(composite_t));
|
||||||
|
|
||||||
|
compositeShallowCopy(composite, compAux);
|
||||||
|
|
||||||
|
function->composite = compAux;
|
||||||
|
return function;
|
||||||
|
}
|
||||||
|
|
||||||
|
function_t * ExpressionFunctionGrammarAction(expression_t * expression) {
|
||||||
|
function_t * function = malloc(sizeof(function_t));
|
||||||
|
expression_t * expAux = malloc(sizeof(expression_t));
|
||||||
|
|
||||||
|
expressionShallowCopy(expression, expAux);
|
||||||
|
function->expression = expAux;
|
||||||
|
return function;
|
||||||
|
}
|
||||||
|
|
||||||
|
void domainShallowCopy(domain_t * src, domain_t * dest) {
|
||||||
|
dest->domain_one = src->domain_one;
|
||||||
|
dest->domain_two = src->domain_two;
|
||||||
|
}
|
||||||
|
|
||||||
|
function_t * ExpressionDomainFunctionGrammarAction(expression_t * expression, domain_t * domain) {
|
||||||
|
function_t * function = malloc(sizeof(function_t));
|
||||||
|
expression_t * expAux = malloc(sizeof(expression_t));
|
||||||
|
domain_t * domAux = malloc(sizeof(domain_t));
|
||||||
|
|
||||||
|
expressionShallowCopy(expression, expAux);
|
||||||
|
domainShallowCopy(domain, domAux);
|
||||||
|
function->expression = expAux;
|
||||||
|
function->domain = domAux;
|
||||||
|
return function;
|
||||||
|
}
|
||||||
|
|
||||||
|
expression_t * ExpressionsGrammarAction(expression_t * exp1, expression_t * exp2) {
|
||||||
|
expression_t * expFinal = malloc(sizeof(expression_t));
|
||||||
|
expression_t * expAux = malloc(sizeof(expression_t));
|
||||||
|
|
||||||
|
expressionShallowCopy(exp1, expFinal);
|
||||||
|
expressionShallowCopy(exp2, expAux);
|
||||||
|
|
||||||
|
expFinal->next = expAux;
|
||||||
|
return expFinal;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_t * PrintExpression(expression_t * expression) {
|
||||||
|
print_t * print = malloc(sizeof(print_t));
|
||||||
|
expression_t * expAux = malloc(sizeof(expression_t));
|
||||||
|
|
||||||
|
expressionShallowCopy(expAux, expression);
|
||||||
|
|
||||||
|
print->exp = expAux;
|
||||||
|
return print;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_t * PrintExpression(char * string) {
|
||||||
|
print_t * print = malloc(sizeof(print_t));
|
||||||
|
char * strAux = malloc(strlen(string));
|
||||||
|
|
||||||
|
strcpy(strAux, string);
|
||||||
|
|
||||||
|
print->string = strAux;
|
||||||
|
return print;
|
||||||
|
}
|
||||||
|
|
||||||
|
statement_t * StatementsGrammarAction(statement_t * stat1, statement_t * stat2) {
|
||||||
|
statement_t * statFinal = malloc(sizeof(statement_t));
|
||||||
|
statement_t * statAux = malloc(sizeof(statement_t));
|
||||||
|
|
||||||
|
statementShallowCopy(stat1, statFinal);
|
||||||
|
statementShallowCopy(stat2, statAux);
|
||||||
|
|
||||||
|
statFinal->next = statAux;
|
||||||
|
return statFinal;
|
||||||
|
}
|
||||||
|
|
||||||
|
void booleanShallowCopy(boolean_t * src, boolean_t * dest) {
|
||||||
|
dest->domain = src->domain;
|
||||||
|
dest->not_bool = src->not_bool;
|
||||||
|
dest->bool_op = src->bool_op;
|
||||||
|
}
|
||||||
|
|
||||||
|
void blockShallowCopy(block_t * src, block_t * dest) {
|
||||||
|
dest->statement = src->statement;
|
||||||
|
}
|
||||||
|
|
||||||
|
if_t * IfBlockGrammarAction(boolean_t * boolean, block_t * block) {
|
||||||
|
if_t * if_st = malloc(sizeof(if_t));
|
||||||
|
boolean_t * boolAux = malloc(sizeof(boolean_t));
|
||||||
|
block_t * blockAux = malloc(sizeof(block_t));
|
||||||
|
|
||||||
|
booleanShallowCopy(boolean, boolAux);
|
||||||
|
blockShallowCopy(block, blockAux);
|
||||||
|
|
||||||
|
if_st->boolean = boolAux;
|
||||||
|
if_st->block = blockAux;
|
||||||
|
return if_st;
|
||||||
|
}
|
||||||
|
|
||||||
|
if_t * IfBlockGrammarAction(boolean_t * boolean, block_t * block) {
|
||||||
|
if_t * if_st = malloc(sizeof(if_t));
|
||||||
|
boolean_t * boolAux = malloc(sizeof(boolean_t));
|
||||||
|
block_t * blockAux = malloc(sizeof(block_t));
|
||||||
|
|
||||||
|
booleanShallowCopy(boolean, boolAux);
|
||||||
|
blockShallowCopy(block, blockAux);
|
||||||
|
|
||||||
|
if_st->boolean = boolAux;
|
||||||
|
if_st->block = block;
|
||||||
|
return if_st;
|
||||||
|
}
|
||||||
|
|
||||||
|
if_t * IfElseBlockGrammarAction(boolean_t * boolean, block_t * block, block_t * else_block) {
|
||||||
|
if_t * if_st = malloc(sizeof(if_t));
|
||||||
|
boolean_t * boolAux = malloc(sizeof(boolean_t));
|
||||||
|
block_t * blockAux = malloc(sizeof(block_t));
|
||||||
|
block_t * elseBlockAux = malloc(sizeof(block_t));
|
||||||
|
|
||||||
|
booleanShallowCopy(boolean, boolAux);
|
||||||
|
blockShallowCopy(block, blockAux);
|
||||||
|
blockShallowCopy(else_block, elseBlockAux);
|
||||||
|
|
||||||
|
if_st->boolean = boolAux;
|
||||||
|
if_st->block = blockAux;
|
||||||
|
if_st->else_block = elseBlockAux;
|
||||||
|
return if_st;
|
||||||
|
}
|
||||||
|
|
||||||
|
while_t * WhileBlockGrammarAction(boolean_t * boolean, block_t * block) {
|
||||||
|
while_t * while_st = malloc(sizeof(while_t));
|
||||||
|
boolean_t * boolAux = malloc(sizeof(boolean_t));
|
||||||
|
block_t * blockAux = malloc(sizeof(block_t));
|
||||||
|
|
||||||
|
booleanShallowCopy(boolean, boolAux);
|
||||||
|
blockShallowCopy(block, blockAux);
|
||||||
|
|
||||||
|
while_st->boolean = boolAux;
|
||||||
|
while_st->block = block;
|
||||||
|
return while_st;
|
||||||
}
|
}
|
|
@ -28,4 +28,14 @@ int ConstantFactorGrammarAction(const int value);
|
||||||
int IntegerConstantGrammarAction(const int value);
|
int IntegerConstantGrammarAction(const int value);
|
||||||
int DoubleConstantGrammarAction(const double value);
|
int DoubleConstantGrammarAction(const double value);
|
||||||
|
|
||||||
|
statement_t * EvaluateGrammarAction(evaluate_t * evaluate);
|
||||||
|
statement_t * IntegrateGrammarAction(integrate_t * integrate);
|
||||||
|
statement_t * DerivativeGrammarAction(derivative_t * derivative);
|
||||||
|
statement_t * IfGrammarAction(if_t * if_st);
|
||||||
|
statement_t * ForGrammarAction(for_t * for_st);
|
||||||
|
statement_t * WhileGrammarAction(while_t * while_st);
|
||||||
|
statement_t * PrintGrammarAction(print_t * print);
|
||||||
|
statement_t * DeclareVariableGrammarAction();
|
||||||
|
statement_t * AssignVariableGrammarAction();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,65 +1,95 @@
|
||||||
%{
|
%{
|
||||||
|
|
||||||
#include "bison-actions.h"
|
#include "bison-actions.h"
|
||||||
|
#include "nodes.h"
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
// IDs de los tokens generados desde Flex:
|
%union {
|
||||||
|
variable_t * variable;
|
||||||
|
function_t * function;
|
||||||
|
statement_t * statement;
|
||||||
|
expression_t * expression;
|
||||||
|
derivative_t * derivative;
|
||||||
|
evaluate_t * evaluate;
|
||||||
|
integrate_t * integrate;
|
||||||
|
algebraic_op_t * algebraic_op;
|
||||||
|
parenthesis_exp_t * parenthesis_exp;
|
||||||
|
boolean_t * boolean;
|
||||||
|
domain_t * domain;
|
||||||
|
int intNumber;
|
||||||
|
double doubleNumber;
|
||||||
|
char * string;
|
||||||
|
int token;
|
||||||
|
}
|
||||||
|
|
||||||
%token ADD
|
%type <variable> variable
|
||||||
%token SUB
|
%type <variable> declare_variable
|
||||||
%token MUL
|
%type <function> function
|
||||||
%token DIV
|
%type <function> functions
|
||||||
%token POW
|
%type <function> declare_function
|
||||||
%token FUNCTION
|
%type <statement> statement
|
||||||
%token IF
|
%type <expression> expression
|
||||||
%token ELSE
|
%type <derivative> derivative
|
||||||
%token FOR
|
%type <integrate> integrate
|
||||||
%token WHILE
|
%type <evaluate> evaluate
|
||||||
%token PRINT
|
%type <algebraic_op> algebraic_op
|
||||||
%token SEMICOLON
|
%type <parenthesis_exp> parenthesis_exp
|
||||||
%token COMPOSITE
|
%type <boolean> boolean
|
||||||
%token SQUOTE
|
%type <domain> domain
|
||||||
%token DERIVATIVE
|
|
||||||
%token INTEGRATE
|
|
||||||
%token BETWEEN
|
|
||||||
%token AND_INT
|
|
||||||
%token EVALUATE
|
|
||||||
%token IN
|
|
||||||
%token OPEN_BRACES
|
|
||||||
%token OPEN_BRACKETS
|
|
||||||
%token CLOSE_BRACES
|
|
||||||
%token CLOSE_BRACKETS
|
|
||||||
%token OPEN_PARENTHESIS
|
|
||||||
%token CLOSE_PARENTHESIS
|
|
||||||
%token ASSIGN
|
|
||||||
%token EQUAL
|
|
||||||
%token AND
|
|
||||||
%token OR
|
|
||||||
%token NOT
|
|
||||||
%token ADD_ASSIGN
|
|
||||||
%token INCREMENT
|
|
||||||
%token SUB_ASSIGN
|
|
||||||
%token DECREMENT
|
|
||||||
%token MUL_ASSIGN
|
|
||||||
%token DIV_ASSIGN
|
|
||||||
%token DQUOTE
|
|
||||||
%token COMMA
|
|
||||||
%token COLON
|
|
||||||
%token LESSER
|
|
||||||
%token LESSER_EQUAL
|
|
||||||
%token GREATER
|
|
||||||
%token GREATER_EQUAL
|
|
||||||
%token NOT_EQUAL
|
|
||||||
%token VAR
|
|
||||||
%token ERR
|
|
||||||
%token TAYLOR
|
|
||||||
%token ESCAPESTRING
|
|
||||||
%token DOUBLE
|
|
||||||
%token INTEGER
|
|
||||||
%token ID
|
|
||||||
|
|
||||||
// Reglas de asociatividad y precedencia (de menor a mayor):
|
%token <token> ADD
|
||||||
|
%token <token> SUB
|
||||||
|
%token <token> MUL
|
||||||
|
%token <token> DIV
|
||||||
|
%token <token> POW
|
||||||
|
%token <token> FUNCTION
|
||||||
|
%token <token> IF
|
||||||
|
%token <token> ELSE
|
||||||
|
%token <token> FOR
|
||||||
|
%token <token> WHILE
|
||||||
|
%token <token> PRINT
|
||||||
|
%token <token> SEMICOLON
|
||||||
|
%token <token> COMPOSITE
|
||||||
|
%token <token> SQUOTE
|
||||||
|
%token <token> DERIVATIVE
|
||||||
|
%token <token> INTEGRATE
|
||||||
|
%token <token> BETWEEN
|
||||||
|
%token <token> AND_INT
|
||||||
|
%token <token> EVALUATE
|
||||||
|
%token <token> IN
|
||||||
|
%token <token> OPEN_BRACES
|
||||||
|
%token <token> OPEN_BRACKETS
|
||||||
|
%token <token> CLOSE_BRACES
|
||||||
|
%token <token> CLOSE_BRACKETS
|
||||||
|
%token <token> OPEN_PARENTHESIS
|
||||||
|
%token <token> CLOSE_PARENTHESIS
|
||||||
|
%token <token> ASSIGN
|
||||||
|
%token <token> EQUAL
|
||||||
|
%token <token> AND
|
||||||
|
%token <token> OR
|
||||||
|
%token <token> NOT
|
||||||
|
%token <token> ADD_ASSIGN
|
||||||
|
%token <token> INCREMENT
|
||||||
|
%token <token> SUB_ASSIGN
|
||||||
|
%token <token> DECREMENT
|
||||||
|
%token <token> MUL_ASSIGN
|
||||||
|
%token <token> DIV_ASSIGN
|
||||||
|
%token <string> DQUOTE
|
||||||
|
%token <token> COMMA
|
||||||
|
%token <token> COLON
|
||||||
|
%token <token> LESSER
|
||||||
|
%token <token> LESSER_EQUAL
|
||||||
|
%token <token> GREATER
|
||||||
|
%token <token> GREATER_EQUAL
|
||||||
|
%token <token> NOT_EQUAL
|
||||||
|
%token <token> VAR
|
||||||
|
%token <intNumber> ERR
|
||||||
|
%token <token> TAYLOR
|
||||||
|
%token <string> ESCAPESTRING
|
||||||
|
%token <doubleNumber> DOUBLE
|
||||||
|
%token <intNumber> INTEGER
|
||||||
|
%token <string> ID
|
||||||
|
|
||||||
%precedence CLOSE_PARENTHESIS
|
%precedence CLOSE_PARENTHESIS
|
||||||
%precedence ELSE
|
%precedence ELSE
|
||||||
|
@ -76,170 +106,170 @@
|
||||||
program: statements { $$ = ProgramGrammarAction($1); }
|
program: statements { $$ = ProgramGrammarAction($1); }
|
||||||
;
|
;
|
||||||
|
|
||||||
statement: evaluate SEMICOLON
|
statement: evaluate SEMICOLON { $$ = EvaluateGrammarAction($1); }
|
||||||
| integrate SEMICOLON
|
| integrate SEMICOLON { $$ = IntegrateGrammarAction($1); }
|
||||||
| derivative SEMICOLON
|
| derivative SEMICOLON { $$ = DerivativeGrammarAction($1); }
|
||||||
| declare_function SEMICOLON
|
| declare_function SEMICOLON { $$ = StatementDeclareFunctionGrammarAction($1); }
|
||||||
| if_statement
|
| if_statement { $$ = IfGrammarAction($1); }
|
||||||
| for_statement
|
| for_statement { $$ = ForGrammarAction($1); }
|
||||||
| while_statement
|
| while_statement { $$ = WhileGrammarAction($1); }
|
||||||
| print SEMICOLON
|
| print SEMICOLON { $$ = PrintGrammarAction($1); }
|
||||||
| declare_variable SEMICOLON
|
| declare_variable SEMICOLON { $$ = VariableStatementGrammarAction($1); }
|
||||||
| assign_variable SEMICOLON
|
| assign_variable SEMICOLON { $$ = VariableStatementGrammarAction($1); }
|
||||||
;
|
;
|
||||||
|
|
||||||
expression: positive_constant
|
expression: positive_constant { $$ = PositiveConstantGrammarAction($1) }
|
||||||
| evaluate
|
| evaluate { $$ = EvaluateGrammarAction($1) }
|
||||||
| integrate
|
| integrate { $$ = IntegrateGrammarAction($1) }
|
||||||
| derivative
|
| derivative { $$ = DerivativeGrammarAction($1) }
|
||||||
| ID
|
| ID { $$ = IdGrammarAction($1) }
|
||||||
| expression ADD expression
|
| expression ADD expression { $$ = ExpressionOperatorGrammarAction($1, $2, $3) }
|
||||||
| expression SUB expression
|
| expression SUB expression { $$ = ExpressionOperatorGrammarAction($1, $2, $3) }
|
||||||
| expression MUL expression
|
| expression MUL expression { $$ = ExpressionOperatorGrammarAction($1, $2, $3) }
|
||||||
| expression DIV expression
|
| expression DIV expression { $$ = ExpressionOperatorGrammarAction($1, $2, $3) }
|
||||||
| expression POW expression
|
| expression POW expression { $$ = ExpressionOperatorGrammarAction($1, $2, $3) }
|
||||||
| OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
| OPEN_PARENTHESIS expression CLOSE_PARENTHESIS { $$ = ParenthesisExpressionGrammarAction($2) }
|
||||||
| SUB expression
|
| SUB expression { $$ = NegativeExpressionGrammarAction($2) }
|
||||||
;
|
;
|
||||||
|
|
||||||
domain: expression LESSER expression
|
domain: expression LESSER expression { $$ = DomainOneOptOperatorGrammarAction($1, $2, $3) }
|
||||||
| expression LESSER_EQUAL expression
|
| expression LESSER_EQUAL expression { $$ = DomainOneOptOperatorGrammarAction($1, $2, $3) }
|
||||||
| expression GREATER_EQUAL expression
|
| expression GREATER_EQUAL expression { $$ = DomainOneOptOperatorGrammarAction($1, $2, $3) }
|
||||||
| expression GREATER expression
|
| expression GREATER expression { $$ = DomainOneOptOperatorGrammarAction($1, $2, $3) }
|
||||||
| expression EQUAL expression
|
| expression EQUAL expression { $$ = DomainOneOptOperatorGrammarAction($1, $2, $3) }
|
||||||
| expression NOT_EQUAL expression
|
| expression NOT_EQUAL expression { $$ = DomainOneOptOperatorGrammarAction($1, $2, $3) }
|
||||||
| expression LESSER expression LESSER expression
|
| expression LESSER expression LESSER expression { $$ = DomainTwoOptOperatorGrammarAction($1, $2, $3, $4, $5) }
|
||||||
| expression LESSER_EQUAL expression LESSER expression
|
| expression LESSER_EQUAL expression LESSER expression { $$ = DomainTwoOptOperatorGrammarAction($1, $2, $3, $4, $5) }
|
||||||
| expression LESSER expression LESSER_EQUAL expression
|
| expression LESSER expression LESSER_EQUAL expression { $$ = DomainTwoOptOperatorGrammarAction($1, $2, $3, $4, $5) }
|
||||||
| expression LESSER_EQUAL expression LESSER_EQUAL expression
|
| expression LESSER_EQUAL expression LESSER_EQUAL expression { $$ = DomainTwoOptOperatorGrammarAction($1, $2, $3, $4, $5) }
|
||||||
;
|
;
|
||||||
|
|
||||||
boolean: domain
|
boolean: domain { $$ = DomainGrammarAction($1) }
|
||||||
| boolean OR boolean
|
| boolean OR boolean { $$ = BooleanOperatorGrammarAction($1, $2, $3) }
|
||||||
| boolean AND boolean
|
| boolean AND boolean { $$ = BooleanOperatorGrammarAction($1, $2, $3) }
|
||||||
| OPEN_PARENTHESIS boolean CLOSE_PARENTHESIS
|
| OPEN_PARENTHESIS boolean CLOSE_PARENTHESIS { $$ = $2 }
|
||||||
| NOT boolean
|
| NOT boolean { $$ = NotBooleanAction($2) }
|
||||||
;
|
;
|
||||||
|
|
||||||
positive_constant: DOUBLE
|
positive_constant: DOUBLE { $$ = DoubleGrammarAction($1) }
|
||||||
| INTEGER
|
| INTEGER { $$ = IntegerGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
declare_function: FUNCTION ID ASSIGN function
|
declare_function: FUNCTION ID ASSIGN function { $$ = DeclareFunctionGrammarAction($2, $4) }
|
||||||
| FUNCTION ID ASSIGN OPEN_BRACES functions CLOSE_BRACES
|
| FUNCTION ID ASSIGN OPEN_BRACES functions CLOSE_BRACES { $$ = DeclareFunctionListGrammarAction($2, $5) }
|
||||||
;
|
;
|
||||||
|
|
||||||
function: expression
|
function: expression { $$ = ExpressionFunctionGrammarAction($1) }
|
||||||
| expression COLON domain
|
| expression COLON domain { $$ = ExpressionDomainFunctionGrammarAction($1, $3) }
|
||||||
| composite
|
| composite { $$ = CompositeFunctionGrammarAction($1) }
|
||||||
| taylor
|
| taylor { $$ = TaylorFunctionGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
functions: function
|
functions: function { $$ = $1 }
|
||||||
| function COMMA functions
|
| function COMMA functions { $$ = FunctionsGrammarAction($1, $3) }
|
||||||
;
|
;
|
||||||
|
|
||||||
composite: ID COMPOSITE ID
|
composite: ID COMPOSITE ID { $$ = CompositeIdGrammarAction($1, $3) }
|
||||||
| composite COMPOSITE ID
|
| composite COMPOSITE ID { $$ = CompositeCompGrammarAction($1, $3) }
|
||||||
;
|
;
|
||||||
|
|
||||||
expressions: expression
|
expressions: expression { $$ = $1 }
|
||||||
| expression COMMA expressions
|
| expression COMMA expressions { $$ = ExpressionsGrammarAction($1, $3) }
|
||||||
;
|
;
|
||||||
|
|
||||||
ids: ID
|
ids: ID { $$ = $1 }
|
||||||
| ID COMMA ids
|
| ID COMMA ids { $$ = DoubleGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
numArray: OPEN_BRACKETS expressions CLOSE_BRACKETS
|
numArray: OPEN_BRACKETS expressions CLOSE_BRACKETS { $$ = DoubleGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
numArrays: numArray
|
numArrays: numArray { $$ = DoubleGrammarAction($1) }
|
||||||
| numArray COMMA numArrays
|
| numArray COMMA numArrays { $$ = DoubleGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
arrayNumArray: OPEN_BRACKETS numArrays CLOSE_BRACKETS
|
arrayNumArray: OPEN_BRACKETS numArrays CLOSE_BRACKETS { $$ = DoubleGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
idArray: OPEN_BRACKETS ids CLOSE_BRACKETS
|
idArray: OPEN_BRACKETS ids CLOSE_BRACKETS { $$ = DoubleGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
escapeString: ESCAPESTRING
|
escapeString: ESCAPESTRING { $$ = DoubleGrammarAction($1) }
|
||||||
| ESCAPESTRING ADD escapeString
|
| ESCAPESTRING ADD escapeString { $$ = DoubleGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
escapeStrings: escapeString
|
escapeStrings: escapeString { $$ = $1 }
|
||||||
| escapeString COMMA escapeStrings
|
| escapeString COMMA escapeStrings { $$ = DoubleGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
escapeStringArray: OPEN_BRACKETS escapeStrings CLOSE_BRACKETS
|
escapeStringArray: OPEN_BRACKETS escapeStrings CLOSE_BRACKETS { $$ = DoubleGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
evaluate: EVALUATE ID IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
evaluate: EVALUATE ID IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS { $$ = DoubleGrammarAction($1) }
|
||||||
| EVALUATE ID IN numArray
|
| EVALUATE ID IN numArray { $$ = DoubleGrammarAction($1) }
|
||||||
| ID OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
| ID OPEN_PARENTHESIS expression CLOSE_PARENTHESIS { $$ = DoubleGrammarAction($1) }
|
||||||
| EVALUATE idArray IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
| EVALUATE idArray IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS { $$ = DoubleGrammarAction($1) }
|
||||||
| EVALUATE idArray IN numArray
|
| EVALUATE idArray IN numArray { $$ = DoubleGrammarAction($1) }
|
||||||
| idArray OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
| idArray OPEN_PARENTHESIS expression CLOSE_PARENTHESIS { $$ = DoubleGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
integrate: INTEGRATE ID BETWEEN OPEN_PARENTHESIS expression AND_INT expression CLOSE_PARENTHESIS
|
integrate: INTEGRATE ID BETWEEN OPEN_PARENTHESIS expression AND_INT expression CLOSE_PARENTHESIS { $$ = DoubleGrammarAction($1) }
|
||||||
| INTEGRATE ID OPEN_PARENTHESIS expression AND_INT expression CLOSE_PARENTHESIS
|
| INTEGRATE ID OPEN_PARENTHESIS expression AND_INT expression CLOSE_PARENTHESIS { $$ = DoubleGrammarAction($1) }
|
||||||
| INTEGRATE idArray BETWEEN OPEN_PARENTHESIS expression AND_INT expression CLOSE_PARENTHESIS
|
| INTEGRATE idArray BETWEEN OPEN_PARENTHESIS expression AND_INT expression CLOSE_PARENTHESIS { $$ = DoubleGrammarAction($1) }
|
||||||
| INTEGRATE idArray OPEN_PARENTHESIS expression AND_INT expression CLOSE_PARENTHESIS
|
| INTEGRATE idArray OPEN_PARENTHESIS expression AND_INT expression CLOSE_PARENTHESIS { $$ = DoubleGrammarAction($1) }
|
||||||
| integrate ERR positive_constant
|
| integrate ERR positive_constant { $$ = DoubleGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
squotes: SQUOTE
|
squotes: SQUOTE { $$ = DoubleGrammarAction($1) }
|
||||||
| SQUOTE squotes
|
| SQUOTE squotes { $$ = DoubleGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
print: PRINT OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
print: PRINT OPEN_PARENTHESIS expression CLOSE_PARENTHESIS { $$ = PrintExpression($3) }
|
||||||
| PRINT OPEN_PARENTHESIS escapeString CLOSE_PARENTHESIS
|
| PRINT OPEN_PARENTHESIS escapeString CLOSE_PARENTHESIS { $$ = PrintExpression($3) }
|
||||||
;
|
;
|
||||||
|
|
||||||
statements: statement
|
statements: statement { $$ = $1 }
|
||||||
| statement statements
|
| statement statements { $$ = StatementsGrammarAction($1, $2) }
|
||||||
;
|
;
|
||||||
|
|
||||||
derivative: DERIVATIVE ID IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
derivative: DERIVATIVE ID IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS { $$ = DoubleGrammarAction($1) }
|
||||||
| DERIVATIVE INTEGER ID IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
| DERIVATIVE INTEGER ID IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS { $$ = DoubleGrammarAction($1) }
|
||||||
| ID squotes OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
| ID squotes OPEN_PARENTHESIS expression CLOSE_PARENTHESIS { $$ = DoubleGrammarAction($1) }
|
||||||
| DERIVATIVE idArray IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
| DERIVATIVE idArray IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS { $$ = DoubleGrammarAction($1) }
|
||||||
| DERIVATIVE INTEGER idArray IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
| DERIVATIVE INTEGER idArray IN OPEN_PARENTHESIS expression CLOSE_PARENTHESIS { $$ = DoubleGrammarAction($1) }
|
||||||
| idArray squotes OPEN_PARENTHESIS expression CLOSE_PARENTHESIS
|
| idArray squotes OPEN_PARENTHESIS expression CLOSE_PARENTHESIS { $$ = DoubleGrammarAction($1) }
|
||||||
| derivative ERR positive_constant
|
| derivative ERR positive_constant { $$ = DoubleGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
block: OPEN_BRACES statements CLOSE_BRACES
|
block: OPEN_BRACES statements CLOSE_BRACES { $$ = DoubleGrammarAction($1) }
|
||||||
| statement
|
| statement { $$ = DoubleGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
if_statement: IF OPEN_PARENTHESIS boolean CLOSE_PARENTHESIS block
|
if_statement: IF OPEN_PARENTHESIS boolean CLOSE_PARENTHESIS block { $$ = IfBlockGrammarAction($3, $5) }
|
||||||
| IF OPEN_PARENTHESIS boolean CLOSE_PARENTHESIS block ELSE block
|
| IF OPEN_PARENTHESIS boolean CLOSE_PARENTHESIS block ELSE block { $$ = IfElseBlockGrammarAction($3, $5, $7) }
|
||||||
;
|
;
|
||||||
|
|
||||||
for_statement: FOR OPEN_PARENTHESIS declare_variable SEMICOLON boolean SEMICOLON assign_variable CLOSE_PARENTHESIS block
|
for_statement: FOR OPEN_PARENTHESIS declare_variable SEMICOLON boolean SEMICOLON assign_variable CLOSE_PARENTHESIS block { $$ = DoubleGrammarAction($1) }
|
||||||
| FOR OPEN_PARENTHESIS SEMICOLON boolean SEMICOLON assign_variable CLOSE_PARENTHESIS block
|
| FOR OPEN_PARENTHESIS SEMICOLON boolean SEMICOLON assign_variable CLOSE_PARENTHESIS block { $$ = DoubleGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
taylor: TAYLOR INTEGER ID
|
taylor: TAYLOR INTEGER ID { $$ = DoubleGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
while_statement: WHILE OPEN_PARENTHESIS boolean CLOSE_PARENTHESIS block
|
while_statement: WHILE OPEN_PARENTHESIS boolean CLOSE_PARENTHESIS block { $$ = WhileBlockGrammarAction($3, $5) }
|
||||||
;
|
;
|
||||||
|
|
||||||
declare_variable: VAR ID
|
declare_variable: VAR ID { $$ = DoubleGrammarAction($1) }
|
||||||
| declare_variable ASSIGN expression
|
| declare_variable ASSIGN expression { $$ = DoubleGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
assign_variable: ID ADD_ASSIGN expression
|
assign_variable: ID ADD_ASSIGN expression { $$ = DoubleGrammarAction($1) }
|
||||||
| ID SUB_ASSIGN expression
|
| ID SUB_ASSIGN expression { $$ = DoubleGrammarAction($1) }
|
||||||
| ID MUL_ASSIGN expression
|
| ID MUL_ASSIGN expression { $$ = DoubleGrammarAction($1) }
|
||||||
| ID DIV_ASSIGN expression
|
| ID DIV_ASSIGN expression { $$ = DoubleGrammarAction($1) }
|
||||||
| ID INCREMENT
|
| ID INCREMENT { $$ = DoubleGrammarAction($1) }
|
||||||
| ID DECREMENT
|
| ID DECREMENT { $$ = DoubleGrammarAction($1) }
|
||||||
| ID ASSIGN expression
|
| ID ASSIGN expression { $$ = DoubleGrammarAction($1) }
|
||||||
;
|
;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
Loading…
Reference in New Issue