From 693519a248ff9d7b646f470888cf6557070f608c Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Tue, 22 Feb 2022 19:30:44 +0000 Subject: [PATCH] Starting chapter 5 now. This is the first part needed to start implementing the syntax tree. --- expr.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 expr.h diff --git a/expr.h b/expr.h new file mode 100644 index 0000000..7d9ac4e --- /dev/null +++ b/expr.h @@ -0,0 +1,44 @@ +#ifndef EXPRESSION_H +#define EXPRESSION_H + +#include "scanner.h" + +typedef enum { + Expression, + Literal, + Grouping, + Unary, + Binary, + Operator +} ExpressionType; + +typedef struct { + ExpressionType type; + union ex { + struct binary; + struct grouping; + struct literal; + struct unary; + } expression; +} Expr; + +typedef struct { + Expr left; + TokenType op; + Expr right; +} binary; + +struct grouping { + Expr expression; +}; + +struct literal { + char* object; +}; + +struct unary { + TokenType op; + Expr right; +}; + +#endif \ No newline at end of file