Add a parser struct.

This commit is contained in:
2018-02-11 22:23:02 -08:00
parent 37a6f31b5f
commit f67b98d7a6
5 changed files with 48 additions and 6 deletions

View File

@@ -4,6 +4,7 @@
#include "ht.h"
#include "lexer.h"
#include "table.h"
#include "parser.h"
#include "libabacus_result.h"
/**
@@ -52,6 +53,11 @@ struct libab_s {
* to tokens.
*/
libab_lexer lexer;
/**
* The parser used to convert
* tokens to a tree.
*/
libab_parser parser;
/**
* The table used to store top-level
* things like functions and operators.

View File

@@ -5,12 +5,36 @@
#include "ll.h"
#include "tree.h"
/**
* The parser that is used by libabacus
* to store information for converting
* tokens into trees.
*/
struct libab_parser_s {
libab_table* base_table;
};
typedef struct libab_parser_s libab_parser;
/**
* Initializes the parser.
* @param parser the parser to intialize.
* @param table the table of "reserved" entries like operators.
*/
void libab_parser_init(libab_parser* parser, libab_table* table);
/**
* Parses the given list of tokens into the given tree pointer.
* @param parser the parser to use for parsing text.
* @param tokens the tokens to use for parsing.
* @param string the string to use for determining token values.
* @param store_into tree pointer to store the new data into.
*/
libab_result libab_parse_tokens(ll* tokens, const char* string, libab_tree** store_into);
libab_result libab_parser_parse(libab_parser* parser, ll* tokens,
const char* string, libab_tree** store_into);
/**
* Releases the resources allocated by the parser.
* @param parser the parser to release.
*/
void libab_parser_free(libab_parser* parser);
#endif

View File

@@ -1,7 +1,7 @@
#ifndef LIBABACUS_TREE_H
#define LIBABACUS_TREE_H
#include "libabacus.h"
#include "libabacus_result.h"
#include "vec.h"
/**