#ifndef HELPER_H #define HELPER_H #include #include #include #include #include "big_endian.h" struct SignedVec { unsigned char *len; unsigned char *capacity; char *data; }; struct UnsignedVec { unsigned char *len; unsigned char *capacity; unsigned char *data; }; struct parser; struct parser *new_parser(char *grammar_string, struct SignedVec *error_vec); void clean_parser(void *parser); int parser_recognize(struct parser *parser, struct UnsignedVec *input_vec, struct SignedVec *error_vec, unsigned char reset_p); struct UnsignedVec * parser_parse (struct parser *parser, struct UnsignedVec *input_vec, struct SignedVec *error_vec, unsigned char reset_p); void clean_signed(struct SignedVec *vec, unsigned char flag); void clean_unsigned(struct UnsignedVec *vec, unsigned char flag); typedef enum Status { Plain = 0, Packed = 1, Clone = 2, } Status; typedef enum Variant { Terminal = 0, Nonterminal = 1, Rule = 2, } Variant; struct Label { Status status; uint64_t clone_index; uint64_t start; uint64_t end; Variant variant; uint64_t content; }; struct Label read_label(unsigned char *ptr); void print_label(struct Label label); // TODO: Add functions for verifying the format of the forest. // // And add functions to query the number from the terminal name, or // the non-terminal name. // // And add functions for queryinf information from the forest. // TODO: Declare opaque struct standing for forests, and connect to // the function for printing labels of forests. // // This can be used in debuggers to help us diagnose the situation. struct CForest; void print_forest_node(struct CForest *forest, unsigned char *node); void print_node(struct CForest *forest, uint64_t node); void print_forest(struct UnsignedVec *forest_vec, struct SignedVec *error_vec, char *filename); void print_forest_file(char *filename, char *output_filename); #endif