commit b39794bf4533e83cc46678f1e1435185db02816d
parent 9778d434bbfe285a9ea8a60619c3392448cb030e
Author: sin <sin@2f30.org>
Date: Fri, 9 May 2014 15:45:33 +0100
Add initial parser - no real functionality yet
Diffstat:
3 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
@@ -1,6 +1,6 @@
BIN = iris
VER = 0.0
-SRC = lexer.c repl.c
+SRC = lexer.c parser.c repl.c
OBJ = ${SRC:.c=.o}
CC = gcc
diff --git a/parser.c b/parser.c
@@ -0,0 +1,22 @@
+/* See LICENSE file for copyright and license details. */
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "parser.h"
+
+struct object *
+newobject(void)
+{
+ struct object *o;
+
+ o = calloc(1, sizeof(*o));
+ if (!o)
+ return NULL;
+ return o;
+}
+
+int
+matchtype(struct object *o, enum objtype t)
+{
+ return o->type == t;
+}
diff --git a/parser.h b/parser.h
@@ -0,0 +1,37 @@
+/* See LICENSE file for copyright and license details. */
+enum objtype {
+ Oidentifier,
+ Obool,
+ Onumber,
+ Ocharacter,
+ Ostring,
+};
+
+struct object {
+ enum objtype type;
+ union {
+ /* identifier */
+ struct {
+ char *s;
+ } i;
+ /* boolean */
+ struct {
+ bool v;
+ } b;
+ /* number */
+ struct {
+ long v;
+ } n;
+ /* character */
+ struct {
+ char v;
+ } c;
+ /* string */
+ struct {
+ char *s;
+ } s;
+ } d;
+};
+
+int matchtype(struct object *, enum objtype);
+struct object *newobject(void);