fix(lexer): get_token => peek_token and pop_token
This commit is contained in:
parent
e5925d69ec
commit
bfaf7aa475
2 changed files with 21 additions and 5 deletions
|
|
@ -77,7 +77,7 @@ char *stream_init(void)
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_token(void)
|
char *peek_token(void)
|
||||||
{
|
{
|
||||||
char *stream = stream_init();
|
char *stream = stream_init();
|
||||||
|
|
||||||
|
|
@ -103,7 +103,14 @@ char *get_token(void)
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
save_state(stream, i);
|
|
||||||
|
|
||||||
return new_token(stream, i);
|
return new_token(stream, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *pop_token(void)
|
||||||
|
{
|
||||||
|
char *token = peek_token();
|
||||||
|
|
||||||
|
save_state(stream, i);
|
||||||
|
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,19 @@
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
/* @return: char*, the next token
|
/*
|
||||||
|
* @brief: returns the next (newly allocated) token without consuming it.
|
||||||
|
* if end of input is reached, returns EOF.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
char *get_token(void);
|
char *peek_token(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @brief: returns the next (newly allocated) token and consumes it.
|
||||||
|
* if end of input is reached, returns EOF.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
char *pop_token(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @warning: NOT IMPLEMENTED.
|
* @warning: NOT IMPLEMENTED.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue