expression.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * ZMap Copyright 2013 Regents of the University of Michigan
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy
  6. * of the License at http://www.apache.org/licenses/LICENSE-2.0
  7. */
  8. #ifndef ZMAP_TREE_H
  9. #define ZMAP_TREE_H
  10. #include "fieldset.h"
  11. #include <string.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <stdint.h>
  15. enum operation {
  16. GT, LT, EQ, NEQ, AND, OR, LT_EQ, GT_EQ
  17. };
  18. enum node_type {
  19. OP, FIELD, STRING, INT
  20. };
  21. struct field_id {
  22. int index;
  23. char *fieldname;
  24. };
  25. union node_value {
  26. struct field_id field;
  27. char *string_literal;
  28. uint64_t int_literal;
  29. enum operation op;
  30. };
  31. typedef struct node_st {
  32. struct node_st *left_child;
  33. struct node_st *right_child;
  34. enum node_type type;
  35. union node_value value;
  36. } node_t;
  37. node_t* make_op_node(enum operation op);
  38. node_t* make_field_node(char *fieldname);
  39. node_t* make_string_node(char *literal);
  40. node_t* make_int_node(int literal);
  41. int evaluate_expression(node_t *root, fieldset_t *fields);
  42. void print_expression(node_t *root);
  43. #endif /* ZMAP_TREE_H */