From fc4598df1e3bfbe9450b584cfa85e919b458f170 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 14 Nov 1994 17:19:36 +0000 Subject: [PATCH] Allow bison or flex to be used. --- Makefile | 10 +++++++++- cupl.l | 11 ++++++++++- cupl.y | 7 ++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 409fc4a..8e95bcf 100644 --- a/Makefile +++ b/Makefile @@ -11,8 +11,16 @@ MODULES = main.o grammar.o lexer.o interpret.o tokdump.o execute.o monitor.o cupl: $(MODULES) $(CC) $(MODULES) -lm -o cupl +# You can use either lex or flex +#LEX = lex +LEX = flex + +# You can use either bison or yacc +#YACC = yacc +YACC = bison -y + lexer.c: cupl.l - lex $(LFLAGS) cupl.l + $(LEX) $(LFLAGS) cupl.l mv lex.yy.c lexer.c grammar.c tokens.h y.output: cupl.y diff --git a/cupl.l b/cupl.l index 1ef53f0..031d5cd 100644 --- a/cupl.l +++ b/cupl.l @@ -16,6 +16,10 @@ lvar *idlist; static node *intern_number(char *); static node *intern_identifier(char *); static node *intern_string(char *); + +#ifdef FLEX_SCANNER +int yylineno; +#endif /* FLEX_SCANNER */ %} D [0-9][0-9]* @@ -83,7 +87,12 @@ WRITE {return(WRITE);} "**" {return(POWER);} [+*/().,=-] {return(yytext[0]);} -[ \t\n] ; +[ \t] ; +\n { +#ifdef FLEX_SCANNER + yylineno++; +#endif /* FLEX_SCANNER */ + } %% diff --git a/cupl.y b/cupl.y index 4b2dde9..fa599e9 100644 --- a/cupl.y +++ b/cupl.y @@ -27,6 +27,12 @@ author first. #ifdef PARSEDEBUG static int statement_count; #endif /* PARSEDEBUG */ + +#include "cupl.h" + +#ifdef YYBISON +int yydebug; +#endif /* YYBISON */ %} %start program @@ -269,7 +275,6 @@ subscr : IDENTIFIER '(' expr ')' {$$ = cons(ISLICE, $1, $5);} ; %% -#include "cupl.h" node *cons(op, left, right) /* make a cons for a binary operation */ -- 2.43.0