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; int i;
/* allocate space */ /* allocate space */
struct Node* node = malloc(sizeof(struct Node)); struct Node* node = (struct Node*) malloc(sizeof(struct Node));
/* set properties */ /* set properties */
node->type = type; node->type = type;

View file

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

View file

@ -5,7 +5,7 @@
#include "variable.h" #include "variable.h"
struct Environment* create_environment(void) { 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; env->num_vars = 0;
for(int i = 0; i < MAX_VARIABLES; i++) { for(int i = 0; i < MAX_VARIABLES; i++) {
env->vars[i] = NULL; 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) { struct Value* make_value(int type, long num, double dec, struct Node* expr, char* str) {
/* allocate space */ /* allocate space */
struct Value* val = malloc(sizeof(struct Value)); struct Value* val = (struct Value*) malloc(sizeof(struct Value));
/* set properties */ /* set properties */
val->type = type; val->type = type;

View file

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

View file

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