1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include "json.h"
// UNTESTED ILLUSTRATION
//
// ON OUR PLATFORM:
// assume sizeof(Element) == 12
// because sizeof(….type) == 4 # because an enum type is internally an int
// because MAX(sizeof(….as_int), sizeof(….as_string), sizeof(….as_list))
// == MAX(4, 8, 8)
// == 8
// assume sizeof(Node) == 20
// because sizeof(.element) == sizeof(Element) == 12
// sizeof(.next) == sizeof(Node*) == sizeof(void*) == 8
// assume sizeof(ParseResult) == 16
// becaues sizeof(….element) == 12
// because sizeof(….is_success) == sizeof(bool) == sizeof(int) == 4
int main(int argc, char* argv[]) {
ParseResult result = parse_json("[1,[2,\"three\"]]");
if(result.is_success) {
free_element(result.element);
}
/*
parse_json("[1,[2,\"three\"]]")
parse_element("[1,[2,\"three\"]]")
parse_list("[1,[2,\"three\"]]")
# eat the '['
parse_element("1,[2,\"three\"]]")
parse_int("1,[2,\"three\"]]")
# eat the ','
parse_element("[2,\"three\"]]")
parse_list("[2,\"three\"]]")
# eat the '['
parse_element("2,\"three\"]]")
parse_int("2,\"three\"]]")
# eat the ','
parse_element("\"three\"]]")
parse_string("\"three\"]]")
# eat the starting '"'
# copy the string inside the double quotes to the heap
# eat the ending '"'
# eat the ']'
# eat the ']'
# DONE
*/
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 expandtab cc=5,9,13,17,21,25,29: */
|
© Copyright 2022 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.