rpn.h 674 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef __sti__rpn_h__
  2. #define __sti__rpn_h__
  3. enum {
  4. STI_OP_ASSOC_LEFT = -1,
  5. STI_OP_ASSOC_NONE = 0,
  6. STI_OP_ASSOC_RIGHT = 1,
  7. STI_OP_OPEN_PAREN = 2,
  8. STI_OP_CLOSE_PAREN = 3,
  9. };
  10. typedef struct sti_op_prec_rule {
  11. char* token;
  12. short prec;
  13. char assoc;
  14. char arity;
  15. } sti_op_prec_rule;
  16. int infix_to_rpn(sti_op_prec_rule* rules, char** infix, char*** rpn, size_t* rpnlen);
  17. int64_t rpn_eval_int_str(char** rpn);
  18. double rpn_eval_double_str(char** rpn);
  19. /*
  20. typedef struct sti_shunting_context {
  21. void* user_data;
  22. char* (get_token_fn*)(void*);
  23. void (output_fn*)(void*, char*);
  24. VEC(sti_op_prec_rule*) stack;
  25. } sti_shunting_context;
  26. */
  27. #endif // __sti__rpn_h__