Archived
1
0
Fork 0

Casted pointers to correct type and seperated out the LAMBDATAG and LAMBDA constants

This commit is contained in:
Brandon Rozek 2018-09-26 15:56:36 -04:00
parent 28e2352eac
commit aa7e348552
6 changed files with 8 additions and 8 deletions

View file

@ -14,7 +14,7 @@ struct Node* make_node(int type, struct Value* value, char* id) {
int i;
/* allocate space */
struct Node* node = malloc(sizeof(struct Node));
struct Node* node = (struct Node*) malloc(sizeof(struct Node));
/* set properties */
node->type = type;

View file

@ -44,7 +44,7 @@
%token COMMENT
%token WHITESPACE
%token DONE
%token <value> LAMBDA
%token <value> LAMBDATAG
%token COLON
/* declare non-terminals */
@ -101,9 +101,9 @@ statements: BEGINTOK substatements END { $$ = $2; }
substatements: statement substatements {$$ = make_node(STATEMENT, NULL, ""); attach_node($$, $1); attach_node($$, $2); }
| statement {$$ = make_node(STATEMENT, NULL, ""); attach_node($$, $1); }
exprlambda: LAMBDA ident COLON expression {
exprlambda: LAMBDATAG ident COLON expression {
// Only supports one argument functions for now
$$ = make_node(LAMBDA, NULL, "");
$$ = make_node(LAMBDATAG, NULL, "");
attach_node($$, $2);
attach_node($$, $4); }
| expression { $$ = $1; }

View file

@ -5,7 +5,7 @@
#include "variable.h"
struct Environment* create_environment(void) {
struct Environment* env = malloc(sizeof(struct Environment));
struct Environment* env = (struct Environment*) malloc(sizeof(struct Environment));
env->num_vars = 0;
for(int i = 0; i < MAX_VARIABLES; i++) {
env->vars[i] = NULL;

View file

@ -6,7 +6,7 @@
struct Value* make_value(int type, long num, double dec, struct Node* expr, char* str) {
/* allocate space */
struct Value* val = malloc(sizeof(struct Value));
struct Value* val = (struct Value*) malloc(sizeof(struct Value));
/* set properties */
val->type = type;

View file

@ -1,7 +1,7 @@
#ifndef VALUE_H
#define VALUE_H
enum TypeTag { DOUBLE, LONG, BOOLEAN, STRING };
enum TypeTag { DOUBLE, LONG, BOOLEAN, STRING, LAMBDA };
typedef union typeval {
long num;

View file

@ -6,7 +6,7 @@
/* creates a new variable and returns it */
struct Variable* make_variable(char* id, struct Value* value) {
/* allocate space */
struct Variable* var = malloc(sizeof(struct Variable));
struct Variable* var = (struct Variable*) malloc(sizeof(struct Variable));
/* set properties */
strcpy(var->id, id);