abstree.h 551 B

1234567891011121314151617181920212223242526272829
  1. // AST definitions
  2. #ifndef __ast_h__
  3. #define __ast_h__
  4. // AST for expressions
  5. struct _Expr {
  6. enum {
  7. E_INTEGER,
  8. E_OPERATION
  9. } kind;
  10. union {
  11. int value; // for integer values
  12. struct {
  13. int operator; // PLUS, MINUS, etc
  14. struct _Expr* left;
  15. struct _Expr* right;
  16. } op; // for binary expressions
  17. } attr;
  18. };
  19. typedef struct _Expr Expr; // Convenience typedef
  20. // Constructor functions (see implementation in ast.c)
  21. Expr* ast_integer(int v);
  22. Expr* ast_operation(int operator, Expr* left, Expr* right);
  23. #endif