]> thyrsus.com Git - cupl.git/commitdiff
Allow bison or flex to be used.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 14 Nov 1994 17:19:36 +0000 (17:19 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 14 Nov 1994 17:19:36 +0000 (17:19 +0000)
Makefile
cupl.l
cupl.y

index 409fc4a7694a10f1e8a9c0684f3a1a68b73100b3..8e95bcf97eedeebeff01098f663476c341cc406d 100644 (file)
--- 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 1ef53f0a49e7b362bbf05bc80818072d89c0e8ea..031d5cd1381bd45555edbdb2c6185cfc352355d1 100644 (file)
--- 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 4b2dde9357340118cecbe56228617bd4523a9a4e..fa599e9a8c9f8fb86768bb20df4d6e03daed19f3 100644 (file)
--- 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 */