Skip to content

Commit

Permalink
Add expression tree interface documentation and include guards
Browse files Browse the repository at this point in the history
  • Loading branch information
breiters committed Nov 19, 2024
1 parent 88b3b67 commit 6364d4f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/calculator_exptree.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// calculator_exptree.c
// TODO: file description

#include <bstrlib.h>
#include <bstrlib_helper.h>
#include "calculator_exptree.h"
Expand Down
46 changes: 41 additions & 5 deletions src/includes/calculator_exptree.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,55 @@
// calculator_exptree.h
// TODO: file description

struct exptree_node; // fwd declaration
#ifndef CALCULATOR_EXPTREE_H_INCLUDED
#define CALCULATOR_EXPTREE_H_INCLUDED

/**
* @brief Forward declaration of struct exptree_node
*
*/
struct exptree_node;

// cannot fwd declare CounterList because it was an anonymous struct (changed)
// thus we named CounterList to avoid unnecessary cyclic inclusion dependency with:
// thus we named CounterList to avoid unnecessary inclusion dependency with:
// #include "perfgroup.h"
struct CounterList; // fwd declaration
/**
* @brief Forward declaration of struct CounterList
*
*/
struct CounterList;

// TODO: documentation of interfaces
// TODO: do we want "print_expression_tree"?

/**
* @brief Builds a binary expression tree from expression expr
*
* @param expr The expression
* @return struct exptree_node* Expression tree node on success, NULL on error
*/
extern struct exptree_node *make_expression_tree(const char *expr);

/**
* @brief Deallocates the binary expression tree
*
* @param root The root node
*/
extern void free_expression_tree(struct exptree_node *root);

extern double evaluate_expression_tree(const struct exptree_node *node, const struct CounterList *clist);
/**
* @brief Evaluates the expression tree with values from counter list
*
* @param root The root node
* @param clist The counter list
* @return double The value of the expression tree evaluation on success, NAN on error
*/
extern double evaluate_expression_tree(const struct exptree_node *root, const struct CounterList *clist);

/**
* @brief Prints the expression tree in infix order
*
* @param root The root node
*/
extern void print_expression_tree(const struct exptree_node *root);

#endif /* CALCULATOR_EXPTREE_H_INCLUDED */

0 comments on commit 6364d4f

Please sign in to comment.