Skip to content
Snippets Groups Projects
Commit cf1032eb authored by expan's avatar expan
Browse files

Merge branch 'atoms' of git.uwaterloo.ca:gweddell/LDI into atoms

parents 788a0672 962b9579
No related branches found
No related tags found
No related merge requests found
File added
No preview for this file type
......@@ -6,6 +6,7 @@
cons_cell* parse(char* input, int size) {
if (input[0] == NULL) {
assert(size == 0);
return NULL;
}
if (input[0] == '(') {
......@@ -14,14 +15,14 @@ cons_cell* parse(char* input, int size) {
end--;
}
char buffer[end];
strncpy(buffer, input[1], end - 1);
strncpy(buffer, &input[1], end - 1);
cons_cell* car_cons = parse(buffer, end - 1);
int next_char = end + 1;
while (input[next_char] == ' ' && input[next_char] != NULL) {
next_char++;
}
char buffer_next[500];
strncpy(buffer_next, input[next_char], size - next_char);
strncpy(buffer_next, &input[next_char], size - next_char);
cons_cell* cdr_cons = parse(buffer_next, size - next_char);
return create_cons_cell(car_cons, cdr_cons);
} else {
......@@ -46,15 +47,14 @@ cons_cell* parse(char* input, int size) {
int main() {
char str[500];
printf("Enter the json-string to parse: ");
printf("Enter the json-string to parse: \n");
scanf("%s", str);
printf("You entered: %s", str);
printf("You entered: %s\n", str);
int size = 0;
while (str[size] != NULL) {
size++;
}
size++;
cons_cell* cons = parse(str, size);
print_cons_tree(cons);
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment