]> git.lizzy.rs Git - nothing.git/blobdiff - src/script/expr.h
(#301) Make parser support lists
[nothing.git] / src / script / expr.h
index 11b033bda8a049053ce4c0f130b188fe2cec8bcd..bf77829988f25a85e9c57a9d86eab6cee3cc4f9e 100644 (file)
@@ -1,15 +1,19 @@
 #ifndef ATOM_H_
 #define ATOM_H_
 
+#include <stdbool.h>
+
 struct Cons;
 struct Atom;
 
 enum ExprType
 {
     EXPR_ATOM = 0,
-    EXPR_CONS
+    EXPR_CONS,
+    EXPR_VOID
 };
 
+// TODO(#285): there is no way to execute struct Expr
 struct Expr
 {
     enum ExprType type;
@@ -21,7 +25,10 @@ struct Expr
 
 struct Expr atom_as_expr(struct Atom *atom);
 struct Expr cons_as_expr(struct Cons *cons);
+struct Expr void_expr(void);
+
 void destroy_expr(struct Expr expr);
+void print_expr_as_sexpr(struct Expr expr);
 
 enum AtomType
 {
@@ -35,14 +42,17 @@ struct Atom
     enum AtomType type;
     union
     {
-        int number;             // ATOM_NUMBER
-        char *name;             // ATOM_SYMBOL
-        char *text;             // ATOM_STRING
+        float num;             // ATOM_NUMBER
+        char *sym;             // ATOM_SYMBOL
+        char *str;             // ATOM_STRING
     };
 };
 
-struct Atom *create_atom(enum AtomType type, ...);
+struct Atom *create_number_atom(float num);
+struct Atom *create_string_atom(const char *str, const char *str_end);
+struct Atom *create_symbol_atom(const char *sym, const char *sym_end);
 void destroy_atom(struct Atom *atom);
+void print_atom_as_sexpr(struct Atom *atom);
 
 struct Cons
 {
@@ -52,5 +62,6 @@ struct Cons
 
 struct Cons *create_cons(struct Expr car, struct Expr cdr);
 void destroy_cons(struct Cons *cons);
+void print_cons_as_sexpr(struct Cons *cons);
 
 #endif  // ATOM_H_