feat(lexer): negation
This commit is contained in:
parent
c48d86c8de
commit
9003675c40
2 changed files with 7 additions and 16 deletions
|
|
@ -60,34 +60,22 @@ static void set_token_keyword(struct token *tok, char *begin, ssize_t size)
|
|||
{
|
||||
if (tok->type != TOKEN_NULL || size == 0)
|
||||
return;
|
||||
if (strncmp(begin, "if", size) == 0 && size == 2)
|
||||
{
|
||||
if (strncmp(begin, "!", size) == 0 && size == 1)
|
||||
tok->type = TOKEN_NEGATION;
|
||||
else if (strncmp(begin, "if", size) == 0 && size == 2)
|
||||
tok->type = TOKEN_IF;
|
||||
}
|
||||
else if (strncmp(begin, "fi", size) == 0 && size == 2)
|
||||
{
|
||||
tok->type = TOKEN_FI;
|
||||
}
|
||||
else if (strncmp(begin, "then", size) == 0 && size == 4)
|
||||
{
|
||||
tok->type = TOKEN_THEN;
|
||||
}
|
||||
else if (strncmp(begin, "else", size) == 0 && size == 4)
|
||||
{
|
||||
tok->type = TOKEN_ELSE;
|
||||
}
|
||||
else if (strncmp(begin, "elif", size) == 0 && size == 4)
|
||||
{
|
||||
tok->type = TOKEN_ELIF;
|
||||
}
|
||||
else if (strncmp(begin, "&&", size) == 0 && size == 2)
|
||||
{
|
||||
tok->type = TOKEN_AND;
|
||||
}
|
||||
else if (strncmp(begin, "||", size) == 0 && size == 2)
|
||||
{
|
||||
tok->type = TOKEN_OR;
|
||||
}
|
||||
|
||||
// no keywords found.
|
||||
if (tok->type == TOKEN_NULL)
|
||||
|
|
@ -95,7 +83,10 @@ static void set_token_keyword(struct token *tok, char *begin, ssize_t size)
|
|||
|
||||
tok->data = calloc(size + 1, sizeof(char));
|
||||
if (tok->data == NULL)
|
||||
{
|
||||
perror("could not allocate memory in lexer");
|
||||
return;
|
||||
}
|
||||
strncpy(tok->data, begin, size);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ enum token_type
|
|||
TOKEN_LEFT_BRACKET,
|
||||
TOKEN_RIGHT_BRACKET,
|
||||
TOKEN_PIPE,
|
||||
TOKEN_NEGATION, // TODO handle
|
||||
TOKEN_NEGATION,
|
||||
|
||||
// TODO merge into one and use the data field
|
||||
// (Too difficult to handle in the parser because of firsts)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue