From e560ef8a3c71839075b7b84b76fb87c4c0a3987a Mon Sep 17 00:00:00 2001 From: kappa Date: Sun, 6 Jan 2019 15:27:54 +0100 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=BD=D1=82=D0=B5=D1=80=D0=BF=D1=80?= =?UTF-8?q?=D0=B5=D1=82=D0=B5=D1=80=20=D1=81=D0=B0=D0=BC=D0=BE=20=D0=BB?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=B8=D1=80=D0=B0=20=D0=BE=D1=81=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=BD=D0=B5=20=D0=BC=D0=B0=D1=82=D0=B5=D0=BC=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D1=87=D0=BA=D0=B5=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=98=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 4 ++-- cirilisp.c | 6 +++++- lexer.c | 13 +++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 58d3b59..0aa1313 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,8 @@ VERSION = 0.0 PREFIX = /usr/local # флегови за C компајлер и линкер -# CFLAGS = -g -std=c99 -pedantic -Wall -O0 -CFLAGS = -std=c99 -pedantic -Wall -O1 +CFLAGS = -g -std=c99 -pedantic -Wall -O0 +# CFLAGS = -std=c99 -pedantic -Wall -O1 LDFLAGS = -lm -lc CC = cc diff --git a/cirilisp.c b/cirilisp.c index 5a1526f..f31fa38 100644 --- a/cirilisp.c +++ b/cirilisp.c @@ -10,7 +10,8 @@ int main(int argc, char **argv) /* Омогућава библиотекама коришћеним у интерпретеру да протумаче српску ћирилицу */ if (setlocale(LC_ALL, "sr_RS.utf8") == NULL) { - fprintf(stderr, "locale couldn't be set to \"sr_RS.utf8\", check if you've enabled it on your system\n"); + fprintf(stderr, "locale couldn't be set to \"sr_RS.utf8\",\ + check if you've enabled it on your system\n"); exit(0); } @@ -26,6 +27,7 @@ int main(int argc, char **argv) } token *tokenList, *current; + current = tokenList = lexLine(input); int i = 0; while (current != NULL) @@ -33,6 +35,8 @@ int main(int argc, char **argv) printf("Токен бр. %d: \"%s\", тип:%s\n", i, current->lexeme, current->type == number ? "number" : (current->type == symbol ? "symbol" : "parenthesis")); + current = current->next; + ++i; } free(input); diff --git a/lexer.c b/lexer.c index 93062b9..6a8f847 100644 --- a/lexer.c +++ b/lexer.c @@ -5,7 +5,7 @@ #include "lexer.h" -token *lex1token(char *input, int *i); +token *lex1Token(char *input, int *i); /* враћа показивач на једну token структуру, која означава један одређен токен, чита улазни стринг од i-тог карактера, и мења i тако да оно затим индексира следећи токен или крај стринга*/ @@ -18,8 +18,7 @@ token *lexLine(char *input) new = &root; while (i < n) { - *new = lex1token(input, &i); - new = &((*new)->next); + *new = lex1Token(input, &i); if ((*new)->type == undefined) { /* уколико се у реду нађе токен који је лексички погрешан, штампа се место тог @@ -35,19 +34,20 @@ token *lexLine(char *input) } return NULL; } + new = &((*new)->next); } return root; } regex_t regNumber, regSymbol, regParenthesis, regSpace; -token *lex1token(char *input, int *i) +token *lex1Token(char *input, int *i) { token *result = malloc(sizeof(token)); result->next = NULL; - regcomp(®Space, "^[:space:]*", REG_EXTENDED); - regcomp(®Number, "^[-+]?[:digit:]+", REG_EXTENDED); + regcomp(®Space, "^[[:space:]]*", REG_EXTENDED); + regcomp(®Number, "^[-+]?[[:digit:]]+", REG_EXTENDED); regcomp(®Symbol, "^[-+/*]", REG_EXTENDED); /* за сада подржава само симболе -, +, * и / */ regcomp(®Parenthesis, "^[()]", REG_EXTENDED); @@ -74,6 +74,7 @@ token *lex1token(char *input, int *i) else { result->type = undefined; + result->lexeme = NULL; goto skipStringCopy; } result->lexeme = malloc((a[0].rm_eo + 1) * sizeof(char));