Casted pointers to correct type and seperated out the LAMBDATAG and LAMBDA constants
This commit is contained in:
parent
28e2352eac
commit
aa7e348552
6 changed files with 8 additions and 8 deletions
|
@ -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;
|
||||||
|
|
|
@ -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; }
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Reference in a new issue