aboutsummaryrefslogtreecommitdiff
path: root/lex.c
diff options
context:
space:
mode:
Diffstat (limited to 'lex.c')
-rw-r--r--lex.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/lex.c b/lex.c
index d729516..1c23212 100644
--- a/lex.c
+++ b/lex.c
@@ -43,7 +43,7 @@ typedef struct Keyword {
int type;
} Keyword;
-Keyword keywords[] ={ /* keep sorted: binary searched */
+const Keyword keywords[] = { /* keep sorted: binary searched */
{ "BEGIN", XBEGIN, XBEGIN },
{ "END", XEND, XEND },
{ "NF", VARNF, VARNF },
@@ -91,14 +91,14 @@ Keyword keywords[] ={ /* keep sorted: binary searched */
#define RET(x) { if(dbg)printf("lex %s\n", tokname(x)); return(x); }
-int peek(void)
+static int peek(void)
{
int c = input();
unput(c);
return c;
}
-int gettok(char **pbuf, int *psz) /* get next input token */
+static int gettok(char **pbuf, int *psz) /* get next input token */
{
int c, retc;
char *buf = *pbuf;
@@ -210,6 +210,11 @@ int yylex(void)
while ((c = input()) != '\n' && c != 0)
;
unput(c);
+ /*
+ * Next line is a hack, itcompensates for
+ * unput's treatment of \n.
+ */
+ lineno++;
break;
case ';':
RET(';');
@@ -440,7 +445,7 @@ int string(void)
}
-int binsearch(char *w, Keyword *kp, int n)
+static int binsearch(char *w, const Keyword *kp, int n)
{
int cond, low, mid, high;
@@ -460,7 +465,7 @@ int binsearch(char *w, Keyword *kp, int n)
int word(char *w)
{
- Keyword *kp;
+ const Keyword *kp;
int c, n;
n = binsearch(w, keywords, sizeof(keywords)/sizeof(keywords[0]));
@@ -572,6 +577,8 @@ int input(void) /* get next lexical input character */
void unput(int c) /* put lexical character back on input */
{
+ if (c == '\n')
+ lineno--;
if (yysptr >= yysbuf + sizeof(yysbuf))
FATAL("pushed back too much: %.20s...", yysbuf);
*yysptr++ = c;