From d2f18f2339b45ce3872949303a0f4f3992c52261 Mon Sep 17 00:00:00 2001 From: kappa Date: Mon, 7 Jan 2019 01:04:40 +0100 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D1=99?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=20=D0=B1=D0=B0=D0=B3=D0=BE=D0=B2=D0=B8=20?= =?UTF-8?q?=D1=83=20=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D1=80=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 8 ++++---- cirilisp.c | 2 +- lexer.c | 14 +++++++------- lexer.h | 8 ++++---- util.h | 22 ++++++++++++++++++++++ 5 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 util.h diff --git a/Makefile b/Makefile index 58d3b59..ff556c4 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # cirilisp - компајлер за ћирилични дијалекат лиспа # ћирилисп верзија -VERSION = 0.0 +VERSION = 0.1 # локација за инсталацију PREFIX = /usr/local @@ -13,7 +13,7 @@ LDFLAGS = -lm -lc CC = cc -SRC = cirilisp.c util.c lexer.c +SRC = cirilisp.c readline.c lexer.c OBJ = $(SRC:.c=.o) all: cirilisp @@ -21,7 +21,7 @@ all: cirilisp .c.o: $(CC) -c $(CFLAGS) $< -$(OBJ): util.h lexer.h +$(OBJ): readline.h lexer.h cirilisp: $(OBJ) $(CC) -o $@ $(OBJ) $(LDFLAGS) @@ -31,7 +31,7 @@ clean: dist: clean mkdir -p cirilisp-$(VERSION) - cp -r Makefile util.h $(SRC) cirilisp-$(VERSION) + cp -r Makefile readline.h $(SRC) cirilisp-$(VERSION) tar -cf cirilisp-$(VERSION).tar cirilisp-$(VERSION) gzip cirilisp-$(VERSION).tar rm -rf cirilisp-$(VERSION) diff --git a/cirilisp.c b/cirilisp.c index 5e2e2cd..446735b 100644 --- a/cirilisp.c +++ b/cirilisp.c @@ -32,7 +32,7 @@ int main(int argc, char **argv) int i = 0; while (current != NULL) { - printf("Токен бр. %d: \"%s\", тип:%s\n", i, current->lexeme, current->type == number ? "number" : (current->type == symbol ? "symbol" : "parenthesis")); + printf("Токен бр. %d: \"%s\", тип:%s\n", i, current->lexeme, current->type == numberToken ? "number" : (current->type == symbolToken ? "symbol" : "parenthesis")); current = current->next; ++i; } diff --git a/lexer.c b/lexer.c index 2be3ab8..8e49ab9 100644 --- a/lexer.c +++ b/lexer.c @@ -19,7 +19,7 @@ token *lexLine(char *input) while (i < n) { *new = lex1Token(input, &i); - if ((*new)->type == undefined) + if ((*new)->type == undefinedToken) { /* уколико се у реду нађе токен који је лексички погрешан, штампа се место тог токена у реду и брише се цела листа, функција враћа NULL*/ @@ -59,21 +59,21 @@ token *lex1Token(char *input, int *i) *i += a[0].rm_eo; /* помера индекс да би се игнорисали почетни "вајт-спејс" карактери */ - if (!regexec(®Symbol, input + *i, nmatches, a, 0)) + if (!regexec(®Number, input + *i, nmatches, a, 0)) { - result->type = symbol; + result->type = numberToken; } - else if (!regexec(®Number, input + *i, nmatches, a, 0)) + else if (!regexec(®Symbol, input + *i, nmatches, a, 0)) { - result->type = number; + result->type = symbolToken; } else if (!regexec(®Parenthesis, input + *i, nmatches, a, 0)) { - result->type = parenthesis; + result->type = parenthesisToken; } else { - result->type = undefined; + result->type = undefinedToken; result->lexeme = NULL; goto skipStringCopy; } diff --git a/lexer.h b/lexer.h index f218a0b..f55769c 100644 --- a/lexer.h +++ b/lexer.h @@ -2,10 +2,10 @@ typedef enum { - undefined, - number, - symbol, - parenthesis + undefinedToken, + numberToken, + symbolToken, + parenthesisToken } tokenType; typedef struct _Token diff --git a/util.h b/util.h new file mode 100644 index 0000000..cadc0ad --- /dev/null +++ b/util.h @@ -0,0 +1,22 @@ +#pragma once + +typedef enum +{ + nilObject, + consObject, + numberObject, + symbolObject +} dataType; + +typedef struct _Object +{ + dataType type; + void *address; +} object; + +typedef struct _Cons +{ + object car; + object cdr; +} cons; +