├── .github ├── dependabot.yml └── workflows │ ├── build.yml │ ├── codeql-analysis.yml │ └── nightly.yml ├── .gitignore ├── .indent.pro ├── .mailmap ├── .prev-version ├── AUTHORS ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── COPYING ├── INSTALL.md ├── Makefile.am ├── NEWS ├── ONEWS ├── README.md ├── THANKS ├── TODO ├── autogen.sh ├── configure.ac ├── control.ac ├── doc ├── .gitignore ├── Makefile.am └── flex.texi ├── examples ├── Makefile.am ├── README ├── debflex.awk ├── fastwc │ ├── Makefile.am │ ├── README │ ├── mywc.c │ ├── wc1.l │ ├── wc2.l │ ├── wc3.l │ ├── wc4.l │ └── wc5.l ├── manual │ ├── ChangeLog │ ├── Makefile.am │ ├── Makefile.examples │ ├── README │ ├── cat.lex │ ├── dates.lex │ ├── datetest.dat │ ├── eof_rules.lex │ ├── eof_test01.txt │ ├── eof_test02.txt │ ├── eof_test03.txt │ ├── example_er.lex │ ├── example_nr.lex │ ├── example_r.lex │ ├── expr.lex │ ├── expr.y │ ├── front.lex │ ├── front.y │ ├── j2t.lex │ ├── myname.lex │ ├── myname.txt │ ├── myname2.lex │ ├── numbers.lex │ ├── pas_include.lex │ ├── pascal.lex │ ├── reject.lex │ ├── replace.lex │ ├── string1.lex │ ├── string2.lex │ ├── strtest.dat │ ├── unput.lex │ ├── user_act.lex │ ├── userinit.lex │ ├── wc.lex │ ├── yymore.lex │ ├── yymore2.lex │ └── yymoretest.dat └── testxxLexer.l ├── lib ├── .gitignore ├── malloc.c └── realloc.c ├── m4 └── ax_prog_cc_for_build.m4 ├── po ├── .gitignore ├── LINGUAS ├── Makevars ├── POTFILES.in ├── bg.po ├── ca.po ├── da.po ├── de.po ├── eo.po ├── es.po ├── fi.po ├── fr.po ├── ga.po ├── hr.po ├── ka.po ├── ko.po ├── nl.po ├── pl.po ├── pt.po ├── pt_BR.po ├── ro.po ├── ru.po ├── sr.po ├── sv.po ├── tr.po ├── uk.po ├── update_linguas.sh ├── vi.po ├── zh_CN.po └── zh_TW.po ├── src ├── .gitignore ├── FlexLexer.h ├── Makefile.am ├── buf.c ├── c99-flex.skl ├── ccl.c ├── chkskel.sh ├── config_for_build.h.in ├── cpp-flex.skl ├── dfa.c ├── ecs.c ├── filter.c ├── flexdef.h ├── flexint.h ├── flexint_shared.h ├── gen.c ├── gettext.h ├── go-flex.skl ├── libfl.pc.in ├── libmain.c ├── libyywrap.c ├── main.c ├── misc.c ├── mkskel.sh ├── nfa.c ├── options.c ├── options.h ├── parse.y ├── regex.c ├── scan.l ├── scanflags.c ├── scanopt.c ├── scanopt.h ├── skeletons.c ├── sym.c ├── tables.c ├── tables.h ├── tables_shared.c ├── tables_shared.h ├── tblcmp.c ├── version.h └── yylex.c ├── tests ├── .gitignore ├── Makefile.am ├── README ├── alloc_extra.txt ├── alloc_extra_c99.l ├── alloc_extra_nr.l ├── array.rules ├── array.txt ├── basic.rules ├── basic.txt ├── bison_nr.txt ├── bison_nr_main.c ├── bison_nr_parser.y ├── bison_nr_scanner.l ├── bison_yylloc.txt ├── bison_yylloc_main.c ├── bison_yylloc_parser.y ├── bison_yylloc_scanner.l ├── bison_yylval.txt ├── bison_yylval_main.c ├── bison_yylval_parser.y ├── bison_yylval_scanner.l ├── bol.rules ├── bol.txt ├── c_cxx_nr.lll ├── c_cxx_nr.txt ├── c_cxx_r.lll ├── c_cxx_r.txt ├── ccl.rules ├── ccl.txt ├── cxx_basic.ll ├── cxx_basic.txt ├── cxx_multiple_scanners.txt ├── cxx_multiple_scanners_1.ll ├── cxx_multiple_scanners_2.ll ├── cxx_multiple_scanners_main.cc ├── cxx_restart.ll ├── cxx_restart.txt ├── cxx_yywrap.ll ├── cxx_yywrap.txt ├── debug.rules ├── debug.txt ├── extended.rules ├── extended.txt ├── fixedtrailing.rules ├── fixedtrailing.txt ├── flexname.rules ├── flexname.txt ├── header_nr.txt ├── header_nr_main.c ├── header_nr_scanner.l ├── header_r.txt ├── header_r_main.c ├── header_r_scanner.l ├── include_by_buffer.direct.l ├── include_by_buffer.direct.txt ├── include_by_buffer.direct_2.txt ├── include_by_buffer.direct_3.txt ├── include_by_push.direct.l ├── include_by_push.direct.txt ├── include_by_push.direct_2.txt ├── include_by_push.direct_3.txt ├── include_by_reentrant.direct.l ├── include_by_reentrant.direct.txt ├── include_by_reentrant.direct_2.txt ├── include_by_reentrant.direct_3.txt ├── lexcompat.rules ├── lexcompat.txt ├── lineno.rules ├── lineno.txt ├── lineno_generated.l.in ├── mem.txt ├── mem_c99.l ├── mem_nr.l ├── mem_r.l ├── multiple_scanners_nr_1.l ├── multiple_scanners_nr_2.l ├── multiple_scanners_nr_main.c ├── multiple_scanners_r_1.l ├── multiple_scanners_r_2.l ├── multiple_scanners_r_main.c ├── no_bison_stub.c ├── options.cn ├── posix.rules ├── posix.txt ├── posixlycorrect.rules ├── posixlycorrect.txt ├── prefix.txt ├── prefix_c99.l ├── prefix_nr.l ├── prefix_r.l ├── preposix.rules ├── preposix.txt ├── pthread.l ├── pthread_1.txt ├── pthread_2.txt ├── pthread_3.txt ├── pthread_4.txt ├── pthread_5.txt ├── quoteincomment.rules ├── quoteincomment.txt ├── quotes.l ├── quotes.txt ├── reject.rules ├── reject.txt ├── rescan_nr.direct.l ├── rescan_nr.direct.txt ├── rescan_r.direct.l ├── rescan_r.direct.txt ├── ruleset.am ├── ruleset.sh ├── state_buf.direct.lll ├── state_buf.direct.txt ├── state_buf_multiple.direct.lll ├── state_buf_multiple.direct.txt ├── string_c99.l ├── string_nr.l ├── string_r.l ├── tableopts.rules ├── tableopts.txt ├── test-yydecl-gen.sh ├── test-yylmax ├── testmaker.m4 ├── testmaker.sh ├── testwrapper-direct.sh ├── testwrapper.sh ├── top.l ├── top.txt ├── top_main.c ├── vartrailing.rules ├── vartrailing.txt ├── yyextra.txt ├── yyextra_c99.l ├── yyextra_nr.l ├── yyless.rules ├── yyless.txt ├── yymore.rules ├── yymore.txt ├── yymorearray.rules ├── yymorearray.txt ├── yymorearraybol.rules ├── yymorearraybol.txt ├── yyunput.rules ├── yyunput.txt └── yywrap_r.i3.l └── tools ├── Makefile.am └── git2cl /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "github-actions" 9 | directory: "/" 10 | schedule: 11 | interval: "weekly" 12 | groups: 13 | github-actions: 14 | patterns: 15 | - "*" 16 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build and Test 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | tags-ignore: 7 | - 'v*' 8 | pull_request: 9 | branches: [ master ] 10 | 11 | permissions: read-all 12 | 13 | jobs: 14 | build: 15 | 16 | runs-on: ubuntu-22.04 17 | 18 | steps: 19 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 20 | - name: apt 21 | run: sudo apt-get update && sudo apt-get install -y gcc autoconf automake libtool gettext autopoint bison help2man lzip texinfo texlive 22 | - name: autogen 23 | run: ./autogen.sh 24 | - name: configure 25 | run: ./configure 26 | - name: make 27 | run: make 28 | - name: make check 29 | run: make check 30 | - name: make distcheck 31 | run: make distcheck 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.orig 2 | *.rej 3 | *.sig 4 | *.tar.gz 5 | *.tar.lz 6 | *~ 7 | .deps 8 | .libs 9 | ABOUT-NLS 10 | ChangeLog 11 | Makefile 12 | Makefile.in 13 | aclocal.m4 14 | autom4te.cache 15 | autoscan.log 16 | build-aux/ 17 | config.log 18 | config.status 19 | configure 20 | configure.scan 21 | flex-*/ 22 | libtool 23 | m4/ 24 | stamp-* 25 | -------------------------------------------------------------------------------- /.indent.pro: -------------------------------------------------------------------------------- 1 | --blank-lines-after-declarations 2 | --blank-lines-after-procedures 3 | -br /* open braces on same line */ 4 | -nce /* start else on new line */ 5 | -nbc /* vars on same line */ 6 | -di8 /* line up var decl at col 8 */ 7 | -brs /* struct brace on same line */ 8 | -i8 /* indent 4 */ 9 | -lp /* line up parens */ 10 | -ts8 /* tab stop */ 11 | -bbo /* break before && || */ 12 | -hnl /* honor newlines */ 13 | --space-special-semicolon 14 | --line-length75 15 | --dont-break-procedure-type 16 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | Aaron Stone 2 | Akim Demaille 3 | Alastair Hughes 4 | Alex Kennedy 5 | Alexis La Goutte 6 | Bastian Köcher 7 | Christoph Junghans 8 | Christos Zoulas 9 | Cyril Brulebois 10 | Demi Obenour 11 | Dennis Clarke 12 | Egor Pugin 13 | Elias Pipping 14 | Explorer09 15 | Hans-Bernhard Broeker 16 | Harald van Dijk 17 | Hugh Sasse 18 | Jaska Uimonen 19 | Jeff Smith 20 | John Millaway 21 | Manoj Srivastava 22 | Mariusz Pluciński 23 | Michael Haubenwallner 24 | Michael McConville 25 | Michael Reed 26 | Michael van Elst 27 | Mightyjo 28 | Mike Frysinger 29 | OBATA Akio 30 | Robert Larice rlar 31 | Robert Larice Robert.Larice Robert Larice 32 | Robert Minsk 33 | Samuel Thibault 34 | Sean McBride 35 | Serguey Parkhomovsky 36 | Simon Sobisch 37 | Stefan Reinauer 38 | Thomas Klausner 39 | Till Varoquaux 40 | Tobias Klauser 41 | Todd C. Miller 42 | Translation Project 43 | Translation Project 44 | Vern Paxson 45 | Will Estes 46 | Yuri 47 | luistung 48 | lukeallardyce 49 | nomis52 50 | viktor.shepel 51 | -------------------------------------------------------------------------------- /.prev-version: -------------------------------------------------------------------------------- 1 | 2.6.4 2 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | 2 | In 2001, Will Estes took over as maintainer of flex. 3 | 4 | John Millaway is a co-author of the current version of flex. He has 5 | contributed a large number of new features, fixed a large number of 6 | outstanding bugs and has made significant contributions to the flex 7 | documentation. 8 | 9 | Aaron Stone has contributed several bug fixes to the flex codebase. 10 | 11 | Vern Paxson wrote flex with the help of many ideas and much 12 | inspiration from Van Jacobson. Original version by Jef Poskanzer. 13 | 14 | The fast table representation is a partial implementation of a design 15 | done by Van Jacobson. The implementation was done by Kevin Gong and 16 | Vern Paxson. 17 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | This project adheres to No Code of Conduct. We are all adults. We accept anyone's contributions. Nothing else matters. 4 | 5 | For more information please visit the [No Code of Conduct](https://github.com/domgetter/NCoC) homepage. 6 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Flex carries the copyright used for BSD software, slightly modified 2 | because it originated at the Lawrence Berkeley (not Livermore!) Laboratory, 3 | which operates under a contract with the Department of Energy: 4 | 5 | Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007 The Flex Project. 6 | 7 | Copyright (c) 1990, 1997 The Regents of the University of California. 8 | All rights reserved. 9 | 10 | This code is derived from software contributed to Berkeley by 11 | Vern Paxson. 12 | 13 | The United States Government has rights in this work pursuant 14 | to contract no. DE-AC03-76SF00098 between the United States 15 | Department of Energy and the University of California. 16 | 17 | Redistribution and use in source and binary forms, with or without 18 | modification, are permitted provided that the following conditions 19 | are met: 20 | 21 | 1. Redistributions of source code must retain the above copyright 22 | notice, this list of conditions and the following disclaimer. 23 | 2. Redistributions in binary form must reproduce the above copyright 24 | notice, this list of conditions and the following disclaimer in the 25 | documentation and/or other materials provided with the distribution. 26 | 27 | Neither the name of the University nor the names of its contributors 28 | may be used to endorse or promote products derived from this software 29 | without specific prior written permission. 30 | 31 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 32 | IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 33 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 34 | PURPOSE. 35 | 36 | This basically says "do whatever you please with this software except 37 | remove this notice or take advantage of the University's (or the flex 38 | authors') name". 39 | 40 | Note that the "flex.skl" scanner skeleton carries no copyright notice. 41 | You are free to do whatever you please with scanners generated using flex; 42 | for them, you are not even bound by the above copyright. 43 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # This file is part of flex. 2 | 3 | # Redistribution and use in source and binary forms, with or without 4 | # modification, are permitted provided that the following conditions 5 | # are met: 6 | 7 | # 1. Redistributions of source code must retain the above copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | # 2. Redistributions in binary form must reproduce the above copyright 10 | # notice, this list of conditions and the following disclaimer in the 11 | # documentation and/or other materials provided with the distribution. 12 | 13 | # Neither the name of the University nor the names of its contributors 14 | # may be used to endorse or promote products derived from this software 15 | # without specific prior written permission. 16 | 17 | # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 18 | # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 19 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 | # PURPOSE. 21 | 22 | # Notes on building: 23 | 24 | # Possible values for DEFS: 25 | # 26 | # By default, flex generates 8-bit scanners when using table compression, 27 | # and 7-bit scanners when using uncompressed tables (-f or -F options). 28 | # For flex to always generate 8-bit scanners, add "-DDEFAULT_CSIZE=256" 29 | # to DEFS. 30 | 31 | ACLOCAL_AMFLAGS = -I m4 32 | 33 | dist_doc_DATA = \ 34 | AUTHORS \ 35 | COPYING \ 36 | NEWS \ 37 | ONEWS \ 38 | README.md 39 | 40 | EXTRA_DIST = \ 41 | .indent.pro \ 42 | INSTALL.md \ 43 | CONTRIBUTING.md 44 | 45 | dist_noinst_SCRIPTS = \ 46 | autogen.sh \ 47 | po/update_linguas.sh 48 | 49 | SUBDIRS = \ 50 | src \ 51 | doc \ 52 | examples \ 53 | po \ 54 | tests \ 55 | tools 56 | 57 | # Convenience targets to build libfl only 58 | # These are actually wrappers around automake- and libtool-generated targets 59 | 60 | libfl: 61 | cd src && $(MAKE) $(AM_MAKEFLAGS) libfl.la libfl.pc 62 | 63 | install-libfl: 64 | cd src && \ 65 | $(MAKE) $(AM_MAKEFLAGS) lib_LTLIBRARIES=libfl.la \ 66 | pkgconfig_DATA=libfl.pc install-libLTLIBRARIES install-pkgconfigDATA 67 | 68 | uninstall-libfl: 69 | cd src && \ 70 | $(MAKE) $(AM_MAKEFLAGS) \ 71 | lib_LTLIBRARIES=libfl.la pkgconfig_DATA=libfl.pc \ 72 | uninstall-libLTLIBRARIES uninstall-pkgconfigDATA 73 | 74 | # libfl.pc is cleaned via 'distclean' target 75 | clean-libfl: 76 | cd src && \ 77 | $(MAKE) $(AM_MAKEFLAGS) lib_LTLIBRARIES=libfl.la clean-libLTLIBRARIES \ 78 | clean-libtool 79 | 80 | # Create the ChangeLog, but only if we're inside a git working directory 81 | 82 | ChangeLog: $(srcdir)/tools/git2cl 83 | if [ -d $(srcdir)/.git ] ; then \ 84 | $(srcdir)/tools/git2cl > $@ \ 85 | ; fi 86 | 87 | indent: 88 | cd src && $(MAKE) $(AM_MAKEFLAGS) indent 89 | 90 | install-exec-hook: 91 | cd $(DESTDIR)$(bindir) && \ 92 | $(LN_S) -f flex$(EXEEXT) flex++$(EXEEXT) 93 | 94 | lint: 95 | shellcheck -f gcc tests/*.sh src/*.sh *.sh 96 | 97 | .PHONY: libfl install-libfl uninstall-libfl clean-libfl \ 98 | ChangeLog indent lint 99 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | Things to be worked on: 2 | 3 | * Tests for %option user-init, %option pre-action, %option post-action. 4 | 5 | * integrate examples directory into tests so that normal testing 6 | proves the examples are up to date. 7 | 8 | * Do away with any need for -lfl by generating a default yywrap 9 | if the user doesn't specify one. 10 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This file is part of flex. 4 | 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions 7 | # are met: 8 | 9 | # 1. Redistributions of source code must retain the above copyright 10 | # notice, this list of conditions and the following disclaimer. 11 | # 2. Redistributions in binary form must reproduce the above copyright 12 | # notice, this list of conditions and the following disclaimer in the 13 | # documentation and/or other materials provided with the distribution. 14 | 15 | # Neither the name of the University nor the names of its contributors 16 | # may be used to endorse or promote products derived from this software 17 | # without specific prior written permission. 18 | 19 | # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 20 | # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 21 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | # PURPOSE. 23 | 24 | # If you see no configure script, then run ./autogen.sh to create it 25 | # and proceed with the "normal" build procedures. 26 | 27 | # use LIBTOOLIZE, if set 28 | if test "x$LIBTOOLIZE" = "x"; then 29 | for ac_prog in libtoolize glibtoolize; do 30 | if $ac_prog --version >/dev/null 2>&1; then 31 | LIBTOOLIZE=$ac_prog 32 | break 33 | fi 34 | done 35 | fi 36 | 37 | # test libtoolize 38 | if test "x$LIBTOOLIZE" = "x" || ! $LIBTOOLIZE --version >/dev/null; then 39 | echo "error: libtoolize not working, re-run with LIBTOOLIZE=/path/to/libtoolize">&2 40 | echo " LIBTOOLIZE is currently \"$LIBTOOLIZE\"">&2 41 | exit 1 42 | fi 43 | 44 | #if we pretend to have a ChangeLog, then automake is less 45 | #worried. (Don't worry, we *do* have a ChangeLog, we just need the 46 | #Makefile first.) 47 | 48 | if ! test -f ChangeLog; then 49 | touch ChangeLog 50 | fi 51 | $LIBTOOLIZE --install --force 52 | autoreconf --install --force 53 | -------------------------------------------------------------------------------- /control.ac: -------------------------------------------------------------------------------- 1 | XBS-Destinations: sourceforge 2 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | flex.aux 2 | flex.cp 3 | flex.cps 4 | flex.dvi 5 | flex.fn 6 | flex.fns 7 | flex.hk 8 | flex.hks 9 | flex.info* 10 | flex.ky 11 | flex.log 12 | flex.op 13 | flex.ops 14 | flex.pg 15 | flex.toc 16 | flex.tp 17 | flex.tps 18 | flex.vr 19 | flex.vrs 20 | Makefile 21 | Makefile.in 22 | flex.1 23 | flex.pdf 24 | flex.ps 25 | version.texi 26 | flex.html 27 | flex.t2p 28 | 29 | flex 30 | flex.exe 31 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | if CROSS 2 | FLEX = $(top_builddir)/src/stage1flex 3 | else 4 | FLEX = $(top_builddir)/src/flex$(EXEEXT) 5 | endif 6 | 7 | TEXI2DVI = @TEXI2DVI@ -I $(srcdir)/../examples/manual/ 8 | TEXI2PDF = @TEXI2PDF@ -I $(srcdir)/../examples/manual/ 9 | 10 | info_TEXINFOS = flex.texi 11 | AM_MAKEINFOFLAGS = -I $(srcdir)/../examples/manual/ 12 | dist_man_MANS = flex.1 13 | MAINTAINERCLEANFILES = flex.1 14 | 15 | CLEANFILES = \ 16 | *.aux \ 17 | *.cp \ 18 | *.cps \ 19 | *.fn \ 20 | *.fns \ 21 | *.hk \ 22 | *.hks \ 23 | *.ky \ 24 | *.log \ 25 | *.op \ 26 | *.ops\ 27 | *.pg \ 28 | *.toc \ 29 | *.tp \ 30 | *.tps \ 31 | *.vr \ 32 | *.vrs \ 33 | flex 34 | 35 | # Use a fixed program name, without extension (such as ".exe"), for man 36 | # page generation. 'help2man' strips directory prefix ("./") from the 37 | # usage string, but not file extensions. 38 | 39 | flex.1: $(top_srcdir)/configure.ac $(top_srcdir)/src/cpp-flex.skl $(top_srcdir)/src/options.c $(top_srcdir)/src/options.h 40 | ( cd $(top_builddir)/src && \ 41 | prog_name=`echo '$(FLEX)' | sed 's|^$(top_builddir)/src/||'` && \ 42 | $(MAKE) $(AM_MAKEFLAGS) $$prog_name \ 43 | ) 44 | $(INSTALL) -m 700 $(FLEX) flex$(EXEEXT) 45 | $(HELP2MAN) \ 46 | --name='$(PACKAGE_NAME)' \ 47 | --section=1 \ 48 | --source='The Flex Project' \ 49 | --manual='Programming' \ 50 | --output=$@ \ 51 | ./flex 52 | -------------------------------------------------------------------------------- /examples/Makefile.am: -------------------------------------------------------------------------------- 1 | # This file is part of flex. 2 | 3 | # Redistribution and use in source and binary forms, with or without 4 | # modification, are permitted provided that the following conditions 5 | # are met: 6 | 7 | # 1. Redistributions of source code must retain the above copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | # 2. Redistributions in binary form must reproduce the above copyright 10 | # notice, this list of conditions and the following disclaimer in the 11 | # documentation and/or other materials provided with the distribution. 12 | 13 | # Neither the name of the University nor the names of its contributors 14 | # may be used to endorse or promote products derived from this software 15 | # without specific prior written permission. 16 | 17 | # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 18 | # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 19 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 | # PURPOSE. 21 | 22 | EXTRA_DIST = \ 23 | testxxLexer.l \ 24 | debflex.awk \ 25 | README 26 | 27 | SUBDIRS = \ 28 | manual \ 29 | fastwc 30 | -------------------------------------------------------------------------------- /examples/README: -------------------------------------------------------------------------------- 1 | This directory contains some examples of what you can do with 2 | flex. These files are not tested regularly so you might have to tinker 3 | a bit before they work for you. Updates, new files and patches are welcome. 4 | 5 | - debflex.awk, an awk script for annotating flex debug output. 6 | It presently only works with gawk and mawk, not with "old" 7 | or "new" awk. 8 | 9 | - testxxLexer.l, a sample C++ program that uses flex's scanner 10 | class option ("-+"). 11 | 12 | - fastwc/, a subdirectory containing examples of how to use flex 13 | to write progressively higher-performance versions of the Unix 14 | "wc" utility. This certainly should work with 2.5, but hasn't 15 | been tested. 16 | -------------------------------------------------------------------------------- /examples/fastwc/Makefile.am: -------------------------------------------------------------------------------- 1 | # This file is part of flex. 2 | 3 | # Redistribution and use in source and binary forms, with or without 4 | # modification, are permitted provided that the following conditions 5 | # are met: 6 | 7 | # 1. Redistributions of source code must retain the above copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | # 2. Redistributions in binary form must reproduce the above copyright 10 | # notice, this list of conditions and the following disclaimer in the 11 | # documentation and/or other materials provided with the distribution. 12 | 13 | # Neither the name of the University nor the names of its contributors 14 | # may be used to endorse or promote products derived from this software 15 | # without specific prior written permission. 16 | 17 | # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 18 | # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 19 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 | # PURPOSE. 21 | 22 | EXTRA_DIST = \ 23 | wc5.l \ 24 | wc4.l \ 25 | wc3.l \ 26 | wc2.l \ 27 | wc1.l \ 28 | mywc.c \ 29 | README 30 | -------------------------------------------------------------------------------- /examples/fastwc/README: -------------------------------------------------------------------------------- 1 | This directory contains some examples illustrating techniques for extracting 2 | high-performance from flex scanners. Each program implements a simplified 3 | version of the Unix "wc" tool: read text from stdin and print the number of 4 | characters, words, and lines present in the text. All programs were compiled 5 | using gcc (version unavailable, sorry) with the -O flag, and run on a 6 | SPARCstation 1+. The input used was a PostScript file, mainly containing 7 | figures, with the following "wc" counts: 8 | 9 | lines words characters 10 | 214217 635954 2592172 11 | 12 | 13 | The basic principles illustrated by these programs are: 14 | 15 | - match as much text with each rule as possible 16 | - adding rules does not slow you down! 17 | - avoid backing up 18 | 19 | and the big caveat that comes with them is: 20 | 21 | - you buy performance with decreased maintainability; make 22 | sure you really need it before applying the above techniques. 23 | 24 | See the "Performance Considerations" section of flexdoc for more 25 | details regarding these principles. 26 | 27 | 28 | The different versions of "wc": 29 | 30 | mywc.c 31 | a simple but fairly efficient C version 32 | 33 | wc1.l a naive flex "wc" implementation 34 | 35 | wc2.l somewhat faster; adds rules to match multiple tokens at once 36 | 37 | wc3.l faster still; adds more rules to match longer runs of tokens 38 | 39 | wc4.l fastest; still more rules added; hard to do much better 40 | using flex (or, I suspect, hand-coding) 41 | 42 | wc5.l identical to wc3.l except one rule has been slightly 43 | shortened, introducing backing-up 44 | 45 | Timing results (all times in user CPU seconds): 46 | 47 | program time notes 48 | ------- ---- ----- 49 | wc1 16.4 default flex table compression (= -Cem) 50 | wc1 6.7 -Cf compression option 51 | /bin/wc 5.8 Sun's standard "wc" tool 52 | mywc 4.6 simple but better C implementation! 53 | wc2 4.6 as good as C implementation; built using -Cf 54 | wc3 3.8 -Cf 55 | wc4 3.3 -Cf 56 | wc5 5.7 -Cf; ouch, backing up is expensive 57 | -------------------------------------------------------------------------------- /examples/fastwc/mywc.c: -------------------------------------------------------------------------------- 1 | /* A simple but fairly efficient C version of the Unix "wc" tool */ 2 | 3 | #include 4 | #include 5 | 6 | main() 7 | { 8 | int c, cc = 0, wc = 0, lc = 0; 9 | FILE *f = stdin; 10 | 11 | while ((c = getc(f)) != EOF) { 12 | ++cc; 13 | if (isgraph(c)) { 14 | ++wc; 15 | do { 16 | c = getc(f); 17 | if (c == EOF) 18 | goto done; 19 | ++cc; 20 | } while (isgraph(c)); 21 | } 22 | if (c == '\n') 23 | ++lc; 24 | } 25 | done: printf( "%8d%8d%8d\n", lc, wc, cc ); 26 | } 27 | -------------------------------------------------------------------------------- /examples/fastwc/wc1.l: -------------------------------------------------------------------------------- 1 | /* First cut at a flex-based "wc" tool. */ 2 | 3 | ws [ \t] 4 | nonws [^ \t\n] 5 | 6 | %option main noyywrap 7 | %% 8 | int cc = 0, wc = 0, lc = 0; 9 | 10 | {nonws}+ cc += yyleng; ++wc; 11 | 12 | {ws}+ cc += yyleng; 13 | 14 | \n ++lc; ++cc; 15 | 16 | <> { 17 | printf( "%8d %8d %8d\n", lc, wc, cc ); 18 | yyterminate(); 19 | } 20 | -------------------------------------------------------------------------------- /examples/fastwc/wc2.l: -------------------------------------------------------------------------------- 1 | /* Somewhat faster "wc" tool: match more text with each rule */ 2 | 3 | ws [ \t] 4 | nonws [^ \t\n] 5 | word {ws}*{nonws}+ 6 | 7 | %option main noyywrap 8 | %% 9 | int cc = 0, wc = 0, lc = 0; 10 | 11 | {word}{ws}* cc += yyleng; ++wc; 12 | {word}{ws}*\n cc += yyleng; ++wc; ++lc; 13 | 14 | {ws}+ cc += yyleng; 15 | 16 | \n+ cc += yyleng; lc += yyleng; 17 | 18 | <> { 19 | printf( "%8d %8d %8d\n", lc, wc, cc ); 20 | yyterminate(); 21 | } 22 | -------------------------------------------------------------------------------- /examples/fastwc/wc3.l: -------------------------------------------------------------------------------- 1 | /* Somewhat faster still: potentially match a lot of text with each rule */ 2 | 3 | ws [ \t] 4 | nonws [^ \t\n] 5 | word {ws}*{nonws}+ 6 | words {word}{ws}+ 7 | 8 | %option main noyywrap 9 | %% 10 | int cc = 0, wc = 0, lc = 0; 11 | 12 | {word}{ws}* cc += yyleng; ++wc; 13 | {word}{ws}*\n cc += yyleng; ++wc; ++lc; 14 | {words}{word}{ws}* cc += yyleng; wc += 2; 15 | {words}{2}{word}{ws}* cc += yyleng; wc += 3; 16 | {words}{3}{word}{ws}* cc += yyleng; wc += 4; 17 | 18 | {ws}+ cc += yyleng; 19 | 20 | \n+ cc += yyleng; lc += yyleng; 21 | 22 | <> { 23 | printf( "%8d %8d %8d\n", lc, wc, cc ); 24 | yyterminate(); 25 | } 26 | -------------------------------------------------------------------------------- /examples/fastwc/wc4.l: -------------------------------------------------------------------------------- 1 | /* Fastest version of wc: add rules to pick up newlines, too */ 2 | 3 | ws [ \t] 4 | nonws [^ \t\n] 5 | word {ws}*{nonws}+ 6 | words {word}{ws}+ 7 | 8 | %option main noyywrap 9 | %% 10 | int cc = 0, wc = 0, lc = 0; 11 | 12 | {word}{ws}* ++wc; cc += yyleng; 13 | {word}{ws}*\n ++wc; cc += yyleng; ++lc; 14 | {words}{word}{ws}* wc += 2; cc += yyleng; 15 | {words}{word}{ws}*\n wc += 2; cc += yyleng; ++lc; 16 | {words}{2}{word}{ws}* wc += 3; cc += yyleng; 17 | {words}{2}{word}{ws}*\n wc += 3; cc += yyleng; ++lc; 18 | {words}{3}{word}{ws}* wc += 4; cc += yyleng; 19 | {words}{3}{word}{ws}*\n wc += 4; cc += yyleng; ++lc; 20 | 21 | {ws}+ cc += yyleng; 22 | 23 | \n+ cc += yyleng; lc += yyleng; 24 | 25 | <> { 26 | printf( "%8d %8d %8d\n", lc, wc, cc ); 27 | yyterminate(); 28 | } 29 | -------------------------------------------------------------------------------- /examples/fastwc/wc5.l: -------------------------------------------------------------------------------- 1 | /* Oops; slight change from wc3.l introduces backtracking */ 2 | 3 | ws [ \t] 4 | nonws [^ \t\n] 5 | word {ws}*{nonws}+ 6 | words {word}{ws}+ 7 | 8 | %option main noyywrap 9 | %% 10 | int cc = 0, wc = 0, lc = 0; 11 | 12 | {word}{ws}* cc += yyleng; ++wc; 13 | {word}{ws}*\n cc += yyleng; ++wc; ++lc; 14 | {words}{word} cc += yyleng; wc += 2; /* oops */ 15 | {words}{2}{word}{ws}* cc += yyleng; wc += 3; 16 | {words}{3}{word}{ws}* cc += yyleng; wc += 4; 17 | 18 | {ws}+ cc += yyleng; 19 | 20 | \n+ cc += yyleng; lc += yyleng; 21 | 22 | <> { 23 | printf( "%8d %8d %8d\n", lc, wc, cc ); 24 | yyterminate(); 25 | } 26 | -------------------------------------------------------------------------------- /examples/manual/ChangeLog: -------------------------------------------------------------------------------- 1 | Tue Oct 5 21:51:59 1993 Vern Paxson 2 | 3 | * Removed FILTER/ subdirectory. 4 | 5 | * Removed alloca.c. 6 | 7 | * Changed Makefile definition of CC to just "gcc -g", removed 8 | assumption of alloca being present. 9 | 10 | * Added pointer to MISC/fastwc/ to wc.lex. 11 | 12 | Tue Jun 8 15:47:39 1993 Gavin Thomas Nicol (nick at sillybugs) 13 | 14 | * Changed main() in wc.lex extensively. The old version would not 15 | work correctly without the YY_NEW_FILE. (lex handles the older 16 | version OK though). 17 | 18 | * Added a rule to expr.lex to handle whitespace. The old version 19 | reported an illegal character. 20 | 21 | * Added -traditional to the gcc flags because the flex definition 22 | for free() clashes with some systems that have old header files. 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/manual/Makefile.am: -------------------------------------------------------------------------------- 1 | # This file is part of flex. 2 | 3 | # Redistribution and use in source and binary forms, with or without 4 | # modification, are permitted provided that the following conditions 5 | # are met: 6 | 7 | # 1. Redistributions of source code must retain the above copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | # 2. Redistributions in binary form must reproduce the above copyright 10 | # notice, this list of conditions and the following disclaimer in the 11 | # documentation and/or other materials provided with the distribution. 12 | 13 | # Neither the name of the University nor the names of its contributors 14 | # may be used to endorse or promote products derived from this software 15 | # without specific prior written permission. 16 | 17 | # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 18 | # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 19 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 | # PURPOSE. 21 | 22 | EXTRA_DIST = \ 23 | ChangeLog \ 24 | Makefile.examples \ 25 | README \ 26 | cat.lex \ 27 | dates.lex \ 28 | datetest.dat \ 29 | eof_rules.lex \ 30 | eof_test01.txt \ 31 | eof_test02.txt \ 32 | eof_test03.txt \ 33 | example_er.lex \ 34 | example_r.lex \ 35 | example_nr.lex \ 36 | expr.lex \ 37 | expr.y \ 38 | front.lex \ 39 | front.y \ 40 | j2t.lex \ 41 | myname.lex \ 42 | myname.txt \ 43 | myname2.lex \ 44 | numbers.lex \ 45 | pas_include.lex \ 46 | pascal.lex \ 47 | reject.lex \ 48 | replace.lex \ 49 | string1.lex \ 50 | string2.lex \ 51 | strtest.dat \ 52 | unput.lex \ 53 | user_act.lex \ 54 | userinit.lex \ 55 | wc.lex \ 56 | yymore.lex \ 57 | yymore2.lex \ 58 | yymoretest.dat 59 | -------------------------------------------------------------------------------- /examples/manual/Makefile.examples: -------------------------------------------------------------------------------- 1 | ############################################################# 2 | # 3 | # Makefile : Makefile for Flex examples. 4 | # Author : G.T.Nicol 5 | # Last Updated : 1993/10/05 6 | # 7 | # If you use bison, you may have to supply an alloca 8 | # 9 | ############################################################# 10 | 11 | CC = gcc -g 12 | LEX = flex -i -I 13 | YACC = bison -d -y 14 | ALLOCA = 15 | 16 | ############################################################ 17 | # 18 | # DO NOT CHANGE ANYTHING FROM HERE ON !!!!!!!!! 19 | # 20 | ############################################################ 21 | PATH := /usr/local/bin:${PATH} 22 | 23 | all: expr front myname eof wc replace user_act string1\ 24 | string2 yymore numbers dates cat 25 | 26 | example_r: example_r.lex 27 | $(LEX) example_r.lex 28 | $(CC) lex.yy.c -o example_r 29 | 30 | example_nr: example_nr.lex 31 | $(LEX) example_nr.lex 32 | $(CC) lex.yy.c -o example_nr 33 | 34 | example_er: example_er.lex 35 | $(LEX) example_er.lex 36 | $(CC) lex.yy.c -o example_er 37 | 38 | expr: expr.y expr.lex 39 | $(YACC) expr.y 40 | $(LEX) expr.lex 41 | $(CC) -o expr lex.yy.c y.tab.c $(ALLOCA) -ll -lm 42 | 43 | front: front.y front.lex 44 | $(YACC) front.y 45 | $(LEX) front.lex 46 | $(CC) -o front lex.yy.c y.tab.c $(ALLOCA) -ll -lm 47 | 48 | numbers: numbers.lex 49 | $(LEX) numbers.lex 50 | $(CC) lex.yy.c -o numbers 51 | 52 | dates: dates.lex 53 | $(LEX) dates.lex 54 | $(CC) lex.yy.c -o dates -ll 55 | 56 | yymore: yymore.lex 57 | $(LEX) yymore.lex 58 | $(CC) lex.yy.c -o yymore -ll 59 | 60 | string1: string1.lex 61 | $(LEX) string1.lex 62 | $(CC) lex.yy.c -o string1 -ll 63 | 64 | string2: string2.lex 65 | $(LEX) string2.lex 66 | $(CC) lex.yy.c -o string2 -ll 67 | 68 | myname: myname.lex 69 | $(LEX) myname.lex 70 | $(CC) lex.yy.c -o myname -ll 71 | 72 | myname2: myname2.lex 73 | $(LEX) myname2.lex 74 | $(CC) lex.yy.c -o myname2 -ll 75 | 76 | eof: eof_rules.lex 77 | $(LEX) eof_rules.lex 78 | $(CC) lex.yy.c -o eof -ll 79 | 80 | wc: wc.lex 81 | $(LEX) wc.lex 82 | $(CC) lex.yy.c -o wc -ll 83 | 84 | cat: cat.lex 85 | $(LEX) cat.lex 86 | $(CC) lex.yy.c -o cat -ll 87 | 88 | replace: replace.lex 89 | $(LEX) replace.lex 90 | $(CC) lex.yy.c -o replace -ll 91 | 92 | user_act: expr.y expr.lex 93 | $(LEX) user_act.lex 94 | $(CC) -o user_act lex.yy.c -ll 95 | 96 | clean: 97 | rm -f *.BAK *.o core *~* *.a 98 | rm -f *.tab.h *.tab.c 99 | rm -f myname expr lex.yy.c *.out eof wc yymore 100 | rm -f replace front user_act string1 string2 101 | rm -f dates numbers cat 102 | -------------------------------------------------------------------------------- /examples/manual/README: -------------------------------------------------------------------------------- 1 | This directory contains the example programs from the manual, and a 2 | few other things as well. To make all the programs, simply type "make 3 | -f Makefile.examples", and assuming you have flex and gcc, all will be 4 | well. 5 | 6 | To build the programs individually, type 7 | 8 | make -f Makefile.examples program_name 9 | 10 | For example: 11 | 12 | make -f Makefile.examples expr 13 | 14 | If you add an example to this directory, don't forget these steps: 15 | 16 | * Add it to the EXTRA_DIST list in Makefile.am 17 | 18 | * Add a build recipe to Makefile/examples. 19 | -------------------------------------------------------------------------------- /examples/manual/cat.lex: -------------------------------------------------------------------------------- 1 | /* 2 | * cat.lex: A demonstration of YY_NEW_FILE. 3 | */ 4 | 5 | %{ 6 | #include 7 | 8 | char **names = NULL; 9 | int current = 1; 10 | %} 11 | 12 | %% 13 | <> { 14 | current += 1; 15 | if(names[current] != NULL){ 16 | yyin = fopen(names[current],"r"); 17 | if(yyin == NULL){ 18 | fprintf(stderr,"cat: unable to open %s\n", 19 | names[current]); 20 | yyterminate(); 21 | } 22 | YY_NEW_FILE; 23 | } else { 24 | yyterminate(); 25 | } 26 | } 27 | %% 28 | 29 | int main(int argc, char **argv) 30 | { 31 | if(argc < 2){ 32 | fprintf(stderr,"Usage: cat files....\n"); 33 | exit(1); 34 | } 35 | names = argv; 36 | 37 | yyin = fopen(names[current],"r"); 38 | if(yyin == NULL){ 39 | fprintf(stderr,"cat: unable to open %s\n", 40 | names[current]); 41 | yyterminate(); 42 | } 43 | 44 | yylex(); 45 | } 46 | -------------------------------------------------------------------------------- /examples/manual/datetest.dat: -------------------------------------------------------------------------------- 1 | short 2 | 1989:12:23 3 | 1989:11:12 4 | 23:12:1989 5 | 11:12:1989 6 | 1989/12/23 7 | 1989/11/12 8 | 23/12/1989 9 | 11/12/1989 10 | 1989-12-23 11 | 1989-11-12 12 | 23-12-1989 13 | 11-12-1989 14 | long 15 | Friday the 5th of January, 1989 16 | Friday, 5th of January, 1989 17 | Friday, January 5th, 1989 18 | Fri, January 5th, 1989 19 | Fri, Jan 5th, 1989 20 | Fri, Jan 5, 1989 21 | FriJan 5, 1989 22 | FriJan5, 1989 23 | FriJan51989 24 | Jan51989 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /examples/manual/eof_rules.lex: -------------------------------------------------------------------------------- 1 | /* 2 | * eof_rules.lex : An example of using multiple buffers 3 | * EOF rules, and start states 4 | */ 5 | 6 | %{ 7 | 8 | #define MAX_NEST 10 9 | 10 | YY_BUFFER_STATE include_stack[MAX_NEST]; 11 | int include_count = -1; 12 | 13 | %} 14 | 15 | 16 | %x INCLUDE 17 | 18 | %% 19 | 20 | ^"#include"[ \t]*\" yybegin(INCLUDE); 21 | \" yybegin(INITIAL); 22 | [^\"]+ { /* get the include file name */ 23 | if ( include_count >= MAX_NEST){ 24 | fprintf( stderr, "Too many include files" ); 25 | exit( 1 ); 26 | } 27 | 28 | include_stack[++include_count] = yy_current_buffer(); 29 | 30 | yyin = fopen( yytext, "r" ); 31 | if ( ! yyin ){ 32 | fprintf( stderr, "Unable to open \"%s\"\n",yytext); 33 | exit( 1 ); 34 | } 35 | 36 | yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE)); 37 | 38 | yybegin(INITIAL); 39 | } 40 | <> 41 | { 42 | fprintf( stderr, "EOF in include" ); 43 | yyterminate(); 44 | } 45 | <> { 46 | if ( include_count <= 0 ){ 47 | yyterminate(); 48 | } else { 49 | yy_delete_buffer(include_stack[include_count--] ); 50 | yy_switch_to_buffer(include_stack[include_count] ); 51 | yybegin(INCLUDE); 52 | } 53 | } 54 | [a-z]+ ECHO; 55 | .|\n ECHO; 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /examples/manual/eof_test01.txt: -------------------------------------------------------------------------------- 1 | This is test file #1 2 | 3 | ------------------------------------------------- 4 | 5 | We will now include test #2 in a standard way. 6 | 7 | #include "eof_test02.txt" 8 | 9 | ------------------------------------------------- 10 | 11 | And now we will include test # 2 with a different 12 | format 13 | 14 | #include "eof_test02.txt" 15 | ------------------------------------------------- 16 | 17 | and this is the end of the test. 18 | -------------------------------------------------------------------------------- /examples/manual/eof_test02.txt: -------------------------------------------------------------------------------- 1 | INCLUDE #2 2 | 3 | This is the second file that will 4 | be included. 5 | 6 | >>> Foo are GNU? 7 | 8 | #include "eof_test03.txt" 9 | -------------------------------------------------------------------------------- /examples/manual/eof_test03.txt: -------------------------------------------------------------------------------- 1 | INCLUDE #3 2 | 3 | This is the third file that will 4 | be included. 5 | 6 | >>> echo "I am `whoami`!!" 7 | 8 | -------------------------------------------------------------------------------- /examples/manual/example_er.lex: -------------------------------------------------------------------------------- 1 | /* basic example, fully reentrant thread-safe version */ 2 | %{ 3 | struct stats { 4 | int num_lines; 5 | int num_chars; 6 | }; 7 | %} 8 | %option reentrant noyywrap 9 | %option extra-type="struct stats" 10 | %% 11 | \n { 12 | struct stats ns = yyget_extra(yyscanner); 13 | ++ns.num_lines; ++ns.num_chars; 14 | yyset_extra(ns, yyscanner); 15 | } 16 | . { 17 | struct stats ns = yyget_extra(yyscanner); 18 | ++ns.num_chars; 19 | yyset_extra(ns, yyscanner); 20 | } 21 | 22 | %% 23 | 24 | int main() { 25 | yyscan_t scanner; 26 | struct stats ns; 27 | 28 | yylex_init ( &scanner ); 29 | yylex ( scanner ); 30 | 31 | ns = yyget_extra(scanner); 32 | printf( "# of lines = %d, # of chars = %d\n", 33 | ns.num_lines, ns.num_chars); 34 | yylex_destroy ( scanner ); 35 | } 36 | -------------------------------------------------------------------------------- /examples/manual/example_nr.lex: -------------------------------------------------------------------------------- 1 | /* basic example - non-reentrant version */ 2 | %{ 3 | int num_lines = 0, num_chars = 0; 4 | %} 5 | %option noyywrap 6 | %% 7 | \n ++num_lines; ++num_chars; 8 | . ++num_chars; 9 | 10 | %% 11 | 12 | int main() { 13 | yylex(); 14 | printf( "# of lines = %d, # of chars = %d\n", 15 | num_lines, num_chars ); 16 | } 17 | -------------------------------------------------------------------------------- /examples/manual/example_r.lex: -------------------------------------------------------------------------------- 1 | /* basic example - flawed reentrant version with global */ 2 | %{ 3 | int num_lines = 0, num_chars = 0; 4 | %} 5 | %option reentrant noyywrap 6 | %% 7 | \n ++num_lines; ++num_chars; 8 | . ++num_chars; 9 | 10 | %% 11 | 12 | int main() { 13 | yyscan_t scanner; 14 | 15 | yylex_init ( &scanner ); 16 | yylex ( scanner ); 17 | yylex_destroy ( scanner ); 18 | 19 | printf( "# of lines = %d, # of chars = %d\n", 20 | num_lines, num_chars ); 21 | } 22 | -------------------------------------------------------------------------------- /examples/manual/expr.lex: -------------------------------------------------------------------------------- 1 | /* 2 | * expr.lex : Scanner for a simple 3 | * expression parser. 4 | */ 5 | 6 | %{ 7 | #include "y.tab.h" 8 | 9 | %} 10 | 11 | %% 12 | 13 | [0-9]+ { yylval.val = atol(yytext); 14 | return(NUMBER); 15 | } 16 | [0-9]+\.[0-9]+ { 17 | sscanf(yytext,"%f",&yylval.val); 18 | return(NUMBER); 19 | } 20 | "+" return(PLUS); 21 | "-" return(MINUS); 22 | "*" return(MULT); 23 | "/" return(DIV); 24 | "^" return(EXPON); 25 | "(" return(LB); 26 | ")" return(RB); 27 | \n return(EOL); 28 | [\t ]* /* throw away whitespace */ 29 | . { yyerror("Illegal character"); 30 | return(EOL); 31 | } 32 | %% 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /examples/manual/expr.y: -------------------------------------------------------------------------------- 1 | /* 2 | * expr.y : A simple yacc expression parser 3 | * Based on the Bison manual example. 4 | */ 5 | 6 | %{ 7 | #include 8 | #include 9 | 10 | %} 11 | 12 | %union { 13 | float val; 14 | } 15 | 16 | %token NUMBER 17 | %token PLUS MINUS MULT DIV EXPON 18 | %token EOL 19 | %token LB RB 20 | 21 | %left MINUS PLUS 22 | %left MULT DIV 23 | %right EXPON 24 | 25 | %type exp NUMBER 26 | 27 | %% 28 | input : 29 | | input line 30 | ; 31 | 32 | line : EOL 33 | | exp EOL { printf("%g\n",$1);} 34 | 35 | exp : NUMBER { $$ = $1; } 36 | | exp PLUS exp { $$ = $1 + $3; } 37 | | exp MINUS exp { $$ = $1 - $3; } 38 | | exp MULT exp { $$ = $1 * $3; } 39 | | exp DIV exp { $$ = $1 / $3; } 40 | | MINUS exp %prec MINUS { $$ = -$2; } 41 | | exp EXPON exp { $$ = pow($1,$3);} 42 | | LB exp RB { $$ = $2; } 43 | ; 44 | 45 | %% 46 | 47 | yyerror(char *message) 48 | { 49 | printf("%s\n",message); 50 | } 51 | 52 | int main(int argc, char *argv[]) 53 | { 54 | yyparse(); 55 | return(0); 56 | } 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /examples/manual/front.lex: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include 4 | #include "y.tab.h" /* this comes from bison */ 5 | 6 | #define copy_and_return(token_type) { strcpy(yylval.name,yytext); \ 7 | return(token_type); } 8 | 9 | int yylexlinenum = 0; /* so we can count lines */ 10 | %} 11 | 12 | %% 13 | /* Lexical scanning rules begin from here. */ 14 | 15 | MEN|WOMEN|STOCKS|TREES copy_and_return(NOUN) 16 | MISTAKES|GNUS|EMPLOYEES copy_and_return(NOUN) 17 | LOSERS|USERS|CARS|WINDOWS copy_and_return(NOUN) 18 | 19 | DATABASE|NETWORK|FSF|GNU copy_and_return(PROPER_NOUN) 20 | COMPANY|HOUSE|OFFICE|LPF copy_and_return(PROPER_NOUN) 21 | 22 | THE|THIS|THAT|THOSE copy_and_return(DECLARATIVE) 23 | 24 | ALL|FIRST|LAST copy_and_return(CONDITIONAL) 25 | 26 | FIND|SEARCH|SORT|ERASE|KILL copy_and_return(VERB) 27 | ADD|REMOVE|DELETE|PRINT copy_and_return(VERB) 28 | 29 | QUICKLY|SLOWLY|CAREFULLY copy_and_return(ADVERB) 30 | 31 | IN|AT|ON|AROUND|INSIDE|ON copy_and_return(POSITIONAL) 32 | 33 | "." return(PERIOD); 34 | "\n" yylexlinenum++; return(NEWLINE); 35 | . 36 | %% 37 | 38 | -------------------------------------------------------------------------------- /examples/manual/myname.lex: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * myname.lex : A sample Flex program 4 | * that does token replacement. 5 | */ 6 | 7 | %% 8 | 9 | %NAME { printf("%s",getenv("LOGNAME")); } 10 | %HOST { printf("%s",getenv("HOST")); } 11 | %HOSTTYPE { printf("%s",getenv("HOSTTYPE"));} 12 | %HOME { printf("%s",getenv("HOME")); } 13 | 14 | %% 15 | 16 | -------------------------------------------------------------------------------- /examples/manual/myname.txt: -------------------------------------------------------------------------------- 1 | Hello, my name name is %NAME. Actually 2 | "%NAME" isn't my real name, it is the 3 | alias I use when I'm on %HOST, which 4 | is the %HOSTTYPE I use. My HOME 5 | directory is %HOME. 6 | 7 | -------------------------------------------------------------------------------- /examples/manual/myname2.lex: -------------------------------------------------------------------------------- 1 | /* 2 | * myname2.lex : A sample Flex program 3 | * that does token replacement. 4 | */ 5 | 6 | %{ 7 | #include 8 | %} 9 | 10 | %x STRING 11 | %% 12 | \" ECHO; BEGIN(STRING); 13 | [^\"\n]* ECHO; 14 | \" ECHO; BEGIN(INITIAL); 15 | 16 | %NAME { printf("%s",getenv("LOGNAME")); } 17 | %HOST { printf("%s",getenv("HOST")); } 18 | %HOSTTYPE { printf("%s",getenv("HOSTTYPE"));} 19 | %HOME { printf("%s",getenv("HOME")); } 20 | -------------------------------------------------------------------------------- /examples/manual/pas_include.lex: -------------------------------------------------------------------------------- 1 | /* 2 | * eof_rules.lex : An example of using multiple buffers 3 | * EOF rules, and start states 4 | */ 5 | 6 | %{ 7 | 8 | #define MAX_NEST 10 9 | 10 | YY_BUFFER_STATE include_stack[MAX_NEST]; 11 | int include_count = -1; 12 | 13 | %} 14 | 15 | 16 | %x INCLUDE 17 | %x COMMENT 18 | 19 | 20 | %% 21 | 22 | "{" yybegin(COMMENT); 23 | 24 | "}" yybegin(INITIAL); 25 | "$include"[ \t]*"(" yybegin(INCLUDE); 26 | [ \t]* /* skip whitespace */ 27 | 28 | ")" yybegin(COMMENT); 29 | [ \t]* /* skip whitespace */ 30 | [^ \t\n() ]+ { /* get the include file name */ 31 | if ( include_count >= MAX_NEST){ 32 | fprintf( stderr, "Too many include files" ); 33 | exit( 1 ); 34 | } 35 | 36 | include_stack[++include_count] = yy_current_buffer(); 37 | 38 | yyin = fopen( yytext, "r" ); 39 | if ( ! yyin ){ 40 | fprintf( stderr, "Unable to open %s",yytext); 41 | exit( 1 ); 42 | } 43 | 44 | yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE)); 45 | 46 | yybegin(INITIAL); 47 | } 48 | <> 49 | { 50 | fprintf( stderr, "EOF in include" ); 51 | yyterminate(); 52 | } 53 | <> 54 | { 55 | fprintf( stderr, "EOF in comment" ); 56 | yyterminate(); 57 | } 58 | <> { 59 | if ( include_count <= 0 ){ 60 | yyterminate(); 61 | } else { 62 | yy_delete_buffer(include_stack[include_count--] ); 63 | yy_switch_to_buffer(include_stack[include_count] ); 64 | yybegin(INCLUDE); 65 | } 66 | } 67 | [a-z]+ yyecho(); 68 | .|\n yyecho(); 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /examples/manual/reject.lex: -------------------------------------------------------------------------------- 1 | /* 2 | * reject.lex: An example of yyreject() and yyunput() 3 | * misuse. 4 | */ 5 | 6 | %% 7 | UNIX { 8 | yyunput('U'); yyunput('N'); yyunput('G'); yyunput('\0'); 9 | yyreject(); 10 | } 11 | GNU printf("GNU is Not Unix!\n"); 12 | %% 13 | -------------------------------------------------------------------------------- /examples/manual/replace.lex: -------------------------------------------------------------------------------- 1 | /* 2 | * replace.lex : A simple filter for renaming 3 | * parts of flex of bison generated 4 | * scanners or parsers. 5 | */ 6 | 7 | %{ 8 | #include 9 | 10 | char lower_replace[1024]; 11 | char upper_replace[1024]; 12 | 13 | %} 14 | 15 | %% 16 | 17 | "yy" printf("%s",lower_replace); 18 | "YY" printf("%s",upper_replace); 19 | , yyecho(); 20 | 21 | %% 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | if(argc < 2){ 26 | printf("Usage %s lower UPPER\n",argv[0]); 27 | exit(1); 28 | } 29 | strcpy(lower_replace,argv[1]); 30 | strcpy(upper_replace,argv[2]); 31 | yylex(); 32 | return(0); 33 | } 34 | -------------------------------------------------------------------------------- /examples/manual/string1.lex: -------------------------------------------------------------------------------- 1 | /* 2 | * string1.lex: Handling strings by using yyinput() 3 | */ 4 | 5 | %{ 6 | #include 7 | #include 8 | 9 | #define ALLOC_SIZE 32 /* for (re)allocating the buffer */ 10 | 11 | #define isodigit(x) ((x) >= '0' && (x) <= '7') 12 | #define hextoint(x) (isdigit((x)) ? (x) - '0' : ((x) - 'A') + 10) 13 | 14 | void yyerror(char *message) 15 | { 16 | printf("\nError: %s\n",message); 17 | } 18 | 19 | %} 20 | 21 | %% 22 | 23 | \" { 24 | int inch,count,max_size; 25 | char *buffer; 26 | int temp; 27 | 28 | buffer = malloc(ALLOC_SIZE); 29 | max_size = ALLOC_SIZE; 30 | inch = yyinput(); 31 | count = 0; 32 | while(inch != EOF && inch != '"' && inch != '\n'){ 33 | if(inch == '\\'){ 34 | inch = yyinput(); 35 | switch(inch){ 36 | case '\n': inch = yyinput(); break; 37 | case 'b' : inch = '\b'; break; 38 | case 't' : inch = '\t'; break; 39 | case 'n' : inch = '\n'; break; 40 | case 'v' : inch = '\v'; break; 41 | case 'f' : inch = '\f'; break; 42 | case 'r' : inch = '\r'; break; 43 | case 'X' : 44 | case 'x' : inch = yyinput(); 45 | if(isxdigit(inch)){ 46 | temp = hextoint(toupper(inch)); 47 | inch = yyinput(); 48 | if(isxdigit(inch)){ 49 | temp = (temp << 4) + hextoint(toupper(inch)); 50 | } else { 51 | unput(inch); 52 | } 53 | inch = temp; 54 | } else { 55 | unput(inch); 56 | inch = 'x'; 57 | } 58 | break; 59 | default: 60 | if(isodigit(inch)){ 61 | temp = inch - '0'; 62 | inch = yyinput(); 63 | if(isodigit(inch)){ 64 | temp = (temp << 3) + (inch - '0'); 65 | } else { 66 | unput(inch); 67 | goto done; 68 | } 69 | inch = yyinput(); 70 | if(isodigit(inch)){ 71 | temp = (temp << 3) + (inch - '0'); 72 | } else { 73 | unput(inch); 74 | } 75 | done: 76 | inch = temp; 77 | } 78 | } 79 | } 80 | buffer[count++] = inch; 81 | if(count >= max_size){ 82 | buffer = realloc(buffer,max_size + ALLOC_SIZE); 83 | max_size += ALLOC_SIZE; 84 | } 85 | inch = yyinput(); 86 | } 87 | if(inch == EOF || inch == '\n'){ 88 | yyerror("Unterminated string."); 89 | } 90 | buffer[count] = '\0'; 91 | printf("String = \"%s\"\n",buffer); 92 | free(buffer); 93 | } 94 | . 95 | \n 96 | %% 97 | 98 | 99 | -------------------------------------------------------------------------------- /examples/manual/strtest.dat: -------------------------------------------------------------------------------- 1 | "This is a string" 2 | "The next string will be empty" 3 | "" 4 | "This is a string with a \b(\\b) in it" 5 | "This is a string with a \t(\\t) in it" 6 | "This is a string with a \n(\\n) in it" 7 | "This is a string with a \v(\\v) in it" 8 | "This is a string with a \f(\\f) in it" 9 | "This is a string with a \r(\\r) in it" 10 | "This is a string with a \"(\\\") in it" 11 | "This is a string with a \z(\\z) in it" 12 | "This is a string with a \X4a(\\X4a) in it" 13 | "This is a string with a \x4a(\\x4a) in it" 14 | "This is a string with a \x7(\\x7) in it" 15 | "This is a string with a \112(\\112) in it" 16 | "This is a string with a \043(\\043) in it" 17 | "This is a string with a \7(\\7) in it" 18 | "This is a multi-line \ 19 | string" 20 | "This is an unterminated string 21 | "This is an unterminated string too 22 | -------------------------------------------------------------------------------- /examples/manual/unput.lex: -------------------------------------------------------------------------------- 1 | /* 2 | * unput.l : An example of what *not* 3 | * to do with yyunput(). 4 | */ 5 | 6 | 7 | %{ 8 | #include 9 | 10 | void putback_yytext(void); 11 | %} 12 | 13 | %% 14 | foobar putback_yytext(); 15 | raboof putback_yytext(); 16 | %% 17 | 18 | void putback_yytext(void) 19 | { 20 | int i; 21 | int l = strlen(yytext); 22 | char buffer[YY_BUF_SIZE]; 23 | 24 | strcpy(buffer,yytext); 25 | printf("Got: %s\n",yytext); 26 | for(i=0; i 4 | 5 | void user_action(void); 6 | 7 | %} 8 | 9 | %option pre-action = "user_action();" 10 | %% 11 | 12 | .* yyecho(); 13 | \n yyecho(); 14 | 15 | %% 16 | 17 | void user_action(void) 18 | { 19 | int loop; 20 | 21 | for(loop=0; loop 8 | 9 | void yyerror(char *message) 10 | { 11 | printf("Error: %s\n",message); 12 | } 13 | 14 | %} 15 | 16 | %x STRING 17 | 18 | %% 19 | \" yybegin(STRING); 20 | 21 | [^\\\n"]* yymore(); 22 | <> yyerror("EOF in string."); yybegin(INITIAL); 23 | \n yyerror("Unterminated string."); yybegin(INITIAL); 24 | \\\n yymore(); 25 | \" { 26 | yytext[yyleng-1] = '\0'; 27 | printf("string = \"%s\"",yytext); yybegin(INITIAL); 28 | } 29 | %% 30 | -------------------------------------------------------------------------------- /examples/manual/yymore2.lex: -------------------------------------------------------------------------------- 1 | /* 2 | * yymore.lex: An example of using yymore() 3 | * to good effect. 4 | */ 5 | 6 | %{ 7 | #include 8 | 9 | void yyerror(char *message) 10 | { 11 | printf("Error: %s\n",message); 12 | } 13 | 14 | %} 15 | 16 | %x STRING 17 | 18 | %% 19 | \" yybegin(STRING); 20 | 21 | [^\\\n"]* yymore(); 22 | <> yyerror("EOF in string."); yybegin(INITIAL); 23 | \n yyerror("Unterminated string."); yybegin(INITIAL); 24 | \\\n { 25 | bcopy(yytext,yytext+2,yyleng-2); 26 | yytext += 2; yyleng -= 2; 27 | yymore(); 28 | } 29 | \" { 30 | yyleng -= 1; yytext[yyleng] = '\0'; 31 | printf("string = \"%s\"",yytext); yybegin(INITIAL); 32 | } 33 | %% 34 | -------------------------------------------------------------------------------- /examples/manual/yymoretest.dat: -------------------------------------------------------------------------------- 1 | "This is a test \ 2 | of multi-line string \ 3 | scanning in flex. \ 4 | This may be breaking some law \ 5 | of usage though..." 6 | 7 | 8 | -------------------------------------------------------------------------------- /examples/testxxLexer.l: -------------------------------------------------------------------------------- 1 | // An example of using the flex C++ scanner class. 2 | 3 | %option C++ noyywrap 4 | 5 | %{ 6 | int mylineno = 0; 7 | %} 8 | 9 | string \"[^\n"]+\" 10 | 11 | ws [ \t]+ 12 | 13 | alpha [A-Za-z] 14 | dig [0-9] 15 | name ({alpha}|{dig}|\$)({alpha}|{dig}|\_|\.|\-|\/|\$)* 16 | num1 [-+]?{dig}+\.?([eE][-+]?{dig}+)? 17 | num2 [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)? 18 | number {num1}|{num2} 19 | 20 | %% 21 | 22 | {ws} /* skip blanks and tabs */ 23 | 24 | "/*" { 25 | int c; 26 | 27 | while((c = yyinput()) != 0) 28 | { 29 | if(c == '\n') 30 | ++mylineno; 31 | 32 | else if(c == '*') 33 | { 34 | if((c = yyinput()) == '/') 35 | break; 36 | else 37 | unput(c); 38 | } 39 | } 40 | } 41 | 42 | {number} std::cout << "number " << YYText() << '\n'; 43 | 44 | \n mylineno++; 45 | 46 | {name} std::cout << "name " << YYText() << '\n'; 47 | 48 | {string} std::cout << "string " << YYText() << '\n'; 49 | 50 | %% 51 | 52 | int main( int /* argc */, char** /* argv */ ) 53 | { 54 | FlexLexer* lexer = new yyFlexLexer; 55 | while(lexer->yylex() != 0) 56 | ; 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /lib/.gitignore: -------------------------------------------------------------------------------- 1 | *.la 2 | *.lo 3 | *.o 4 | *.obj 5 | -------------------------------------------------------------------------------- /lib/malloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef malloc 3 | 4 | #include 5 | 6 | void *malloc (size_t n); 7 | 8 | /* Allocate an N-byte block of memory from the heap. 9 | If N is zero, allocate a 1-byte block. */ 10 | 11 | void * 12 | rpl_malloc (size_t n) 13 | { 14 | if (n == 0) 15 | n = 1; 16 | return malloc (n); 17 | } 18 | -------------------------------------------------------------------------------- /lib/realloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef realloc 3 | #undef malloc 4 | 5 | #include 6 | 7 | #include 8 | 9 | void * rpl_realloc (void *p, size_t n) 10 | { 11 | void *result; 12 | 13 | if (n == 0) 14 | { 15 | n = 1; 16 | } 17 | 18 | if (p == NULL) 19 | { 20 | result = malloc (n); 21 | } 22 | else 23 | result = realloc (p, n); 24 | 25 | if (result == NULL) 26 | errno = ENOMEM; 27 | 28 | return result; 29 | } 30 | -------------------------------------------------------------------------------- /po/.gitignore: -------------------------------------------------------------------------------- 1 | *.gmo 2 | Makefile 3 | Makefile.in 4 | Makefile.in.in 5 | Makevars.template 6 | POTFILES 7 | Rules-quot 8 | boldquot.sed 9 | en@boldquot.*header 10 | en@boldquot.po 11 | en@quot.*header 12 | en@quot.po 13 | flex.pot 14 | insert-header.sin 15 | quot.sed 16 | remove-potcdate.sed 17 | remove-potcdate.sin 18 | stamp-* 19 | -------------------------------------------------------------------------------- /po/LINGUAS: -------------------------------------------------------------------------------- 1 | # List of available languages. 2 | bg ca da de en@boldquot en@quot eo es fi fr ga hr ko nl pl pt pt_BR ro ru sr sv tr uk vi zh_CN zh_TW 3 | -------------------------------------------------------------------------------- /po/POTFILES.in: -------------------------------------------------------------------------------- 1 | src/buf.c 2 | src/ccl.c 3 | src/dfa.c 4 | src/ecs.c 5 | src/gen.c 6 | src/libmain.c 7 | src/libyywrap.c 8 | src/main.c 9 | src/misc.c 10 | src/nfa.c 11 | src/options.c 12 | src/parse.y 13 | src/scan.l 14 | src/scanopt.c 15 | src/sym.c 16 | src/tblcmp.c 17 | src/yylex.c 18 | -------------------------------------------------------------------------------- /po/da.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/westes/flex/bf254c75b1e0d2641ebbd7fc85fb183f36a62ea7/po/da.po -------------------------------------------------------------------------------- /po/ko.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/westes/flex/bf254c75b1e0d2641ebbd7fc85fb183f36a62ea7/po/ko.po -------------------------------------------------------------------------------- /po/update_linguas.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # shell for updating the translations before a release 3 | 4 | # Let this be executed in the po/ subdir. 5 | cd "$(dirname "$0")" || exit 6 | 7 | echo "Updating translations via TP" 8 | rsync -Lrtvz translationproject.org::tp/latest/flex/ . # || exit 9 | 10 | # Are there now PO files that are not in svn yet? 11 | NEWSTUFF=$(git status --porcelain *.po | grep "^??") 12 | 13 | if [ -n "${NEWSTUFF}" ]; then 14 | echo "New languages found; updating LINGUAS" 15 | echo "# List of available languages." >LINGUAS 16 | echo $(printf '%s\n' *.po | LC_ALL=C sort | sed 's/\.po//g') >>LINGUAS 17 | fi 18 | 19 | echo "Regenerating POT file and remerging and recompiling PO files..." 20 | make update-po 21 | 22 | # Ensure that the PO files are newer than the POT. 23 | touch *.po 24 | 25 | # Compile PO files 26 | make 27 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | *.la 2 | *.lo 3 | *.o 4 | *-flex.h 5 | config.h 6 | config.h.in 7 | config_for_build.h 8 | flex 9 | libfl.pc 10 | parse.c 11 | parse.h 12 | scan.c 13 | stage1scan.c 14 | stage1flex 15 | stage2compare 16 | stage2scan.c 17 | 18 | # for MSWindows 19 | 20 | *.obj 21 | *.exe 22 | -------------------------------------------------------------------------------- /src/chkskel.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # This file is part of flex. 4 | 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions 7 | # are met: 8 | 9 | # 1. Redistributions of source code must retain the above copyright 10 | # notice, this list of conditions and the following disclaimer. 11 | # 2. Redistributions in binary form must reproduce the above copyright 12 | # notice, this list of conditions and the following disclaimer in the 13 | # documentation and/or other materials provided with the distribution. 14 | 15 | # Neither the name of the University nor the names of its contributors 16 | # may be used to endorse or promote products derived from this software 17 | # without specific prior written permission. 18 | 19 | # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 20 | # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 21 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | # PURPOSE. 23 | 24 | if test ! $# = 1; then 25 | echo 'Usage: chkskel.sh file' >&2 26 | exit 1 27 | fi 28 | file=$1 29 | lines=$(grep -c '^ "%%' "${file}") 30 | if [ ! "${lines}" -eq 6 ]; then 31 | echo 'ERROR: skeleton does not have the right number of %% section lines' 32 | exit 2 33 | fi 34 | -------------------------------------------------------------------------------- /src/config_for_build.h.in: -------------------------------------------------------------------------------- 1 | /* config_for_build - minimal config header for bootstrapping flex */ 2 | 3 | /* This file is part of flex. */ 4 | 5 | /* Redistribution and use in source and binary forms, with or without */ 6 | /* modification, are permitted provided that the following conditions */ 7 | /* are met: */ 8 | 9 | /* 1. Redistributions of source code must retain the above copyright */ 10 | /* notice, this list of conditions and the following disclaimer. */ 11 | /* 2. Redistributions in binary form must reproduce the above copyright */ 12 | /* notice, this list of conditions and the following disclaimer in the */ 13 | /* documentation and/or other materials provided with the distribution. */ 14 | 15 | /* Neither the name of the University nor the names of its contributors */ 16 | /* may be used to endorse or promote products derived from this software */ 17 | /* without specific prior written permission. */ 18 | 19 | /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */ 20 | /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ 21 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 22 | /* PURPOSE. */ 23 | 24 | /* The "config_for_build.h.in" file is intended to be processed by "configure" 25 | * in order to produce working PACKAGE, VERSION and M4 definitions. 26 | * Add "config_for_build.h.in" to AC_CONFIG_FILES. Do not add it to 27 | * AC_CONFIG_HEADERS as it would break our intentional #undef's and mess up 28 | * with the #define statements. 29 | */ 30 | #define PACKAGE "@PACKAGE@" 31 | #define VERSION "@VERSION@" 32 | #define M4 "@M4@" 33 | 34 | #undef ENABLE_NLS 35 | /* Flex includes only if NLS is enabled, but we undef it anyway. */ 36 | #undef HAVE_LOCALE_H 37 | 38 | #undef HAVE_NETINET_IN_H 39 | #ifdef __has_include 40 | # if __has_include() 41 | # define HAVE_NETINET_IN_H 1 42 | # endif 43 | #endif 44 | 45 | #undef HAVE_REALLOCARRAY 46 | #undef HAVE_REALLOCARR 47 | 48 | /* Always use malloc/realloc wrappers. */ 49 | #undef malloc 50 | #define malloc rpl_malloc 51 | #undef realloc 52 | #define realloc rpl_realloc 53 | 54 | /* The Bison-generated parser in flex code controls the use of alloca() through 55 | * its own macro (YYSTACK_USE_ALLOCA) and not defines from Autoconf. 56 | * alloca() is not used in other parts of flex code. 57 | */ 58 | #undef HAVE_ALLOCA_H 59 | #undef HAVE_ALLOCA 60 | #undef C_ALLOCA 61 | 62 | /* HAVE_INTTYPES_H is defined by Autoconf but not used in flex code. Flex has 63 | * flexint.h that provides fallback definitions. 64 | */ 65 | /* 66 | #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L 67 | # undef HAVE_INTTYPES_H 68 | #endif 69 | */ 70 | 71 | #undef HAVE_STDBOOL_H 72 | #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L 73 | # undef HAVE__BOOL 74 | #endif 75 | 76 | /* Standard C89 stuff which "configure" provides fallback #define's for. */ 77 | #ifndef __STDC__ 78 | # undef HAVE_LIMITS_H 79 | # define const /* const */ 80 | # define size_t unsigned int 81 | #endif 82 | -------------------------------------------------------------------------------- /src/flexint.h: -------------------------------------------------------------------------------- 1 | /* flex integer type definitions */ 2 | 3 | #ifndef FLEXINT_H 4 | #define FLEXINT_H 5 | 6 | /* C++ systems might need __STDC_LIMIT_MACROS defined before including 7 | * , if you want the limit (max/min) macros for int types. 8 | */ 9 | #ifndef __STDC_LIMIT_MACROS 10 | #define __STDC_LIMIT_MACROS 1 11 | #endif 12 | 13 | /* "flexint_shared.h" will be included also in skeleton. It will include 14 | * (if available) and define flex's integral types. 15 | */ 16 | #include "flexint_shared.h" 17 | 18 | /* Limits of integral types. */ 19 | #ifndef INT8_MIN 20 | #define INT8_MIN (-128) 21 | #endif 22 | #ifndef INT16_MIN 23 | #define INT16_MIN (-32767-1) 24 | #endif 25 | #ifndef INT32_MIN 26 | #define INT32_MIN (-2147483647-1) 27 | #endif 28 | #ifndef INT8_MAX 29 | #define INT8_MAX (127) 30 | #endif 31 | #ifndef INT16_MAX 32 | #define INT16_MAX (32767) 33 | #endif 34 | #ifndef INT32_MAX 35 | #define INT32_MAX (2147483647) 36 | #endif 37 | #ifndef UINT8_MAX 38 | #define UINT8_MAX (255U) 39 | #endif 40 | #ifndef UINT16_MAX 41 | #define UINT16_MAX (65535U) 42 | #endif 43 | #ifndef UINT32_MAX 44 | #define UINT32_MAX (4294967295U) 45 | #endif 46 | 47 | #ifndef INT_MAX 48 | #define INT_MAX ((int)(~0U)>>1) 49 | #endif 50 | #ifndef SIZE_MAX 51 | #define SIZE_MAX (~(size_t)0) 52 | #endif 53 | 54 | #endif /* ! FLEXINT_H */ 55 | -------------------------------------------------------------------------------- /src/flexint_shared.h: -------------------------------------------------------------------------------- 1 | /* flex integer type definitions */ 2 | 3 | #ifndef YYFLEX_INTTYPES_DEFINED 4 | #define YYFLEX_INTTYPES_DEFINED 5 | 6 | /* Prefer C99 integer types if available. */ 7 | 8 | # if defined(__cplusplus) && __cplusplus >= 201103L 9 | #include 10 | # define YYFLEX_USE_STDINT 11 | # endif 12 | # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 13 | /* Include and not because Solaris 2.6 has the former 14 | * and not the latter. 15 | */ 16 | #include 17 | # define YYFLEX_USE_STDINT 18 | # else 19 | # if defined(_MSC_VER) && _MSC_VER >= 1600 20 | /* Visual C++ 2010 does not define __STDC_VERSION__ and has but not 21 | * . 22 | */ 23 | #include 24 | # define YYFLEX_USE_STDINT 25 | # endif 26 | # endif 27 | # ifdef YYFLEX_USE_STDINT 28 | typedef int8_t flex_int8_t; 29 | typedef uint8_t flex_uint8_t; 30 | typedef int16_t flex_int16_t; 31 | typedef uint16_t flex_uint16_t; 32 | typedef int32_t flex_int32_t; 33 | typedef uint32_t flex_uint32_t; 34 | # else 35 | typedef unsigned char flex_uint8_t; 36 | typedef short int flex_int16_t; 37 | typedef unsigned short int flex_uint16_t; 38 | # ifdef __STDC__ 39 | typedef signed char flex_int8_t; 40 | /* ISO C only requires at least 16 bits for int. */ 41 | # ifdef __cplusplus 42 | #include 43 | # else 44 | #include 45 | # endif 46 | # if UINT_MAX >= 4294967295 47 | # define YYFLEX_INT32_DEFINED 48 | typedef int flex_int32_t; 49 | typedef unsigned int flex_uint32_t; 50 | # endif 51 | # else 52 | typedef char flex_int8_t; 53 | # endif 54 | # ifndef YYFLEX_INT32_DEFINED 55 | typedef long int flex_int32_t; 56 | typedef unsigned long int flex_uint32_t; 57 | # endif 58 | # endif 59 | #endif /* YYFLEX_INTTYPES_DEFINED */ 60 | -------------------------------------------------------------------------------- /src/gettext.h: -------------------------------------------------------------------------------- 1 | /* Convenience header for conditional use of GNU . 2 | Copyright (C) 1995-1998, 2000-2002 Free Software Foundation, Inc. 3 | 4 | This program is free software; you can redistribute it and/or modify it 5 | under the terms of the GNU Library General Public License as published 6 | by the Free Software Foundation; either version 2, or (at your option) 7 | any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 17 | USA. */ 18 | 19 | #ifndef _LIBGETTEXT_H 20 | #define _LIBGETTEXT_H 1 21 | 22 | /* NLS can be disabled through the configure --disable-nls option. */ 23 | #ifdef ENABLE_NLS 24 | 25 | /* Get declarations of GNU message catalog functions. */ 26 | # include 27 | 28 | #else 29 | 30 | /* Disabled NLS. 31 | The casts to 'const char *' serve the purpose of producing warnings 32 | for invalid uses of the value returned from these functions. 33 | On pre-ANSI systems without 'const', the config.h file is supposed to 34 | contain "#define const". */ 35 | # define gettext(Msgid) ((const char *) (Msgid)) 36 | # define dgettext(Domainname, Msgid) ((const char *) (Msgid)) 37 | # define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid)) 38 | # define ngettext(Msgid1, Msgid2, N) \ 39 | ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) 40 | # define dngettext(Domainname, Msgid1, Msgid2, N) \ 41 | ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) 42 | # define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ 43 | ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) 44 | # define textdomain(Domainname) ((const char *) (Domainname)) 45 | # define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname)) 46 | # define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset)) 47 | 48 | #endif 49 | 50 | /* A pseudo function call that serves as a marker for the automated 51 | extraction of messages, but does not call gettext(). The run-time 52 | translation is done at a different place in the code. 53 | The argument, String, should be a literal string. Concatenated strings 54 | and other string expressions won't work. 55 | The macro's expansion is not parenthesized, so that it is suitable as 56 | initializer for static 'char[]' or 'const char[]' variables. */ 57 | #define gettext_noop(String) String 58 | 59 | #endif /* _LIBGETTEXT_H */ 60 | -------------------------------------------------------------------------------- /src/libfl.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | 5 | Name: libfl 6 | Description: Flex (the fast lexical analyzer) support library 7 | Version: @PACKAGE_VERSION@ 8 | Libs: -L${libdir} -lfl 9 | -------------------------------------------------------------------------------- /src/libmain.c: -------------------------------------------------------------------------------- 1 | /* libmain - flex run-time support library "main" function */ 2 | 3 | /* This file is part of flex. */ 4 | 5 | /* Redistribution and use in source and binary forms, with or without */ 6 | /* modification, are permitted provided that the following conditions */ 7 | /* are met: */ 8 | 9 | /* 1. Redistributions of source code must retain the above copyright */ 10 | /* notice, this list of conditions and the following disclaimer. */ 11 | /* 2. Redistributions in binary form must reproduce the above copyright */ 12 | /* notice, this list of conditions and the following disclaimer in the */ 13 | /* documentation and/or other materials provided with the distribution. */ 14 | 15 | /* Neither the name of the University nor the names of its contributors */ 16 | /* may be used to endorse or promote products derived from this software */ 17 | /* without specific prior written permission. */ 18 | 19 | /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */ 20 | /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ 21 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 22 | /* PURPOSE. */ 23 | 24 | #include 25 | 26 | extern int yylex (void); 27 | 28 | int main (int argc, char *argv[]) 29 | { 30 | (void)argc; 31 | (void)argv; 32 | 33 | while (yylex () != 0) ; 34 | 35 | exit(0); 36 | } 37 | -------------------------------------------------------------------------------- /src/libyywrap.c: -------------------------------------------------------------------------------- 1 | /* libyywrap - flex run-time support library "yywrap" function */ 2 | 3 | /* This file is part of flex. */ 4 | 5 | /* Redistribution and use in source and binary forms, with or without */ 6 | /* modification, are permitted provided that the following conditions */ 7 | /* are met: */ 8 | 9 | /* 1. Redistributions of source code must retain the above copyright */ 10 | /* notice, this list of conditions and the following disclaimer. */ 11 | /* 2. Redistributions in binary form must reproduce the above copyright */ 12 | /* notice, this list of conditions and the following disclaimer in the */ 13 | /* documentation and/or other materials provided with the distribution. */ 14 | 15 | /* Neither the name of the University nor the names of its contributors */ 16 | /* may be used to endorse or promote products derived from this software */ 17 | /* without specific prior written permission. */ 18 | 19 | /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */ 20 | /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ 21 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 22 | /* PURPOSE. */ 23 | 24 | int yywrap (void); 25 | 26 | int yywrap (void) 27 | { 28 | return 1; 29 | } 30 | -------------------------------------------------------------------------------- /src/mkskel.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # This file is part of flex. 4 | 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions 7 | # are met: 8 | 9 | # 1. Redistributions of source code must retain the above copyright 10 | # notice, this list of conditions and the following disclaimer. 11 | # 2. Redistributions in binary form must reproduce the above copyright 12 | # notice, this list of conditions and the following disclaimer in the 13 | # documentation and/or other materials provided with the distribution. 14 | 15 | # Neither the name of the University nor the names of its contributors 16 | # may be used to endorse or promote products derived from this software 17 | # without specific prior written permission. 18 | 19 | # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 20 | # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 21 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | # PURPOSE. 23 | 24 | if test ! $# = 4; then 25 | echo 'Usage: mkskel.sh lang srcdir m4 version' >&2 26 | exit 1 27 | fi 28 | lang=$1 29 | srcdir=$2 30 | m4=$3 31 | VERSION=$(echo $4 | cut -d '-' -f 1) 32 | case $VERSION in 33 | *[!0-9.]*) echo 'Invalid version number' >&2; exit 1;; 34 | esac 35 | 36 | cr=`printf '\r'` 37 | 38 | IFS=. 39 | # we do want word splitting, so we won't put double quotes around it (see IFS above) 40 | # shellcheck disable=2086 41 | set -- $VERSION 42 | sed 's/4_/a4_/g 43 | s/m4preproc_/m4_/g 44 | ' "$srcdir/${lang}-flex.skl" | 45 | "$m4" -P -I "$srcdir" "-DFLEX_MAJOR_VERSION=$1" \ 46 | "-DFLEX_MINOR_VERSION=$2" \ 47 | "-DFLEX_SUBMINOR_VERSION=$3" | 48 | sed '/^%#/d 49 | s/m4_/m4preproc_/g 50 | s/a4_/4_/g 51 | s/[\\"]/\\&/g 52 | s/[^'"$cr"']*/ "&",/' 53 | -------------------------------------------------------------------------------- /src/scanflags.c: -------------------------------------------------------------------------------- 1 | /* scanflags - flags used by scanning. */ 2 | 3 | /* Copyright (c) 1990 The Regents of the University of California. */ 4 | /* All rights reserved. */ 5 | 6 | /* This code is derived from software contributed to Berkeley by */ 7 | /* Vern Paxson. */ 8 | 9 | /* The United States Government has rights in this work pursuant */ 10 | /* to contract no. DE-AC03-76SF00098 between the United States */ 11 | /* Department of Energy and the University of California. */ 12 | 13 | /* This file is part of flex. */ 14 | 15 | /* Redistribution and use in source and binary forms, with or without */ 16 | /* modification, are permitted provided that the following conditions */ 17 | /* are met: */ 18 | 19 | /* 1. Redistributions of source code must retain the above copyright */ 20 | /* notice, this list of conditions and the following disclaimer. */ 21 | /* 2. Redistributions in binary form must reproduce the above copyright */ 22 | /* notice, this list of conditions and the following disclaimer in the */ 23 | /* documentation and/or other materials provided with the distribution. */ 24 | 25 | /* Neither the name of the University nor the names of its contributors */ 26 | /* may be used to endorse or promote products derived from this software */ 27 | /* without specific prior written permission. */ 28 | 29 | /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */ 30 | /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ 31 | /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 32 | /* PURPOSE. */ 33 | 34 | #include "flexdef.h" 35 | 36 | scanflags_t* _sf_stk = NULL; 37 | size_t _sf_top_ix=0, _sf_max=0; 38 | 39 | void 40 | sf_push (void) 41 | { 42 | if (_sf_top_ix + 1 >= _sf_max) { 43 | _sf_max += 32; 44 | _sf_stk = realloc(_sf_stk, sizeof(scanflags_t) * _sf_max); 45 | } 46 | 47 | // copy the top element 48 | _sf_stk[_sf_top_ix + 1] = _sf_stk[_sf_top_ix]; 49 | ++_sf_top_ix; 50 | } 51 | 52 | void 53 | sf_pop (void) 54 | { 55 | assert(_sf_top_ix > 0); 56 | --_sf_top_ix; 57 | } 58 | 59 | /* one-time initialization. Should be called before any sf_ functions. */ 60 | void 61 | sf_init (void) 62 | { 63 | assert(_sf_stk == NULL); 64 | _sf_max = 32; 65 | _sf_stk = malloc(sizeof(scanflags_t) * _sf_max); 66 | if (!_sf_stk) 67 | lerr_fatal(_("Unable to allocate %zu of stack"), sizeof(scanflags_t)); 68 | _sf_stk[_sf_top_ix] = 0; 69 | } 70 | 71 | /* vim:set expandtab cindent tabstop=4 softtabstop=4 shiftwidth=4 textwidth=0: */ 72 | -------------------------------------------------------------------------------- /src/tables_shared.c: -------------------------------------------------------------------------------- 1 | #ifdef FLEX_SCANNER 2 | /* 3 | dnl tables_shared.c - tables serialization code 4 | dnl 5 | dnl Copyright (c) 1990 The Regents of the University of California. 6 | dnl All rights reserved. 7 | dnl 8 | dnl This code is derived from software contributed to Berkeley by 9 | dnl Vern Paxson. 10 | dnl 11 | dnl The United States Government has rights in this work pursuant 12 | dnl to contract no. DE-AC03-76SF00098 between the United States 13 | dnl Department of Energy and the University of California. 14 | dnl 15 | dnl This file is part of flex. 16 | dnl 17 | dnl Redistribution and use in source and binary forms, with or without 18 | dnl modification, are permitted provided that the following conditions 19 | dnl are met: 20 | dnl 21 | dnl 1. Redistributions of source code must retain the above copyright 22 | dnl notice, this list of conditions and the following disclaimer. 23 | dnl 2. Redistributions in binary form must reproduce the above copyright 24 | dnl notice, this list of conditions and the following disclaimer in the 25 | dnl documentation and/or other materials provided with the distribution. 26 | dnl 27 | dnl Neither the name of the University nor the names of its contributors 28 | dnl may be used to endorse or promote products derived from this software 29 | dnl without specific prior written permission. 30 | dnl 31 | dnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 32 | dnl IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 33 | dnl WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 34 | dnl PURPOSE. 35 | dnl 36 | */ 37 | 38 | /* This file is meant to be included in both the skeleton and the actual 39 | * flex code (hence the name "_shared"). 40 | */ 41 | #ifndef yyskel_static 42 | #define yyskel_static static 43 | #endif 44 | #else 45 | #include "flexdef.h" 46 | #include "tables.h" 47 | #ifndef yyskel_static 48 | #define yyskel_static 49 | #endif 50 | #endif 51 | 52 | 53 | /** Get the number of integers in this table. This is NOT the 54 | * same thing as the number of elements. 55 | * @param tbl the table 56 | * @return the number of integers in the table 57 | */ 58 | yyskel_static flex_int32_t yytbl_calc_total_len (const struct yytbl_data *tbl) 59 | { 60 | flex_uint32_t n; 61 | 62 | /* total number of ints */ 63 | n = tbl->td_lolen; 64 | if (tbl->td_hilen > 0) 65 | n *= tbl->td_hilen; 66 | 67 | if (tbl->td_id == YYTD_ID_TRANSITION) 68 | n *= 2; 69 | return (flex_int32_t) n; 70 | } 71 | -------------------------------------------------------------------------------- /src/version.h: -------------------------------------------------------------------------------- 1 | #define FLEX_VERSION VERSION 2 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | # common files generated by the test suite as it runs 2 | 3 | *.log 4 | *.trs 5 | *.tables 6 | *.o 7 | 8 | # test specific files 9 | 10 | alloc_extra_nr 11 | alloc_extra_nr.c 12 | alloc_extra_c99 13 | alloc_extra_c99.c 14 | array* 15 | !array.rules 16 | !array.txt 17 | basic* 18 | !basic.rules 19 | !basic.txt 20 | alloc_extra 21 | alloc_extra.c 22 | array_nr 23 | array_nr.c 24 | array_r 25 | array_r.c 26 | basic_nr 27 | basic_nr.c 28 | basic_r 29 | basic_r.c 30 | bison_nr 31 | bison_nr_scanner.[ch] 32 | bison_nr_parser.[ch] 33 | bison_yylloc 34 | bison_yylloc_parser.[ch] 35 | bison_yylloc_scanner.[ch] 36 | bison_yylval 37 | bison_yylval_parser.[ch] 38 | bison_yylval_scanner.[ch] 39 | bol* 40 | !bol.rules 41 | !bol.txt 42 | c_cxx_nr 43 | c_cxx_nr.cc 44 | c_cxx_r 45 | c_cxx_r.cc 46 | ccl* 47 | !ccl.rules 48 | !ccl.txt 49 | cxx_basic 50 | cxx_basic.cc 51 | cxx_multiple_scanners 52 | cxx_multiple_scanners_[12].cc 53 | cxx_restart 54 | cxx_restart.cc 55 | cxx_yywrap.i3 56 | cxx_yywrap.cc 57 | debug* 58 | !debug.rules 59 | !debug.txt 60 | extended* 61 | !extended.rules 62 | !extended.txt 63 | fixedtrailing* 64 | !fixedtrailing.rules 65 | !fixedtrailing.txt 66 | flexname* 67 | !flexname.rules 68 | !flexname.txt 69 | header_nr 70 | header_nr_scanner.[ch] 71 | header_r 72 | header_r_scanner.[ch] 73 | include_by_buffer.direct 74 | include_by_buffer.direct.c 75 | include_by_push.direct 76 | include_by_push.direct.c 77 | include_by_reentrant.direct 78 | include_by_reentrant.direct.c 79 | lexcompat* 80 | !lexcompat.rules 81 | !lexcompat.txt 82 | lineno* 83 | !lineno_generated.l.in 84 | !lineno.rules 85 | !lineno.txt 86 | mem_nr 87 | mem_nr.c 88 | mem_r 89 | mem_r.c 90 | mem_c99 91 | mem_c99.c 92 | multiple_scanners_nr 93 | multiple_scanners_nr_[12].[ch] 94 | multiple_scanners_r 95 | multiple_scanners_r_[12].[ch] 96 | posix* 97 | !posix.rules 98 | !posix.txt 99 | posixlycorrect* 100 | !posixlycorrect.rules 101 | !posixlycorrect.txt 102 | prefix_nr 103 | prefix_nr.c 104 | prefix_r 105 | prefix_r.c 106 | prefix_c99 107 | prefix_c99.c 108 | preposix* 109 | !preposix.rules 110 | !preposix.txt 111 | pthread.pthread 112 | pthread.c 113 | quoteincomment* 114 | !quoteincomment.rules 115 | !quoteincomment.txt 116 | quotes 117 | quotes.c 118 | reject* 119 | !reject.rules 120 | !reject.txt 121 | rescan_nr.direct 122 | rescan_nr.direct.c 123 | rescan_r.direct 124 | rescan_r.direct.c 125 | string_nr 126 | string_nr.c 127 | string_r 128 | string_r.c 129 | string_c99 130 | string_c99.c 131 | tableopts* 132 | !tableopts.rules 133 | !tableopts.txt 134 | top 135 | top.[ch] 136 | vartrailing* 137 | !vartrailing.rules 138 | !vartrailing.txt 139 | yyextra_nr 140 | yyextra_nr.c 141 | yyextra_c99 142 | yyextra_c99.c 143 | yyless* 144 | !yyless.rules 145 | !yyless.txt 146 | yymore* 147 | !yymore.rules 148 | !yymore.txt 149 | !yymorearray.rules 150 | !yymorearray.txt 151 | !yymorearraybol.rules 152 | !yymorearraybol.txt 153 | yyunput* 154 | !yyunput.rules 155 | !yyunput.txt 156 | test-yydecl-* 157 | !test-yydecl-gen.sh 158 | *.opt 159 | *.ser 160 | *.ver 161 | 162 | # for MSWindows 163 | 164 | *.obj 165 | *.exe 166 | -------------------------------------------------------------------------------- /tests/array.rules: -------------------------------------------------------------------------------- 1 | /* This file is part of flex. 2 | * 3 | * Redistribution and use in source and binary forms, with or without 4 | * modification, are permitted provided that the following conditions 5 | * are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 | * PURPOSE. 21 | */ 22 | %option 8bit 23 | %option nounput nomain noyywrap noinput 24 | %option warn array 25 | %% 26 | 27 | .|\n { } 28 | 29 | ### 30 | 0000 foo 1111 foo 0000 bar 31 | 0000 foo 1111 foo 0000 bar 32 | -------------------------------------------------------------------------------- /tests/array.txt: -------------------------------------------------------------------------------- 1 | 0000 foo 1111 foo 0000 bar 2 | 0000 foo 1111 foo 0000 bar 3 | -------------------------------------------------------------------------------- /tests/basic.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | /* TEST scanner. 25 | 26 | Sample Input: 27 | # this is a comment 28 | foo = true 29 | bar = "string value" 30 | integer = 43 31 | */ 32 | 33 | %option nounput noyywrap noyylineno warn nodefault noinput 34 | 35 | IDENT [[:alnum:]_-] 36 | WS [[:blank:]] 37 | %% 38 | 39 | ^{IDENT}+{WS}*={WS}*(true|false){WS}*\r?\n { return 100;} 40 | ^{IDENT}+{WS}*={WS}*\"[^\"\n\r]*\"{WS}*\r?\n { return 101;} 41 | ^{IDENT}+{WS}*={WS}*[[:digit:]]+{WS}*\r?\n { return 102;} 42 | ^{WS}*#.*\r?\n { } 43 | ^{WS}*\r?\n { } 44 | .|\n {M4_TEST_FAILMESSAGE} 45 | 46 | ### 47 | # this is a comment 48 | foo = "bar" 49 | num = 43 50 | setting = false 51 | 52 | -------------------------------------------------------------------------------- /tests/basic.txt: -------------------------------------------------------------------------------- 1 | # this is a comment 2 | foo = "bar" 3 | num = 43 4 | setting = false 5 | 6 | -------------------------------------------------------------------------------- /tests/bison_nr.txt: -------------------------------------------------------------------------------- 1 | 0001: FIRSTNAME=firstname 2 | 0002: MIDDLENAME=middle 3 | 0003: LASTNAME=lastname 4 | 0004: ADDRESS=address 5 | -------------------------------------------------------------------------------- /tests/bison_nr_main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | #include "bison_nr_parser.h" 25 | #include "bison_nr_scanner.h" 26 | 27 | 28 | int main ( int argc, char** argv ) 29 | { 30 | (void)argc; 31 | (void)argv; 32 | 33 | /*yydebug =1;*/ 34 | testin = stdin; 35 | testparse ( ); 36 | return 0; 37 | } 38 | 39 | 40 | 41 | /* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */ 42 | -------------------------------------------------------------------------------- /tests/bison_nr_parser.y: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | /* 25 | How to compile: 26 | bison --defines --output-file="parser.c" --name-prefix="test" parser.y 27 | */ 28 | %{ 29 | #include 30 | #include 31 | #include 32 | #include "config.h" 33 | #include "bison_nr_parser.h" 34 | #include "bison_nr_scanner.h" 35 | 36 | #define YYERROR_VERBOSE 1 37 | /* #define YYPARSE_PARAM scanner */ 38 | /* #define YYLEX_PARAM scanner */ 39 | 40 | int yyerror(const char* msg); 41 | 42 | 43 | /* A dummy function. A check against seg-faults in yylval->str. */ 44 | static int process_text(char* s) { 45 | int total =0; 46 | while(*s) { 47 | total += (int) *s; 48 | ++s; 49 | } 50 | return total; 51 | } 52 | 53 | 54 | %} 55 | 56 | %pure-parser 57 | 58 | %union { 59 | int lineno; 60 | char * str; 61 | } 62 | %token IDENT 63 | %token LINENO 64 | %token EQUAL "=" 65 | %token COLON ":" 66 | %token SPACE " " 67 | %% 68 | 69 | file: 70 | line 71 | | file line 72 | ; 73 | 74 | line: 75 | LINENO COLON SPACE IDENT EQUAL IDENT 76 | { 77 | process_text($4); 78 | process_text($6); 79 | /* Check lineno. */ 80 | if( $1 != @1.first_line || $1 != testget_lineno()) 81 | { 82 | yyerror("Parse failed: Line numbers do not match."); 83 | YYABORT; 84 | } 85 | 86 | /* Recreate the line to stdout. */ 87 | printf ( "%04d: %s=%s\n", @1.first_line, $4, $6); 88 | } 89 | ; 90 | 91 | %% 92 | 93 | int yyerror(const char* msg) { 94 | fprintf(stderr,"%s\n",msg); 95 | return 0; 96 | } 97 | 98 | -------------------------------------------------------------------------------- /tests/bison_nr_scanner.l: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* The scanner expects to link to bison yylval . */ 26 | #include 27 | #include 28 | #include "bison_nr_parser.h" 29 | #include "config.h" 30 | static char* STRDUP(char* s1); 31 | #define YY_EXTRA_TYPE int 32 | %} 33 | 34 | %option 8bit prefix="test" 35 | %option bison-locations yylineno 36 | %option prefix="test" header="bison_nr_scanner.h" yylineno 37 | %option nomain nounput noyy_top_state noyywrap nodefault noinput warn 38 | 39 | 40 | %% 41 | 42 | ^[[:digit:]]+ { 43 | yylval->lineno = yylineno; 44 | yylloc->first_line = (int)strtol(yytext,NULL,10); 45 | return LINENO; 46 | } 47 | ":" { return COLON; } 48 | " " { return SPACE; } 49 | "=" { return EQUAL; } 50 | [[:alnum:]_]+ { yylval->str = STRDUP(yytext); return IDENT;} 51 | 52 | \r|\n { } 53 | . { yyterminate();} 54 | %% 55 | 56 | 57 | static char* STRDUP(char* s1) 58 | { 59 | char* s2 = malloc(strlen(s1)+1); 60 | sprintf(s2,"%s",s1); 61 | return s2; 62 | } 63 | -------------------------------------------------------------------------------- /tests/bison_yylloc.txt: -------------------------------------------------------------------------------- 1 | 0001: FIRSTNAME=firstname 2 | 0002: MIDDLENAME=middle 3 | 0003: LASTNAME=lastname 4 | 0004: ADDRESS=address 5 | -------------------------------------------------------------------------------- /tests/bison_yylloc_main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | #include "bison_yylloc_parser.h" 25 | #include "bison_yylloc_scanner.h" 26 | 27 | int main ( int argc, char** argv ) 28 | { 29 | yyscan_t scanner; 30 | 31 | (void)argc; 32 | (void)argv; 33 | 34 | /*yydebug =1;*/ 35 | testlex_init ( &scanner ); 36 | testset_in(stdin,scanner); 37 | testparse ( scanner ); 38 | testlex_destroy ( scanner ); 39 | return 0; 40 | } 41 | 42 | 43 | 44 | /* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */ 45 | -------------------------------------------------------------------------------- /tests/bison_yylloc_parser.y: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %parse-param { void* scanner } 25 | %lex-param { void* scanner } 26 | 27 | /* 28 | How to compile: 29 | bison --defines --output-file="bison_yylloc_parser.c" --name-prefix="test" parser.y 30 | */ 31 | %{ 32 | #include 33 | #include 34 | #include 35 | #include "config.h" 36 | #include "bison_yylloc_parser.h" 37 | #include "bison_yylloc_scanner.h" 38 | 39 | int yyerror(YYLTYPE *location, void* scanner, const char* msg); 40 | 41 | #define YYERROR_VERBOSE 1 42 | 43 | 44 | /* A dummy function. A check against seg-faults in yylval->str. */ 45 | static int process_text(char* s) { 46 | int total =0; 47 | while(*s) { 48 | total += (int) *s; 49 | ++s; 50 | } 51 | return total; 52 | } 53 | 54 | 55 | %} 56 | 57 | %pure-parser 58 | 59 | %union { 60 | int lineno; 61 | char * str; 62 | } 63 | %token IDENT 64 | %token LINENO 65 | %token EQUAL "=" 66 | %token COLON ":" 67 | %token SPACE " " 68 | %% 69 | 70 | file: 71 | line 72 | | file line 73 | ; 74 | 75 | line: 76 | LINENO COLON SPACE IDENT EQUAL IDENT 77 | { 78 | process_text($4); 79 | process_text($6); 80 | /* Check lineno. */ 81 | if( $1 != @1.first_line || $1 != testget_lineno(scanner)) 82 | { 83 | yyerror(0, 0, "Parse failed: Line numbers do not match."); 84 | YYABORT; 85 | } 86 | 87 | /* Recreate the line to stdout. */ 88 | printf ( "%04d: %s=%s\n", @1.first_line, $4, $6); 89 | } 90 | ; 91 | 92 | %% 93 | 94 | int yyerror(YYLTYPE *location, void* scanner, const char* msg) { 95 | (void)location; 96 | (void)scanner; 97 | fprintf(stderr,"%s\n",msg); 98 | return 0; 99 | } 100 | 101 | -------------------------------------------------------------------------------- /tests/bison_yylloc_scanner.l: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* The scanner expects to link to bison yylval . */ 26 | #include 27 | #include 28 | #include "bison_yylloc_parser.h" 29 | #include "config.h" 30 | static char* STRDUP(char* s1); 31 | #define YY_EXTRA_TYPE int 32 | %} 33 | 34 | %option 8bit prefix="test" 35 | %option reentrant bison-bridge bison-locations yylineno 36 | %option header="bison_yylloc_scanner.h" 37 | %option nomain nounput noyy_top_state noyywrap nodefault noinput warn 38 | 39 | 40 | %% 41 | 42 | if ( !yyextra) 43 | yyextra = 1; 44 | 45 | ^[[:digit:]]+ { 46 | yylval->lineno = yyextra++; 47 | yylloc->first_line = (int)strtol(yytext,NULL,10); 48 | return LINENO; 49 | } 50 | ":" { return COLON; } 51 | " " { return SPACE; } 52 | "=" { return EQUAL; } 53 | [[:alnum:]_]+ { yylval->str = STRDUP(yytext); return IDENT;} 54 | 55 | \r|\n { } 56 | . { yyterminate();} 57 | %% 58 | 59 | 60 | static char* STRDUP(char* s1) 61 | { 62 | char* s2 = malloc(strlen(s1)+1); 63 | sprintf(s2,"%s",s1); 64 | return s2; 65 | } 66 | -------------------------------------------------------------------------------- /tests/bison_yylval.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | This is a test 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/bison_yylval_main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | #include "bison_yylval_parser.h" 25 | #include "bison_yylval_scanner.h" 26 | 27 | int main ( int argc, char** argv ) 28 | { 29 | yyscan_t scanner; 30 | 31 | (void)argc; 32 | (void)argv; 33 | 34 | /*yydebug =1;*/ 35 | testlex_init ( &scanner ); 36 | testset_in(stdin,scanner); 37 | testparse ( scanner ); 38 | testlex_destroy ( scanner ); 39 | return 0; 40 | } 41 | 42 | 43 | /* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */ 44 | -------------------------------------------------------------------------------- /tests/bison_yylval_parser.y: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | /* Accepts html-like input. 25 | How to compile: 26 | bison --defines --output-file="parser.c" --name-prefix="test" parser.y 27 | */ 28 | %parse-param { void* scanner } 29 | %lex-param { void* scanner } 30 | %{ 31 | #include 32 | #include 33 | #include 34 | #include "config.h" 35 | #include "bison_yylval_parser.h" 36 | #include "bison_yylval_scanner.h" 37 | 38 | #define YYERROR_VERBOSE 1 39 | 40 | int yyerror(void* scanner, const char* msg); 41 | 42 | /* A dummy function. A check against seg-faults in yylval->str. */ 43 | static int process_text(char* s) { 44 | int total =0; 45 | while(*s) { 46 | total += (int) *s; 47 | ++s; 48 | } 49 | return total; 50 | } 51 | 52 | 53 | %} 54 | 55 | %pure-parser 56 | 57 | %union { 58 | long unused; 59 | char * str; 60 | } 61 | 62 | %token TAGNAME TEXT 63 | %token LT 64 | %token GT 65 | %token LTSLASH " 27 | #include 28 | #include "bison_yylval_parser.h" 29 | #include "config.h" 30 | static char* STRDUP(char* s1); 31 | 32 | enum yesno_t { no=0, yes=1 }; 33 | #define YY_EXTRA_TYPE enum yesno_t 34 | %} 35 | 36 | %option 8bit prefix="test" 37 | %option reentrant bison-bridge 38 | %option header="bison_yylval_scanner.h" 39 | %option noyywrap nomain nounput noyy_top_state noyywrap nodefault noinput warn 40 | %option stack 41 | 42 | 43 | %x IN_TAG 44 | %x DISCARD_THRU_GT 45 | %% 46 | 47 | #define YY_USER_INIT yyextra = no; 48 | #define NEED_TAG_NAME yyextra 49 | 50 | 51 | { 52 | "str = STRDUP(yytext); return TEXT;} 56 | } 57 | { 58 | ">" { yy_pop_state( yyscanner ); return GT; } 59 | [[:alpha:]][[:alnum:]]* { 60 | if( NEED_TAG_NAME == yes){ 61 | NEED_TAG_NAME=no; 62 | yylval->str = STRDUP(yytext); 63 | return TAGNAME; 64 | } 65 | } 66 | 67 | .|\r|\n { } 68 | } 69 | { 70 | [^>]{1,512} { } 71 | ">" { yy_pop_state(yyscanner);} 72 | } 73 | %% 74 | 75 | 76 | static char* STRDUP(char* s1) 77 | { 78 | char* s2 = malloc(strlen(s1)+1); 79 | sprintf(s2,"%s",s1); 80 | return s2; 81 | } 82 | -------------------------------------------------------------------------------- /tests/bol.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | /* Test BOL matching, 25 | * If the ^ operator does not constrain pattern patching, these rules 26 | * will false-match on after :bar: the line of input and fail. 27 | */ 28 | 29 | %option nounput noyywrap noyylineno warn nodefault noinput 30 | %% 31 | ^foo {M4_TEST_FAILMESSAGE} 32 | .|\n {} 33 | 34 | ### 35 | barfoo 36 | -------------------------------------------------------------------------------- /tests/bol.txt: -------------------------------------------------------------------------------- 1 | barfoo 2 | -------------------------------------------------------------------------------- /tests/c_cxx_nr.lll: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* A template scanner file to build "scanner.c". 26 | The scanner is not really important -- we only care if 27 | it compiles under a c++ compiler, and runs. */ 28 | #include 29 | #include 30 | #include "config.h" 31 | /*#include "parser.h" */ 32 | 33 | %} 34 | 35 | %option 8bit prefix="test" 36 | %option nounput nomain noyywrap 37 | %option warn 38 | 39 | 40 | %% 41 | 42 | . { } 43 | 44 | %% 45 | 46 | int main(void); 47 | 48 | int 49 | main () 50 | { 51 | testin = stdin; 52 | testout = stdout; 53 | testlex(); 54 | testlex_destroy(); 55 | printf("TEST RETURNING OK.\n"); 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /tests/c_cxx_nr.txt: -------------------------------------------------------------------------------- 1 | 0000 foo 1111 foo 0000 bar 2 | 0000 foo 1111 foo 0000 bar 3 | -------------------------------------------------------------------------------- /tests/c_cxx_r.lll: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* A template scanner file to build "scanner.c". 26 | The scanner is not really important -- we only care if 27 | it compiles under a c++ compiler, and runs. */ 28 | #include 29 | #include 30 | #include "config.h" 31 | /*#include "parser.h" */ 32 | 33 | %} 34 | 35 | %option 8bit prefix="test" 36 | %option nounput nomain noyywrap 37 | %option warn reentrant 38 | 39 | 40 | %% 41 | 42 | . { } 43 | 44 | %% 45 | 46 | int main(void); 47 | 48 | int 49 | main () 50 | { 51 | yyscan_t lexer; 52 | testlex_init( &lexer ); 53 | testset_out ( stdout,lexer); 54 | testset_in ( stdin, lexer); 55 | while( testlex(lexer) ) 56 | { 57 | } 58 | testlex_destroy( lexer ); 59 | printf("TEST RETURNING OK.\n"); 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /tests/c_cxx_r.txt: -------------------------------------------------------------------------------- 1 | 0000 foo 1111 foo 0000 bar 2 | 0000 foo 1111 foo 0000 bar 3 | -------------------------------------------------------------------------------- /tests/ccl.txt: -------------------------------------------------------------------------------- 1 | ^alpha:0123456789 ~!@#$%^&*(){}[]':;"<>,./?\+=_-`@alpha@ 2 | ^digit:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ~!@#$%^&*(){}[]':;"<>,./?\+=_-`@digit@ 3 | ^alnum:~!@#$%^&*(){}[]':;"<>,./?\+=_-`@alnum@ 4 | ^upper:abcdefghijklmnopqrstuvwxyz0123456789 ~!@#$%^&*(){}[]':;"<>,./?\+=_-`@upper@ 5 | ^lower:ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEF ~!@#$%^&*(){}[]':;"<>,./?\+=_-`@lower@ 6 | ^space:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEF~!@#$%^&*(){}[]':;"<>,./?\+=_-`@space@ 7 | ^blank:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEF~!@#$%^&*(){}[]':;"<>,./?\+=_-`@blank@ 8 | ^punct:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEF Z@punct@ 9 | ^cntrl:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEF~!@#$%^&*(){}[]':;"<>,./?\+=_-`@cntrl@ 10 | ^xdigit:ghijklmnopqrstuvwxyzGHIJKLMNOPQRSTUVWXYZ ~!@#$%^&*(){}[]':;"<>,./?\+=_-`@xdigit@ 11 | a-d:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@a-d@ 12 | l-xyz:abcdefghijklmnopqrstuvw@l-xyz@ 13 | abcd-bc:aaaaddddaaaa@abcd-bc@ 14 | abcde-b-c:aaaaddddeeee@abcde-b-c@ 15 | ^XY-^XYZ:ZZZZZZZZZZZ@^XY-^XYZ@ 16 | a+d:abc0123xyz789@a+d@ 17 | a-u+Q:abcQQQQxyz@a-u+Q@ 18 | ia:AaAa@ia@ 19 | iabc:ABCabcAbCaBc@iabc@ 20 | ia-c:ABCabcAbCaBc@ia-c@ 21 | check-a:a@ 22 | dot-all-1:XXX junk 23 | junk 24 | junk 25 | @dot-all-1@ 26 | x1:abaabb@x1@ 27 | x2:abaabb@x2@ 28 | -------------------------------------------------------------------------------- /tests/cxx_basic.ll: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | 26 | #include "config.h" 27 | 28 | %} 29 | 30 | %option 8bit prefix="test" 31 | %option warn c++ 32 | %option nounput nomain noinput noyywrap 33 | 34 | %% 35 | 36 | . { } 37 | 38 | %% 39 | 40 | int main(void); 41 | 42 | int 43 | main (void) 44 | { 45 | yyFlexLexer f; 46 | f.switch_streams(&std::cin, &std::cout); 47 | f.yylex(); 48 | std::cout << "TEST RETURNING OK." << std::endl; 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /tests/cxx_basic.txt: -------------------------------------------------------------------------------- 1 | 0000 foo 1111 foo 0000 bar 2 | 0000 foo 1111 foo 0000 bar 3 | -------------------------------------------------------------------------------- /tests/cxx_multiple_scanners.txt: -------------------------------------------------------------------------------- 1 | foo on bar off 2 | -------------------------------------------------------------------------------- /tests/cxx_multiple_scanners_1.ll: -------------------------------------------------------------------------------- 1 | // This file is part of flex. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions 5 | // are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // 2. Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // 13 | // Neither the name of the University nor the names of its contributors 14 | // may be used to endorse or promote products derived from this software 15 | // without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 18 | // IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 19 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 | // PURPOSE. 21 | 22 | %{ 23 | #include "config.h" 24 | 25 | %} 26 | 27 | %option 8bit prefix="S1_" 28 | %option nounput nomain noyywrap 29 | %option warn stack noyy_top_state 30 | 31 | %x ON 32 | %x OFF 33 | %% 34 | { 35 | on yy_push_state(ON); return 10; 36 | off yy_push_state(OFF); return 11; 37 | .|\n return 12; 38 | } 39 | .|\n yy_pop_state(); return 13; 40 | 41 | .|\n yy_pop_state(); return 14; 42 | 43 | %% 44 | 45 | -------------------------------------------------------------------------------- /tests/cxx_multiple_scanners_2.ll: -------------------------------------------------------------------------------- 1 | // This file is part of flex. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions 5 | // are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // 2. Redistributions in binary form must reproduce the above copyright 10 | // notice, this list of conditions and the following disclaimer in the 11 | // documentation and/or other materials provided with the distribution. 12 | // 13 | // Neither the name of the University nor the names of its contributors 14 | // may be used to endorse or promote products derived from this software 15 | // without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 18 | // IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 19 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 | // PURPOSE. 21 | 22 | %{ 23 | #include "config.h" 24 | 25 | %} 26 | 27 | %option 8bit prefix="S2_" 28 | %option nounput nomain 29 | %option warn stack noyy_top_state 30 | 31 | %x OFF 32 | %x ON 33 | %% 34 | { 35 | on yy_push_state(ON); return 3; 36 | off yy_push_state(OFF); return 4; 37 | .|\n return 5; 38 | } 39 | .|\n yy_pop_state(); return 6; 40 | 41 | .|\n yy_pop_state(); return 7; 42 | %% 43 | 44 | int S2_FlexLexer::yywrap() 45 | { 46 | std::cout << "NOW WRAPPING." << std::endl; 47 | return 1; 48 | } 49 | -------------------------------------------------------------------------------- /tests/cxx_multiple_scanners_main.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | #include 25 | 26 | #undef yyFlexLexer 27 | #define yyFlexLexer S1_FlexLexer 28 | #include 29 | 30 | #undef yyFlexLexer 31 | #define yyFlexLexer S2_FlexLexer 32 | #include 33 | 34 | int 35 | main ( int argc, char** argv ) 36 | { 37 | int S1_ok=1, S2_ok=1; 38 | S1_FlexLexer* S1 = new S1_FlexLexer; 39 | S2_FlexLexer* S2 = new S2_FlexLexer; 40 | 41 | // scan simultaneously. 42 | while(S1_ok || S2_ok) 43 | { 44 | if (S1_ok) 45 | S1_ok = S1->yylex(); 46 | if (S2_ok) 47 | S2_ok = S2->yylex(); 48 | } 49 | printf("TEST RETURNING OK.\n"); 50 | delete S1; 51 | delete S2; 52 | return 0; 53 | } 54 | 55 | 56 | /* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */ 57 | -------------------------------------------------------------------------------- /tests/cxx_restart.ll: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | 26 | #include "config.h" 27 | 28 | %} 29 | 30 | %option 8bit prefix="test" 31 | %option warn c++ 32 | %option nounput nomain noinput noyywrap 33 | 34 | %% 35 | 36 | . { } 37 | 38 | %% 39 | 40 | int main(void); 41 | 42 | int 43 | main (void) 44 | { 45 | yyFlexLexer f; 46 | f.switch_streams(&std::cin, &std::cout); 47 | f.yylex(); 48 | f.yyrestart(NULL); 49 | std::cout << "TEST RETURNING OK." << std::endl; 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /tests/cxx_restart.txt: -------------------------------------------------------------------------------- 1 | 0000 foo 1111 foo 0000 bar 2 | 0000 foo 1111 foo 0000 bar 3 | -------------------------------------------------------------------------------- /tests/cxx_yywrap.ll: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | 26 | #include "config.h" 27 | #include 28 | 29 | %} 30 | 31 | %option 8bit prefix="test" 32 | %option nounput nomain 33 | %option warn c++ 34 | 35 | 36 | %% 37 | 38 | . { } 39 | 40 | %% 41 | 42 | #define MAX_FILES 10 43 | 44 | char *files[MAX_FILES] = { 0 }; 45 | int filecounter = 0; 46 | 47 | int testFlexLexer::yywrap() 48 | { 49 | if (filecounter-- > 0) { 50 | std::cout << "NOW WRAPPING TO READ " << files[filecounter] << std::endl; 51 | std::ifstream *ifs = new std::ifstream(files[filecounter]); 52 | switch_streams(ifs); 53 | return 0; 54 | } 55 | return 1; 56 | } 57 | 58 | int 59 | main (int argc, char *argv[]) 60 | { 61 | for (int i = 1; i < argc && i <= MAX_FILES; i++) { 62 | files[i-1] = argv[i]; 63 | filecounter++; 64 | } 65 | testFlexLexer* f = new testFlexLexer; 66 | f->yywrap(); 67 | f->yylex(); 68 | std::cout << "TEST RETURNING OK." << std::endl; 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /tests/cxx_yywrap.txt: -------------------------------------------------------------------------------- 1 | 0000 foo 1111 foo 0000 bar 2 | 0000 foo 1111 foo 0000 bar 3 | -------------------------------------------------------------------------------- /tests/debug.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | define(`M4_TEST_ENABLEDEBUG', `') 24 | 25 | %option 8bit 26 | %option nounput nomain noyywrap noinput 27 | %option warn debug 28 | 29 | %% 30 | .+ { } 31 | \n { } 32 | ### 33 | Any input will do for this test. 34 | We are only testing if it actually runs in debug mode. 35 | -------------------------------------------------------------------------------- /tests/debug.txt: -------------------------------------------------------------------------------- 1 | Any input will do for this test. 2 | We are only testing if it actually runs in debug mode. 3 | -------------------------------------------------------------------------------- /tests/extended.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | /* Output should match the input. */ 24 | 25 | %option 8bit nounput nomain noyywrap noinput warn 26 | %% 27 | 28 | abc(?# Single Line Comment )def {M4_TEST_DO(yyecho())} 29 | ghi(?# 30 | multi-line 31 | comment 32 | )jkl {M4_TEST_DO(yyecho())} 33 | 34 | mno(?# 35 | multi-line // 36 | comment with ## 37 | ~~!@#$ %^&*(@-_+=\|,.<>/ ?: ; 38 | punctuation 39 | )pqr {M4_TEST_DO(yyecho())} 40 | (?# Start of a rule.)stu {M4_TEST_DO(yyecho())} 41 | vwxyz(?#End of a rule.) {M4_TEST_DO(yyecho())} 42 | A(?x: B 43 | /* comment */ 44 | C D) {M4_TEST_DO(yyecho())} 45 | 46 | \n {M4_TEST_DO(yyecho())} 47 | ### 48 | abcdefghijklmnopqrstuvwxyz 49 | ABCD 50 | -------------------------------------------------------------------------------- /tests/extended.txt: -------------------------------------------------------------------------------- 1 | abcdefghijklmnopqrstuvwxyz 2 | ABCD 3 | -------------------------------------------------------------------------------- /tests/fixedtrailing.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | /* 25 | * Test rules with variable trailing context. 26 | * Input should match first rule, but only 27 | * consume the "foo". Therefore the second 28 | * rule should not match, but the third should. 29 | */ 30 | 31 | %option nounput noyywrap noyylineno warn nodefault noinput 32 | 33 | %% 34 | 35 | foo/a+ {M4_TEST_ASSERT(yyleng== 3)} 36 | foo {M4_TEST_FAILMESSAGE} 37 | aa { } 38 | \n { } 39 | . {M4_TEST_FAILMESSAGE} 40 | 41 | ### 42 | fooaa 43 | -------------------------------------------------------------------------------- /tests/fixedtrailing.txt: -------------------------------------------------------------------------------- 1 | fooaa 2 | -------------------------------------------------------------------------------- /tests/flexname.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | /* 25 | * Test Lex incompatibility. This is the compatibility exanmple from 26 | * the documentation; with !lex-compat it *should* match the string "foo". 27 | * For the complementary test, see lexcompat.rules. 28 | */ 29 | %option nounput nomain noyywrap noinput 30 | %option warn nolex-compat 31 | 32 | NAME [A-Z][A-Z0-9]* 33 | %% 34 | foo{NAME}? {M4_TEST_DO(yyecho())} 35 | \n {M4_TEST_DO(yyecho())} 36 | . {M4_TEST_FAILMESSAGE} 37 | ### 38 | foo 39 | -------------------------------------------------------------------------------- /tests/flexname.txt: -------------------------------------------------------------------------------- 1 | foo 2 | -------------------------------------------------------------------------------- /tests/header_nr.txt: -------------------------------------------------------------------------------- 1 | Any input is ok for this scanner. 2 | We only care if it links. 3 | 4 | -------------------------------------------------------------------------------- /tests/header_nr_main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | #include "header_nr_scanner.h" 25 | 26 | int 27 | main ( int argc, char** argv ) 28 | { 29 | (void)argc; 30 | (void)argv; 31 | 32 | testin = stdin; 33 | testout = stdout; 34 | testlex(); 35 | printf("TEST RETURNING OK.\n"); 36 | return 0; 37 | } 38 | 39 | 40 | /* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */ 41 | -------------------------------------------------------------------------------- /tests/header_nr_scanner.l: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* A template scanner file to build "scanner.c". */ 26 | #include 27 | #include 28 | #include "config.h" 29 | 30 | %} 31 | 32 | %option 8bit prefix="test" header="header_nr_scanner.h" 33 | %option nounput nomain noyywrap noinput 34 | %option warn 35 | 36 | 37 | %% 38 | 39 | .|\n { } 40 | 41 | %% 42 | 43 | -------------------------------------------------------------------------------- /tests/header_r.txt: -------------------------------------------------------------------------------- 1 | Any input is ok for this scanner. 2 | We only care if it links. 3 | 4 | -------------------------------------------------------------------------------- /tests/header_r_main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | #include 25 | 26 | #include "header_r_scanner.h" 27 | 28 | /* The scanner itself is not important here. 29 | * We simply try to use all the functions that are exported in the 30 | * header, to see if we get any compiler warnings. 31 | */ 32 | int 33 | main ( int argc, char** argv ) 34 | { 35 | (void)argc; 36 | (void)argv; 37 | 38 | yyscan_t scanner; 39 | FILE *fp; 40 | char * extra = "EXTRA"; 41 | 42 | testlex_init(&scanner); 43 | testset_in(stdin,scanner); 44 | testset_out(stdout,scanner); 45 | testset_extra(extra,scanner); 46 | 47 | fp = testget_in(scanner); 48 | assert(fp == stdin); 49 | fp = testget_out(scanner); 50 | assert(fp == stdout); 51 | 52 | while(testlex(scanner)) { 53 | char * text; 54 | int line; 55 | line = testget_lineno(scanner); 56 | text = testget_text(scanner); 57 | 58 | if( (char*)testget_extra(scanner) != extra) 59 | break; 60 | 61 | if ( !text || line < 0) 62 | continue; 63 | } 64 | testlex_destroy(scanner); 65 | printf("TEST RETURNING OK.\n"); 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /tests/header_r_scanner.l: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* Build "scanner.c". 26 | The scanner is not important. 27 | This test is really about compilation. See "main.c". 28 | */ 29 | #include 30 | #include 31 | #include "config.h" 32 | 33 | %} 34 | 35 | %option reentrant 36 | %option 8bit prefix="test" header="header_r_scanner.h" 37 | %option nounput nomain noyywrap noinput 38 | %option warn 39 | 40 | 41 | %% 42 | 43 | .|\n { } 44 | 45 | %% 46 | 47 | -------------------------------------------------------------------------------- /tests/include_by_buffer.direct.txt: -------------------------------------------------------------------------------- 1 | Beginning of "include_by_buffer.direct.txt" 2 | #include 3 | End of "include_by_buffer.direct.txt" 4 | -------------------------------------------------------------------------------- /tests/include_by_buffer.direct_2.txt: -------------------------------------------------------------------------------- 1 | Beginning of "include_by_buffer.direct_2.txt" 2 | #include 3 | End of "include_by_buffer.direct_2.txt" 4 | -------------------------------------------------------------------------------- /tests/include_by_buffer.direct_3.txt: -------------------------------------------------------------------------------- 1 | Beginning of "include_by_buffer.direct_3.txt" 2 | End of "include_by_buffer.direct_3.txt" 3 | -------------------------------------------------------------------------------- /tests/include_by_push.direct.l: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* A scanner file to build "scanner.c". 26 | Input language is any text. 27 | "#include " causes a buffer switch. 28 | */ 29 | #include 30 | #include 31 | #include "config.h" 32 | 33 | int error = 0; 34 | %} 35 | 36 | %option 8bit prefix="test" 37 | %option nounput nomain noyywrap noinput 38 | %option warn 39 | 40 | %x GET_FILENAME 41 | 42 | %% 43 | 44 | { 45 | ^"#include"[[:blank:]]+"<" { yybegin(GET_FILENAME); } 46 | .|\n { yyecho(); } 47 | } 48 | 49 | { 50 | [[:alnum:]_.-]+> { 51 | /* recurse */ 52 | yytext[yyleng-1]='\0'; 53 | if((yyin=fopen(yytext,"r"))==NULL) { 54 | fprintf(stderr,"*** Error: Could not open include file \"%s\".\n",yytext); 55 | error = 1; 56 | yyterminate(); 57 | } 58 | testpush_buffer_state( yy_create_buffer( yyin, YY_BUF_SIZE )); 59 | yybegin(0); 60 | } 61 | .|\n { 62 | fprintf(stderr,"Invalid input \"%s\".\n", yytext); 63 | error = 1; 64 | yyterminate(); 65 | } 66 | } 67 | 68 | <> { 69 | fclose(yyin); 70 | testpop_buffer_state(); 71 | if(!yy_current_buffer()) 72 | yyterminate(); 73 | } 74 | 75 | %% 76 | 77 | int main(int argc, char** argv); 78 | 79 | int 80 | main ( int argc, char** argv ) 81 | { 82 | FILE * fp; 83 | if( argc != 2 ) { 84 | fprintf(stderr,"*** Error: Must specify one filename.\n"); 85 | exit(-1); 86 | } 87 | if((fp=fopen(argv[1],"r"))==NULL) { 88 | fprintf(stderr,"*** Error: fopen(%s) failed.\n",argv[1]); 89 | exit(-1); 90 | } 91 | yyin = fp; 92 | yyout = stdout; 93 | yylex(); 94 | if (!error) 95 | printf("TEST RETURNING OK.\n"); 96 | else 97 | exit(-1); 98 | return 0; 99 | } 100 | -------------------------------------------------------------------------------- /tests/include_by_push.direct.txt: -------------------------------------------------------------------------------- 1 | Beginning of "include_by_push.direct.txt" 2 | #include 3 | End of "include_by_push.direct.txt" 4 | -------------------------------------------------------------------------------- /tests/include_by_push.direct_2.txt: -------------------------------------------------------------------------------- 1 | Beginning of "include_by_push.direct_2.txt" 2 | #include 3 | End of "include_by_push.direct_2.txt" 4 | -------------------------------------------------------------------------------- /tests/include_by_push.direct_3.txt: -------------------------------------------------------------------------------- 1 | Beginning of "include_by_push.direct_3.txt" 2 | End of "include_by_push.direct_3.txt" 3 | -------------------------------------------------------------------------------- /tests/include_by_reentrant.direct.l: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* A scanner file to build "scanner.c". 26 | Input language is any text. 27 | "#include " causes a new scanner to be created. 28 | */ 29 | #include 30 | #include 31 | #include "config.h" 32 | 33 | int error = 0; 34 | %} 35 | 36 | %option 8bit prefix="test" 37 | %option nounput nomain noyywrap noinput 38 | %option reentrant 39 | %option warn 40 | 41 | %x GET_FILENAME 42 | 43 | %% 44 | 45 | { 46 | ^"#include"[[:blank:]]+"<" { yybegin(GET_FILENAME); } 47 | .|\n { yyecho(); } 48 | } 49 | 50 | { 51 | [[:alnum:]_.-]+> { 52 | /* recurse */ 53 | yyscan_t scanner; 54 | FILE * fp; 55 | yytext[yyleng-1]='\0'; 56 | if((fp=fopen(yytext,"r"))==NULL) { 57 | fprintf(stderr,"*** Error: Could not open include file \"%s\".\n", 58 | yytext); 59 | error = 1; 60 | yyterminate(); 61 | } 62 | testlex_init(&scanner); 63 | testset_in( fp, scanner); 64 | testset_out( stdout, scanner); 65 | testlex(scanner); 66 | testlex_destroy(scanner); 67 | 68 | yybegin(0); 69 | } 70 | .|\n { 71 | fprintf(stderr,"Invalid input \"%s\".\n", yytext); 72 | error = 1; 73 | yyterminate(); 74 | } 75 | } 76 | 77 | <> { fclose(yyin); yyterminate();} 78 | 79 | %% 80 | 81 | int main (int argc, char** argv); 82 | 83 | int 84 | main ( int argc, char **argv ) 85 | { 86 | FILE * fp; 87 | yyscan_t scanner; 88 | if( argc != 2 ) { 89 | fprintf(stderr,"*** Error: Must specify one filename.\n"); 90 | exit(-1); 91 | } 92 | if((fp=fopen(argv[1],"r"))==NULL) { 93 | fprintf(stderr,"*** Error: fopen(%s) failed.\n",argv[1]); 94 | exit(-1); 95 | } 96 | testlex_init(&scanner); 97 | testset_in( fp, scanner); 98 | testset_out( stdout, scanner); 99 | testlex(scanner); 100 | testlex_destroy(scanner); 101 | if (!error) 102 | printf("TEST RETURNING OK.\n"); 103 | else 104 | exit(-1); 105 | return 0; 106 | } 107 | -------------------------------------------------------------------------------- /tests/include_by_reentrant.direct.txt: -------------------------------------------------------------------------------- 1 | Beginning of "include_by_reentrant.direct.txt". 2 | #include 3 | End of "include_by_reentrant.direct.txt". 4 | -------------------------------------------------------------------------------- /tests/include_by_reentrant.direct_2.txt: -------------------------------------------------------------------------------- 1 | Beginning of "include_by_reentrant.direct_2.txt". 2 | #include 3 | End of "include_by_reentrant.direct_2.txt". 4 | -------------------------------------------------------------------------------- /tests/include_by_reentrant.direct_3.txt: -------------------------------------------------------------------------------- 1 | Beginning of "include_by_reentrant.direct_3.txt". 2 | End of "include_by_reentrant.direct_3.txt". 3 | -------------------------------------------------------------------------------- /tests/lexcompat.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | /* 25 | * Test Lex compatibility. This is the compatibility example from 26 | * the documentation; with lex-compat it should *not* match the string 27 | * "foo". For the complementary test, see flexname.rules. 28 | */ 29 | %option nounput nomain noyywrap noinput 30 | %option warn lex-compat 31 | 32 | NAME [A-Z][A-Z0-9]* 33 | %% 34 | foo{NAME}? {M4_TEST_FAILMESSAGE} 35 | \n {M4_TEST_DO(yyecho())} 36 | . {M4_TEST_DO(yyecho())} 37 | ### 38 | foo 39 | -------------------------------------------------------------------------------- /tests/lexcompat.txt: -------------------------------------------------------------------------------- 1 | foo 2 | -------------------------------------------------------------------------------- /tests/lineno.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | /* The goal here is to test the yylineno processing by: 25 | * - providing some rules than CAN match newlines and 26 | * other rules that can NOT match newlines, 27 | * - matching several newlines in one rule, 28 | * - directly modifying yylineno. 29 | * FIXME: Exposes a bug, probably in the Flex scanner. 30 | * If "--yylineno" in the action is "yylineno--", the pattern 31 | * is not recognized and the magic rewrite rule for yylineo 32 | * does not fire. Only an issue for non-default back ends that 33 | * do magic rewrites rather than relying on the C preprocessor. 34 | */ 35 | %option 8bit 36 | %option nounput nomain noyywrap noinput yylineno 37 | %option warn 38 | 39 | WORD [[:alpha:]]+ 40 | DIGIT [[:digit:]] 41 | 42 | %% 43 | "yylineno++" M4_TEST_INCREMENT(yylineno); 44 | "yylineno--" M4_TEST_DECREMENT(yylineno); 45 | [[:blank:]]+ 46 | {WORD} 47 | {DIGIT}+(\n{DIGIT}+)* 48 | \n 49 | . 50 | <> {M4_TEST_ASSERT(yylineno == 20) M4_TEST_DO(yyterminate())} 51 | 52 | ### 53 | These words 54 | are separated 55 | by newlines 56 | and sometimes 57 | spaces 58 | too. 59 | The next three lines are numbers with only intervening newlines 60 | 01123 61 | 581321 62 | 34 63 | And now for some blank lines.... 64 | 65 | 66 | Finally, we directly modify yylineno, but then change it back afterwards 67 | (see scanner.l): 68 | 69 | yylineno++ 70 | 71 | yylineno-- 72 | -------------------------------------------------------------------------------- /tests/lineno.txt: -------------------------------------------------------------------------------- 1 | These words 2 | are separated 3 | by newlines 4 | and sometimes 5 | spaces 6 | too. 7 | The next three lines are numbers with only intervening newlines 8 | 01123 9 | 581321 10 | 34 11 | And now for some blank lines.... 12 | 13 | 14 | Finally, we directly modify yylineno, but then change it back afterwards 15 | (see scanner.l): 16 | 17 | yylineno++ 18 | 19 | yylineno-- 20 | -------------------------------------------------------------------------------- /tests/lineno_generated.l.in: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* Test generated line numbers. Be careful editing this file 26 | as it's all about ensuring flex generates correct line 27 | directives, so the @LINE@ markers must be on the same line as a 28 | their corresponding __LINE__ macros. 29 | */ 30 | #include 31 | #include "config.h" 32 | 33 | static int defs_percent_expect = @LINE@, defs_percent_got = __LINE__; 34 | static int error_count = 0; 35 | 36 | static void test_line (const char *desc, int expect, int got); 37 | 38 | %} 39 | 40 | static int defs_indent_expect = @LINE@, defs_indent_got = __LINE__; 41 | 42 | %option nounput noyywrap noinput 43 | %option warn 44 | 45 | %% 46 | test_line ("prolog indent", @LINE@, __LINE__); 47 | %{ 48 | test_line ("prolog percent", @LINE@, __LINE__); 49 | %} 50 | \n { test_line ("rules braced", @LINE@, __LINE__); } 51 | . test_line ("rules bare", @LINE@, __LINE__); 52 | 53 | %% 54 | 55 | static void 56 | test_line (const char *desc, int expect, int got) 57 | { 58 | printf ("%s: expect: %d got: %d\n", desc, expect, got); 59 | error_count += expect != got; 60 | } 61 | 62 | int 63 | main (void) 64 | { 65 | yybuffer buffer = yy_scan_string ("a\na\n"); 66 | yylex (); 67 | yy_delete_buffer (buffer); 68 | test_line ("defs percent", defs_percent_expect, defs_percent_got); 69 | test_line ("defs indent", defs_indent_expect, defs_indent_got); 70 | test_line ("user code", @LINE@, __LINE__); 71 | 72 | return error_count != 0; 73 | } 74 | -------------------------------------------------------------------------------- /tests/mem.txt: -------------------------------------------------------------------------------- 1 | First we push a lot on the stack by nesting parenthesis: 2 | 3 | (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((( 4 | (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((( 5 | ((((((((((((((((((((((((((((((((((((((((((( 6 | 7 | (should be 200 states pushed here) 8 | 9 | )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) 10 | )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) 11 | ))))))))))))))))))))))))))))))))))))))))))) 12 | 13 | Now we match progressively bigger tokens to increase the read buffer: 14 | 15 | len=1 0 16 | len=2 00 17 | len=4 0000 18 | len=8 00000000 19 | len=16 0000000000000000 20 | len=32 00000000000000000000000000000000 21 | len=64 0000000000000000000000000000000000000000000000000000000000000000 22 | len=128 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 23 | len=256 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 24 | len=512 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 25 | len=1024 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 26 | -------------------------------------------------------------------------------- /tests/multiple_scanners_nr_1.l: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* A template scanner file to build "scanner-1.c" and "scanner-1.h". */ 26 | #include 27 | #include 28 | #include "config.h" 29 | 30 | %} 31 | 32 | %option header="multiple_scanners_nr_1.h" 33 | %option 8bit prefix="S1_" 34 | %option nounput nomain noyywrap noinput 35 | %option warn stack noyy_top_state 36 | 37 | %x ON 38 | %x OFF 39 | %% 40 | { 41 | on yy_push_state(ON); return 10; 42 | off yy_push_state(OFF); return 11; 43 | .|\n return 12; 44 | } 45 | .|\n yy_pop_state(); return 13; 46 | 47 | .|\n yy_pop_state(); return 14; 48 | 49 | %% 50 | 51 | -------------------------------------------------------------------------------- /tests/multiple_scanners_nr_2.l: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* A template scanner file to build "scanner-2.c" and "scanner-2.h". */ 26 | #include 27 | #include 28 | #include "config.h" 29 | 30 | %} 31 | 32 | %option header="multiple_scanners_nr_2.h" 33 | %option 8bit prefix="S2_" 34 | %option nounput nomain noyywrap noinput 35 | %option warn stack noyy_top_state 36 | 37 | %x OFF 38 | %x ON 39 | %% 40 | { 41 | on yy_push_state(ON); return 3; 42 | off yy_push_state(OFF); return 4; 43 | .|\n return 5; 44 | } 45 | .|\n yy_pop_state(); return 6; 46 | 47 | .|\n yy_pop_state(); return 7; 48 | %% 49 | 50 | -------------------------------------------------------------------------------- /tests/multiple_scanners_nr_main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | #include "multiple_scanners_nr_1.h" 25 | #include "multiple_scanners_nr_2.h" 26 | 27 | int 28 | main ( int argc, char** argv ) 29 | { 30 | (void)argc; 31 | (void)argv; 32 | 33 | int S1_ok=1, S2_ok=1; 34 | yybuffer buff1, buff2; 35 | S1_out = S2_out = stdout; 36 | buff1 = S1__scan_string("foo on bar off"); 37 | buff2 = S2__scan_string("on blah blah off foo on bar off"); 38 | 39 | /* scan simultaneously. */ 40 | while(S1_ok || S2_ok) 41 | { 42 | if (S1_ok) 43 | S1_ok = S1_lex(); 44 | if (S2_ok) 45 | S2_ok = S2_lex(); 46 | } 47 | S1__delete_buffer(buff1); 48 | S2__delete_buffer(buff2); 49 | printf("TEST RETURNING OK.\n"); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /tests/multiple_scanners_r_1.l: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* A template scanner file to build "scanner-1.c" and "scanner-1.h". */ 26 | #include 27 | #include 28 | #include "config.h" 29 | 30 | %} 31 | 32 | %option header="multiple_scanners_r_1.h" 33 | %option 8bit prefix="S1_" 34 | %option nounput nomain noyywrap noinput noyy_top_state 35 | %option warn stack reentrant 36 | 37 | %x ON 38 | %x OFF 39 | %% 40 | { 41 | on yy_push_state(ON, yyscanner); return 10; 42 | off yy_push_state(OFF, yyscanner); return 11; 43 | .|\n return 12; 44 | } 45 | .|\n yy_pop_state(yyscanner); return 13; 46 | 47 | .|\n yy_pop_state(yyscanner); return 14; 48 | 49 | %% 50 | 51 | -------------------------------------------------------------------------------- /tests/multiple_scanners_r_2.l: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* A template scanner file to build "scanner-2.c" and "scanner-2.h". */ 26 | #include 27 | #include 28 | #include "config.h" 29 | 30 | %} 31 | 32 | %option header="multiple_scanners_r_2.h" 33 | %option 8bit prefix="S2_" 34 | %option nounput nomain noyywrap noinput 35 | %option warn stack reentrant noyy_top_state 36 | 37 | %x OFF 38 | %x ON 39 | %% 40 | { 41 | on yy_push_state(ON, yyscanner); return 3; 42 | off yy_push_state(OFF, yyscanner); return 4; 43 | .|\n return 5; 44 | } 45 | .|\n yy_pop_state(yyscanner); return 6; 46 | 47 | .|\n yy_pop_state(yyscanner); return 7; 48 | %% 49 | 50 | -------------------------------------------------------------------------------- /tests/multiple_scanners_r_main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | #include "multiple_scanners_r_1.h" 25 | #include "multiple_scanners_r_2.h" 26 | 27 | int 28 | main ( int argc, char** argv ) 29 | { 30 | (void)argc; 31 | (void)argv; 32 | 33 | int S1_ok=1, S2_ok=1; 34 | yybuffer buff1, buff2; 35 | yyscan_t scan1, scan2; 36 | 37 | S1_lex_init(&scan1); 38 | S2_lex_init(&scan2); 39 | 40 | S1_set_out(stdout,scan1); 41 | S2_set_out(S1_get_out(scan1),scan2); 42 | 43 | buff1 = S1__scan_string("foo on bar off", scan1); 44 | buff2 = S2__scan_string("on blah blah off foo on bar off", scan2); 45 | 46 | /* scan simultaneously. */ 47 | while(S1_ok || S2_ok) 48 | { 49 | if (S1_ok) 50 | S1_ok = S1_lex(scan1); 51 | if (S2_ok) 52 | S2_ok = S2_lex(scan2); 53 | } 54 | S1__delete_buffer(buff1, scan1); 55 | S2__delete_buffer(buff2, scan2); 56 | 57 | S1_lex_destroy(scan1); 58 | S2_lex_destroy(scan2); 59 | printf("TEST RETURNING OK.\n"); 60 | return 0; 61 | } 62 | 63 | 64 | /* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */ 65 | -------------------------------------------------------------------------------- /tests/no_bison_stub.c: -------------------------------------------------------------------------------- 1 | /* This stub will be used when Bison is not available on the user's host. */ 2 | 3 | /* This file is part of flex. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE. 23 | */ 24 | #include 25 | 26 | int main (int argc, char *argv[]) 27 | { 28 | (void)argc; 29 | (void)argv; 30 | puts( 31 | "This test requires Bison. Install Bison and re-run \"configure && make check\"\n" 32 | "to perform this test. (This file is stub code.)" 33 | ); 34 | 35 | /* Exit status for a skipped test */ 36 | return 77; 37 | } 38 | 39 | /* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */ 40 | -------------------------------------------------------------------------------- /tests/options.cn: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Test that flex handles the grouped noop options -c and -n properly. 4 | 5 | echo %% | $1 -cn -o /dev/null 6 | -------------------------------------------------------------------------------- /tests/posix.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | /* The goal of this test is to verify that we are getting the counter-intuitive 25 | * POSIX behavior of the repeat operator `{}' when posix-compat is on. 26 | * 27 | * ab{3} - In traditional flex, this matches "abbb". 28 | * In posix, this matches "ababab". 29 | * The input file should contain just the second string. 30 | */ 31 | %option nounput nomain noyywrap noinput 32 | %option warn posix-compat 33 | 34 | %% 35 | 36 | ab{3} { } 37 | \n { } 38 | . {M4_TEST_FAILMESSAGE} 39 | 40 | ### 41 | ababab 42 | -------------------------------------------------------------------------------- /tests/posix.txt: -------------------------------------------------------------------------------- 1 | ababab 2 | -------------------------------------------------------------------------------- /tests/posixlycorrect.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | /* 25 | * The goal of this test is to verify that we are getting the 26 | * counter-intuitive POSIX behavior of the repeat operator `{}' when 27 | * posix_compat is off but POSIXLY_CORRECT=1 is set in the 28 | * environment. Note: This depends on the test framework to actually 29 | * set that variable! When it does not, Flex will match abbb 30 | * 31 | * ab{3} - In traditional flex, this matches "abbb". 32 | * In posix, this matches "ababab". 33 | * The input file should contain just the second string. 34 | */ 35 | %option nounput nomain noyywrap noinput 36 | %option warn 37 | 38 | %% 39 | 40 | ab{3} { } 41 | \n { } 42 | . {M4_TEST_FAILMESSAGE} 43 | 44 | ### 45 | ababab 46 | -------------------------------------------------------------------------------- /tests/posixlycorrect.txt: -------------------------------------------------------------------------------- 1 | ababab 2 | -------------------------------------------------------------------------------- /tests/prefix.txt: -------------------------------------------------------------------------------- 1 | Dummy input. 2 | -------------------------------------------------------------------------------- /tests/prefix_c99.l: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* Builds "scanner.c". */ 26 | /* The scanner itself is a no-op. A successful compilation is all we want. */ 27 | #include 28 | #include 29 | #include "config.h" 30 | 31 | %} 32 | %option emit="c99" 33 | %option 8bit prefix="FOO" 34 | %option nounput nomain noyywrap noinput 35 | %option warn 36 | 37 | 38 | %% 39 | 40 | 41 | .|\n|\r { 42 | 43 | /* Compile, but do not execute the following code. */ 44 | if( 0 ) { 45 | FOO_create_buffer( (FILE*)0, 0, yyscanner); 46 | FOO_delete_buffer( (yybuffer)0, yyscanner); 47 | FOO_flush_buffer( (yybuffer)0, yyscanner); 48 | FOO_init_buffer( (yybuffer)0, (FILE*)0, yyscanner); 49 | FOO_load_buffer_state( yyscanner); 50 | FOO_scan_buffer( (char*)0, (size_t)0, yyscanner); 51 | FOO_scan_bytes( (const char*)0, 0, yyscanner); 52 | FOO_scan_string( (const char*)0, yyscanner); 53 | FOO_switch_to_buffer( (yybuffer)0, yyscanner); 54 | FOOrestart( (FILE*)0, (yyscan_t )0); 55 | 56 | /* Commented out because the C99 back end is more 57 | * careful about not compiling in things it doesn't 58 | * need. 59 | */ 60 | //FOOget_extra( (yyscan_t )0 ); 61 | FOOget_in( (yyscan_t )0 ); 62 | FOOget_leng( (yyscan_t )0 ); 63 | FOOget_out( (yyscan_t )0 ); 64 | FOOget_text( (yyscan_t )0 ); 65 | FOOlex( (yyscan_t )0 ); 66 | //FOOlex_destroy( (yyscan_t )0 ); 67 | //FOOlex_init( (yyscan_t *)0 ); 68 | //FOOset_extra( (void *)0, (yyscan_t )0 ); 69 | FOOset_in( (FILE*)0, (yyscan_t )0 ); 70 | FOOset_out( (FILE*)0, (yyscan_t )0 ); 71 | } 72 | } 73 | %% 74 | 75 | int main(void); 76 | 77 | int 78 | main (void) 79 | { 80 | yyscan_t scanner; 81 | FOOlex_init( &scanner); 82 | FOOlex( scanner); 83 | FOOlex_destroy( scanner); 84 | printf( "TEST RETURNING OK.\n"); 85 | return 0; 86 | } 87 | 88 | -------------------------------------------------------------------------------- /tests/prefix_nr.l: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* Builds "scanner.c". */ 26 | /* The scanner itself is a no-op. A successful compilation is all we want. */ 27 | #include 28 | #include 29 | #include "config.h" 30 | 31 | %} 32 | 33 | %option 8bit prefix="FOO" 34 | %option nounput nomain noyywrap noinput 35 | %option warn 36 | 37 | 38 | %% 39 | 40 | .|\n|\r { 41 | 42 | /* Compile, but do not execute the following code. */ 43 | if( 0) { 44 | FOO_create_buffer((FILE*)0,0); 45 | FOO_delete_buffer((yybuffer)0); 46 | FOO_flush_buffer((yybuffer)0); 47 | FOO_init_buffer((yybuffer)0,(FILE*)0); 48 | FOO_load_buffer_state(); 49 | FOO_scan_buffer((char*)0,(yy_size_t)0); 50 | FOO_scan_bytes((const char*)0, 0); 51 | FOO_scan_string((const char*)0); 52 | FOO_switch_to_buffer((yybuffer)0); 53 | yyin = (FILE*)0; 54 | yyout = (FILE*)0; 55 | yyleng = 0; 56 | yylex(); 57 | yyrestart((FILE*)0); 58 | yytext = (char*)0; 59 | } 60 | } 61 | %% 62 | 63 | 64 | int main(void); 65 | 66 | int 67 | main (void) 68 | { 69 | yyin = stdin; 70 | yyout = stdout; 71 | FOOlex(); 72 | printf("TEST RETURNING OK.\n"); 73 | return 0; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /tests/prefix_r.l: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* Builds "scanner.c". */ 26 | /* The scanner itself is a no-op. A successful compilation is all we want. */ 27 | #include 28 | #include 29 | #include "config.h" 30 | 31 | %} 32 | %option reentrant 33 | %option 8bit prefix="FOO" 34 | %option nounput nomain noyywrap noinput 35 | %option warn 36 | 37 | 38 | %% 39 | 40 | 41 | .|\n|\r { 42 | 43 | /* Compile, but do not execute the following code. */ 44 | if( 0 ) { 45 | FOO_create_buffer( (FILE*)0, 0, yyscanner); 46 | FOO_delete_buffer( (yybuffer)0, yyscanner); 47 | FOO_flush_buffer( (yybuffer)0, yyscanner); 48 | FOO_init_buffer( (yybuffer)0, (FILE*)0, yyscanner); 49 | FOO_load_buffer_state( yyscanner); 50 | FOO_scan_buffer( (char*)0, (yy_size_t)0, yyscanner); 51 | FOO_scan_bytes( (const char*)0, 0, yyscanner); 52 | FOO_scan_string( (const char*)0, yyscanner); 53 | FOO_switch_to_buffer( (yybuffer)0, yyscanner); 54 | FOOrestart( (FILE*)0, (yyscan_t )0); 55 | 56 | FOOget_extra( (yyscan_t )0 ); 57 | FOOget_in( (yyscan_t )0 ); 58 | FOOget_leng( (yyscan_t )0 ); 59 | FOOget_out( (yyscan_t )0 ); 60 | FOOget_text( (yyscan_t )0 ); 61 | FOOlex( (yyscan_t )0 ); 62 | FOOlex_destroy( (yyscan_t )0 ); 63 | FOOlex_init( (yyscan_t *)0 ); 64 | FOOset_extra( (void *)0, (yyscan_t )0 ); 65 | FOOset_in( (FILE*)0, (yyscan_t )0 ); 66 | FOOset_out( (FILE*)0, (yyscan_t )0 ); 67 | } 68 | } 69 | %% 70 | 71 | int main(void); 72 | 73 | int 74 | main (void) 75 | { 76 | yyscan_t scanner; 77 | FOOlex_init( &scanner); 78 | FOOlex( scanner); 79 | FOOlex_destroy( scanner); 80 | printf( "TEST RETURNING OK.\n"); 81 | return 0; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /tests/preposix.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | /* The goal of this test is to verify that we are getting the traditional 25 | * pre-POSIX behavior of the repeat operator `{}' when posix-compat is not on 26 | * and POSIXLY_CORRECT is not set to 1. 27 | * 28 | * ab{3} - In traditional flex, this matches "abbb". 29 | * In posix, this matches "ababab". 30 | * The input file should contain just the first string. 31 | */ 32 | %option nounput nomain noyywrap noinput 33 | %option warn 34 | 35 | %% 36 | 37 | ab{3} { } 38 | \n { } 39 | . {M4_TEST_FAILMESSAGE} 40 | 41 | ### 42 | abbb 43 | -------------------------------------------------------------------------------- /tests/preposix.txt: -------------------------------------------------------------------------------- 1 | abbb 2 | -------------------------------------------------------------------------------- /tests/quoteincomment.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | %option 8bit noyywrap 24 | %% 25 | .|\n { M4_TEST_DO(yyecho()) 26 | //' " 27 | } 28 | ### 29 | test 30 | -------------------------------------------------------------------------------- /tests/quoteincomment.txt: -------------------------------------------------------------------------------- 1 | test 2 | -------------------------------------------------------------------------------- /tests/quotes.txt: -------------------------------------------------------------------------------- 1 | 0000 foo 1111 foo 0000 bar 2 | 0000 foo 1111 foo 0000 bar 3 | -------------------------------------------------------------------------------- /tests/reject.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | /* 24 | * Test yyreject() by seeing if we jump out of the main rule below 25 | * rather than reaching the abort. 26 | */ 27 | 28 | %option 8bit 29 | %option nounput nomain noyywrap noinput 30 | %option warn reject 31 | %% 32 | 33 | . {M4_TEST_DO(yyreject()) M4_TEST_FAILMESSAGE} 34 | .|\n ; 35 | 36 | ### 37 | 0000 foo 1111 foo 0000 bar 38 | 0000 foo 1111 foo 0000 bar 39 | 40 | -------------------------------------------------------------------------------- /tests/reject.txt: -------------------------------------------------------------------------------- 1 | 0000 foo 1111 foo 0000 bar 2 | 0000 foo 1111 foo 0000 bar 3 | 4 | -------------------------------------------------------------------------------- /tests/rescan_nr.direct.l: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* A template scanner file to build "scanner.c". */ 26 | #include 27 | #include 28 | %} 29 | 30 | %option 8bit prefix="test" 31 | %option nounput nomain noyywrap noinput 32 | %option warn stack never-interactive 33 | %x STATE_1 34 | 35 | %% 36 | 37 | { 38 | 0 yy_push_state (STATE_1); 39 | .|\n return 1; 40 | } 41 | { 42 | 1 yy_pop_state(); 43 | .|\n return yy_top_state() + 1; 44 | } 45 | 46 | %% 47 | 48 | int 49 | main (int argc, char* const argv[]) 50 | { 51 | FILE* fp; 52 | int i; 53 | 54 | (void)argc; 55 | 56 | if ((fp = fopen(argv[1],"r")) == NULL){ 57 | perror("Failed to open input file."); 58 | return 1; 59 | } 60 | 61 | testset_out ( stdout); 62 | 63 | for (i=0; i < 4; ++i){ 64 | rewind(fp); 65 | testset_in ( fp); 66 | while( testlex() ) 67 | ; 68 | testlex_destroy(); 69 | } 70 | printf("TEST RETURNING OK.\n"); 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /tests/rescan_nr.direct.txt: -------------------------------------------------------------------------------- 1 | 0000 foo 1111 foo 0000 bar 2 | 0000 foo 1111 foo 0000 bar 3 | -------------------------------------------------------------------------------- /tests/rescan_r.direct.l: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* A template scanner file to build "scanner.c". */ 26 | #include 27 | #include 28 | %} 29 | 30 | %option 8bit prefix="test" 31 | %option nounput nomain noyywrap noinput reentrant 32 | %option warn stack never-interactive 33 | %x STATE_1 34 | 35 | %% 36 | 37 | { 38 | 0 yy_push_state (STATE_1, yyscanner); 39 | .|\n return 1; 40 | } 41 | { 42 | 1 yy_pop_state(yyscanner); 43 | .|\n return yy_top_state(yyscanner) + 1; 44 | } 45 | 46 | %% 47 | 48 | int 49 | main (int argc, char* const argv[]) 50 | { 51 | FILE* fp; 52 | int i; 53 | yyscan_t yyscanner; 54 | 55 | (void)argc; 56 | 57 | if ((fp = fopen(argv[1],"r")) == NULL){ 58 | perror("Failed to open input file."); 59 | return 1; 60 | } 61 | 62 | printf("Test 1: Reusing same scanner.\n"); 63 | testlex_init( &yyscanner ); 64 | testset_out ( stdout, yyscanner); 65 | 66 | for (i=0; i < 4; ++i){ 67 | 68 | rewind(fp); 69 | testset_in ( fp, yyscanner); 70 | 71 | while( testlex(yyscanner) ) 72 | ; 73 | } 74 | testlex_destroy( yyscanner ); 75 | printf("Test 1 OK\n\n"); 76 | 77 | printf("Test 2: Rescanning with new scanner each time.\n"); 78 | 79 | memset(&yyscanner,0,sizeof(yyscanner)); // Just to be clean about it. 80 | 81 | for (i=0; i < 4; ++i){ 82 | yyscan_t s; 83 | testlex_init( &s ); 84 | testset_out ( stdout, s); 85 | rewind(fp); 86 | testset_in ( fp, s); 87 | 88 | while( testlex(s) ) 89 | ; 90 | testlex_destroy( s ); 91 | } 92 | printf("Test 2 OK\n\n"); 93 | 94 | 95 | printf("TEST RETURNING OK.\n"); 96 | return 0; 97 | } 98 | -------------------------------------------------------------------------------- /tests/rescan_r.direct.txt: -------------------------------------------------------------------------------- 1 | 0000 foo 1111 foo 0000 bar 2 | 0000 foo 1111 foo 0000 bar 3 | -------------------------------------------------------------------------------- /tests/state_buf.direct.lll: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* A template scanner file to build "scanner.cc". 26 | The scanner tests that we correctly initialize the state buffer 27 | for long input buffers owned by code that calls yylex. 28 | 29 | This tests guards against reversions to CVE-2006-0459, 30 | in particular when variable trailing context rules are used. 31 | */ 32 | #include 33 | #include 34 | #include 35 | 36 | #define ECHO 37 | %} 38 | 39 | %option prefix="test" 40 | %option noyywrap 41 | 42 | ID [_a-zA-Z]+[_0-9a-zA-Z]* 43 | 44 | BBC1 ([^(]*|"("[^(]*")") 45 | 46 | /** 47 | * Balanced Bracketed Content. 48 | * May not contain bracket, but if it does then it is balanced. 49 | */ 50 | BBC ({BBC1}*|"("{BBC1}*")") 51 | 52 | FPD "("{BBC}*")" 53 | 54 | %% 55 | 56 | {ID}/{FPD}\{ { 57 | return 1234; 58 | } 59 | 60 | %% 61 | 62 | std::vector readFile(const char* filename) 63 | { 64 | std::vector contents; 65 | std::ifstream in(filename, std::ios::in | std::ios::binary); 66 | if (in) 67 | { 68 | in.seekg(0, std::ios::end); 69 | size_t size = static_cast(in.tellg()); 70 | contents.resize(size + 2); 71 | in.seekg(0, std::ios::beg); 72 | in.read(contents.data(), size); 73 | in.close(); 74 | 75 | contents[size + 0] = '\0'; 76 | contents[size + 1] = '\0'; 77 | } 78 | else { 79 | std::cerr << "*** Error: std::ifstream(" << filename << ") failed." << std::endl; 80 | exit(-1); 81 | } 82 | return contents; 83 | } 84 | 85 | int main(int argc, char** argv) 86 | { 87 | if ( argc != 2 ) { 88 | std::cerr << "*** Error: Must specify one filename." << std::endl; 89 | exit(-1); 90 | } 91 | 92 | std::vector stm = readFile( argv[1] ); 93 | test_scan_buffer(stm.data(), stm.size()); 94 | 95 | testlex(); 96 | 97 | return 0; // All went well. 98 | } 99 | -------------------------------------------------------------------------------- /tests/string_nr.l: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* A template scanner file to build "scanner.c". */ 26 | #include 27 | #include 28 | #include "config.h" 29 | 30 | #define NUMBER 200 31 | #define WORD 201 32 | 33 | %} 34 | 35 | %option 8bit prefix="test" 36 | %option nounput nomain nodefault noyywrap noinput 37 | %option warn 38 | 39 | 40 | %% 41 | 42 | [[:space:]]+ { } 43 | [[:digit:]]+ { printf("NUMBER "); fflush(stdout);} 44 | [[:alpha:]]+ { printf("WORD "); fflush(stdout);} 45 | . { 46 | fprintf(stderr,"*** Error: Unrecognized character '%c' while scanning.\n", 47 | yytext[0]); 48 | yyterminate(); 49 | } 50 | 51 | <> { printf("<>\n"); yyterminate();} 52 | 53 | %% 54 | 55 | 56 | #define INPUT_STRING_1 "1234 foo bar" 57 | #define INPUT_STRING_2 "1234 foo bar *@&@&###@^$#&#*" 58 | 59 | int main(void); 60 | 61 | int 62 | main (void) 63 | { 64 | char * buf; 65 | size_t len; 66 | yybuffer state; 67 | 68 | /* Scan a good string. */ 69 | printf("Testing: test_scan_string(%s): ",INPUT_STRING_1); fflush(stdout); 70 | state = test_scan_string ( INPUT_STRING_1 ); 71 | testlex(); 72 | yy_delete_buffer(state); 73 | 74 | /* Scan only the first 12 chars of a string. */ 75 | printf("Testing: test_scan_bytes(%s): ",INPUT_STRING_2); fflush(stdout); 76 | state = test_scan_bytes ( INPUT_STRING_2, 12 ); 77 | testlex(); 78 | test_delete_buffer(state); 79 | 80 | /* Scan directly from a buffer. 81 | We make a copy, since the buffer will be modified by flex.*/ 82 | printf("Testing: test_scan_buffer(%s): ",INPUT_STRING_1); fflush(stdout); 83 | len = strlen(INPUT_STRING_1) + 2; 84 | buf = malloc(len); 85 | strcpy( buf, INPUT_STRING_1); 86 | buf[ len -2 ] = 0; /* Flex requires two NUL bytes at end of buffer. */ 87 | buf[ len -1 ] =0; 88 | 89 | state = test_scan_buffer( buf, len ); 90 | testlex(); 91 | test_delete_buffer(state); 92 | 93 | printf("TEST RETURNING OK.\n"); 94 | return 0; 95 | } 96 | -------------------------------------------------------------------------------- /tests/tableopts.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | /* The simple grammar used as a test of table-compression options */ 24 | 25 | %option 8bit 26 | %option nounput nomain noyywrap noinput 27 | %option warn yylineno 28 | %% 29 | 30 | foo|bar ; 31 | [[:digit:]]+ ; 32 | [[:blank:]]+ ; 33 | .|\n ; 34 | ### 35 | 0000 foo 1111 foo 0000 bar foobar 36 | 0000 foo 1111 foo 0000 bar foobar 37 | -------------------------------------------------------------------------------- /tests/tableopts.txt: -------------------------------------------------------------------------------- 1 | 0000 foo 1111 foo 0000 bar foobar 2 | 0000 foo 1111 foo 0000 bar foobar 3 | -------------------------------------------------------------------------------- /tests/test-yydecl-gen.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Generate test for the %yydecl option of flex on a specified back end 3 | backend="$1" 4 | FLEX="$2" 5 | 6 | cat </tmp/td\$\$ </dev/null 38 | then 39 | echo "%yydecl test on ${backend} SUCCEEDED" 40 | exit 0 41 | else 42 | echo "%yydecl test on ${backend} FAILED." >&2; 43 | exit 1 44 | fi 45 | EOF_OUTER 46 | -------------------------------------------------------------------------------- /tests/test-yylmax: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Test %yylmax option of flex in any cpp-based back end 3 | 4 | trap 'rm /tmp/td$$' EXIT HUP INT QUIT TERM 5 | cat >/tmp/td$$ </dev/null ) || (echo "%yylmax test failed." >&2; exit 1) 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/testwrapper-direct.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo 'set -euvx' 3 | set -euvx 4 | 5 | # testwrapper-direct.sh: run some specialized flex tests that care where 6 | # they're run from. 7 | BINARY_DIR="." 8 | SOURCE_DIR="." 9 | 10 | while getopts :b:s: OPTION ; do 11 | case $OPTION in 12 | b) BINARY_DIR=$OPTARG ;; 13 | s) SOURCE_DIR=$OPTARG ;; 14 | *) echo "Usage: ${0} [-b BINARY_DIR] [-s SOURCE_DIR] TESTNAME" 15 | exit 1 16 | ;; 17 | esac 18 | done 19 | 20 | shift $((OPTIND-1)) 21 | TESTNAME=$1 22 | 23 | INPUT_NAME=$(basename "${TESTNAME%.exe}").txt 24 | 25 | cd "${SOURCE_DIR}" && "${BINARY_DIR}/${TESTNAME}" "${INPUT_NAME}" 26 | -------------------------------------------------------------------------------- /tests/testwrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo 'set -euvx' 3 | set -euvx 4 | 5 | # testwrapper.sh: run a flex test, typically called by a Makefile 6 | 7 | # Each test will exercise some feature or aspect of flex. Run the test with any 8 | # input it may need. 9 | 10 | INPUT_DIRECTORY="" 11 | INPUT_NAME="" 12 | INPUT_COUNT=0 13 | USE_REDIRECT=0 14 | 15 | while getopts d:i:r OPTION ; do 16 | case $OPTION in 17 | d) INPUT_DIRECTORY=$OPTARG ;; 18 | i) 19 | if [ "$INPUT_NAME" = "" ] ; then 20 | INPUT_NAME="$OPTARG" 21 | else 22 | INPUT_NAME="$INPUT_NAME $OPTARG" 23 | fi 24 | INPUT_COUNT=$((INPUT_COUNT+1)) 25 | ;; 26 | r) USE_REDIRECT=1 ;; 27 | *) echo "Usage: ${0} [-d INPUT_DIRECTORY] [-i INPUT_NAME] [-r] TESTNAME" 28 | exit 1 29 | ;; 30 | esac 31 | done 32 | 33 | shift $((OPTIND-1)) 34 | TESTNAME=$1 35 | 36 | # There may be a specific input file for this test 37 | INPUT_NAME=${INPUT_NAME:-$INPUT_DIRECTORY/$(basename "${TESTNAME%.exe}").txt} 38 | 39 | # If it doesn't exist, try stripping out a backend suffix. 40 | # There might be a generic input for all tests with this stem. 41 | # For this purpose we consider _r and _nr to be back ends. 42 | inputs=$INPUT_NAME 43 | INPUT_NAME= 44 | for input in $inputs; do 45 | if [ ! -f "${input}" ] ; then 46 | input=$(echo "${input}" | sed -e 's/_[a-z0-9]*.txt$/.txt/') 47 | fi 48 | if [ "${INPUT_NAME}" = "" ] ; then 49 | INPUT_NAME="${input}" 50 | else 51 | INPUT_NAME="${INPUT_NAME} ${input}" 52 | fi 53 | done 54 | 55 | # Detect if the test wants a table argument. If it does, the test maker will have generated 56 | # a tables=-file option do that the a table file named afte the test was created when the 57 | # scanner was built. Thus we can assume that it will be looking for the table data at 58 | # the matching path we're about to generate. 59 | case ${TESTNAME} in 60 | *ver|*ser|*_ver_*|*_ser_*) USE_TABLES=1 ;; 61 | esac 62 | 63 | if [ $INPUT_COUNT -gt 1 ] ; then 64 | # INPUT_NAME has multiple filenames, so we do want word expansion 65 | # shellcheck disable=SC2086 66 | $TESTNAME ${USE_TABLES:+"${INPUT_DIRECTORY}/${TESTNAME%.exe}.tables"} ${INPUT_NAME} 67 | exit $? 68 | fi 69 | 70 | # Set up input redirection as required 71 | if [ -f "${INPUT_NAME}" ] ; then 72 | if [ $USE_REDIRECT = 1 ] ; then 73 | $TESTNAME ${USE_TABLES:+${INPUT_DIRECTORY}/${TESTNAME%.exe}.tables} < "$INPUT_NAME" 74 | else 75 | $TESTNAME ${USE_TABLES:+${INPUT_DIRECTORY}/${TESTNAME%.exe}.tables} "$INPUT_NAME" 76 | fi 77 | else 78 | $TESTNAME 79 | fi 80 | -------------------------------------------------------------------------------- /tests/top.l: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | %{ 25 | /* Build "scanner.c". 26 | The scanner is not important. 27 | This test is backend-independent; what it's really testing 28 | is Flex's ability to accumulate and ship preamble code sections. 29 | */ 30 | #include 31 | #include 32 | #include "config.h" 33 | 34 | #ifndef DEFINE_ME 35 | #error "DEFINE_ME undefined!" 36 | #endif 37 | %} 38 | 39 | %top{ 40 | #define DEFINE_ME 1 41 | } 42 | 43 | %option reentrant 44 | %option 8bit header="top.h" prefix="test" 45 | %option nounput nomain noyywrap noinput 46 | %option warn 47 | 48 | 49 | %% 50 | 51 | .|\n { } 52 | 53 | %% 54 | 55 | -------------------------------------------------------------------------------- /tests/top.txt: -------------------------------------------------------------------------------- 1 | Any input is ok for this scanner. 2 | We only care if it links. 3 | 4 | -------------------------------------------------------------------------------- /tests/top_main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | #include 25 | 26 | #include "top.h" 27 | 28 | /* The scanner itself is not important here. 29 | * We simply try to use all the functions that are exported in the 30 | * header, to see if we get any compiler warnings. 31 | */ 32 | int 33 | main ( int argc, char** argv ) 34 | { 35 | (void)argc; 36 | (void)argv; 37 | 38 | yyscan_t scanner; 39 | FILE *fp; 40 | char * extra = "EXTRA"; 41 | 42 | testlex_init(&scanner); 43 | testset_in(stdin,scanner); 44 | testset_out(stdout,scanner); 45 | testset_extra(extra,scanner); 46 | 47 | fp = testget_in(scanner); 48 | assert(fp == stdin); 49 | fp = testget_out(scanner); 50 | assert(fp == stdout); 51 | 52 | while(testlex(scanner)) { 53 | char * text; 54 | int line; 55 | line = testget_lineno(scanner); 56 | text = testget_text(scanner); 57 | 58 | if( (char*)testget_extra(scanner) != extra) 59 | break; 60 | 61 | if ( !text || line < 0) 62 | continue; 63 | } 64 | testlex_destroy(scanner); 65 | printf("TEST RETURNING OK.\n"); 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /tests/vartrailing.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | 24 | /* The goal here is to test the yylineno in the context of trailing-contexts. 25 | * Using rules that have newlines in look-ahead. 26 | */ 27 | 28 | %option 8bit 29 | %option nounput nomain noyywrap noinput yylineno 30 | %option warn 31 | 32 | WORD [[:alpha:]]+ 33 | 34 | %% 35 | "Fixed_trailing:"/[\n]"test"[\n] {} 36 | "Var_trailing:"{WORD}/[\n] {} 37 | "Var_prefix_and_trailing:"{WORD}":"/(\n{WORD})* {} 38 | \n {} 39 | . {} 40 | <> {M4_TEST_ASSERT(yylineno==16) M4_TEST_DO(yyterminate())} 41 | 42 | ### 43 | We are testing rules with trailing contexts containing newlines (see scanner.l): 44 | 45 | Fixed_trailing: 46 | test 47 | 48 | Var_trailing:word 49 | test 50 | 51 | Var_prefix_and_trailing:word: 52 | more 53 | text 54 | comes 55 | here 56 | 57 | 58 | -------------------------------------------------------------------------------- /tests/vartrailing.txt: -------------------------------------------------------------------------------- 1 | We are testing rules with trailing contexts containing newlines (see scanner.l): 2 | 3 | Fixed_trailing: 4 | test 5 | 6 | Var_trailing:word 7 | test 8 | 9 | Var_prefix_and_trailing:word: 10 | more 11 | text 12 | comes 13 | here 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/yyless.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | /* 24 | * Test yyless. What should happen is: 25 | * 1. "foobar" is matched by the first rule. 26 | * 2. "bar" is pushed back by yyless(3) 27 | * 3. "bar" is matched by the second rule 28 | * 4. Trailing \n is matched and discareded 29 | * 5. Final rule is never reached. 30 | */ 31 | 32 | %option nounput noyywrap noyylineno warn nodefault noinput 33 | %% 34 | foobar {M4_TEST_DO(yyless(3))} 35 | bar ; 36 | \n ; 37 | . {M4_TEST_FAILMESSAGE} 38 | 39 | ### 40 | foobar 41 | -------------------------------------------------------------------------------- /tests/yyless.txt: -------------------------------------------------------------------------------- 1 | foobar 2 | -------------------------------------------------------------------------------- /tests/yymore.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | /* 24 | * Test yymore with default pointer buffer. What should happen is: 25 | * 1. "foo" is matched by the first rule but not consumed. 26 | * 2. "bar" is matched, but the token length is 6 rather than 3. 27 | * We use a ^ to force the extra code for BOL checking. 28 | */ 29 | 30 | %option nounput noyywrap noyylineno warn noinput 31 | %% 32 | foo {M4_TEST_DO(yymore())} 33 | bar {M4_TEST_ASSERT(yyleng == 6)} 34 | ### 35 | ^foobar 36 | -------------------------------------------------------------------------------- /tests/yymore.txt: -------------------------------------------------------------------------------- 1 | ^foobar 2 | -------------------------------------------------------------------------------- /tests/yymorearray.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | /* 24 | * Test yymore with array buffer representation. What should happen is: 25 | * 1. "foo" is matched by the first rule but not consumed. 26 | * 2. "bar" is matched, but the token length is 6 rather than 3. 27 | * Also see the yymorearraybol ruleset. 28 | */ 29 | 30 | %array 31 | %option nounput noyywrap noyylineno warn noinput 32 | %% 33 | foo {M4_TEST_DO(yymore())} 34 | bar {M4_TEST_ASSERT(yyleng == 6)} 35 | ### 36 | foobar 37 | -------------------------------------------------------------------------------- /tests/yymorearray.txt: -------------------------------------------------------------------------------- 1 | foobar 2 | -------------------------------------------------------------------------------- /tests/yymorearraybol.rules: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | %} 4 | /* 5 | * This file is part of flex. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * Neither the name of the University nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR 22 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24 | * PURPOSE. 25 | */ 26 | /* 27 | * Test yymore with array buffer representation. What should happen is: 28 | * 1. "foo" is matched by the first rule but not consumed. 29 | * 2. "bar" is matched, but the token length is 6 rather than 3. 30 | * We use a ^ to force the extra code for BOL checking. 31 | */ 32 | 33 | %array 34 | %option nounput noyywrap yylineno warn noinput 35 | %% 36 | ^foo {yymore();} 37 | bar {if (!(yyleng == 6)) {fprintf(stderr,"ASSERT FAILED.\n"); exit(1);}} 38 | ### 39 | foobar 40 | -------------------------------------------------------------------------------- /tests/yymorearraybol.txt: -------------------------------------------------------------------------------- 1 | foobar 2 | -------------------------------------------------------------------------------- /tests/yyunput.rules: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of flex. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * Neither the name of the University nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | * PURPOSE. 22 | */ 23 | /* A test of the yyunput function */ 24 | 25 | %option 8bit 26 | %option nomain noyywrap noinput 27 | %option warn yylineno array 28 | %% 29 | 30 | foo {yyunput('k');} 31 | kick ; 32 | \n ; 33 | . {M4_TEST_FAILMESSAGE} 34 | ### 35 | -------------------------------------------------------------------------------- /tests/yyunput.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/westes/flex/bf254c75b1e0d2641ebbd7fc85fb183f36a62ea7/tests/yyunput.txt -------------------------------------------------------------------------------- /tools/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = \ 2 | git2cl 3 | --------------------------------------------------------------------------------