True and False values.
This commit is contained in:
parent
ab8b26d6f0
commit
e342fb31de
|
|
@ -62,6 +62,8 @@ Ulam Spiral).
|
||||||
|
|
||||||
|
|
||||||
const char *BLANKS = " \t";
|
const char *BLANKS = " \t";
|
||||||
|
const char *FALSE = "false";
|
||||||
|
const char *TRUE = "true";
|
||||||
|
|
||||||
|
|
||||||
enum JoyTypeType {
|
enum JoyTypeType {
|
||||||
|
|
@ -85,7 +87,7 @@ struct JoyType {
|
||||||
|
|
||||||
|
|
||||||
struct list_node {
|
struct list_node {
|
||||||
struct JoyType head;
|
struct JoyType head; /* Should this be a pointer? */
|
||||||
struct list_node* tail;
|
struct list_node* tail;
|
||||||
} JoyList;
|
} JoyList;
|
||||||
|
|
||||||
|
|
@ -182,11 +184,24 @@ struct list_node*
|
||||||
make_symbol_node(char *text, size_t size)
|
make_symbol_node(char *text, size_t size)
|
||||||
{
|
{
|
||||||
struct list_node *node;
|
struct list_node *node;
|
||||||
|
char * sym;
|
||||||
|
|
||||||
|
sym = GC_malloc(size + 1); /* one more for the zero, right? */
|
||||||
|
strncat(sym, text, size);
|
||||||
|
|
||||||
node = GC_malloc(sizeof(struct list_node));
|
node = GC_malloc(sizeof(struct list_node));
|
||||||
node->head.kind = joySymbol;
|
if (!strncmp(sym, FALSE, 6)) { /* I know it's wrong to hardcode the length here. Sorry. */
|
||||||
node->head.value.symbol = (char *)GC_malloc(size + 1);
|
/* If head was a pointer we could reuse Boolean singletons... */
|
||||||
strncat(node->head.value.symbol, text, size);
|
node->head.kind = joyFalse;
|
||||||
/*printf("%s\n", node->head.value.symbol);*/
|
node->head.value.boolean = 0;
|
||||||
|
} else if (!strncmp(sym, TRUE, 5)) { /* I know it's wrong to hardcode the length here. Sorry. */
|
||||||
|
node->head.kind = joyTrue;
|
||||||
|
node->head.value.boolean = 1;
|
||||||
|
} else {
|
||||||
|
node->head.kind = joySymbol;
|
||||||
|
node->head.value.symbol = sym;
|
||||||
|
}
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -327,7 +342,6 @@ text_to_expression(char *text)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
|
|
@ -345,6 +359,20 @@ main(void)
|
||||||
while (1) {
|
while (1) {
|
||||||
status = gets_s(line, 1025);
|
status = gets_s(line, 1025);
|
||||||
if (NULL == status) {
|
if (NULL == status) {
|
||||||
|
/*
|
||||||
|
From the man page:
|
||||||
|
|
||||||
|
> Upon successful completion, fgets(), gets_s(), and gets() return a
|
||||||
|
pointer to the string. If end-of-file occurs before any characters are
|
||||||
|
read, they return NULL and the buffer contents remain unchanged. If an
|
||||||
|
error occurs, they return NULL and the buffer contents are indeterminate.
|
||||||
|
The fgets(), gets_s(), and gets() functions do not distinguish between
|
||||||
|
end-of-file and error, and callers must use feof(3) and ferror(3) to
|
||||||
|
determine which occurred.
|
||||||
|
|
||||||
|
TODO: "use feof(3) and ferror(3)"...
|
||||||
|
|
||||||
|
*/
|
||||||
printf("bye\n");
|
printf("bye\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue