Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with finishing the lex and yacc files. A thorough explantion with each step please or a step in the right direction. Here

I need help with finishing the lex and yacc files. A thorough explantion with each step please or a step in the right direction. Here are my files thus far.
.h File
#ifndef __cilisp_h_
#define __cilisp_h_
#include
#include
#include
#include
#include
#include
#define NAN_RET_VAL (RET_VAL){DOUBLE_TYPE, NAN}
#define ZERO_RET_VAL (RET_VAL){INT_TYPE, 0}
#define BISON_FLEX_LOG_PATH "bison_flex.log"
FILE* read_target;
FILE* flex_bison_log_file;
size_t yyreadline(char **lineptr, size_t *n, FILE *stream, size_t n_terminate);
int yyparse(void);
int yylex(void);
void yyerror(char *,...);
void warning(char*,...);
typedef enum func_type {
NEG_FUNC,
ABS_FUNC,
ADD_FUNC,
SUB_FUNC,
MULT_FUNC,
DIV_FUNC,
EXP_FUNC,
REMAINDER_FUNC,
EXP2_FUNC,
POW_FUNC,
LOG_FUNC,
SQRT_FUNC,
CBRT_FUNC,
HYPOT_FUNC,
MAX_FUNC,
MIN_FUNC,
CUSTOM_FUNC
} FUNC_TYPE;
FUNC_TYPE resolveFunc(char *);
typedef enum num_type {
INT_TYPE,
DOUBLE_TYPE,
} NUM_TYPE;
typedef struct {
NUM_TYPE type;
double value;
} AST_NUMBER;
typedef AST_NUMBER RET_VAL;
typedef struct ast_function {
FUNC_TYPE func;
struct ast_node *opList;
} AST_FUNCTION;
typedef enum ast_node_type {
NUM_NODE_TYPE,
FUNC_NODE_TYPE
} AST_NODE_TYPE;
typedef struct ast_node {
AST_NODE_TYPE type;
union {
AST_NUMBER number;
AST_FUNCTION function;
} data;
struct ast_node *next;
} AST_NODE;
AST_NODE *createNumberNode(double value, NUM_TYPE type);
AST_NODE *createFunctionNode(FUNC_TYPE func, AST_NODE *opList);
AST_NODE *addExpressionToList(AST_NODE *newExpr, AST_NODE *exprList);
RET_VAL eval(AST_NODE *node);
void printRetVal(RET_VAL val);
void freeNode(AST_NODE *node);
#endif
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions