]> granicus.if.org Git - flex/commitdiff
test c++ with multiple scanners
authorWill Estes <wlestes@users.sourceforge.net>
Tue, 1 Oct 2002 15:10:12 +0000 (15:10 +0000)
committerWill Estes <wlestes@users.sourceforge.net>
Tue, 1 Oct 2002 15:10:12 +0000 (15:10 +0000)
configure.in
tests/Makefile.am
tests/test-c++-multiple-scanners/.cvsignore [new file with mode: 0644]
tests/test-c++-multiple-scanners/Makefile.am [new file with mode: 0644]
tests/test-c++-multiple-scanners/main.cpp [new file with mode: 0644]
tests/test-c++-multiple-scanners/scanner-1.l [new file with mode: 0644]
tests/test-c++-multiple-scanners/scanner-2.l [new file with mode: 0644]
tests/test-c++-multiple-scanners/test.input [new file with mode: 0644]

index db392a4bd86b89e35c2bed988e85a44bf8a56093..135d48bd39a26887d2c5ddb798ecbcd20b24e8bd 100644 (file)
@@ -114,6 +114,7 @@ tests/test-table-opts/Makefile
 tests/test-c++-basic/Makefile
 tests/test-bison-nr/Makefile
 tests/test-reject/Makefile
+tests/test-c++-multiple-scanners/Makefile
 dnl --new-test-here-- This line is processed by tests/create-test.
 )
 
index 09308c3452e831cb7988ad0cfb17766ca67a9a01..5d200b10f0e6d550555d1f9f75306050c5514f33 100644 (file)
@@ -26,6 +26,7 @@ noinst_SCRIPTS = \
        create-test
 
 DIST_SUBDIRS = \
+       test-c++-multiple-scanners \
        test-reject \
        test-bison-nr \
        test-c++-basic \
@@ -61,6 +62,7 @@ DIST_SUBDIRS = \
        test-table-opts
 
 SUBDIRS = \
+       test-c++-multiple-scanners \
        test-reject \
        test-bison-nr \
        test-c++-basic \
diff --git a/tests/test-c++-multiple-scanners/.cvsignore b/tests/test-c++-multiple-scanners/.cvsignore
new file mode 100644 (file)
index 0000000..ed9376c
--- /dev/null
@@ -0,0 +1,7 @@
+Makefile
+Makefile.in
+scanner-1.cpp
+scanner-2.cpp
+OUTPUT
+.deps
+test-c++-multiple-scanners
diff --git a/tests/test-c++-multiple-scanners/Makefile.am b/tests/test-c++-multiple-scanners/Makefile.am
new file mode 100644 (file)
index 0000000..66b98c0
--- /dev/null
@@ -0,0 +1,52 @@
+# This file is part of flex.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+
+# Neither the name of the University nor the names of its contributors
+# may be used to endorse or promote products derived from this software
+# without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE.
+
+BISON = @BISON@
+FLEX = $(top_builddir)/flex
+
+EXTRA_DIST = scanner-1.l scanner-2.l main.cpp
+CLEANFILES = scanner-1.cpp scanner-1.h test-c++-multiple-scanners OUTPUT $(OBJS) scanner-2.cpp scanner-2.h
+OBJS = scanner-1.o scanner-2.o main.o
+
+AM_CXXFLAGS = -I$(srcdir) -I$(top_srcdir) -I$(top_builddir)
+#LDFLAGS = $(top_srcdir)/libfl.a 
+#YFLAGS = --defines --output=parser.c
+
+testname = test-c++-multiple-scanners
+
+scanner-1.cpp: $(srcdir)/scanner-1.l
+       $(FLEX) -+ $(LFLAGS) --header=scanner-1.h $<
+
+scanner-2.cpp: $(srcdir)/scanner-2.l
+       $(FLEX) -+ $(LFLAGS) --header=scanner-2.h $<
+
+$(testname)$(EXEEXT): $(OBJS)
+       $(CXX) -o $@ $(LDFLAGS) $(OBJS) $(LOADLIBES)
+
+test: $(testname)$(EXEEXT)
+       $(builddir)/$(testname)$(EXEEXT) < $(srcdir)/test.input
+
+.cpp.o:
+       $(CXX) -c -o $@ $(AM_CXXFLAGS) $(CPPFLAGS) $(CXXFLAGS) $<
+
+main.o: scanner-1.h scanner-2.h
+scanner-1.h: scanner-1.cpp
+scanner-2.h: scanner-2.cpp
diff --git a/tests/test-c++-multiple-scanners/main.cpp b/tests/test-c++-multiple-scanners/main.cpp
new file mode 100644 (file)
index 0000000..aa89949
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * This file is part of flex.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ * Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
+#include <stdio.h>
+
+#undef yyFlexLexer
+#define yyFlexLexer S1_FlexLexer
+#include <FlexLexer.h>
+
+#undef yyFlexLexer
+#define yyFlexLexer S2_FlexLexer
+#include <FlexLexer.h>
+
+int
+main ( int argc, char** argv )
+{
+    int S1_ok=1, S2_ok=1;
+    S1_FlexLexer* S1 = new S1_FlexLexer;
+    S2_FlexLexer* S2 = new S2_FlexLexer;
+
+    // scan simultaneously. 
+    while(S1_ok || S2_ok)
+    {
+        if (S1_ok)
+            S1_ok = S1->yylex();
+        if (S2_ok)
+            S2_ok = S2->yylex();
+    }
+    printf("TEST RETURNING OK.\n");
+    return 0;
+}
+
+
+/* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */
diff --git a/tests/test-c++-multiple-scanners/scanner-1.l b/tests/test-c++-multiple-scanners/scanner-1.l
new file mode 100644 (file)
index 0000000..38cc5d7
--- /dev/null
@@ -0,0 +1,44 @@
+ //  This file is part of flex.
+ //  
+ //  Redistribution and use in source and binary forms, with or without
+ //  modification, are permitted provided that the following conditions
+ //  are met:
+ //  
+ //  1. Redistributions of source code must retain the above copyright
+ //     notice, this list of conditions and the following disclaimer.
+ //  2. Redistributions in binary form must reproduce the above copyright
+ //     notice, this list of conditions and the following disclaimer in the
+ //     documentation and/or other materials provided with the distribution.
+ //  
+ //  Neither the name of the University nor the names of its contributors
+ //  may be used to endorse or promote products derived from this software
+ //  without specific prior written permission.
+ //  
+ //  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ //  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ //  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ //  PURPOSE.
+
+%{
+#include "config.h"
+
+%}
+
+%option 8bit outfile="scanner-1.cpp" prefix="S1_"
+%option nounput nomain noyywrap
+%option warn stack noyy_top_state
+
+%x ON
+%x OFF
+%%
+<INITIAL>{
+on    yy_push_state(ON); return 10;
+off   yy_push_state(OFF); return 11;
+.|\n  return 12;
+}
+<ON>.|\n  yy_pop_state(); return 13;
+
+<OFF>.|\n yy_pop_state(); return 14;
+
+%%
+
diff --git a/tests/test-c++-multiple-scanners/scanner-2.l b/tests/test-c++-multiple-scanners/scanner-2.l
new file mode 100644 (file)
index 0000000..db84402
--- /dev/null
@@ -0,0 +1,43 @@
+ //  This file is part of flex.
+ //  
+ //  Redistribution and use in source and binary forms, with or without
+ //  modification, are permitted provided that the following conditions
+ //  are met:
+ //  
+ //  1. Redistributions of source code must retain the above copyright
+ //     notice, this list of conditions and the following disclaimer.
+ //  2. Redistributions in binary form must reproduce the above copyright
+ //     notice, this list of conditions and the following disclaimer in the
+ //     documentation and/or other materials provided with the distribution.
+ //  
+ //  Neither the name of the University nor the names of its contributors
+ //  may be used to endorse or promote products derived from this software
+ //  without specific prior written permission.
+ //  
+ //  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ //  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ //  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ //  PURPOSE.
+
+%{
+#include "config.h"
+
+%}
+
+%option 8bit outfile="scanner-2.cpp" prefix="S2_"
+%option nounput nomain noyywrap
+%option warn stack noyy_top_state
+
+%x OFF
+%x ON
+%%
+<INITIAL>{
+on    yy_push_state(ON); return 3;
+off   yy_push_state(OFF); return 4;
+.|\n  return 5;
+}
+<ON>.|\n  yy_pop_state(); return 6;
+
+<OFF>.|\n yy_pop_state(); return 7;
+%%
+
diff --git a/tests/test-c++-multiple-scanners/test.input b/tests/test-c++-multiple-scanners/test.input
new file mode 100644 (file)
index 0000000..08498fa
--- /dev/null
@@ -0,0 +1 @@
+foo on bar off