From f9781801909e5ca53c887ae31247501caa065580 Mon Sep 17 00:00:00 2001 From: kappa Date: Sun, 20 Jan 2019 01:24:29 +0100 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B5=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D1=99=D0=B5=D0=BD=D0=B0=20=D0=B4=D0=B5=D1=84=D0=B8=D0=BD=D0=B8?= =?UTF-8?q?=D1=86=D0=B8=D1=98=D0=B0=20=D1=81=D0=B8=D0=BC=D0=B1=D0=BE=D0=BB?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- read.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/read.c b/read.c index df855a8..7b4ba34 100644 --- a/read.c +++ b/read.c @@ -130,7 +130,8 @@ void append(token **head, token *tail) *current = tail; } -regex_t regNumber, regSymbol, regLParenthesis, regRParenthesis, regSpace; +regex_t regNumber, regSymbol, regLParenthesis, regRParenthesis, regSpace, + regQuote; token *lex1Token(char *input, int *i) { @@ -140,7 +141,8 @@ token *lex1Token(char *input, int *i) regcomp(®Space, "^[[:space:]]*", REG_EXTENDED); regcomp(®Number, "^[-+]?[[:digit:]]+", REG_EXTENDED); - regcomp(®Symbol, "^[-+/*[:alnum:]]+", REG_EXTENDED); + regcomp(®Symbol, "^[-+/*_\\\\=<>!&[:alnum:]]+", REG_EXTENDED); + regcomp(®Quote, "^'", REG_EXTENDED); regcomp(®LParenthesis, "^\\(", REG_EXTENDED); regcomp(®RParenthesis, "^\\)", REG_EXTENDED); @@ -151,13 +153,24 @@ token *lex1Token(char *input, int *i) *i += a[0].rm_eo; /* помера индекс да би се игнорисали почетни "вајт-спејс" карактери */ - if (!regexec(®Number, input + *i, nmatches, a, 0)) + if (!regexec(®Symbol, input + *i, nmatches, a, 0)) { - result->type = numberToken; - } - else if (!regexec(®Symbol, input + *i, nmatches, a, 0)) - { - result->type = symbolToken; + int tmp = a[0].rm_eo; + if (!regexec(®Number, input + *i, nmatches, a, 0) && + tmp == a[0].rm_eo) +/* симбол може садржати цифре на било којој позицији али не може сам бити број + * не постоји погодан начина да се ово путем regex-a запише стога овај if + * исказ */ + { + result->type = numberToken; + } + else + { + regexec(®Symbol, input + *i, nmatches, a, 0); +/* претходни regexec позив је променио вредност a[0].rm_eo, овиме се она враћа + * на дужину нађеног симбола */ + result->type = symbolToken; + } } else if (!regexec(®LParenthesis, input + *i, nmatches, a, 0)) {