scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 34ac4d9aeeace5c62f6e08195da7bf9fa7e0b17a
parent 4a43d3a6ce5978d490c58ae2a5e15fc186961d12
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 10 Feb 2024 23:30:02 +0100

as: Add ahead()

The ahead() function returns the next non blank
character and it can be used to perform one char
read ahead and take decisions in the next character
after the current token.

Diffstat:
Msrc/cmd/as/as.h | 1+
Msrc/cmd/as/parser.c | 11+++++++++++
2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/src/cmd/as/as.h b/src/cmd/as/as.h @@ -184,6 +184,7 @@ extern Node *getreg(void); extern Node *operand(char **s); extern void addinput(char *fname); extern int delinput(void); +extern int ahead(void); /* expr.c */ extern Node *expr(void); diff --git a/src/cmd/as/parser.c b/src/cmd/as/parser.c @@ -167,6 +167,17 @@ operator(void) } int +ahead(void) +{ + while (isspace(*textp)) + ++textp; + + if (*textp != '\0') + return *textp; + return EOS; +} + +int next(void) { int c;