comparison lwlink/expr.c @ 8:fdc11ef4115b

Switched lwlink to lw_cmdline from argp and also brought in lw_alloc and lw_string to replace util.c
author lost@l-w.ca
date Sat, 22 Jan 2011 09:58:24 -0700
parents 7317fbe024af
children
comparison
equal deleted inserted replaced
7:917b608b8c66 8:fdc11ef4115b
26 26
27 #include <ctype.h> 27 #include <ctype.h>
28 #include <stdlib.h> 28 #include <stdlib.h>
29 #include <string.h> 29 #include <string.h>
30 30
31 #include <lw_alloc.h>
32 #include <lw_string.h>
33
31 #include "expr.h" 34 #include "expr.h"
32 #include "util.h"
33 35
34 lw_expr_stack_t *lw_expr_stack_create(void) 36 lw_expr_stack_t *lw_expr_stack_create(void)
35 { 37 {
36 lw_expr_stack_t *s; 38 lw_expr_stack_t *s;
37 39
38 s = lw_malloc(sizeof(lw_expr_stack_t)); 40 s = lw_alloc(sizeof(lw_expr_stack_t));
39 s -> head = NULL; 41 s -> head = NULL;
40 s -> tail = NULL; 42 s -> tail = NULL;
41 return s; 43 return s;
42 } 44 }
43 45
78 80
79 lw_expr_term_t *lw_expr_term_create_oper(int oper) 81 lw_expr_term_t *lw_expr_term_create_oper(int oper)
80 { 82 {
81 lw_expr_term_t *t; 83 lw_expr_term_t *t;
82 84
83 t = lw_malloc(sizeof(lw_expr_term_t)); 85 t = lw_alloc(sizeof(lw_expr_term_t));
84 t -> term_type = LW_TERM_OPER; 86 t -> term_type = LW_TERM_OPER;
85 t -> value = oper; 87 t -> value = oper;
86 return t; 88 return t;
87 } 89 }
88 90
89 lw_expr_term_t *lw_expr_term_create_int(int val) 91 lw_expr_term_t *lw_expr_term_create_int(int val)
90 { 92 {
91 lw_expr_term_t *t; 93 lw_expr_term_t *t;
92 94
93 t = lw_malloc(sizeof(lw_expr_term_t)); 95 t = lw_alloc(sizeof(lw_expr_term_t));
94 t -> term_type = LW_TERM_INT; 96 t -> term_type = LW_TERM_INT;
95 t -> value = val; 97 t -> value = val;
96 return t; 98 return t;
97 } 99 }
98 100
99 lw_expr_term_t *lw_expr_term_create_sym(char *sym, int symtype) 101 lw_expr_term_t *lw_expr_term_create_sym(char *sym, int symtype)
100 { 102 {
101 lw_expr_term_t *t; 103 lw_expr_term_t *t;
102 104
103 t = lw_malloc(sizeof(lw_expr_term_t)); 105 t = lw_alloc(sizeof(lw_expr_term_t));
104 t -> term_type = LW_TERM_SYM; 106 t -> term_type = LW_TERM_SYM;
105 t -> symbol = lw_strdup(sym); 107 t -> symbol = lw_strdup(sym);
106 t -> value = symtype; 108 t -> value = symtype;
107 return t; 109 return t;
108 } 110 }
133 if (!s) 135 if (!s)
134 { 136 {
135 exit(1); 137 exit(1);
136 } 138 }
137 139
138 n = lw_malloc(sizeof(lw_expr_stack_node_t)); 140 n = lw_alloc(sizeof(lw_expr_stack_node_t));
139 n -> next = NULL; 141 n -> next = NULL;
140 n -> prev = s -> tail; 142 n -> prev = s -> tail;
141 n -> term = lw_expr_term_dup(t); 143 n -> term = lw_expr_term_dup(t);
142 144
143 if (s -> head) 145 if (s -> head)