Преправљена дефиниција симбола
This commit is contained in:
parent
cee90aee74
commit
f978180190
1 changed files with 21 additions and 8 deletions
29
read.c
29
read.c
|
@ -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(®Space, "^[[:space:]]*", REG_EXTENDED);
|
regcomp(®Space, "^[[:space:]]*", REG_EXTENDED);
|
||||||
|
|
||||||
regcomp(®Number, "^[-+]?[[:digit:]]+", 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(®LParenthesis, "^\\(", REG_EXTENDED);
|
||||||
regcomp(®RParenthesis, "^\\)", REG_EXTENDED);
|
regcomp(®RParenthesis, "^\\)", REG_EXTENDED);
|
||||||
|
|
||||||
|
@ -151,13 +153,24 @@ token *lex1Token(char *input, int *i)
|
||||||
*i += a[0].rm_eo;
|
*i += a[0].rm_eo;
|
||||||
/* помера индекс да би се игнорисали почетни "вајт-спејс" карактери */
|
/* помера индекс да би се игнорисали почетни "вајт-спејс" карактери */
|
||||||
|
|
||||||
if (!regexec(®Number, input + *i, nmatches, a, 0))
|
if (!regexec(®Symbol, input + *i, nmatches, a, 0))
|
||||||
{
|
{
|
||||||
result->type = numberToken;
|
int tmp = a[0].rm_eo;
|
||||||
}
|
if (!regexec(®Number, input + *i, nmatches, a, 0) &&
|
||||||
else if (!regexec(®Symbol, input + *i, nmatches, a, 0))
|
tmp == a[0].rm_eo)
|
||||||
{
|
/* симбол може садржати цифре на било којој позицији али не може сам бити број
|
||||||
result->type = symbolToken;
|
* не постоји погодан начина да се ово путем 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))
|
else if (!regexec(®LParenthesis, input + *i, nmatches, a, 0))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue