From 11f8fd4418a068c76fc7c810967a6bf285ee74b6 Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 27 Oct 2025 09:06:05 -0500 Subject: add expression scaffold --- expression.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 expression.h (limited to 'expression.h') diff --git a/expression.h b/expression.h new file mode 100644 index 0000000..36a0e02 --- /dev/null +++ b/expression.h @@ -0,0 +1,42 @@ +#ifndef LICHEN_EXPRESSION_H +#define LICHEN_EXPRESSION_H + +/**************************************************************** + * + * a grammar is built on both nonterminals and terminals. both are + * represented by integers; nonterminals must be less than MAX_NONTERMINAL + * and terminals must be greater. the intended way to do this is to define + * an enum with all symbols, and have a MAX_NONTERMINAL symbol dividing the + * (low) nonterminals from the (high) terminals. + * + **************************************************************** + */ + +struct li_production_t { + int *seq; + size_t seq_len; + struct li_production_t *next; +}; + +struct li_production_t * li_production_alloc(size_t seq_len); +void li_production_free(struct li_production_t *prod); + +struct li_production_rule_t { + size_t num_productions; + struct li_production_t *head; +}; + +struct li_production_rule_t * li_prod_rule_alloc(); +void li_prod_rule_free(struct li_production_rule_t *rule); +int li_prod_rule_add(struct li_production_rule_t *rule, size_t seq_len, int *seq); + +typedef struct li_grammar_t { + struct li_production_rule_t *rules; + size_t num_nonterminal; +} li_grammar_t; + +li_rammar_t * li_grammar_alloc(size_t num_nonterminal); +void li_grammar_free(li_grammar_t *grammar); +int li_grammar_rule_add(li_grammar_t *grammar, int nonterminal, size_t seq_len, int *seq); + +#endif -- cgit v1.2.1