Преправљена дефиниција симбола

This commit is contained in:
kappa 2019-01-20 01:24:29 +01:00
parent cee90aee74
commit f978180190

29
read.c
View file

@ -130,7 +130,8 @@ void append(token **head, token *tail)
*current = tail; *current = tail;
} }
regex_t regNumber, regSymbol, regLParenthesis, regRParenthesis, regSpace; regex_t regNumber, regSymbol, regLParenthesis, regRParenthesis, regSpace,
regQuote;
token *lex1Token(char *input, int *i) token *lex1Token(char *input, int *i)
{ {
@ -140,7 +141,8 @@ token *lex1Token(char *input, int *i)
regcomp(&regSpace, "^[[:space:]]*", REG_EXTENDED); regcomp(&regSpace, "^[[:space:]]*", REG_EXTENDED);
regcomp(&regNumber, "^[-+]?[[:digit:]]+", REG_EXTENDED); regcomp(&regNumber, "^[-+]?[[:digit:]]+", REG_EXTENDED);
regcomp(&regSymbol, "^[-+/*[:alnum:]]+", REG_EXTENDED); regcomp(&regSymbol, "^[-+/*_\\\\=<>!&[:alnum:]]+", REG_EXTENDED);
regcomp(&regQuote, "^'", REG_EXTENDED);
regcomp(&regLParenthesis, "^\\(", REG_EXTENDED); regcomp(&regLParenthesis, "^\\(", REG_EXTENDED);
regcomp(&regRParenthesis, "^\\)", REG_EXTENDED); regcomp(&regRParenthesis, "^\\)", REG_EXTENDED);
@ -151,13 +153,24 @@ token *lex1Token(char *input, int *i)
*i += a[0].rm_eo; *i += a[0].rm_eo;
/* помера индекс да би се игнорисали почетни "вајт-спејс" карактери */ /* помера индекс да би се игнорисали почетни "вајт-спејс" карактери */
if (!regexec(&regNumber, input + *i, nmatches, a, 0)) if (!regexec(&regSymbol, input + *i, nmatches, a, 0))
{ {
result->type = numberToken; int tmp = a[0].rm_eo;
} if (!regexec(&regNumber, input + *i, nmatches, a, 0) &&
else if (!regexec(&regSymbol, input + *i, nmatches, a, 0)) tmp == a[0].rm_eo)
{ /* симбол може садржати цифре на било којој позицији али не може сам бити број
result->type = symbolToken; * не постоји погодан начина да се ово путем regex-a запише стога овај if
* исказ */
{
result->type = numberToken;
}
else
{
regexec(&regSymbol, input + *i, nmatches, a, 0);
/* претходни regexec позив је променио вредност a[0].rm_eo, овиме се она враћа
* на дужину нађеног симбола */
result->type = symbolToken;
}
} }
else if (!regexec(&regLParenthesis, input + *i, nmatches, a, 0)) else if (!regexec(&regLParenthesis, input + *i, nmatches, a, 0))
{ {