├── .gitignore ├── .indent.pro ├── ABOUT-NLS ├── AUTHORS ├── COPYING ├── ChangeLog ├── INSTALL ├── Makefile.am ├── Makefile.in ├── NEWS ├── ONEWS ├── README ├── README.md ├── THANKS ├── TODO ├── aclocal.m4 ├── autogen.sh ├── build-aux ├── compile ├── config.guess ├── config.rpath ├── config.sub ├── depcomp ├── install-sh ├── ltmain.sh ├── mdate-sh ├── missing ├── test-driver ├── texinfo.tex └── ylwrap ├── configure ├── configure.ac ├── doc ├── Makefile.am ├── Makefile.in ├── flex.1 ├── flex.info ├── flex.info-1 ├── flex.info-2 ├── flex.pdf ├── flex.texi ├── stamp-vti └── version.texi ├── examples ├── Makefile.am ├── Makefile.in ├── README ├── debflex.awk ├── fastwc │ ├── Makefile.am │ ├── Makefile.in │ ├── README │ ├── mywc.c │ ├── wc1.l │ ├── wc2.l │ ├── wc3.l │ ├── wc4.l │ └── wc5.l ├── manual │ ├── ChangeLog │ ├── Makefile.am │ ├── Makefile.examples │ ├── Makefile.in │ ├── README │ ├── cat.lex │ ├── dates.lex │ ├── datetest.dat │ ├── eof_rules.lex │ ├── eof_test01.txt │ ├── eof_test02.txt │ ├── eof_test03.txt │ ├── 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 ├── Makefile.am ├── Makefile.in ├── lib.c ├── malloc.c └── realloc.c ├── m4 ├── gettext.m4 ├── iconv.m4 ├── intlmacosx.m4 ├── lib-ld.m4 ├── lib-link.m4 ├── lib-prefix.m4 ├── libtool.m4 ├── ltoptions.m4 ├── ltsugar.m4 ├── ltversion.m4 ├── lt~obsolete.m4 ├── nls.m4 ├── po.m4 └── progtest.m4 ├── po ├── LINGUAS ├── Makefile.in.in ├── Makevars ├── POTFILES.in ├── Rules-quot ├── boldquot.sed ├── ca.gmo ├── ca.po ├── da.gmo ├── da.po ├── de.gmo ├── de.po ├── en@boldquot.gmo ├── en@boldquot.header ├── en@boldquot.po ├── en@quot.gmo ├── en@quot.header ├── en@quot.po ├── eo.gmo ├── eo.po ├── es.gmo ├── es.po ├── fi.gmo ├── fi.po ├── flex.pot ├── fr.gmo ├── fr.po ├── ga.gmo ├── ga.po ├── hr.gmo ├── hr.po ├── insert-header.sin ├── ko.gmo ├── ko.po ├── nl.gmo ├── nl.po ├── pl.gmo ├── pl.po ├── pt_BR.gmo ├── pt_BR.po ├── quot.sed ├── remove-potcdate.sin ├── ro.gmo ├── ro.po ├── ru.gmo ├── ru.po ├── sr.gmo ├── sr.po ├── stamp-po ├── sv.gmo ├── sv.po ├── tr.gmo ├── tr.po ├── vi.gmo ├── vi.po ├── zh_CN.gmo ├── zh_CN.po ├── zh_TW.gmo └── zh_TW.po ├── src ├── FlexLexer.h ├── Makefile.am ├── Makefile.in ├── buf.c ├── ccl.c ├── config.h.in ├── dfa.c ├── ecs.c ├── filter.c ├── flex.skl ├── flex_go.skl ├── flexdef.h ├── flexint.h ├── gen.c ├── gen_go.c ├── gettext.h ├── libmain.c ├── libyywrap.c ├── main.c ├── misc.c ├── mkskel.sh ├── mkskel_go.sh ├── nfa.c ├── options.c ├── options.h ├── parse.c ├── parse.h ├── parse.y ├── regex.c ├── scan.c ├── scan.l ├── scanflags.c ├── scanopt.c ├── scanopt.h ├── skel.c ├── skel_go.c ├── sym.c ├── tables.c ├── tables.h ├── tables_shared.c ├── tables_shared.h ├── tblcmp.c ├── version.h └── yylex.c ├── tests ├── Makefile.am ├── Makefile.in ├── README ├── alloc_extra.l ├── alloc_extra.txt ├── array_nr.l ├── array_nr.txt ├── array_r.l ├── array_r.txt ├── basic_nr.l ├── basic_nr.txt ├── basic_r.l ├── basic_r.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 ├── c_cxx_nr.lll ├── c_cxx_nr.txt ├── c_cxx_r.lll ├── c_cxx_r.txt ├── ccl.l ├── 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_yywrap.ll ├── cxx_yywrap.txt ├── debug_nr.l ├── debug_nr.txt ├── debug_r.l ├── debug_r.txt ├── extended.l ├── extended.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 ├── lineno_nr.l ├── lineno_nr.one.txt ├── lineno_r.l ├── lineno_r.one.txt ├── lineno_trailing.l ├── lineno_trailing.one.txt ├── mem_nr.l ├── mem_nr.txt ├── mem_r.l ├── mem_r.txt ├── 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 ├── noansi_nr.l ├── noansi_nr.txt ├── noansi_r.l ├── noansi_r.txt ├── options.cn ├── posix.l ├── posixly_correct.l ├── prefix_nr.l ├── prefix_nr.txt ├── prefix_r.l ├── prefix_r.txt ├── pthread.l ├── pthread_1.txt ├── pthread_2.txt ├── pthread_3.txt ├── pthread_4.txt ├── pthread_5.txt ├── quotes.l ├── quotes.txt ├── reject.l4 ├── reject.txt ├── rescan_nr.direct.l ├── rescan_nr.direct.txt ├── rescan_r.direct.l ├── rescan_r.direct.txt ├── string_nr.l ├── string_r.l ├── tableopts.am ├── tableopts.l4 ├── tableopts.sh ├── tableopts.txt ├── testwrapper.sh ├── top.l ├── top.txt ├── top_main.c ├── yyextra.l └── yyextra.txt ├── tests_go ├── Make.go ├── Make.yaml ├── Makefile ├── Test1c.l ├── Test1go.l ├── Test2c.l ├── Test2go.l ├── minimal-c.l ├── minimal-go.l ├── nul-c.l ├── nul-go.l ├── nul.txt ├── test01c.l ├── test01go.l ├── test02c.l ├── test02go.l ├── test03c.l ├── test03go.l ├── test04c.l ├── test04go.l ├── test05c.l ├── test05go.l ├── test06c.l ├── test06go.l ├── test07c.l ├── test07go.l ├── test08c.l ├── test08go.l ├── text1.txt ├── text2.txt ├── text3.txt ├── text4.txt ├── txt01 ├── txt02 ├── txt03 ├── txt04 ├── txt05 └── txt06 └── tools ├── Makefile.am ├── Makefile.in └── git2cl /.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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | # For Vax/VMS, add "-DVMS" to DEFS. 32 | # 33 | # For MS-DOS, add "-DMS_DOS" to DEFS. See the directory MISC/MSDOS for 34 | # additional info. 35 | 36 | ACLOCAL_AMFLAGS = -I m4 37 | indent = @INDENT@ 38 | 39 | dist_doc_DATA = \ 40 | AUTHORS \ 41 | COPYING \ 42 | NEWS \ 43 | ONEWS \ 44 | README 45 | 46 | EXTRA_DIST = \ 47 | .indent.pro \ 48 | autogen.sh 49 | 50 | SUBDIRS = \ 51 | lib \ 52 | src \ 53 | doc \ 54 | examples \ 55 | po \ 56 | tests \ 57 | tools 58 | 59 | # Create the ChangeLog, but only if we're inside a git working directory 60 | 61 | ChangeLog: $(srcdir)/tools/git2cl 62 | if [ -d $(srcdir)/.git ] ; then \ 63 | $(srcdir)/tools/git2cl > $@ \ 64 | ; fi 65 | 66 | install-exec-hook: 67 | cd $(DESTDIR)$(bindir) && \ 68 | $(LN_S) -f flex$(EXEEXT) flex++$(EXEEXT) 69 | cd $(DESTDIR)$(bindir) && \ 70 | $(LN_S) -f flex$(EXEEXT) flexgo$(EXEEXT) 71 | 72 | .PHONY: ChangeLog tags indent 73 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | * the manual: 2 | 3 | ** do an end-to-end proofread of the manual (this is under way, but is 4 | going slowly) 5 | 6 | ** pretty up the dvi output; overflows, etc. 7 | 8 | ** faq 9 | 10 | *** clean up the faqs section. The information is good; the texinfo 11 | could use some touching up. 12 | 13 | *** index the faq entries 14 | 15 | *** mention that it's possible to use a variable to scan matching 16 | brackets, nested comments etc. 17 | 18 | *** include something about lexing/parsing fortran 19 | 20 | ** create a section on flex design, features, etc. 21 | 22 | * getext 23 | 24 | ** make sure all flex modules use gettext translation facilities 25 | 26 | *subdirectories 27 | 28 | ** in examples/manual, integrate the Makefile.examples into the 29 | Makefile.am 30 | 31 | * test suite 32 | 33 | ** integrate the test suite into automake's framework (note that the 34 | test suite can be run from the top level directory with "make 35 | check". Still, we want to get it completely under automake's control.) 36 | 37 | ** make test suite more complete 38 | 39 | * generic coding 40 | 41 | ** move as much skeleton code as possible out of gen.c and into 42 | flex.skl 43 | 44 | ** figure out whether we want to add the capability to have 45 | auto-generated backout rules 46 | 47 | ** token-type and token buffer support 48 | 49 | ** check if we still need to #undef macros at the end of a header 50 | 51 | ** merge yylineno into support for location tracking 52 | 53 | ** bug where yylineno is not decremented on REJECT 54 | 55 | ** bug where yylineno is counted in trailing context 56 | 57 | * C++ 58 | 59 | ** have a separate skeleton for c++ 60 | 61 | ** revisit the C++ API. We get requests to make it more complete. 62 | 63 | Local Variables: 64 | Mode: text 65 | mode: outline-minor 66 | End: 67 | -------------------------------------------------------------------------------- /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 procede with the "normal" build procedures. 26 | 27 | #if we pretend to have a ChangeLog, then automake is less 28 | #worried. (Don't worry, we *do* have a ChangeLog, we just need the 29 | #Makefile first.) 30 | 31 | touch ChangeLog 32 | libtoolize --install --force 33 | autoreconf --install --force 34 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | help2man = @HELP2MAN@ 2 | 3 | info_TEXINFOS = flex.texi 4 | dist_man_MANS = flex.1 5 | dist_doc_DATA= flex.pdf 6 | 7 | CLEANFILES = \ 8 | flex.aux \ 9 | flex.cp \ 10 | flex.cps \ 11 | flex.fn \ 12 | flex.fns \ 13 | flex.hk \ 14 | flex.hks \ 15 | flex.ky \ 16 | flex.log \ 17 | flex.op \ 18 | flex.ops \ 19 | flex.pg \ 20 | flex.toc \ 21 | flex.tp \ 22 | flex.tps \ 23 | flex.vr \ 24 | flex.vrs 25 | 26 | $(dist_man_MANS): $(top_srcdir)/configure.ac $(top_srcdir)/src/flex.skl $(top_srcdir)/src/options.c $(top_srcdir)/src/options.h 27 | for i in $(dist_man_MANS) ; do \ 28 | $(help2man) --name='$(PACKAGE_NAME)' \ 29 | --section=`echo $$i | sed -e 's/.*\.\([^.]*\)$$/\1/'` \ 30 | $(top_srcdir)/src/flex$(EXEEXT) > $$i || rm -f $$i ; \ 31 | done 32 | -------------------------------------------------------------------------------- /doc/flex.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/doc/flex.pdf -------------------------------------------------------------------------------- /doc/stamp-vti: -------------------------------------------------------------------------------- 1 | @set UPDATED 10 November 2015 2 | @set UPDATED-MONTH November 2015 3 | @set EDITION 2.6.0 4 | @set VERSION 2.6.0 5 | -------------------------------------------------------------------------------- /doc/version.texi: -------------------------------------------------------------------------------- 1 | @set UPDATED 10 November 2015 2 | @set UPDATED-MONTH November 2015 3 | @set EDITION 2.6.0 4 | @set VERSION 2.6.0 5 | -------------------------------------------------------------------------------- /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 anotating 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 | expr.lex \ 34 | expr.y \ 35 | front.lex \ 36 | front.y \ 37 | j2t.lex \ 38 | myname.lex \ 39 | myname.txt \ 40 | myname2.lex \ 41 | numbers.lex \ 42 | pas_include.lex \ 43 | pascal.lex \ 44 | reject.lex \ 45 | replace.lex \ 46 | string1.lex \ 47 | string2.lex \ 48 | strtest.dat \ 49 | unput.lex \ 50 | user_act.lex \ 51 | userinit.lex \ 52 | wc.lex \ 53 | yymore.lex \ 54 | yymore2.lex \ 55 | yymoretest.dat 56 | -------------------------------------------------------------------------------- /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 | 22 | all: expr front myname eof wc replace user_act string1\ 23 | string2 yymore numbers dates cat 24 | 25 | expr: expr.y expr.lex 26 | $(YACC) expr.y 27 | $(LEX) expr.lex 28 | $(CC) -o expr lex.yy.c y.tab.c $(ALLOCA) -ll -lm 29 | 30 | front: front.y front.lex 31 | $(YACC) front.y 32 | $(LEX) front.lex 33 | $(CC) -o front lex.yy.c y.tab.c $(ALLOCA) -ll -lm 34 | 35 | numbers: numbers.lex 36 | $(LEX) numbers.lex 37 | $(CC) lex.yy.c -o numbers 38 | 39 | dates: dates.lex 40 | $(LEX) dates.lex 41 | $(CC) lex.yy.c -o dates -ll 42 | 43 | yymore: yymore.lex 44 | $(LEX) yymore.lex 45 | $(CC) lex.yy.c -o yymore -ll 46 | 47 | string1: string1.lex 48 | $(LEX) string1.lex 49 | $(CC) lex.yy.c -o string1 -ll 50 | 51 | string2: string2.lex 52 | $(LEX) string2.lex 53 | $(CC) lex.yy.c -o string2 -ll 54 | 55 | myname: myname.lex 56 | $(LEX) myname.lex 57 | $(CC) lex.yy.c -o myname -ll 58 | 59 | myname2: myname2.lex 60 | $(LEX) myname2.lex 61 | $(CC) lex.yy.c -o myname2 -ll 62 | 63 | eof: eof_rules.lex 64 | $(LEX) eof_rules.lex 65 | $(CC) lex.yy.c -o eof -ll 66 | 67 | wc: wc.lex 68 | $(LEX) wc.lex 69 | $(CC) lex.yy.c -o wc -ll 70 | 71 | cat: cat.lex 72 | $(LEX) cat.lex 73 | $(CC) lex.yy.c -o cat -ll 74 | 75 | replace: replace.lex 76 | $(LEX) replace.lex 77 | $(CC) lex.yy.c -o replace -ll 78 | 79 | user_act: expr.y expr.lex 80 | $(LEX) user_act.lex 81 | $(CC) -o user_act lex.yy.c -ll 82 | 83 | clean: 84 | rm -f *.BAK *.o core *~* *.a 85 | rm -f *.tab.h *.tab.c 86 | rm -f myname expr lex.yy.c *.out eof wc yymore 87 | rm -f replace front user_act string1 string2 88 | rm -f dates numbers cat 89 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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]*\" BEGIN(INCLUDE); 21 | \" BEGIN(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 | BEGIN(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 | BEGIN(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/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 TRUE 1 7 | #define FALSE 0 8 | 9 | #define copy_and_return(token_type) { strcpy(yylval.name,yytext); \ 10 | return(token_type); } 11 | 12 | int yylexlinenum = 0; /* so we can count lines */ 13 | %} 14 | 15 | %% 16 | /* Lexical scanning rules begin from here. */ 17 | 18 | MEN|WOMEN|STOCKS|TREES copy_and_return(NOUN) 19 | MISTAKES|GNUS|EMPLOYEES copy_and_return(NOUN) 20 | LOSERS|USERS|CARS|WINDOWS copy_and_return(NOUN) 21 | 22 | DATABASE|NETWORK|FSF|GNU copy_and_return(PROPER_NOUN) 23 | COMPANY|HOUSE|OFFICE|LPF copy_and_return(PROPER_NOUN) 24 | 25 | THE|THIS|THAT|THOSE copy_and_return(DECLARATIVE) 26 | 27 | ALL|FIRST|LAST copy_and_return(CONDITIONAL) 28 | 29 | FIND|SEARCH|SORT|ERASE|KILL copy_and_return(VERB) 30 | ADD|REMOVE|DELETE|PRINT copy_and_return(VERB) 31 | 32 | QUICKLY|SLOWLY|CAREFULLY copy_and_return(ADVERB) 33 | 34 | IN|AT|ON|AROUND|INSIDE|ON copy_and_return(POSITIONAL) 35 | 36 | "." return(PERIOD); 37 | "\n" yylexlinenum++; return(NEWLINE); 38 | . 39 | %% 40 | 41 | -------------------------------------------------------------------------------- /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 | "{" BEGIN(COMMENT); 23 | 24 | "}" BEGIN(INITIAL); 25 | "$include"[ \t]*"(" BEGIN(INCLUDE); 26 | [ \t]* /* skip whitespace */ 27 | 28 | ")" BEGIN(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 | BEGIN(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 | BEGIN(INCLUDE); 65 | } 66 | } 67 | [a-z]+ ECHO; 68 | .|\n ECHO; 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /examples/manual/reject.lex: -------------------------------------------------------------------------------- 1 | /* 2 | * reject.lex: An example of REJECT and unput() 3 | * misuse. 4 | */ 5 | 6 | %% 7 | UNIX { 8 | unput('U'); unput('N'); unput('G'); unput('\0'); 9 | REJECT; 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 | , ECHO; 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/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 unput(). 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 | #define YY_USER_ACTION user_action(); 8 | 9 | %} 10 | 11 | %% 12 | 13 | .* ECHO; 14 | \n ECHO; 15 | 16 | %% 17 | 18 | void user_action(void) 19 | { 20 | int loop; 21 | 22 | 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 | \" BEGIN(STRING); 20 | 21 | [^\\\n"]* yymore(); 22 | <> yyerror("EOF in string."); BEGIN(INITIAL); 23 | \n yyerror("Unterminated string."); BEGIN(INITIAL); 24 | \\\n yymore(); 25 | \" { 26 | yytext[yyleng-1] = '\0'; 27 | printf("string = \"%s\"",yytext); BEGIN(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 | \" BEGIN(STRING); 20 | 21 | [^\\\n"]* yymore(); 22 | <> yyerror("EOF in string."); BEGIN(INITIAL); 23 | \n yyerror("Unterminated string."); BEGIN(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); BEGIN(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} FLEX_STD cout << "number " << YYText() << '\n'; 43 | 44 | \n mylineno++; 45 | 46 | {name} FLEX_STD cout << "name " << YYText() << '\n'; 47 | 48 | {string} FLEX_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/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libcompat.la 2 | libcompat_la_SOURCES = lib.c 3 | libcompat_la_LIBADD = $(LTLIBOBJS) 4 | 5 | -------------------------------------------------------------------------------- /lib/lib.c: -------------------------------------------------------------------------------- 1 | /* Since building an empty library could cause problems, we provide a 2 | * function to go into the library. We could make this non-trivial by 3 | * moving something that flex treats as a library function into this 4 | * directory. */ 5 | 6 | void do_nothing(){ return;} 7 | 8 | -------------------------------------------------------------------------------- /lib/malloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #undef malloc 3 | 4 | #include 5 | 6 | void *malloc (); 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 | -------------------------------------------------------------------------------- /m4/intlmacosx.m4: -------------------------------------------------------------------------------- 1 | # intlmacosx.m4 serial 5 (gettext-0.18.2) 2 | dnl Copyright (C) 2004-2014 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | dnl 7 | dnl This file can can be used in projects which are not available under 8 | dnl the GNU General Public License or the GNU Library General Public 9 | dnl License but which still want to provide support for the GNU gettext 10 | dnl functionality. 11 | dnl Please note that the actual code of the GNU gettext library is covered 12 | dnl by the GNU Library General Public License, and the rest of the GNU 13 | dnl gettext package package is covered by the GNU General Public License. 14 | dnl They are *not* in the public domain. 15 | 16 | dnl Checks for special options needed on Mac OS X. 17 | dnl Defines INTL_MACOSX_LIBS. 18 | AC_DEFUN([gt_INTL_MACOSX], 19 | [ 20 | dnl Check for API introduced in Mac OS X 10.2. 21 | AC_CACHE_CHECK([for CFPreferencesCopyAppValue], 22 | [gt_cv_func_CFPreferencesCopyAppValue], 23 | [gt_save_LIBS="$LIBS" 24 | LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" 25 | AC_LINK_IFELSE( 26 | [AC_LANG_PROGRAM( 27 | [[#include ]], 28 | [[CFPreferencesCopyAppValue(NULL, NULL)]])], 29 | [gt_cv_func_CFPreferencesCopyAppValue=yes], 30 | [gt_cv_func_CFPreferencesCopyAppValue=no]) 31 | LIBS="$gt_save_LIBS"]) 32 | if test $gt_cv_func_CFPreferencesCopyAppValue = yes; then 33 | AC_DEFINE([HAVE_CFPREFERENCESCOPYAPPVALUE], [1], 34 | [Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in the CoreFoundation framework.]) 35 | fi 36 | dnl Check for API introduced in Mac OS X 10.3. 37 | AC_CACHE_CHECK([for CFLocaleCopyCurrent], [gt_cv_func_CFLocaleCopyCurrent], 38 | [gt_save_LIBS="$LIBS" 39 | LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" 40 | AC_LINK_IFELSE( 41 | [AC_LANG_PROGRAM( 42 | [[#include ]], 43 | [[CFLocaleCopyCurrent();]])], 44 | [gt_cv_func_CFLocaleCopyCurrent=yes], 45 | [gt_cv_func_CFLocaleCopyCurrent=no]) 46 | LIBS="$gt_save_LIBS"]) 47 | if test $gt_cv_func_CFLocaleCopyCurrent = yes; then 48 | AC_DEFINE([HAVE_CFLOCALECOPYCURRENT], [1], 49 | [Define to 1 if you have the Mac OS X function CFLocaleCopyCurrent in the CoreFoundation framework.]) 50 | fi 51 | INTL_MACOSX_LIBS= 52 | if test $gt_cv_func_CFPreferencesCopyAppValue = yes || test $gt_cv_func_CFLocaleCopyCurrent = yes; then 53 | INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation" 54 | fi 55 | AC_SUBST([INTL_MACOSX_LIBS]) 56 | ]) 57 | -------------------------------------------------------------------------------- /m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004, 2011-2015 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # @configure_input@ 11 | 12 | # serial 4179 ltversion.m4 13 | # This file is part of GNU Libtool 14 | 15 | m4_define([LT_PACKAGE_VERSION], [2.4.6]) 16 | m4_define([LT_PACKAGE_REVISION], [2.4.6]) 17 | 18 | AC_DEFUN([LTVERSION_VERSION], 19 | [macro_version='2.4.6' 20 | macro_revision='2.4.6' 21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 22 | _LT_DECL(, macro_revision, 0) 23 | ]) 24 | -------------------------------------------------------------------------------- /m4/nls.m4: -------------------------------------------------------------------------------- 1 | # nls.m4 serial 5 (gettext-0.18) 2 | dnl Copyright (C) 1995-2003, 2005-2006, 2008-2014 Free Software Foundation, 3 | dnl Inc. 4 | dnl This file is free software; the Free Software Foundation 5 | dnl gives unlimited permission to copy and/or distribute it, 6 | dnl with or without modifications, as long as this notice is preserved. 7 | dnl 8 | dnl This file can can be used in projects which are not available under 9 | dnl the GNU General Public License or the GNU Library General Public 10 | dnl License but which still want to provide support for the GNU gettext 11 | dnl functionality. 12 | dnl Please note that the actual code of the GNU gettext library is covered 13 | dnl by the GNU Library General Public License, and the rest of the GNU 14 | dnl gettext package package is covered by the GNU General Public License. 15 | dnl They are *not* in the public domain. 16 | 17 | dnl Authors: 18 | dnl Ulrich Drepper , 1995-2000. 19 | dnl Bruno Haible , 2000-2003. 20 | 21 | AC_PREREQ([2.50]) 22 | 23 | AC_DEFUN([AM_NLS], 24 | [ 25 | AC_MSG_CHECKING([whether NLS is requested]) 26 | dnl Default is enabled NLS 27 | AC_ARG_ENABLE([nls], 28 | [ --disable-nls do not use Native Language Support], 29 | USE_NLS=$enableval, USE_NLS=yes) 30 | AC_MSG_RESULT([$USE_NLS]) 31 | AC_SUBST([USE_NLS]) 32 | ]) 33 | -------------------------------------------------------------------------------- /po/LINGUAS: -------------------------------------------------------------------------------- 1 | ca 2 | da 3 | de 4 | en@quot 5 | en@boldquot 6 | eo 7 | es 8 | fi 9 | fr 10 | ga 11 | hr 12 | ko 13 | nl 14 | pl 15 | pt_BR 16 | ro 17 | ru 18 | sr 19 | sv 20 | tr 21 | vi 22 | zh_CN 23 | zh_TW 24 | -------------------------------------------------------------------------------- /po/Makevars: -------------------------------------------------------------------------------- 1 | # Makefile variables for PO directory in any package using GNU gettext. 2 | 3 | # Usually the message domain is the same as the package name. 4 | DOMAIN = $(PACKAGE) 5 | 6 | # These two variables depend on the location of this directory. 7 | subdir = po 8 | top_builddir = .. 9 | 10 | # These options get passed to xgettext. 11 | XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ 12 | 13 | # This is the copyright holder that gets inserted into the header of the 14 | # $(DOMAIN).pot file. Set this to the copyright holder of the surrounding 15 | # package. (Note that the msgstr strings, extracted from the package's 16 | # sources, belong to the copyright holder of the package.) Translators are 17 | # expected to transfer the copyright for their translations to this person 18 | # or entity, or to disclaim their copyright. The empty string stands for 19 | # the public domain; in this case the translators are expected to disclaim 20 | # their copyright. 21 | COPYRIGHT_HOLDER = 22 | 23 | # This is the email address or URL to which the translators shall report 24 | # bugs in the untranslated strings: 25 | # - Strings which are not entire sentences, see the maintainer guidelines 26 | # in the GNU gettext documentation, section 'Preparing Strings'. 27 | # - Strings which use unclear terms or require additional context to be 28 | # understood. 29 | # - Strings which make invalid assumptions about notation of date, time or 30 | # money. 31 | # - Pluralisation problems. 32 | # - Incorrect English spelling. 33 | # - Incorrect formatting. 34 | # It can be your email address, or a mailing list address where translators 35 | # can write to without being subscribed, or the URL of a web page through 36 | # which the translators can contact you. 37 | MSGID_BUGS_ADDRESS = flex-devel@lists.sourceforge.net 38 | 39 | # This is the list of locale categories, beyond LC_MESSAGES, for which the 40 | # message catalogs shall be used. It is usually empty. 41 | EXTRA_LOCALE_CATEGORIES = 42 | -------------------------------------------------------------------------------- /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/skel.c 16 | src/sym.c 17 | src/tblcmp.c 18 | src/yylex.c 19 | -------------------------------------------------------------------------------- /po/Rules-quot: -------------------------------------------------------------------------------- 1 | # This file, Rules-quot, can be copied and used freely without restrictions. 2 | # Special Makefile rules for English message catalogs with quotation marks. 3 | 4 | DISTFILES.common.extra1 = quot.sed boldquot.sed en@quot.header en@boldquot.header insert-header.sin Rules-quot 5 | 6 | .SUFFIXES: .insert-header .po-update-en 7 | 8 | en@quot.po-create: 9 | $(MAKE) en@quot.po-update 10 | en@boldquot.po-create: 11 | $(MAKE) en@boldquot.po-update 12 | 13 | en@quot.po-update: en@quot.po-update-en 14 | en@boldquot.po-update: en@boldquot.po-update-en 15 | 16 | .insert-header.po-update-en: 17 | @lang=`echo $@ | sed -e 's/\.po-update-en$$//'`; \ 18 | if test "$(PACKAGE)" = "gettext-tools"; then PATH=`pwd`/../src:$$PATH; GETTEXTLIBDIR=`cd $(top_srcdir)/src && pwd`; export GETTEXTLIBDIR; fi; \ 19 | tmpdir=`pwd`; \ 20 | echo "$$lang:"; \ 21 | ll=`echo $$lang | sed -e 's/@.*//'`; \ 22 | LC_ALL=C; export LC_ALL; \ 23 | cd $(srcdir); \ 24 | if $(MSGINIT) -i $(DOMAIN).pot --no-translator -l $$lang -o - 2>/dev/null \ 25 | | $(SED) -f $$tmpdir/$$lang.insert-header | $(MSGCONV) -t UTF-8 | \ 26 | { case `$(MSGFILTER) --version | sed 1q | sed -e 's,^[^0-9]*,,'` in \ 27 | '' | 0.[0-9] | 0.[0-9].* | 0.1[0-8] | 0.1[0-8].*) \ 28 | $(MSGFILTER) $(SED) -f `echo $$lang | sed -e 's/.*@//'`.sed \ 29 | ;; \ 30 | *) \ 31 | $(MSGFILTER) `echo $$lang | sed -e 's/.*@//'` \ 32 | ;; \ 33 | esac } 2>/dev/null > $$tmpdir/$$lang.new.po \ 34 | ; then \ 35 | if cmp $$lang.po $$tmpdir/$$lang.new.po >/dev/null 2>&1; then \ 36 | rm -f $$tmpdir/$$lang.new.po; \ 37 | else \ 38 | if mv -f $$tmpdir/$$lang.new.po $$lang.po; then \ 39 | :; \ 40 | else \ 41 | echo "creation of $$lang.po failed: cannot move $$tmpdir/$$lang.new.po to $$lang.po" 1>&2; \ 42 | exit 1; \ 43 | fi; \ 44 | fi; \ 45 | else \ 46 | echo "creation of $$lang.po failed!" 1>&2; \ 47 | rm -f $$tmpdir/$$lang.new.po; \ 48 | fi 49 | 50 | en@quot.insert-header: insert-header.sin 51 | sed -e '/^#/d' -e 's/HEADER/en@quot.header/g' $(srcdir)/insert-header.sin > en@quot.insert-header 52 | 53 | en@boldquot.insert-header: insert-header.sin 54 | sed -e '/^#/d' -e 's/HEADER/en@boldquot.header/g' $(srcdir)/insert-header.sin > en@boldquot.insert-header 55 | 56 | mostlyclean: mostlyclean-quot 57 | mostlyclean-quot: 58 | rm -f *.insert-header 59 | -------------------------------------------------------------------------------- /po/boldquot.sed: -------------------------------------------------------------------------------- 1 | s/"\([^"]*\)"/“\1”/g 2 | s/`\([^`']*\)'/‘\1’/g 3 | s/ '\([^`']*\)' / ‘\1’ /g 4 | s/ '\([^`']*\)'$/ ‘\1’/g 5 | s/^'\([^`']*\)' /‘\1’ /g 6 | s/“”/""/g 7 | s/“/“/g 8 | s/”/”/g 9 | s/‘/‘/g 10 | s/’/’/g 11 | -------------------------------------------------------------------------------- /po/ca.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/ca.gmo -------------------------------------------------------------------------------- /po/da.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/da.gmo -------------------------------------------------------------------------------- /po/da.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/da.po -------------------------------------------------------------------------------- /po/de.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/de.gmo -------------------------------------------------------------------------------- /po/en@boldquot.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/en@boldquot.gmo -------------------------------------------------------------------------------- /po/en@boldquot.header: -------------------------------------------------------------------------------- 1 | # All this catalog "translates" are quotation characters. 2 | # The msgids must be ASCII and therefore cannot contain real quotation 3 | # characters, only substitutes like grave accent (0x60), apostrophe (0x27) 4 | # and double quote (0x22). These substitutes look strange; see 5 | # http://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html 6 | # 7 | # This catalog translates grave accent (0x60) and apostrophe (0x27) to 8 | # left single quotation mark (U+2018) and right single quotation mark (U+2019). 9 | # It also translates pairs of apostrophe (0x27) to 10 | # left single quotation mark (U+2018) and right single quotation mark (U+2019) 11 | # and pairs of quotation mark (0x22) to 12 | # left double quotation mark (U+201C) and right double quotation mark (U+201D). 13 | # 14 | # When output to an UTF-8 terminal, the quotation characters appear perfectly. 15 | # When output to an ISO-8859-1 terminal, the single quotation marks are 16 | # transliterated to apostrophes (by iconv in glibc 2.2 or newer) or to 17 | # grave/acute accent (by libiconv), and the double quotation marks are 18 | # transliterated to 0x22. 19 | # When output to an ASCII terminal, the single quotation marks are 20 | # transliterated to apostrophes, and the double quotation marks are 21 | # transliterated to 0x22. 22 | # 23 | # This catalog furthermore displays the text between the quotation marks in 24 | # bold face, assuming the VT100/XTerm escape sequences. 25 | # 26 | -------------------------------------------------------------------------------- /po/en@quot.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/en@quot.gmo -------------------------------------------------------------------------------- /po/en@quot.header: -------------------------------------------------------------------------------- 1 | # All this catalog "translates" are quotation characters. 2 | # The msgids must be ASCII and therefore cannot contain real quotation 3 | # characters, only substitutes like grave accent (0x60), apostrophe (0x27) 4 | # and double quote (0x22). These substitutes look strange; see 5 | # http://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html 6 | # 7 | # This catalog translates grave accent (0x60) and apostrophe (0x27) to 8 | # left single quotation mark (U+2018) and right single quotation mark (U+2019). 9 | # It also translates pairs of apostrophe (0x27) to 10 | # left single quotation mark (U+2018) and right single quotation mark (U+2019) 11 | # and pairs of quotation mark (0x22) to 12 | # left double quotation mark (U+201C) and right double quotation mark (U+201D). 13 | # 14 | # When output to an UTF-8 terminal, the quotation characters appear perfectly. 15 | # When output to an ISO-8859-1 terminal, the single quotation marks are 16 | # transliterated to apostrophes (by iconv in glibc 2.2 or newer) or to 17 | # grave/acute accent (by libiconv), and the double quotation marks are 18 | # transliterated to 0x22. 19 | # When output to an ASCII terminal, the single quotation marks are 20 | # transliterated to apostrophes, and the double quotation marks are 21 | # transliterated to 0x22. 22 | # 23 | -------------------------------------------------------------------------------- /po/eo.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/eo.gmo -------------------------------------------------------------------------------- /po/es.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/es.gmo -------------------------------------------------------------------------------- /po/es.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/es.po -------------------------------------------------------------------------------- /po/fi.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/fi.gmo -------------------------------------------------------------------------------- /po/fr.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/fr.gmo -------------------------------------------------------------------------------- /po/ga.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/ga.gmo -------------------------------------------------------------------------------- /po/hr.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/hr.gmo -------------------------------------------------------------------------------- /po/insert-header.sin: -------------------------------------------------------------------------------- 1 | # Sed script that inserts the file called HEADER before the header entry. 2 | # 3 | # At each occurrence of a line starting with "msgid ", we execute the following 4 | # commands. At the first occurrence, insert the file. At the following 5 | # occurrences, do nothing. The distinction between the first and the following 6 | # occurrences is achieved by looking at the hold space. 7 | /^msgid /{ 8 | x 9 | # Test if the hold space is empty. 10 | s/m/m/ 11 | ta 12 | # Yes it was empty. First occurrence. Read the file. 13 | r HEADER 14 | # Output the file's contents by reading the next line. But don't lose the 15 | # current line while doing this. 16 | g 17 | N 18 | bb 19 | :a 20 | # The hold space was nonempty. Following occurrences. Do nothing. 21 | x 22 | :b 23 | } 24 | -------------------------------------------------------------------------------- /po/ko.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/ko.gmo -------------------------------------------------------------------------------- /po/ko.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/ko.po -------------------------------------------------------------------------------- /po/nl.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/nl.gmo -------------------------------------------------------------------------------- /po/pl.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/pl.gmo -------------------------------------------------------------------------------- /po/pl.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/pl.po -------------------------------------------------------------------------------- /po/pt_BR.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/pt_BR.gmo -------------------------------------------------------------------------------- /po/quot.sed: -------------------------------------------------------------------------------- 1 | s/"\([^"]*\)"/“\1”/g 2 | s/`\([^`']*\)'/‘\1’/g 3 | s/ '\([^`']*\)' / ‘\1’ /g 4 | s/ '\([^`']*\)'$/ ‘\1’/g 5 | s/^'\([^`']*\)' /‘\1’ /g 6 | s/“”/""/g 7 | -------------------------------------------------------------------------------- /po/remove-potcdate.sin: -------------------------------------------------------------------------------- 1 | # Sed script that remove the POT-Creation-Date line in the header entry 2 | # from a POT file. 3 | # 4 | # The distinction between the first and the following occurrences of the 5 | # pattern is achieved by looking at the hold space. 6 | /^"POT-Creation-Date: .*"$/{ 7 | x 8 | # Test if the hold space is empty. 9 | s/P/P/ 10 | ta 11 | # Yes it was empty. First occurrence. Remove the line. 12 | g 13 | d 14 | bb 15 | :a 16 | # The hold space was nonempty. Following occurrences. Do nothing. 17 | x 18 | :b 19 | } 20 | -------------------------------------------------------------------------------- /po/ro.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/ro.gmo -------------------------------------------------------------------------------- /po/ro.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/ro.po -------------------------------------------------------------------------------- /po/ru.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/ru.gmo -------------------------------------------------------------------------------- /po/sr.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/sr.gmo -------------------------------------------------------------------------------- /po/stamp-po: -------------------------------------------------------------------------------- 1 | timestamp 2 | -------------------------------------------------------------------------------- /po/sv.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/sv.gmo -------------------------------------------------------------------------------- /po/sv.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/sv.po -------------------------------------------------------------------------------- /po/tr.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/tr.gmo -------------------------------------------------------------------------------- /po/vi.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/vi.gmo -------------------------------------------------------------------------------- /po/zh_CN.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/zh_CN.gmo -------------------------------------------------------------------------------- /po/zh_TW.gmo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/po/zh_TW.gmo -------------------------------------------------------------------------------- /src/flexint.h: -------------------------------------------------------------------------------- 1 | /* flex integer type definitions */ 2 | 3 | #ifndef FLEXINT_H 4 | #define FLEXINT_H 5 | 6 | /* C99 systems have . Non-C99 systems may or may not. */ 7 | 8 | #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 9 | 10 | /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, 11 | * if you want the limit (max/min) macros for int types. 12 | */ 13 | #ifndef __STDC_LIMIT_MACROS 14 | #define __STDC_LIMIT_MACROS 1 15 | #endif 16 | 17 | #include 18 | typedef int8_t flex_int8_t; 19 | typedef uint8_t flex_uint8_t; 20 | typedef int16_t flex_int16_t; 21 | typedef uint16_t flex_uint16_t; 22 | typedef int32_t flex_int32_t; 23 | typedef uint32_t flex_uint32_t; 24 | #else 25 | typedef signed char flex_int8_t; 26 | typedef short int flex_int16_t; 27 | typedef int flex_int32_t; 28 | typedef unsigned char flex_uint8_t; 29 | typedef unsigned short int flex_uint16_t; 30 | typedef unsigned int flex_uint32_t; 31 | 32 | /* Limits of integral types. */ 33 | #ifndef INT8_MIN 34 | #define INT8_MIN (-128) 35 | #endif 36 | #ifndef INT16_MIN 37 | #define INT16_MIN (-32767-1) 38 | #endif 39 | #ifndef INT32_MIN 40 | #define INT32_MIN (-2147483647-1) 41 | #endif 42 | #ifndef INT8_MAX 43 | #define INT8_MAX (127) 44 | #endif 45 | #ifndef INT16_MAX 46 | #define INT16_MAX (32767) 47 | #endif 48 | #ifndef INT32_MAX 49 | #define INT32_MAX (2147483647) 50 | #endif 51 | #ifndef UINT8_MAX 52 | #define UINT8_MAX (255U) 53 | #endif 54 | #ifndef UINT16_MAX 55 | #define UINT16_MAX (65535U) 56 | #endif 57 | #ifndef UINT32_MAX 58 | #define UINT32_MAX (4294967295U) 59 | #endif 60 | 61 | #endif /* ! C99 */ 62 | 63 | #endif /* ! FLEXINT_H */ 64 | -------------------------------------------------------------------------------- /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 | extern int yylex (void); 25 | 26 | int main (int argc, char *argv[]) 27 | { 28 | (void)argc; 29 | (void)argv; 30 | 31 | while (yylex () != 0) ; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /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 | cat <= _sf_max) 43 | _sf_stk = (scanflags_t*) flex_realloc ( (void*) _sf_stk, sizeof(scanflags_t) * (_sf_max += 32)); 44 | 45 | // copy the top element 46 | _sf_stk[_sf_top_ix + 1] = _sf_stk[_sf_top_ix]; 47 | ++_sf_top_ix; 48 | } 49 | 50 | void 51 | sf_pop (void) 52 | { 53 | assert(_sf_top_ix > 0); 54 | --_sf_top_ix; 55 | } 56 | 57 | /* one-time initialization. Should be called before any sf_ functions. */ 58 | void 59 | sf_init (void) 60 | { 61 | assert(_sf_stk == NULL); 62 | _sf_stk = (scanflags_t*) flex_alloc ( sizeof(scanflags_t) * (_sf_max = 32)); 63 | if (!_sf_stk) 64 | lerr_fatal(_("Unable to allocate %zu of stack"), sizeof(scanflags_t)); 65 | _sf_stk[_sf_top_ix] = 0; 66 | } 67 | 68 | /* vim:set expandtab cindent tabstop=4 softtabstop=4 shiftwidth=4 textwidth=0: */ 69 | -------------------------------------------------------------------------------- /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_int32_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 n; 70 | } 71 | -------------------------------------------------------------------------------- /src/version.h: -------------------------------------------------------------------------------- 1 | #define FLEX_VERSION VERSION 2 | -------------------------------------------------------------------------------- /tests/README: -------------------------------------------------------------------------------- 1 | This file describes the flex test suite. 2 | 3 | * WHO SHOULD USE THE TEST SUITE? 4 | 5 | The test suite is intended to be used by flex developers, i.e., anyone hacking 6 | the flex distribution. If you are simply installing flex, then you can ignore 7 | this directory and its contents. 8 | 9 | * STRUCTURE OF THE TEST SUITE 10 | 11 | The testsuite consists of several tests. Each test is centered around 12 | a scanner known to work with the most recent version of flex. In 13 | general, after you modify your copy of the flex distribution, you 14 | should re-run the test suite. Some of the tests may require certain 15 | tools to be available (e.g., bison, diff). If any test returns an 16 | error or generates an error message, then your modifications *may* 17 | have broken a feature of flex. At a minimum, you'll want to 18 | investigate the failure and determine if it's truly significant. 19 | 20 | * HOW TO RUN THE TEST SUITE 21 | 22 | To build and execute all tests from the top level of the flex source tree: 23 | 24 | $ make check 25 | 26 | To build and execute a single test: 27 | 28 | $ cd tests/ # from the top level of the flex tree. 29 | $ make testname.log 30 | 31 | where "testname" is the name of the test. This is an automake-ism 32 | that will create (or re-create, if need be), a log of the particular 33 | test run that you're working on. 34 | 35 | * HOW TO ADD A NEW TEST TO THE TEST SUITE 36 | 37 | ** List your test in the TESTS variable in Makefile.am in this 38 | directory. Note that due to the large number of tests, we use 39 | variables to group similar tests together. This also helps with 40 | handling the automake test suite requirements. Hopefully your test 41 | can be listed in SIMPLE_TESTS. You'll need to add the appropriate 42 | automake _SOURCES variable as well. If you're unsure, then consult 43 | the automake manual, paying attention to the parallel test harness 44 | section. 45 | 46 | ** On success, your test should return zero. 47 | 48 | ** On error, your test should return 1 (one) and print a message to 49 | stderr, which will have been redirected to the log file created by the 50 | automake test suite harness. 51 | 52 | ** If your test is skipped (e.g., because bison was not found), then 53 | the test should return 2 (two). 54 | 55 | ** Once your work is done, submit a patch via the flex development 56 | mailing list, the github pull request mechanism or some other 57 | suitable means. 58 | -------------------------------------------------------------------------------- /tests/array_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 | /*#include "parser.h" */ 30 | 31 | %} 32 | 33 | %option 8bit prefix="test" 34 | %option nounput nomain noyywrap noinput 35 | %option warn array 36 | 37 | 38 | %% 39 | 40 | .|\n { } 41 | 42 | 43 | %% 44 | 45 | int main (void); 46 | 47 | int 48 | main () 49 | { 50 | yyin = stdin; 51 | yyout = stdout; 52 | yylex(); 53 | printf("TEST RETURNING OK.\n"); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /tests/array_nr.txt: -------------------------------------------------------------------------------- 1 | 0000 foo 1111 foo 0000 bar 2 | 0000 foo 1111 foo 0000 bar 3 | -------------------------------------------------------------------------------- /tests/array_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 | /* A template scanner file to build "scanner.c". */ 26 | #include 27 | #include 28 | #include "config.h" 29 | /*#include "parser.h" */ 30 | 31 | %} 32 | 33 | %option 8bit prefix="test" 34 | %option nounput nomain noyywrap noinput 35 | %option warn array reentrant 36 | 37 | 38 | %% 39 | 40 | .|\n { } 41 | 42 | 43 | %% 44 | 45 | int main(void); 46 | 47 | int 48 | main () 49 | { 50 | yyscan_t lexer; 51 | 52 | yylex_init(&lexer); 53 | yyset_in(stdin, lexer); 54 | yyset_out(stdout, lexer); 55 | 56 | yylex( lexer ); 57 | 58 | yylex_destroy( lexer); 59 | printf("TEST RETURNING OK.\n"); 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /tests/array_r.txt: -------------------------------------------------------------------------------- 1 | 0000 foo 1111 foo 0000 bar 2 | 0000 foo 1111 foo 0000 bar 3 | -------------------------------------------------------------------------------- /tests/basic_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 | /* TEST scanner. 25 | Basic non-reentrant scanner. 26 | 27 | Sample Input: 28 | # this is a comment 29 | foo = true 30 | bar = "string value" 31 | integer = 43 32 | */ 33 | %{ 34 | #include "config.h" 35 | %} 36 | 37 | %option prefix="test" 38 | %option nounput noyywrap noyylineno warn nodefault noinput 39 | 40 | IDENT [[:alnum:]_-] 41 | WS [[:blank:]] 42 | %% 43 | 44 | ^{IDENT}+{WS}*={WS}*(true|false){WS}*\r?\n { return 100;} 45 | ^{IDENT}+{WS}*={WS}*\"[^\"\n\r]*\"{WS}*\r?\n { return 101;} 46 | ^{IDENT}+{WS}*={WS}*[[:digit:]]+{WS}*\r?\n { return 102;} 47 | ^{WS}*#.*\r?\n { } 48 | ^{WS}*\r?\n { } 49 | .|\n { fprintf(stderr,"Invalid line.\n"); exit(-1);} 50 | 51 | %% 52 | 53 | int main(void); 54 | 55 | int main () 56 | { 57 | yyin = stdin; 58 | yyout = stdout; 59 | while( yylex() ) 60 | { 61 | } 62 | printf("TEST RETURNING OK.\n"); 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /tests/basic_nr.txt: -------------------------------------------------------------------------------- 1 | # this is a comment 2 | foo = "bar" 3 | num = 43 4 | setting = false 5 | 6 | -------------------------------------------------------------------------------- /tests/basic_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 | /* A reentrant scanner. 25 | This file will not compile under flex version <= 2.5.4. 26 | Sample Input: 27 | # this is a comment 28 | foo = true 29 | bar = "string value" 30 | integer = 43 31 | */ 32 | %{ 33 | #include "config.h" 34 | %} 35 | 36 | %option prefix="test" 37 | %option nounput noyywrap noyylineno warn nodefault noinput 38 | %option reentrant 39 | 40 | IDENT [[:alnum:]_-] 41 | WS [[:blank:]] 42 | %% 43 | 44 | ^{IDENT}+{WS}*={WS}*(true|false){WS}*\r?\n { return 100;} 45 | ^{IDENT}+{WS}*={WS}*\"[^\"\n\r]*\"{WS}*\r?\n { return 101;} 46 | ^{IDENT}+{WS}*={WS}*[[:digit:]]+{WS}*\r?\n { return 102;} 47 | ^{WS}*#.*\r?\n { } 48 | ^{WS}*\r?\n { } 49 | .|\n { fprintf(stderr,"Invalid line.\n"); exit(-1);} 50 | 51 | %% 52 | 53 | int main(void); 54 | 55 | int main () 56 | { 57 | yyscan_t lexer; 58 | yylex_init( &lexer ); 59 | yyset_out ( stdout,lexer); 60 | yyset_in ( stdin, lexer); 61 | while( yylex(lexer) ) 62 | { 63 | } 64 | yylex_destroy( lexer ); 65 | printf("TEST RETURNING OK.\n"); 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /tests/basic_r.txt: -------------------------------------------------------------------------------- 1 | # this is a comment 2 | foo = "bar" 3 | num = 43 4 | setting = false 5 | -------------------------------------------------------------------------------- /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 | extern int testparse(void); 28 | 29 | int main ( int argc, char** argv ) 30 | { 31 | (void)argc; 32 | (void)argv; 33 | 34 | /*yydebug =1;*/ 35 | testin = stdin; 36 | testparse ( ); 37 | return 0; 38 | } 39 | 40 | 41 | 42 | /* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */ 43 | -------------------------------------------------------------------------------- /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 | extern int testget_lineno(void); 42 | 43 | 44 | /* A dummy function. A check against seg-faults in yylval->str. */ 45 | 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()) 82 | { 83 | yyerror("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(const char* msg) { 95 | fprintf(stderr,"%s\n",msg); 96 | return 0; 97 | } 98 | 99 | -------------------------------------------------------------------------------- /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 = (char*)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_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 = (char*)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 | 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 = (char*)malloc(strlen(s1)+1); 79 | sprintf(s2,"%s",s1); 80 | return s2; 81 | } 82 | -------------------------------------------------------------------------------- /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 | yyin = stdin; 52 | yyout = stdout; 53 | yylex(); 54 | yylex_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 | yylex_init( &lexer ); 53 | yyset_out ( stdout,lexer); 54 | yyset_in ( stdin, lexer); 55 | while( yylex(lexer) ) 56 | { 57 | } 58 | yylex_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_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_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 | %} 31 | 32 | %option 8bit prefix="test" 33 | %option nounput nomain noyywrap noinput 34 | %option warn debug 35 | 36 | %% 37 | .+ { } 38 | \n { } 39 | %% 40 | 41 | int main(void); 42 | 43 | int 44 | main () 45 | { 46 | yyin = stdin; 47 | yyout = stdout; 48 | yy_flex_debug = 1; 49 | yylex(); 50 | printf("TEST RETURNING OK.\n"); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /tests/debug_nr.txt: -------------------------------------------------------------------------------- 1 | Any input will do for this test. 2 | We are only testing if it actually runs in debug mode. 3 | -------------------------------------------------------------------------------- /tests/debug_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 | /* A template scanner file to build "scanner.c". */ 26 | #include 27 | #include 28 | #include "config.h" 29 | 30 | %} 31 | 32 | %option 8bit prefix="test" 33 | %option nounput nomain noyywrap noinput 34 | %option warn debug reentrant 35 | 36 | %% 37 | .+ { } 38 | \n { } 39 | %% 40 | 41 | int main(void); 42 | 43 | int main () 44 | { 45 | yyscan_t lexer; 46 | yylex_init( &lexer ); 47 | yyset_out ( stdout,lexer); 48 | yyset_in ( stdin, lexer); 49 | 50 | /* Just see if the next line compiles. */ 51 | testset_debug (testget_debug(lexer), lexer); 52 | 53 | while( yylex(lexer) ) 54 | { 55 | } 56 | yylex_destroy( lexer ); 57 | printf("TEST RETURNING OK.\n"); 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /tests/debug_r.txt: -------------------------------------------------------------------------------- 1 | Any input will do for this test. 2 | We are only testing if it actually runs in debug mode. 3 | -------------------------------------------------------------------------------- /tests/extended.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 | /* This test is for correctness of extended (?...) patterns. */ 26 | 27 | #include 28 | #include 29 | #include "config.h" 30 | 31 | %} 32 | 33 | %option 8bit prefix="test" 34 | %option nounput nomain noyywrap noinput 35 | %option warn 36 | 37 | 38 | %% 39 | 40 | /* Output should match the input. */ 41 | 42 | abc(?# Single Line Comment )def ECHO; 43 | ghi(?# 44 | multi-line 45 | comment 46 | )jkl ECHO; 47 | 48 | mno(?# 49 | multi-line // 50 | comment with ## 51 | ~~!@#$ %^&*(@-_+=\|,.<>/ ?: ; 52 | punctuation 53 | )pqr ECHO; 54 | (?# Start of a rule.)stu ECHO; 55 | vwxyz(?#End of a rule.) ECHO; 56 | A(?x: B 57 | /* comment */ 58 | C D) ECHO; 59 | 60 | \n ECHO; 61 | %% 62 | 63 | int main(void); 64 | 65 | int 66 | main () 67 | { 68 | yyin = stdin; 69 | yyout = stdout; 70 | yylex(); 71 | //printf("TEST RETURNING OK.\n"); 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /tests/extended.txt: -------------------------------------------------------------------------------- 1 | abcdefghijklmnopqrstuvwxyz 2 | ABCD 3 | -------------------------------------------------------------------------------- /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 | 34 | %option 8bit prefix="test" 35 | %option nounput nomain noyywrap noinput 36 | %option warn 37 | 38 | %x GET_FILENAME 39 | 40 | %% 41 | 42 | { 43 | ^"#include"[[:blank:]]+"<" { BEGIN(GET_FILENAME); } 44 | .|\n { ECHO; } 45 | } 46 | 47 | { 48 | [[:alnum:]_.-]+> { 49 | /* recurse */ 50 | yytext[yyleng-1]='\0'; 51 | if((yyin=fopen(yytext,"r"))==NULL) { 52 | fprintf(stderr,"*** Error: Could not open include file \"%s\".\n",yytext); 53 | yyterminate(); 54 | } 55 | yypush_buffer_state( yy_create_buffer( yyin, YY_BUF_SIZE )); 56 | BEGIN(0); 57 | } 58 | .|\n { 59 | fprintf(stderr,"Invalid input \"%s\".\n", yytext); 60 | yyterminate(); 61 | } 62 | } 63 | 64 | <> { 65 | fclose(yyin); 66 | yypop_buffer_state(); 67 | if(!YY_CURRENT_BUFFER) 68 | yyterminate(); 69 | } 70 | 71 | %% 72 | 73 | int main(int argc, char** argv); 74 | 75 | int 76 | main ( int argc, char** argv ) 77 | { 78 | FILE * fp; 79 | if( argc != 2 ) { 80 | fprintf(stderr,"*** Error: Must specify one filename.\n"); 81 | exit(-1); 82 | } 83 | if((fp=fopen(argv[1],"r"))==NULL) { 84 | fprintf(stderr,"*** Error: fopen(%s) failed.\n",argv[1]); 85 | exit(-1); 86 | } 87 | yyin = fp; 88 | yyout = stdout; 89 | yylex(); 90 | printf("TEST RETURNING OK.\n"); 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /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.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/lineno_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 | Run as: 27 | test-lineno-nr # report flex's yylineno 28 | test-lineno-nr 1 # report count_newlines(stdin) 29 | */ 30 | 31 | #include 32 | #include 33 | #include "config.h" 34 | 35 | %} 36 | 37 | %option 8bit prefix="test" 38 | %option nounput nomain noyywrap noinput yylineno 39 | %option warn 40 | 41 | WORD [[:alpha:]]+ 42 | DIGIT [[:digit:]] 43 | 44 | %% 45 | /* The goal here is to test the yylineno processing by: 46 | - providing some rules than CAN match newlines and 47 | other rules that can NOT match newlines, 48 | - matching several newlines in one rule, 49 | - directly modifying yylineno. 50 | */ 51 | 52 | "yylineno++" yylineno++; 53 | "yylineno--" yylineno--; 54 | [[:blank:]]+ 55 | {WORD} 56 | {DIGIT}+(\n{DIGIT}+)* 57 | \n 58 | . 59 | <> { printf("%d\n", yylineno); 60 | yyterminate(); 61 | } 62 | 63 | %% 64 | 65 | /* returns number of '\n' characters in input, plus one. 66 | This is what flex does, essentially. */ 67 | 68 | static int 69 | count_newlines (FILE* in) 70 | { 71 | int n=1,c; 72 | while ((c=fgetc(in)) != EOF) 73 | if( c == '\n') 74 | n++; 75 | return n; 76 | } 77 | 78 | int main ( int, char**); 79 | 80 | int 81 | main ( argc, argv ) 82 | int argc; 83 | char** argv; 84 | { 85 | (void)argv; 86 | 87 | if( argc > 1 ) 88 | printf("%d\n", count_newlines(stdin)); 89 | 90 | else{ 91 | yyin = stdin; 92 | yyout = stdout; 93 | yylex(); 94 | } 95 | return 0; 96 | } 97 | -------------------------------------------------------------------------------- /tests/lineno_nr.one.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_r.one.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_trailing.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 | Run as: 27 | test-lineno-trailing # report flex's yylineno 28 | test-lineno-trailing 1 # report count_newlines(stdin) 29 | */ 30 | 31 | #include 32 | #include 33 | #include "config.h" 34 | 35 | %} 36 | 37 | %option 8bit prefix="test" 38 | %option nounput nomain noyywrap noinput yylineno 39 | %option warn 40 | 41 | WORD [[:alpha:]]+ 42 | 43 | %% 44 | /* The goal here is to test the yylineno in the context of trailing-contexts. 45 | Using rules that have newlines in look-ahead. 46 | */ 47 | "Fixed_trailing:"/[\n]"test"[\n] {} 48 | "Var_trailing:"{WORD}/[\n] {} 49 | "Var_prefix_and_trailing:"{WORD}":"/(\n{WORD})* {} 50 | \n {} 51 | . {} 52 | <> { printf("%d\n", yylineno); 53 | yyterminate(); 54 | } 55 | 56 | %% 57 | 58 | /* returns number of '\n' characters in input, plus one. 59 | This is what flex does, essentially. */ 60 | 61 | static int 62 | count_newlines (FILE* in) 63 | { 64 | int n=1,c; 65 | while ((c=fgetc(in)) != EOF) 66 | if( c == '\n') 67 | n++; 68 | return n; 69 | } 70 | 71 | int main ( int, char**); 72 | 73 | int 74 | main ( argc, argv ) 75 | int argc; 76 | char** argv; 77 | { 78 | (void)argv; 79 | 80 | if( argc > 1 ) 81 | printf("%d\n", count_newlines(stdin)); 82 | 83 | else{ 84 | yyin = stdin; 85 | yyout = stdout; 86 | yylex(); 87 | } 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /tests/lineno_trailing.one.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 | -------------------------------------------------------------------------------- /tests/mem_nr.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/mem_r.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 | YY_BUFFER_STATE 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 | FILE * fp; 35 | YY_BUFFER_STATE buff1, buff2; 36 | yyscan_t scan1, scan2; 37 | 38 | S1_lex_init(&scan1); 39 | S2_lex_init(&scan2); 40 | 41 | S1_set_out(stdout,scan1); 42 | S2_set_out(S1_get_out(scan1),scan2); 43 | 44 | buff1 = S1__scan_string("foo on bar off", scan1); 45 | buff2 = S2__scan_string("on blah blah off foo on bar off", scan2); 46 | 47 | /* scan simultaneously. */ 48 | while(S1_ok || S2_ok) 49 | { 50 | if (S1_ok) 51 | S1_ok = S1_lex(scan1); 52 | if (S2_ok) 53 | S2_ok = S2_lex(scan2); 54 | } 55 | S1__delete_buffer(buff1, scan1); 56 | S2__delete_buffer(buff2, scan2); 57 | 58 | S1_lex_destroy(scan1); 59 | S2_lex_destroy(scan2); 60 | printf("TEST RETURNING OK.\n"); 61 | return 0; 62 | } 63 | 64 | 65 | /* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */ 66 | -------------------------------------------------------------------------------- /tests/noansi_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 | /* TEST scanner. 25 | Basic non-reentrant scanner, but with non-ansi function defs. 26 | Compile with: flex scanner.l 27 | 28 | Sample Input: 29 | # this is a comment 30 | foo = true 31 | bar = "string value" 32 | integer = 43 33 | */ 34 | %{ 35 | #include "config.h" 36 | %} 37 | 38 | %option prefix="test" 39 | %option nounput noyywrap noyylineno warn nodefault noinput 40 | %option noansi-prototypes noansi-definitions 41 | 42 | IDENT [[:alnum:]_-] 43 | WS [[:blank:]] 44 | %% 45 | 46 | ^{IDENT}+{WS}*={WS}*(true|false){WS}*\r?\n { return 100;} 47 | ^{IDENT}+{WS}*={WS}*\"[^\"\n\r]*\"{WS}*\r?\n { return 101;} 48 | ^{IDENT}+{WS}*={WS}*[[:digit:]]+{WS}*\r?\n { return 102;} 49 | ^{WS}*#.*\r?\n { } 50 | ^{WS}*\r?\n { } 51 | .|\n { fprintf(stderr,"Invalid line.\n"); exit(-1);} 52 | 53 | %% 54 | 55 | int main(void); 56 | 57 | int main () 58 | { 59 | yyin = stdin; 60 | yyout = stdout; 61 | while( yylex() ) 62 | { 63 | } 64 | printf("TEST RETURNING OK.\n"); 65 | return 0; 66 | } 67 | 68 | -------------------------------------------------------------------------------- /tests/noansi_nr.txt: -------------------------------------------------------------------------------- 1 | # this is a comment 2 | foo = "bar" 3 | num = 43 4 | setting = false 5 | 6 | -------------------------------------------------------------------------------- /tests/noansi_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 | /* A reentrant scanner. 25 | This file will not compile under flex version <= 2.5.4. 26 | Sample Input: 27 | # this is a comment 28 | foo = true 29 | bar = "string value" 30 | integer = 43 31 | */ 32 | %{ 33 | #include "config.h" 34 | %} 35 | 36 | %option prefix="test" 37 | %option nounput noyywrap noyylineno warn nodefault noinput 38 | %option reentrant 39 | %option noansi-definitions noansi-prototypes 40 | 41 | IDENT [[:alnum:]_-] 42 | WS [[:blank:]] 43 | %% 44 | 45 | ^{IDENT}+{WS}*={WS}*(true|false){WS}*\r?\n { return 100;} 46 | ^{IDENT}+{WS}*={WS}*\"[^\"\n\r]*\"{WS}*\r?\n { return 101;} 47 | ^{IDENT}+{WS}*={WS}*[[:digit:]]+{WS}*\r?\n { return 102;} 48 | ^{WS}*#.*\r?\n { } 49 | ^{WS}*\r?\n { } 50 | .|\n { fprintf(stderr,"Invalid line.\n"); exit(-1);} 51 | 52 | %% 53 | 54 | int main(void); 55 | 56 | int main () 57 | { 58 | yyscan_t lexer; 59 | yylex_init( &lexer ); 60 | yyset_out ( stdout,lexer); 61 | yyset_in ( stdin, lexer); 62 | while( yylex(lexer) ) 63 | { 64 | } 65 | yylex_destroy( lexer ); 66 | printf("TEST RETURNING OK.\n"); 67 | return 0; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /tests/noansi_r.txt: -------------------------------------------------------------------------------- 1 | # this is a comment 2 | foo = "bar" 3 | num = 43 4 | setting = false 5 | -------------------------------------------------------------------------------- /tests/options.cn: -------------------------------------------------------------------------------- 1 | #!/bin/bash 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.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 goal of this test is to verify that we are getting the counter-intuitive 26 | * posix behavior of the repeat operator `{}'. 27 | * 28 | * ab{3} - In traditional flex, this matches "abbb". 29 | * In posix, this matches "ababab". 30 | */ 31 | #include 32 | #include 33 | #include "config.h" 34 | 35 | #define NUM_TESTS 1 36 | char * tests[NUM_TESTS] = { "ababab"}; 37 | int main(void); 38 | 39 | int tests_ok[NUM_TESTS] = { 0 }; 40 | 41 | %} 42 | 43 | %option 8bit prefix="test" 44 | %option nounput nomain noyywrap noinput 45 | %option warn posix-compat 46 | 47 | 48 | %% 49 | 50 | ab{3} tests_ok[0] = 1; return 0; 51 | .|\n return 0; 52 | 53 | %% 54 | 55 | 56 | int main () 57 | { 58 | YY_BUFFER_STATE state; 59 | int i; 60 | 61 | yyin = stdin; 62 | yyout = stdout; 63 | 64 | /* Run the tests */ 65 | for (i=0; i < NUM_TESTS; i++){ 66 | printf("Testing: yy_scan_string(%s): ", tests[i]); 67 | state = yy_scan_string(tests[i]); 68 | yylex(); 69 | yy_delete_buffer(state); 70 | printf("... %s\n", tests_ok[i] ? "OK" : "FAILED"); 71 | } 72 | 73 | for (i=0; i < NUM_TESTS; i++) 74 | if (!tests_ok[i]) 75 | exit(1); 76 | 77 | printf("TEST RETURNING OK.\n"); 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /tests/posixly_correct.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 goal of this test is to verify that we are getting the counter-intuitive 26 | * posix behavior of the repeat operator `{}'. 27 | * 28 | * ab{3} - In traditional flex, this matches "abbb". 29 | * In posix, this matches "ababab". 30 | */ 31 | #include 32 | #include 33 | #include "config.h" 34 | 35 | #define NUM_TESTS 1 36 | char * tests[NUM_TESTS] = { "ababab"}; 37 | int main(void); 38 | 39 | int tests_ok[NUM_TESTS] = { 0 }; 40 | 41 | %} 42 | 43 | %option 8bit prefix="test" 44 | %option nounput nomain noyywrap noinput 45 | %option warn 46 | 47 | 48 | %% 49 | 50 | ab{3} tests_ok[0] = 1; return 0; 51 | .|\n return 0; 52 | 53 | %% 54 | 55 | 56 | int main () 57 | { 58 | YY_BUFFER_STATE state; 59 | int i; 60 | 61 | yyin = stdin; 62 | yyout = stdout; 63 | 64 | /* Run the tests */ 65 | for (i=0; i < NUM_TESTS; i++){ 66 | printf("Testing: yy_scan_string(%s): ", tests[i]); 67 | state = yy_scan_string(tests[i]); 68 | yylex(); 69 | yy_delete_buffer(state); 70 | printf("... %s\n", tests_ok[i] ? "OK" : "FAILED"); 71 | } 72 | 73 | for (i=0; i < NUM_TESTS; i++) 74 | if (!tests_ok[i]) 75 | exit(1); 76 | 77 | printf("TEST RETURNING OK.\n"); 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /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((YY_BUFFER_STATE)0); 46 | FOO_flush_buffer((YY_BUFFER_STATE)0); 47 | FOO_init_buffer((YY_BUFFER_STATE)0,(FILE*)0); 48 | FOO_load_buffer_state(); 49 | FOO_scan_buffer((char*)0,(yy_size_t)0); 50 | FOO_scan_bytes((yyconst char*)0, 0); 51 | FOO_scan_string((yyconst char*)0); 52 | FOO_switch_to_buffer((YY_BUFFER_STATE)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 () 68 | { 69 | yyin = stdin; 70 | yyout = stdout; 71 | FOOlex(); 72 | printf("TEST RETURNING OK.\n"); 73 | return 0; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /tests/prefix_nr.txt: -------------------------------------------------------------------------------- 1 | Dummy input. 2 | -------------------------------------------------------------------------------- /tests/prefix_r.txt: -------------------------------------------------------------------------------- 1 | Dummy input. 2 | -------------------------------------------------------------------------------- /tests/quotes.txt: -------------------------------------------------------------------------------- 1 | 0000 foo 1111 foo 0000 bar 2 | 0000 foo 1111 foo 0000 bar 3 | -------------------------------------------------------------------------------- /tests/reject.l4: -------------------------------------------------------------------------------- 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 | #include 26 | #include 27 | #include "config.h" 28 | 29 | %} 30 | 31 | %option 8bit prefix="test" 32 | %option nounput nomain noyywrap noinput 33 | %option warn reject 34 | 35 | 36 | %% 37 | 38 | . { REJECT; } 39 | .|\n ; 40 | 41 | %% 42 | 43 | int main ( int argc, char** argv ) 44 | { 45 | FILE* fp = NULL; 46 | void *yyscanner=0; 47 | M4_YY_DECL_GUTS_VAR(); 48 | 49 | #ifdef TEST_IS_REENTRANT 50 | yylex_init(&yyscanner); 51 | #else 52 | (void)yyscanner; 53 | #endif 54 | 55 | #ifdef TEST_HAS_TABLES_EXTERNAL 56 | if((fp = fopen(argv[1],"r"))== NULL) 57 | YY_FATAL_ERROR("could not open tables file for reading"); 58 | 59 | if(yytables_fload(fp M4_YY_CALL_LAST_ARG) < 0) 60 | YY_FATAL_ERROR("yytables_fload returned < 0"); 61 | if(M4_YY_TABLES_VERIFY) 62 | exit(0); 63 | #endif 64 | 65 | if(argc > 2){ 66 | if((fp = fopen(argv[2],"r"))== NULL) 67 | YY_FATAL_ERROR("could not open input file for reading"); 68 | yyin = fp; 69 | } 70 | while(yylex(M4_YY_CALL_ONLY_ARG) != 0) 71 | ; 72 | 73 | #ifdef TEST_HAS_TABLES_EXTERNAL 74 | yytables_destroy(M4_YY_CALL_ONLY_ARG); 75 | #endif 76 | yylex_destroy(M4_YY_CALL_ONLY_ARG); 77 | 78 | if(argc < 0) /* silence the compiler */ 79 | yyscanner = (void*)fp; 80 | 81 | return 0; 82 | } 83 | -------------------------------------------------------------------------------- /tests/reject.txt: -------------------------------------------------------------------------------- 1 | 0000 foo 1111 foo 0000 bar 2 | 0000 foo 1111 foo 0000 bar 3 | -------------------------------------------------------------------------------- /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 | yyset_out ( stdout); 62 | 63 | for (i=0; i < 4; ++i){ 64 | rewind(fp); 65 | yyset_in ( fp); 66 | while( yylex() ) 67 | ; 68 | yylex_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.txt: -------------------------------------------------------------------------------- 1 | 0000 foo 1111 foo 0000 bar 2 | 0000 foo 1111 foo 0000 bar 3 | -------------------------------------------------------------------------------- /tests/tableopts.l4: -------------------------------------------------------------------------------- 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 | %option 8bit 32 | %option nounput nomain noyywrap noinput 33 | %option warn yylineno 34 | 35 | 36 | 37 | %% 38 | 39 | foo|bar ; 40 | [[:digit:]]+ ; 41 | [[:blank:]]+ ; 42 | .|\n ; 43 | %% 44 | 45 | int main ( int argc, char** argv ) 46 | { 47 | FILE* fp = NULL; 48 | void *yyscanner=0; 49 | M4_YY_DECL_GUTS_VAR(); 50 | 51 | #ifdef TEST_IS_REENTRANT 52 | yylex_init(&yyscanner); 53 | #else 54 | (void)yyscanner; 55 | #endif 56 | 57 | #ifdef TEST_HAS_TABLES_EXTERNAL 58 | if((fp = fopen(argv[1],"r"))== NULL) 59 | YY_FATAL_ERROR("could not open tables file for reading"); 60 | 61 | if(yytables_fload(fp M4_YY_CALL_LAST_ARG) < 0) 62 | YY_FATAL_ERROR("yytables_fload returned < 0"); 63 | if(M4_YY_TABLES_VERIFY) 64 | exit(0); 65 | #endif 66 | 67 | if(argc > 2){ 68 | if((fp = fopen(argv[2],"r"))== NULL) 69 | YY_FATAL_ERROR("could not open input file for reading"); 70 | yyin = fp; 71 | } 72 | while(yylex(M4_YY_CALL_ONLY_ARG) != 0) 73 | ; 74 | 75 | #ifdef TEST_HAS_TABLES_EXTERNAL 76 | yytables_destroy(M4_YY_CALL_ONLY_ARG); 77 | #endif 78 | yylex_destroy(M4_YY_CALL_ONLY_ARG); 79 | 80 | if(argc < 0) /* silence the compiler */ 81 | yyscanner = (void*)fp; 82 | 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /tests/tableopts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | 5 | # This script is present to generate the automake _SOURCES variables 6 | # for the tableopts_* tests. It also generates the linking rules for 7 | # each test since automake isn't able to handle the pattern rules that 8 | # would be natural to use. Output is written to standard output for 9 | # inclusion in a Makefile.am, typically by redirecting the output and then an automake include directive. 10 | 11 | TABLEOPTS_TESTS="" 12 | tableopts_tables="" 13 | 14 | for kind in opt ser ver ; do 15 | for threading in nr r ; do 16 | for opt in -Ca -Ce -Cf -CF -Cm -Cem -Cae -Caef -CaeF -Cam -Caem ; do 17 | testname=tableopts_${kind}_${threading}${opt}.${kind} 18 | if [ "${TABLEOPTS_TESTS}" = "" ] ;then 19 | TABLEOPTS_TESTS=${testname} 20 | if [ "$kind" = "ser" -o "$kind" = "ver" ] ; then 21 | tableopts_tables=${testname}.tables 22 | fi 23 | else 24 | TABLEOPTS_TESTS="${TABLEOPTS_TESTS} ${testname}" 25 | if [ "$kind" = "ser" -o "$kind" = "ver" ] ; then 26 | tableopts_tables="${tableopts_tables} ${testname}.tables" 27 | fi 28 | fi 29 | 30 | bare_opt=${opt#-} 31 | cat << EOF 32 | tableopts_${kind}_${threading}_${bare_opt}_${kind}_SOURCES = tableopts.l4 33 | 34 | ${testname}\$(EXEEXT): tableopts_${kind}_${threading}${opt}.\$(OBJEXT) 35 | \$(LINK) -o \$@ \$< 36 | 37 | EOF 38 | done 39 | done 40 | done 41 | 42 | echo TABLEOPTS_TESTS = ${TABLEOPTS_TESTS} 43 | echo 44 | echo tableopts_tables = ${tableopts_tables} 45 | -------------------------------------------------------------------------------- /tests/tableopts.txt: -------------------------------------------------------------------------------- 1 | 0000 foo 1111 foo 0000 bar foobar 2 | 0000 foo 1111 foo 0000 bar foobar 3 | -------------------------------------------------------------------------------- /tests/testwrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -vx 2 | set -euo pipefail 3 | 4 | # testwrapper.sh: run a flex test, typically called by a Makefile 5 | 6 | # Each test will exercise some feature or aspect of flex. Run the test with any input it may need. 7 | 8 | INPUT_DIRECTORY="" 9 | INPUT_NAME="" 10 | INPUT_COUNT=0 11 | USE_REDIRECT=0 12 | DO_COMPARISON=0 13 | 14 | while getopts :d:i:rt1 OPTION ; do 15 | case $OPTION in 16 | d) INPUT_DIRECTORY=$OPTARG ;; 17 | i) 18 | if [ "$INPUT_NAME" == "" ] ; then 19 | INPUT_NAME="$OPTARG" 20 | else 21 | INPUT_NAME="$INPUT_NAME $OPTARG" 22 | fi 23 | INPUT_COUNT=$(($INPUT_COUNT+1)) 24 | ;; 25 | r) USE_REDIRECT=1 ;; 26 | t) USE_TABLES=1 ;; 27 | 1) DO_COMPARISON=1 ;; 28 | esac 29 | done 30 | 31 | TESTNAME="${!OPTIND}" 32 | 33 | INPUT_NAME=${INPUT_NAME:-`basename $TESTNAME`.txt} 34 | 35 | if [ "$DO_COMPARISON" -eq "1" ] ; then 36 | test `$TESTNAME 1 < $INPUT_DIRECTORY/$INPUT_NAME` -eq `$TESTNAME < $INPUT_DIRECTORY/$INPUT_NAME` 37 | exit $? 38 | fi 39 | 40 | if [ $INPUT_COUNT -gt 1 ] ; then 41 | $TESTNAME ${USE_TABLES:+${INPUT_DIRECTORY}/${TESTNAME}.tables} ${INPUT_NAME} 42 | exit $? 43 | fi 44 | 45 | if [ -f ${INPUT_DIRECTORY}/${INPUT_NAME} ] ; then 46 | if [ $USE_REDIRECT == 1 ] ; then 47 | $TESTNAME ${USE_TABLES:+${INPUT_DIRECTORY}/${TESTNAME}.tables} < $INPUT_DIRECTORY/$INPUT_NAME 48 | else 49 | $TESTNAME ${USE_TABLES:+${INPUT_DIRECTORY}/${TESTNAME}.tables} $INPUT_DIRECTORY/$INPUT_NAME 50 | fi 51 | else 52 | $TESTNAME 53 | fi 54 | -------------------------------------------------------------------------------- /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 really about compilation. See "main.c". 28 | */ 29 | #include 30 | #include 31 | #include "config.h" 32 | 33 | #ifndef DEFINE_ME 34 | #error "DEFINE_ME undefined!" 35 | #endif 36 | %} 37 | 38 | %top{ 39 | #define DEFINE_ME 1 40 | } 41 | 42 | %option reentrant 43 | %option 8bit header="top.h" prefix="test" 44 | %option nounput nomain noyywrap noinput 45 | %option warn 46 | 47 | 48 | %% 49 | 50 | .|\n { } 51 | 52 | %% 53 | 54 | -------------------------------------------------------------------------------- /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_go/Makefile: -------------------------------------------------------------------------------- 1 | 2 | .SUFFIXES: 3 | 4 | all: makemake makeall 5 | 6 | clean: makemake makeclean 7 | 8 | makemake: Makefile2 9 | 10 | Makefile2: Make Make.yaml 11 | ./Make 12 | 13 | makeall: 14 | make -f Makefile2 all 15 | 16 | makeclean: 17 | make -f Makefile2 clean 18 | rm -f Makefile2 Make .gitignore 19 | 20 | Make: Make.go 21 | go build Make.go 22 | -------------------------------------------------------------------------------- /tests_go/minimal-c.l: -------------------------------------------------------------------------------- 1 | %{ 2 | 3 | #include 4 | 5 | #define YY_NO_INPUT 6 | #define YY_NO_UNPUT 7 | 8 | int yywrap(void) { 9 | return 1; 10 | } 11 | 12 | %} 13 | 14 | %% 15 | 16 | %% 17 | 18 | int main (int argc, char *argv []) { 19 | yyin = fopen(argv[1], "r"); 20 | yylex(); 21 | fclose(yyin); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /tests_go/minimal-go.l: -------------------------------------------------------------------------------- 1 | %top{ 2 | 3 | package main 4 | 5 | import ( 6 | "io" 7 | "log" 8 | "os" 9 | ) 10 | 11 | // return type of yy.Lex() 12 | type YYtype interface{} 13 | 14 | 15 | // type of Scanner.Context 16 | type YYcontext interface{} 17 | 18 | } 19 | 20 | %{ 21 | 22 | YY_USER_DATA( 23 | // my very own user data 24 | ) 25 | 26 | YY_USER_INIT( 27 | // my very own user init 28 | ) 29 | 30 | YY_USER_ACTION( 31 | // my very own user action 32 | ) 33 | %} 34 | 35 | // definitions: no definition 36 | 37 | 38 | %% 39 | 40 | // rules: no rules, just echo all input to output 41 | 42 | %% 43 | 44 | func main() { 45 | // runs the scanner on files given as arguments, or stdin if there are no arguments 46 | YYmain(os.Args[1:]...) 47 | } 48 | -------------------------------------------------------------------------------- /tests_go/nul-c.l: -------------------------------------------------------------------------------- 1 | %{ 2 | 3 | #include 4 | 5 | #define YY_NO_INPUT 6 | #define YY_NO_UNPUT 7 | 8 | int yywrap(void) { 9 | return 1; 10 | } 11 | 12 | int i; 13 | 14 | %} 15 | 16 | %% 17 | 18 | \0 fputs("", yyout); 19 | 20 | a\0b fputs("[a0b]", yyout); 21 | 22 | a*\0+b* { 23 | for (i = yyleng - 1; i >= 0; i--) 24 | if (yytext[i] == 0) 25 | yytext[i] = '0'; 26 | fputc('(', yyout); 27 | fputs(yytext, yyout); 28 | fputc(')', yyout); 29 | } 30 | 31 | %% 32 | 33 | int main (int argc, char *argv []) { 34 | yyin = fopen(argv[1], "r"); 35 | yylex(); 36 | fclose(yyin); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /tests_go/nul-go.l: -------------------------------------------------------------------------------- 1 | %top{ 2 | 3 | package main 4 | 5 | import ( 6 | "io" 7 | "log" 8 | "os" 9 | ) 10 | 11 | // return type of yy.Lex() 12 | type YYtype interface{} 13 | 14 | // type of Scanner.Context 15 | type YYcontext interface{} 16 | 17 | } 18 | 19 | %{ 20 | 21 | var ( 22 | nul = []byte("") 23 | a0b = []byte("[a0b]") 24 | L = []byte("(") 25 | R = []byte(")") 26 | ) 27 | 28 | %} 29 | 30 | %% 31 | 32 | notthis yyterminate() 33 | 34 | \0 yyout.Write(nul) 35 | 36 | a\0b yyout.Write(a0b) 37 | 38 | a*\0+b* { 39 | for i := yyleng - 1; i >= 0; i-- { 40 | if yytext[i] == 0 { 41 | yytext[i] = '0' 42 | } 43 | } 44 | yyout.Write(L) 45 | yyout.Write(yytext) 46 | yyout.Write(R) 47 | } 48 | 49 | wontmatch yyterminate() 50 | 51 | %% 52 | 53 | func main() { 54 | YYmain(os.Args[1:]...) 55 | } 56 | -------------------------------------------------------------------------------- /tests_go/test01c.l: -------------------------------------------------------------------------------- 1 | %{ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define YY_NO_INPUT 8 | #define YY_NO_UNPUT 9 | #define YY_SKIP_YYWRAP 10 | #ifdef yywrap 11 | # undef yywrap 12 | #endif 13 | 14 | int 15 | g_argc = 0; 16 | char 17 | **g_argv; 18 | 19 | int yywrap() 20 | { 21 | if (g_argc) { 22 | fclose (yyin); 23 | g_argc--; 24 | g_argv++; 25 | } 26 | 27 | if (!g_argc) 28 | return 1; 29 | 30 | yyin = fopen(g_argv[0], "r"); 31 | if (yyin == NULL) { 32 | fprintf(stderr, "Error opening file \"%s\": %s\n", g_argv[0], strerror(errno)); 33 | return 1; 34 | } 35 | 36 | return 0; 37 | } 38 | 39 | %} 40 | 41 | 42 | %% 43 | 44 | foo | 45 | 46 | bar fprintf(yyout, strcmp (yytext, "foo") ? "BAR" : "FOO"); 47 | 48 | C fprintf(yyout, "Go"); 49 | 50 | %% 51 | 52 | int main(int argc, char *argv []) { 53 | 54 | if (argc > 1) { 55 | g_argc = argc - 1; 56 | g_argv = argv; 57 | g_argv++; 58 | 59 | yyin = fopen(g_argv[0], "r"); 60 | if (yyin == NULL) { 61 | fprintf(stderr, "Error opening file \"%s\": %s\n", g_argv[0], strerror(errno)); 62 | return 1; 63 | } 64 | } 65 | yylex(); 66 | 67 | printf("Done\n"); 68 | return 0; 69 | 70 | } 71 | -------------------------------------------------------------------------------- /tests_go/test01go.l: -------------------------------------------------------------------------------- 1 | %top{ 2 | 3 | package main 4 | 5 | import ( 6 | "bytes" 7 | "fmt" 8 | "io" 9 | "log" 10 | "os" 11 | ) 12 | 13 | // return type of yy.Lex() 14 | type YYtype interface{} 15 | 16 | // type of Scanner.Context 17 | type YYcontext interface{} 18 | 19 | } 20 | 21 | %% 22 | 23 | foo | 24 | 25 | bar yyout.Write(bytes.ToUpper(yytext)) 26 | 27 | C yyout.Write([]byte("Go")) 28 | 29 | %% 30 | 31 | func main() { 32 | result, err := YYmain(os.Args[1:]...) 33 | if err != nil { 34 | log.Fatal(err) 35 | } 36 | if result != nil { 37 | fmt.Println(result) 38 | } 39 | fmt.Println("Done") 40 | } 41 | -------------------------------------------------------------------------------- /tests_go/test02c.l: -------------------------------------------------------------------------------- 1 | %{ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define YY_NO_INPUT 8 | #define YY_NO_UNPUT 9 | #define YY_SKIP_YYWRAP 10 | #ifdef yywrap 11 | # undef yywrap 12 | #endif 13 | 14 | int 15 | g_argc = 0; 16 | char 17 | **g_argv; 18 | 19 | int yywrap() 20 | { 21 | if (g_argc) { 22 | fclose (yyin); 23 | g_argc--; 24 | g_argv++; 25 | } 26 | 27 | if (!g_argc) 28 | return 1; 29 | 30 | yyin = fopen(g_argv[0], "r"); 31 | if (yyin == NULL) { 32 | fprintf(stderr, "Error opening file \"%s\": %s\n", g_argv[0], strerror(errno)); 33 | return 1; 34 | } 35 | 36 | return 0; 37 | } 38 | 39 | 40 | %} 41 | 42 | 43 | %% 44 | 45 | ^. fprintf(yyout, "%4i.\t%c", yylineno, yytext[0] - ((yytext[0] >= 'a' && yytext[0] <= 'z') ? 32 : 0)); 46 | 47 | .|\n ECHO; /* or yylineno won't get updated */ 48 | 49 | %% 50 | 51 | int main(int argc, char *argv []) { 52 | 53 | if (argc > 1) { 54 | g_argc = argc - 1; 55 | g_argv = argv; 56 | g_argv++; 57 | 58 | yyin = fopen(g_argv[0], "r"); 59 | if (yyin == NULL) { 60 | fprintf(stderr, "Error opening file \"%s\": %s\n", g_argv[0], strerror(errno)); 61 | return 1; 62 | } 63 | } 64 | yylex(); 65 | 66 | printf("Done\n"); 67 | return 0; 68 | 69 | } 70 | -------------------------------------------------------------------------------- /tests_go/test02go.l: -------------------------------------------------------------------------------- 1 | %top{ 2 | 3 | package main 4 | 5 | import ( 6 | "bytes" 7 | "fmt" 8 | "io" 9 | "log" 10 | "os" 11 | ) 12 | 13 | // return type of yy.Lex() 14 | type YYtype interface{} 15 | 16 | // type of Scanner.Context 17 | type YYcontext interface{} 18 | 19 | } 20 | 21 | %% 22 | 23 | ^. fmt.Fprintf(yyout, "%4d.\t%c", yylineno, bytes.ToUpper(yytext)[0]) 24 | 25 | .|\n ECHO // or yylineno won't get updated 26 | 27 | %% 28 | 29 | func main() { 30 | result, err := YYmain(os.Args[1:]...) 31 | if err != nil { 32 | log.Fatal(err) 33 | } 34 | if result != nil { 35 | fmt.Println(result) 36 | } 37 | fmt.Println("Done") 38 | } 39 | -------------------------------------------------------------------------------- /tests_go/test03c.l: -------------------------------------------------------------------------------- 1 | %{ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define YY_NO_INPUT 8 | #define YY_NO_UNPUT 9 | #define YY_SKIP_YYWRAP 10 | #ifdef yywrap 11 | # undef yywrap 12 | #endif 13 | 14 | int 15 | toggle = 1; 16 | 17 | int 18 | g_argc = 0; 19 | char 20 | **g_argv; 21 | 22 | int yywrap() 23 | { 24 | if (g_argc) { 25 | fclose (yyin); 26 | g_argc--; 27 | g_argv++; 28 | } 29 | 30 | if (!g_argc) 31 | return 1; 32 | 33 | yyin = fopen(g_argv[0], "r"); 34 | if (yyin == NULL) { 35 | fprintf(stderr, "Error opening file \"%s\": %s\n", g_argv[0], strerror(errno)); 36 | return 1; 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | %} 43 | 44 | 45 | %% 46 | 47 | ^. fprintf(yyout, "%c", yytext[0] - ((yytext[0] >= 'a' && yytext[0] <= 'z') ? 32 : 0)); 48 | 49 | foo/bar { 50 | toggle = 1 - toggle; 51 | if (toggle) 52 | fprintf(yyout, "FOO"); 53 | else 54 | REJECT; 55 | } 56 | 57 | %% 58 | 59 | int main(int argc, char *argv []) { 60 | 61 | if (argc > 1) { 62 | g_argc = argc - 1; 63 | g_argv = argv; 64 | g_argv++; 65 | 66 | yyin = fopen(g_argv[0], "r"); 67 | if (yyin == NULL) { 68 | fprintf(stderr, "Error opening file \"%s\": %s\n", g_argv[0], strerror(errno)); 69 | return 1; 70 | } 71 | } 72 | yylex(); 73 | 74 | printf("Done\n"); 75 | return 0; 76 | 77 | } 78 | -------------------------------------------------------------------------------- /tests_go/test03go.l: -------------------------------------------------------------------------------- 1 | %top{ 2 | 3 | package main 4 | 5 | import ( 6 | "bytes" 7 | "fmt" 8 | "io" 9 | "log" 10 | "os" 11 | ) 12 | 13 | // return type of yy.Lex() 14 | type YYtype interface{} 15 | 16 | // type of Scanner.Context 17 | type YYcontext interface{} 18 | 19 | } 20 | 21 | %{ 22 | 23 | var toggle = true 24 | 25 | %} 26 | 27 | 28 | %% 29 | 30 | ^. yyout.Write(bytes.ToUpper(yytext)) 31 | 32 | foo/bar { 33 | toggle = !toggle 34 | if (toggle) { 35 | yyout.Write([]byte("FOO")) 36 | } else { 37 | REJECT 38 | } 39 | } 40 | 41 | %% 42 | 43 | func main() { 44 | result, err := YYmain(os.Args[1:]...) 45 | if err != nil { 46 | log.Fatal(err) 47 | } 48 | if result != nil { 49 | fmt.Println(result) 50 | } 51 | fmt.Println("Done") 52 | } 53 | -------------------------------------------------------------------------------- /tests_go/test04c.l: -------------------------------------------------------------------------------- 1 | %{ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define YY_NO_INPUT 8 | #define YY_NO_UNPUT 9 | #define YY_SKIP_YYWRAP 10 | #ifdef yywrap 11 | # undef yywrap 12 | #endif 13 | 14 | int 15 | g_argc = 0; 16 | char 17 | **g_argv; 18 | 19 | int yywrap() 20 | { 21 | if (g_argc) { 22 | fclose (yyin); 23 | g_argc--; 24 | g_argv++; 25 | } 26 | 27 | if (!g_argc) 28 | return 1; 29 | 30 | yyin = fopen(g_argv[0], "r"); 31 | if (yyin == NULL) { 32 | fprintf(stderr, "Error opening file \"%s\": %s\n", g_argv[0], strerror(errno)); 33 | return 1; 34 | } 35 | 36 | return 0; 37 | } 38 | 39 | char *upstring(char *s) { 40 | int i; 41 | for (i = 0; s[i]; i++) 42 | if (s[i] >= 'a' && s[i] <= 'z') 43 | s[i] -= 32; 44 | return s; 45 | } 46 | 47 | %} 48 | 49 | 50 | %% 51 | 52 | foo/bar { fprintf(yyout, "%sB", upstring(yytext)); } 53 | fo+/[a-np-z]+ { fprintf(yyout, "%sX", upstring(yytext)); } 54 | 55 | %% 56 | 57 | int main(int argc, char *argv []) { 58 | 59 | if (argc > 1) { 60 | g_argc = argc - 1; 61 | g_argv = argv; 62 | g_argv++; 63 | 64 | yyin = fopen(g_argv[0], "r"); 65 | if (yyin == NULL) { 66 | fprintf(stderr, "Error opening file \"%s\": %s\n", g_argv[0], strerror(errno)); 67 | return 1; 68 | } 69 | } 70 | yylex(); 71 | 72 | printf("Done\n"); 73 | return 0; 74 | 75 | } 76 | -------------------------------------------------------------------------------- /tests_go/test04go.l: -------------------------------------------------------------------------------- 1 | %top{ 2 | 3 | package main 4 | 5 | import ( 6 | "bytes" 7 | "fmt" 8 | "io" 9 | "log" 10 | "os" 11 | ) 12 | 13 | // return type of yy.Lex() 14 | type YYtype interface{} 15 | 16 | // type of Scanner.Context 17 | type YYcontext interface{} 18 | 19 | } 20 | 21 | %% 22 | 23 | foo/bar { 24 | yyout.Write(bytes.ToUpper(yytext)) 25 | yyout.Write([]byte{'B'}) 26 | } 27 | fo+/[a-np-z]+ { 28 | yyout.Write(bytes.ToUpper(yytext)) 29 | yyout.Write([]byte{'X'}) 30 | } 31 | 32 | %% 33 | 34 | func main() { 35 | result, err := YYmain(os.Args[1:]...) 36 | if err != nil { 37 | log.Fatal(err) 38 | } 39 | if result != nil { 40 | fmt.Println(result) 41 | } 42 | fmt.Println("Done") 43 | } 44 | -------------------------------------------------------------------------------- /tests_go/test05c.l: -------------------------------------------------------------------------------- 1 | %{ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define YY_NO_INPUT 8 | #define YY_NO_UNPUT 9 | #define YY_SKIP_YYWRAP 10 | #ifdef yywrap 11 | # undef yywrap 12 | #endif 13 | 14 | int 15 | toggle = 1; 16 | 17 | int 18 | g_argc = 0; 19 | char 20 | **g_argv; 21 | 22 | int yywrap() 23 | { 24 | if (g_argc) { 25 | fclose (yyin); 26 | g_argc--; 27 | g_argv++; 28 | } 29 | 30 | if (!g_argc) 31 | return 1; 32 | 33 | yyin = fopen(g_argv[0], "r"); 34 | if (yyin == NULL) { 35 | fprintf(stderr, "Error opening file \"%s\": %s\n", g_argv[0], strerror(errno)); 36 | return 1; 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | %} 43 | 44 | 45 | %x _str 46 | 47 | %% 48 | 49 | { 50 | 51 | \" { fprintf(yyout, "<<"); 52 | BEGIN _str; 53 | } 54 | 55 | ^. fprintf(yyout, "%c", yytext[0] - ((yytext[0] >= 'a' && yytext[0] <= 'z') ? 32 : 0)); 56 | 57 | foo/bar { 58 | toggle = 1 - toggle; 59 | if (!toggle) 60 | REJECT; 61 | fprintf(yyout, "FOO"); 62 | } 63 | 64 | } 65 | 66 | <_str>{ 67 | 68 | [^\"\\]+ ECHO; 69 | 70 | \\. fprintf(yyout, "%c", yytext[1]); 71 | 72 | \" { fprintf(yyout, ">>"); 73 | BEGIN INITIAL; 74 | } 75 | 76 | <> { 77 | printf("Closing quote is missing\n"); 78 | yyterminate(); 79 | } 80 | 81 | } 82 | 83 | %% 84 | 85 | int main(int argc, char *argv []) { 86 | 87 | if (argc > 1) { 88 | g_argc = argc - 1; 89 | g_argv = argv; 90 | g_argv++; 91 | 92 | yyin = fopen(g_argv[0], "r"); 93 | if (yyin == NULL) { 94 | fprintf(stderr, "Error opening file \"%s\": %s\n", g_argv[0], strerror(errno)); 95 | return 1; 96 | } 97 | } 98 | yylex(); 99 | 100 | printf("Done\n"); 101 | return 0; 102 | 103 | } 104 | -------------------------------------------------------------------------------- /tests_go/test05go.l: -------------------------------------------------------------------------------- 1 | %top{ 2 | 3 | package main 4 | 5 | import ( 6 | "bytes" 7 | "fmt" 8 | "io" 9 | "log" 10 | "os" 11 | ) 12 | 13 | // return type of yy.Lex() 14 | type YYtype interface{} 15 | 16 | // type of Scanner.Context 17 | type YYcontext interface{} 18 | 19 | } 20 | 21 | %{ 22 | 23 | var toggle = true 24 | 25 | %} 26 | 27 | %x _str 28 | 29 | %% 30 | 31 | { 32 | 33 | \" { 34 | yyout.Write([]byte("<<")) 35 | BEGIN _str 36 | } 37 | 38 | ^. yyout.Write(bytes.ToUpper(yytext)) 39 | 40 | foo/bar { 41 | toggle = !toggle 42 | if !toggle { 43 | REJECT 44 | } 45 | yyout.Write(bytes.ToUpper(yytext)) 46 | } 47 | 48 | } 49 | 50 | <_str>{ 51 | 52 | [^\"\\]+ ECHO 53 | 54 | \\. yyout.Write(yytext[1:]) 55 | 56 | \" { 57 | yyout.Write([]byte(">>")) 58 | BEGIN INITIAL 59 | } 60 | 61 | <> return fmt.Errorf("Closing quote is missing") 62 | 63 | } 64 | 65 | %% 66 | 67 | func main() { 68 | result, err := YYmain(os.Args[1:]...) 69 | if err != nil { 70 | log.Fatal(err) 71 | } 72 | if result != nil { 73 | fmt.Println(result) 74 | } 75 | fmt.Println("Done") 76 | } 77 | -------------------------------------------------------------------------------- /tests_go/test06c.l: -------------------------------------------------------------------------------- 1 | %{ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define YY_NO_INPUT 8 | #define YY_NO_UNPUT 9 | #define YY_SKIP_YYWRAP 10 | #ifdef yywrap 11 | # undef yywrap 12 | #endif 13 | 14 | int 15 | toggle = 1; 16 | 17 | int 18 | g_argc = 0; 19 | char 20 | **g_argv; 21 | 22 | int yywrap() 23 | { 24 | if (g_argc) { 25 | fclose (yyin); 26 | g_argc--; 27 | g_argv++; 28 | } 29 | 30 | if (!g_argc) 31 | return 1; 32 | 33 | yyin = fopen(g_argv[0], "r"); 34 | if (yyin == NULL) { 35 | fprintf(stderr, "Error opening file \"%s\": %s\n", g_argv[0], strerror(errno)); 36 | return 1; 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | %} 43 | 44 | %% 45 | 46 | fofo { fprintf(yyout, "[FOFO]"); 47 | yyless(2); 48 | } 49 | 50 | %% 51 | 52 | int main(int argc, char *argv []) { 53 | 54 | if (argc > 1) { 55 | g_argc = argc - 1; 56 | g_argv = argv; 57 | g_argv++; 58 | 59 | yyin = fopen(g_argv[0], "r"); 60 | if (yyin == NULL) { 61 | fprintf(stderr, "Error opening file \"%s\": %s\n", g_argv[0], strerror(errno)); 62 | return 1; 63 | } 64 | } 65 | yylex(); 66 | 67 | printf("Done\n"); 68 | return 0; 69 | 70 | } 71 | -------------------------------------------------------------------------------- /tests_go/test06go.l: -------------------------------------------------------------------------------- 1 | %top{ 2 | 3 | package main 4 | 5 | import ( 6 | "fmt" 7 | "io" 8 | "log" 9 | "os" 10 | ) 11 | 12 | // return type of yy.Lex() 13 | type YYtype interface{} 14 | 15 | // type of Scanner.Context 16 | type YYcontext interface{} 17 | 18 | } 19 | 20 | %% 21 | 22 | fofo { yyout.Write([]byte("[FOFO]")) 23 | yyless(2) 24 | } 25 | 26 | %% 27 | 28 | func main() { 29 | result, err := YYmain(os.Args[1:]...) 30 | if err != nil { 31 | log.Fatal(err) 32 | } 33 | if result != nil { 34 | fmt.Println(result) 35 | } 36 | fmt.Println("Done") 37 | } 38 | -------------------------------------------------------------------------------- /tests_go/test07c.l: -------------------------------------------------------------------------------- 1 | %{ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define YY_NO_INPUT 8 | #define YY_NO_UNPUT 9 | #define YY_SKIP_YYWRAP 10 | #ifdef yywrap 11 | # undef yywrap 12 | #endif 13 | 14 | int 15 | g_argc = 0; 16 | char 17 | **g_argv; 18 | 19 | int yywrap() 20 | { 21 | if (g_argc) { 22 | fclose (yyin); 23 | g_argc--; 24 | g_argv++; 25 | } 26 | 27 | if (!g_argc) 28 | return 1; 29 | 30 | yyin = fopen(g_argv[0], "r"); 31 | if (yyin == NULL) { 32 | fprintf(stderr, "Error opening file \"%s\": %s\n", g_argv[0], strerror(errno)); 33 | return 1; 34 | } 35 | 36 | return 0; 37 | } 38 | 39 | char *upstring(char *s) { 40 | int i; 41 | for (i = 0; s[i]; i++) 42 | if (s[i] >= 'a' && s[i] <= 'z') 43 | s[i] -= 32; 44 | return s; 45 | } 46 | 47 | 48 | %} 49 | 50 | %% 51 | 52 | ^. fprintf(yyout, "%4d.\t%s", yylineno, upstring(yytext)); 53 | 54 | \n ECHO; /* or yylineno won't get updated */ 55 | 56 | %% 57 | 58 | int main(int argc, char *argv []) { 59 | 60 | if (argc > 1) { 61 | g_argc = argc - 1; 62 | g_argv = argv; 63 | g_argv++; 64 | 65 | yyin = fopen(g_argv[0], "r"); 66 | if (yyin == NULL) { 67 | fprintf(stderr, "Error opening file \"%s\": %s\n", g_argv[0], strerror(errno)); 68 | return 1; 69 | } 70 | } 71 | yylex(); 72 | 73 | printf("Done\n"); 74 | return 0; 75 | 76 | } 77 | -------------------------------------------------------------------------------- /tests_go/test07go.l: -------------------------------------------------------------------------------- 1 | %top{ 2 | 3 | package main 4 | 5 | import ( 6 | "fmt" 7 | "io" 8 | "log" 9 | "os" 10 | "strings" 11 | ) 12 | 13 | // return type of yy.Lex() 14 | type YYtype interface{} 15 | 16 | // type of Scanner.Context 17 | type YYcontext interface{} 18 | 19 | } 20 | 21 | %% 22 | 23 | ^. { fmt.Fprintf(yyout, "%4d.\t%s", yy.Lineno, strings.ToUpper(string(yytext))) } 24 | 25 | \n ECHO // or yy.Lineno won't get updated 26 | 27 | %% 28 | 29 | func main() { 30 | result, err := YYmain(os.Args[1:]...) 31 | if err != nil { 32 | log.Fatal(err) 33 | } 34 | if result != nil { 35 | fmt.Println(result) 36 | } 37 | fmt.Println("Done") 38 | } 39 | -------------------------------------------------------------------------------- /tests_go/test08c.l: -------------------------------------------------------------------------------- 1 | %{ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define YY_SKIP_YYWRAP 8 | #ifdef yywrap 9 | # undef yywrap 10 | #endif 11 | 12 | int 13 | i, 14 | g_argc = 0; 15 | char 16 | **g_argv; 17 | 18 | int yywrap() 19 | { 20 | if (g_argc) { 21 | fclose (yyin); 22 | g_argc--; 23 | g_argv++; 24 | } 25 | 26 | if (!g_argc) 27 | return 1; 28 | 29 | yyin = fopen(g_argv[0], "r"); 30 | if (yyin == NULL) { 31 | fprintf(stderr, "Error opening file \"%s\": %s\n", g_argv[0], strerror(errno)); 32 | return 1; 33 | } 34 | 35 | return 0; 36 | } 37 | 38 | %} 39 | 40 | %s f1 41 | 42 | %% 43 | 44 | { 45 | 46 | (.|\n){4} { 47 | fprintf(yyout, "{1:%s}", yytext); 48 | for (i = 0; i < 10000; i++) { 49 | unput (32 + i % 96); 50 | } 51 | BEGIN f1; 52 | } 53 | } 54 | 55 | { 56 | 57 | foo { 58 | ECHO; 59 | yymore(); 60 | } 61 | 62 | bar { 63 | ECHO; 64 | int c = input(); 65 | fprintf(yyout, "%c%c%c", c, c, c); 66 | } 67 | 68 | \[baz\] { 69 | ECHO; 70 | ECHO; 71 | } 72 | 73 | baz { 74 | int i; 75 | /* Copy yytext because unput() trashes yytext */ 76 | char *yycopy = strdup( yytext ); 77 | unput( ']' ); 78 | for ( i = yyleng - 1; i >= 0; --i ) 79 | unput( yycopy[i] ); 80 | unput( '[' ); 81 | free( yycopy ); 82 | } 83 | 84 | "FINAL PART" { 85 | ECHO; 86 | fprintf(yyout, "\n>>>"); 87 | while ((i = input()) != EOF) 88 | fputc(i, yyout); 89 | fprintf(yyout, "<<<\n"); 90 | yyterminate(); 91 | } 92 | 93 | } 94 | 95 | %% 96 | 97 | int main(int argc, char *argv []) { 98 | 99 | if (argc > 1) { 100 | g_argc = argc - 1; 101 | g_argv = argv; 102 | g_argv++; 103 | 104 | yyin = fopen(g_argv[0], "r"); 105 | if (yyin == NULL) { 106 | fprintf(stderr, "Error opening file \"%s\": %s\n", g_argv[0], strerror(errno)); 107 | return 1; 108 | } 109 | } 110 | yylex(); 111 | 112 | printf("Done\n"); 113 | return 0; 114 | 115 | } 116 | -------------------------------------------------------------------------------- /tests_go/test08go.l: -------------------------------------------------------------------------------- 1 | %top{ 2 | 3 | package main 4 | 5 | import ( 6 | "fmt" 7 | "io" 8 | "log" 9 | "os" 10 | ) 11 | 12 | // return type of yy.Lex() 13 | type YYtype interface{} 14 | 15 | // type of Scanner.Context 16 | type YYcontext interface{} 17 | 18 | } 19 | 20 | %s f1 21 | 22 | %% 23 | 24 | { 25 | 26 | (.|\n){4} { 27 | fmt.Fprintf(yyout, "{1:%s}", string(yytext)) 28 | for i := 0; i < 10000; i++ { 29 | yyunput(byte(32 + i % 96)) 30 | } 31 | BEGIN f1 32 | } 33 | 34 | } 35 | 36 | { 37 | 38 | foo { 39 | ECHO 40 | yymore() 41 | } 42 | 43 | bar { 44 | ECHO 45 | c, err := yyinput() 46 | if err != nil { 47 | log.Fatalln(err) 48 | } 49 | yyout.Write([]byte{c,c,c}) 50 | } 51 | 52 | \[baz\] { 53 | ECHO 54 | ECHO 55 | } 56 | 57 | baz { 58 | yycopy := string(yytext) // Copy yytext because yy.Unput() trashes yytext 59 | yyunput(']') 60 | for i := yyleng - 1; i >= 0; i-- { 61 | yyunput(yycopy[i]) 62 | } 63 | yyunput('[') 64 | } 65 | 66 | "FINAL PART" { 67 | ECHO 68 | yyout.Write([]byte("\n>>>")) 69 | b := make([]byte, 1) 70 | for { 71 | c, err := yyinput() 72 | if err != nil { 73 | break 74 | } 75 | b[0] = c 76 | yyout.Write(b) 77 | } 78 | yyout.Write([]byte("<<<\n")) 79 | yyterminate() 80 | } 81 | 82 | } 83 | 84 | %% 85 | 86 | func main() { 87 | result, err := YYmain(os.Args[1:]...) 88 | if err != nil { 89 | log.Fatal(err) 90 | } 91 | if result != nil { 92 | fmt.Println(result) 93 | } 94 | fmt.Println("Done") 95 | } 96 | -------------------------------------------------------------------------------- /tests_go/text1.txt: -------------------------------------------------------------------------------- 1 | lorem ipsum dolor sit amet, consectetur adipiscing elit. 2 | sed sem lectus, fringilla eget facilisis eget, convallis eu libero. 3 | vivamus quis bibendum dolor. 4 | nunc ultrices neque ligula, egestas placerat dolor auctor ut. 5 | morbi malesuada quam vitae nisl lacinia, id vulputate justo vulputate. 6 | fusce eleifend est quis purus auctor venenatis. 7 | nullam vitae faucibus felis, -------------------------------------------------------------------------------- /tests_go/text2.txt: -------------------------------------------------------------------------------- 1 | vitae mollis odio. 2 | in lobortis sollicitudin pulvinar. 3 | phasellus id tellus in felis molestie dignissim. 4 | vivamus ut condimentum justo, nec pellentesque eros. 5 | curabitur nec enim vitae mauris hendrerit accumsan nec at massa. 6 | duis egestas tempor sapien ut varius. 7 | vivamus id varius mi. 8 | duis in tortor ac purus fermentum pharetra. 9 | praesent risus tortor, pellentesque et risus ac, vehicula luctus odio. 10 | -------------------------------------------------------------------------------- /tests_go/text3.txt: -------------------------------------------------------------------------------- 1 | foo bar baz foo bar baz foo bar baz 2 | foo foo foo 3 | bar bar bar 4 | baz baz baz 5 | foobar foo bar foobar foo bar foobar foo bar 6 | foobar foo bar foobar foo bar foobar foo bar 7 | foot fool fooble 8 | this is fofo and this is fofofo 9 | "foobar" "foo\"bar" "foo\ 10 | bar" 11 | barf"barf 12 | -------------------------------------------------------------------------------- /tests_go/text4.txt: -------------------------------------------------------------------------------- 1 | This is C. 2 | -------------------------------------------------------------------------------- /tests_go/txt01: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /tests_go/txt02: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/tests_go/txt02 -------------------------------------------------------------------------------- /tests_go/txt03: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebbe/flexgo/118c5c6fde1e4c335e212798c71832b846316293/tests_go/txt03 -------------------------------------------------------------------------------- /tests_go/txt04: -------------------------------------------------------------------------------- 1 | foo bar baz foo bar baz foo bar baz 2 | foo foo foo 3 | bar bar bar 4 | baz baz baz 5 | foobar foo bar foobar foo bar foobar foo bar 6 | foobar foo bar foobar foo bar foobar foo bar 7 | foot fool fooble 8 | this is fofo and this is fofofo 9 | "foobar" "foo\"bar" "foo\ 10 | bar" 11 | barf"barf 12 | -------------------------------------------------------------------------------- /tests_go/txt06: -------------------------------------------------------------------------------- 1 | FINAL PART 2 | FINAL PART 3 | -------------------------------------------------------------------------------- /tools/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = \ 2 | git2cl 3 | --------------------------------------------------------------------------------