├── CMakeLists.txt ├── COPYING ├── README.md ├── cmake ├── FindLEMON.cmake ├── FindPERPLEX.cmake ├── FindRE2C.cmake ├── LEMON_Util.cmake ├── PERPLEX_Util.cmake └── RE2C_Util.cmake ├── lemon.dist ├── lemon ├── CMakeLists.txt ├── README ├── lemon.c └── lempar.c ├── perplex.dist ├── perplex ├── CHANGELOG.txt ├── CMake │ ├── FindLEMON.cmake │ ├── FindRE2C.cmake │ ├── LEMON_Util.cmake │ └── RE2C_Util.cmake ├── CMakeLists.txt ├── README.txt ├── mbo_getopt.cpp ├── mbo_getopt.h ├── parser.y ├── perplex.cpp ├── perplex.h ├── perplex_template.c ├── scanner.re └── token_type.h ├── re2c.dist └── re2c ├── CHANGELOG ├── CMake ├── FindLEMON.cmake ├── FindYACC.cmake └── LEMON_Util.cmake ├── CMakeLists.txt ├── README.in ├── actions.cc ├── basics.h ├── bootstrap └── scanner.cc ├── code.cc ├── code.h ├── code_names.h ├── config.h.in ├── config_w32.h.in ├── configure.in ├── dfa.cc ├── dfa.h ├── doc ├── loplas.ps └── sample.bib ├── examples ├── basemmap.c ├── c.re ├── cmmap.re ├── cnokw.re ├── cunroll.re ├── modula.re ├── pp-c.re ├── push.re ├── repeater.re ├── rexx │ ├── README │ ├── rexx.l │ └── scanio.c ├── sample.re └── simple.re ├── globals.h ├── htdocs └── manual.html.in ├── ins.h ├── lessons ├── 001_upn_calculator │ ├── calc_001.c │ ├── calc_001.re │ ├── calc_002.c │ ├── calc_002.re │ ├── calc_003.c │ ├── calc_003.re │ ├── calc_004.c │ ├── calc_004.re │ ├── calc_005.c │ ├── calc_005.re │ ├── calc_006.s.c │ ├── calc_006.s.re │ ├── calc_007.b.c │ ├── calc_007.b.re │ ├── calc_008.b.c │ ├── calc_008.b.re │ ├── readme.txt │ └── windows │ │ ├── BuildAndRun.bat │ │ ├── HiResTimer.h │ │ ├── TestRe2c-2005.sln │ │ ├── TestRe2c-2005.vcproj │ │ ├── TestRe2c.dsp │ │ ├── TestRe2c.dsw │ │ ├── TestRe2c.ncb │ │ ├── TestRe2c.sln │ │ ├── TestRe2c.suo │ │ ├── TestRe2c.vcproj │ │ ├── main.b.c │ │ └── main.b.re ├── 002_strip_comments │ ├── readme.txt │ ├── strip_001.s.c │ ├── strip_001.s.re │ ├── strip_002.s.c │ ├── strip_002.s.re │ ├── strip_003.b.c │ └── strip_003.b.re └── readme.txt ├── main.cc ├── mbo_getopt.cc ├── mbo_getopt.h ├── parser.yy ├── re.h ├── re2c.1.in ├── re2c.spec.in ├── re2c_parser.h ├── run_tests.sh.in ├── scanner.h ├── scanner.re ├── stream_lc.h ├── substr.cc ├── substr.h ├── test ├── bug1054496.c ├── bug1054496.re ├── bug1163046.c ├── bug1163046.re ├── bug1187785.c ├── bug1187785.re ├── bug1297658.c ├── bug1297658.re ├── bug1390174.c ├── bug1390174.re ├── bug1454253.c ├── bug1454253.re ├── bug1454253.s.c ├── bug1454253.s.re ├── bug1454253b.s.c ├── bug1454253b.s.re ├── bug1472770.b.c ├── bug1472770.b.re ├── bug1472770.c ├── bug1472770.f.c ├── bug1472770.f.re ├── bug1472770.re ├── bug1472770.s.c ├── bug1472770.s.re ├── bug1479044.b.c ├── bug1479044.b.re ├── bug1479044.c ├── bug1479044.re ├── bug1479044.s.c ├── bug1479044.s.re ├── bug1528269.c ├── bug1528269.re ├── bug1529351.c ├── bug1529351.re ├── bug1682718.c ├── bug1682718.is.c ├── bug1682718.is.re ├── bug1682718.re ├── bug1708378.ib.c ├── bug1708378.ib.re ├── bug1711240.eis.c ├── bug1711240.eis.re ├── c.c ├── c.re ├── casing-flags.i--case-insensitive.c ├── casing-flags.i--case-insensitive.re ├── casing-flags.i--case-inverted.c ├── casing-flags.i--case-inverted.re ├── casing-flags.i.c ├── casing-flags.i.re ├── cmmap.c ├── cmmap.re ├── cnokw.c ├── cnokw.re ├── cond_error_00.c ├── cond_error_00.re ├── cond_error_01.c.c ├── cond_error_01.c.re ├── cond_error_02.c.c ├── cond_error_02.c.re ├── cond_error_03.c.c ├── cond_error_03.c.re ├── cond_error_04.c.c ├── cond_error_04.c.re ├── cond_error_05.c.c ├── cond_error_05.c.re ├── cond_error_06.c.c ├── cond_error_06.c.re ├── cond_error_07.c.c ├── cond_error_07.c.re ├── cond_error_08.c.c ├── cond_error_08.c.re ├── cond_error_09.c.c ├── cond_error_09.c.re ├── cond_error_10.c.c ├── cond_error_10.c.re ├── cond_error_11.c.c ├── cond_error_11.c.re ├── condition_01.c.c ├── condition_01.c.re ├── condition_01a.c.c ├── condition_01a.c.re ├── condition_01b.c.c ├── condition_01b.c.re ├── condition_02.c.c ├── condition_02.c.re ├── condition_02.cg.c ├── condition_02.cg.re ├── condition_03.cg.c ├── condition_03.cg.re ├── condition_04.cg.c ├── condition_04.cg.re ├── condition_05.cg.c ├── condition_05.cg.re ├── condition_05.cgitcondition_05.cgit.h.c ├── condition_05.cgitcondition_05.cgit.h.h ├── condition_05.cgitcondition_05.cgit.h.re ├── condition_05.cgtcondition_05.cgt.h.c ├── condition_05.cgtcondition_05.cgt.h.h ├── condition_05.cgtcondition_05.cgt.h.re ├── condition_05.cs.c ├── condition_05.cs.re ├── condition_06.cs.c ├── condition_06.cs.re ├── condition_07.cbi.c ├── condition_07.cbi.re ├── condition_08.cbi.c ├── condition_08.cbi.re ├── condition_08.cbif.c ├── condition_08.cbif.re ├── condition_09.cbif.c ├── condition_09.cbif.re ├── condition_09.cgif.c ├── condition_09.cgif.re ├── condition_10.cgif.c ├── condition_10.cgif.re ├── condition_11.cg.c ├── condition_11.cg.re ├── condition_12.cgif.c ├── condition_12.cgif.re ├── condition_13.cg.c ├── condition_13.cg.re ├── condition_14.cbif.c ├── condition_14.cbif.re ├── condition_14.cgif.c ├── condition_14.cgif.re ├── condition_14.cif.c ├── condition_14.cif.re ├── condition_14.csif.c ├── condition_14.csif.re ├── condition_15.csif.c ├── condition_15.csif.re ├── config1.c ├── config1.re ├── config10.c ├── config10.re ├── config2.s.c ├── config2.s.re ├── config3.c ├── config3.re ├── config4a.f.c ├── config4a.f.re ├── config4b.f.c ├── config4b.f.re ├── config4c.f.c ├── config4c.f.re ├── config4d.f.c ├── config4d.f.re ├── config4e.f.c ├── config4e.f.re ├── config4f.f.c ├── config4f.f.re ├── config4g.ifs.c ├── config4g.ifs.re ├── config5.c ├── config5.re ├── config6.c ├── config6.re ├── config7a.g.c ├── config7a.g.re ├── config7b.g.c ├── config7b.g.re ├── config8.c ├── config8.re ├── config9.b.c ├── config9.b.re ├── ctx.b.c ├── ctx.b.re ├── ctx.c ├── ctx.re ├── ctx.s.c ├── ctx.s.re ├── cunroll.c ├── cunroll.re ├── cvsignore.b.c ├── cvsignore.b.re ├── cvsignore.c ├── cvsignore.re ├── cvsignore.s.c ├── cvsignore.s.re ├── cvsignore.u.c ├── cvsignore.u.re ├── cvsignore.ub.c ├── cvsignore.ub.re ├── cvsignore.w.c ├── cvsignore.w.re ├── cvsignore.wb.c ├── cvsignore.wb.re ├── dot.D.c ├── dot.D.re ├── dot_conditions.Dc.c ├── dot_conditions.Dc.re ├── error1.c ├── error1.re ├── error10.c ├── error10.re ├── error11.c ├── error11.re ├── error12.c ├── error12.re ├── error13.1.c ├── error13.1.re ├── error13.c ├── error13.re ├── error14.1.c ├── error14.1.re ├── error14.c ├── error14.re ├── error2.c ├── error2.re ├── error3.c ├── error3.re ├── error4.c ├── error4.re ├── error5.c ├── error5.re ├── error6.c ├── error6.re ├── error7.c ├── error7.re ├── error8.c ├── error8.re ├── error9.c ├── error9.re ├── flex-01.i.c ├── flex-01.i.re ├── flex-01.iF.c ├── flex-01.iF.re ├── input1.c ├── input1.re ├── input10.b.c ├── input10.b.re ├── input10.c ├── input10.re ├── input10.s.c ├── input10.s.re ├── input11.b.c ├── input11.b.re ├── input11.c ├── input11.i.c ├── input11.i.re ├── input11.re ├── input11.s.c ├── input11.s.re ├── input12.boinput12.c.c ├── input12.boinput12.c.re ├── input12.oinput12.c.c ├── input12.oinput12.c.re ├── input13.c ├── input13.re ├── input2.c ├── input2.re ├── input3.c ├── input3.re ├── input4.c ├── input4.re ├── input5.c ├── input5.re ├── input6.c ├── input6.re ├── input7.c ├── input7.re ├── input8.b.c ├── input8.b.re ├── input8.c ├── input8.g.c ├── input8.g.re ├── input8.re ├── input9.c ├── input9.re ├── line-01.c ├── line-01.re ├── modula.c ├── modula.re ├── overflow-1.c ├── overflow-1.re ├── overflow-2.c ├── overflow-2.re ├── overflow-3.c ├── overflow-3.re ├── overflow-4.c ├── overflow-4.re ├── parse_date.b.c ├── parse_date.b.re ├── parse_date.c ├── parse_date.db.c ├── parse_date.db.re ├── parse_date.g.c ├── parse_date.g.re ├── parse_date.re ├── parse_date.s.c ├── parse_date.s.re ├── parse_date_1_78.db.c ├── parse_date_1_78.db.re ├── push.c ├── push.f.c ├── push.f.re ├── push.fb.c ├── push.fb.re ├── push.fg.c ├── push.fg.re ├── push.fs.c ├── push.fs.re ├── push.re ├── repeat-00.cgi.c ├── repeat-00.cgi.re ├── repeat-01.cgir.c ├── repeat-01.cgir.re ├── repeat-02.cgir.c ├── repeat-02.cgir.re ├── repeat-03.cgir.c ├── repeat-03.cgir.re ├── repeat-04.cgir.c ├── repeat-04.cgir.re ├── repeat-05.cgir.c ├── repeat-05.cgir.re ├── repeat-06.gir.c ├── repeat-06.gir.re ├── repeat-07.gir.c ├── repeat-07.gir.re ├── repeater.c ├── repeater.re ├── sample.c ├── sample.re ├── scanner.c ├── scanner.fs.c ├── scanner.fs.re ├── scanner.re ├── scanner.s.c ├── scanner.s.re ├── simple.c ├── simple.re ├── yyaccept_missing.bci.c └── yyaccept_missing.bci.re ├── token.h └── translate.cc /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 2 | PROJECT( baffledCitrus ) 3 | 4 | # perplex, lemon, re2c 5 | 6 | # set some variables so that we don't have to use FIND() 7 | # also add dependencies so that perplex is built after re2c and 8 | # re2c is built after lemon 9 | if( DISABLE_BAFFLEDCITRUS_BUNDLE ) 10 | message( WARNING "Bundle disabled. This CMakeLists.txt isn't very useful without that!" ) 11 | else() 12 | # Output directories. 13 | IF(NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY) 14 | SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib CACHE INTERNAL "Single output directory for building all libraries.") 15 | ENDIF(NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY) 16 | IF(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY) 17 | SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib CACHE INTERNAL "Single output directory for building all archives.") 18 | ENDIF(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY) 19 | IF(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY) 20 | SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE INTERNAL "Single output directory for building all executables.") 21 | ENDIF(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY) 22 | 23 | #lemon 24 | set( LEMON_SKIP_INSTALL TRUE ) 25 | set( LEMON_TEMPLATE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/lempar.c" ) 26 | set( LEMON_EXECUTABLE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/lemon" ) 27 | include( cmake/LEMON_Util.cmake ) 28 | 29 | #re2c 30 | set( RE2C_IS_SUBBUILD TRUE ) 31 | set( RE2C_EXECUTABLE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/re2c" ) 32 | set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}" ) 33 | 34 | #perplex 35 | set( PERPLEX_IS_SUBBUILD TRUE ) 36 | endif( DISABLE_BAFFLEDCITRUS_BUNDLE ) 37 | 38 | 39 | add_subdirectory(lemon) 40 | add_subdirectory(re2c) 41 | add_subdirectory(perplex) 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | baffledCitrus 2 | ============= 3 | 4 | A cross-platform (Linux/OSX/Windows/etc) lexer/parser generator replacement for lex/flex and yacc/bison 5 | 6 | * [Lemon](lemon/README): an LALR(1) parser generator from SQLite 7 | * [re2c](re2c/README.in): a tool for writing very fast and very flexible scanners 8 | * [Perplex](perplex/README.txt): a simple tool to simplify the creation of scanners using re2c 9 | 10 | 11 | This combination is used in BRL-CAD as a replacement for flex and bison. 12 | 13 | #### Compiling #### 14 | Requires: CMake >= 2.8, C/C++ compiler (MSVC, GCC, Clang, etc) 15 | 16 | On Windows, use CMake-GUI. On other OSes, use CMake-GUI or type the following: 17 | ```sh 18 | cd baffledCitrus 19 | mkdir build 20 | cd build 21 | cmake .. 22 | make 23 | ``` 24 | 25 | ----------------------- 26 | 27 | #### Other Code Generators #### 28 | * [Comparison of parser generators](http://en.wikipedia.org/wiki/Comparison_of_parser_generators) on Wikipedia 29 | * [Ragel State Machine Compiler](http://www.complang.org/ragel/) 30 | * [flex](http://flex.sourceforge.net/) 31 | * [bison](http://www.gnu.org/software/bison/) 32 | 33 | 34 | #### Syntax checkers #### 35 | * [bnfparser2](http://www.anfdata.cz/bnfparser2/) BNF/EBNF/ABNF syntax verification utility 36 | * [BNF Syntax Checker](http://www.icosaedro.it/bnf_chk/) 37 | 38 | -------------------------------------------------------------------------------- /cmake/FindRE2C.cmake: -------------------------------------------------------------------------------- 1 | # The module defines the following variables: 2 | # RE2C_EXECUTABLE - the path to the re2c executable 3 | # 4 | #============================================================================= 5 | 6 | find_program(RE2C_EXECUTABLE re2c DOC "path to the re2c executable") 7 | mark_as_advanced(RE2C_EXECUTABLE) 8 | 9 | include(FindPackageHandleStandardArgs) 10 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(RE2C DEFAULT_MSG RE2C_EXECUTABLE) 11 | -------------------------------------------------------------------------------- /lemon.dist: -------------------------------------------------------------------------------- 1 | SET(lemon_ignore_files 2 | README 3 | lempar.c 4 | ) 5 | -------------------------------------------------------------------------------- /lemon/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Minimum required version of CMake 2 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 3 | IF(COMMAND CMAKE_POLICY) 4 | CMAKE_POLICY(SET CMP0003 NEW) 5 | if ("${CMAKE_VERSION}" VERSION_GREATER 2.99) 6 | CMAKE_POLICY(SET CMP0026 OLD) 7 | endif ("${CMAKE_VERSION}" VERSION_GREATER 2.99) 8 | ENDIF(COMMAND CMAKE_POLICY) 9 | 10 | # Set CMake project name 11 | PROJECT(LEMON) 12 | 13 | add_executable(lemon lemon.c) 14 | # Install 15 | if(NOT BIN_DIR) 16 | set(BIN_DIR bin) 17 | endif(NOT BIN_DIR) 18 | if(NOT LEMON_SKIP_INSTALL) 19 | install(TARGETS lemon DESTINATION ${BIN_DIR}) 20 | endif(NOT LEMON_SKIP_INSTALL) 21 | 22 | # Handle lempar.c template file 23 | if(NOT CMAKE_CONFIGURATION_TYPES) 24 | set(LEMPAR_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) 25 | else(NOT CMAKE_CONFIGURATION_TYPES) 26 | set(LEMPAR_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${BIN_DIR}) 27 | endif(NOT CMAKE_CONFIGURATION_TYPES) 28 | add_custom_command( 29 | OUTPUT ${LEMPAR_DIR}/lempar.c 30 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/lempar.c ${LEMPAR_DIR}/lempar.c 31 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lempar.c 32 | ) 33 | add_custom_target(lempar_cp ALL DEPENDS ${LEMPAR_DIR}/lempar.c) 34 | add_dependencies(lemon lempar_cp) 35 | 36 | if(NOT LEMON_SKIP_INSTALL) 37 | install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lempar.c DESTINATION ${BIN_DIR}) 38 | endif(NOT LEMON_SKIP_INSTALL) 39 | 40 | # Local Variables: 41 | # tab-width: 8 42 | # mode: cmake 43 | # indent-tabs-mode: t 44 | # End: 45 | # ex: shiftwidth=2 tabstop=8 46 | -------------------------------------------------------------------------------- /lemon/README: -------------------------------------------------------------------------------- 1 | The LEMON Parser Generator 2 | 3 | The Lemon program is an LALR(1) parser generator. It takes 4 | a context free grammar and converts it into a subroutine 5 | that will parse a file using that grammar. 6 | 7 | Lemon is similar to the much more famous programs "YACC" 8 | and "BISON". But lemon is not compatible with either yacc 9 | or bison. There are several important differences: 10 | 11 | * Lemon using a different grammar syntax which is less 12 | prone to programming errors. 13 | 14 | * The parser generated by Lemon is both re-entrant and 15 | thread-safe. 16 | 17 | * Lemon includes the concept of a non-terminal destructor, 18 | which makes it much easier to write a parser that does 19 | not leak memory. 20 | 21 | The complete source code to the lemon parser generator is 22 | contained in two files. The file lemon.c is the parser 23 | generator program itself. A separate file lempar.c is the 24 | template for the parser subroutine that lemon generates. 25 | Documentation on lemon is also available at: 26 | http://www.hwaci.com/sw/lemon/lemon.html 27 | 28 | Both the source code to lemon itself and the code that 29 | lemon generates are in the public domain. 30 | 31 | To see an example of how to use lemon, see the source code 32 | to the SQLite database engine. Lemon is maintained as part 33 | of the SQLite project. 34 | -------------------------------------------------------------------------------- /perplex.dist: -------------------------------------------------------------------------------- 1 | SET(perplex_ignore_files 2 | CMake 3 | mbo_getopt.h 4 | parser.y 5 | perplex.h 6 | README.txt 7 | scanner.re 8 | perplex_template.c 9 | token_type.h 10 | ) 11 | -------------------------------------------------------------------------------- /perplex/CHANGELOG.txt: -------------------------------------------------------------------------------- 1 | Version 1.0.1 (2014-06-24) 2 | -------------------------- 3 | * Fixed a casting bug in perplex_template.c. Benign on most systems, but 4 | triggered a warning from some compilers. 5 | -------------------------------------------------------------------------------- /perplex/CMake/FindRE2C.cmake: -------------------------------------------------------------------------------- 1 | # The module defines the following variables: 2 | # RE2C_EXECUTABLE - the path to the re2c executable 3 | # 4 | #============================================================================= 5 | 6 | find_program(RE2C_EXECUTABLE re2c DOC "path to the re2c executable") 7 | mark_as_advanced(RE2C_EXECUTABLE) 8 | 9 | include(FindPackageHandleStandardArgs) 10 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(RE2C DEFAULT_MSG RE2C_EXECUTABLE) 11 | -------------------------------------------------------------------------------- /perplex/mbo_getopt.h: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Marcus Boerger 3 | */ 4 | 5 | /* Public Domain (file originally from re2c) */ 6 | 7 | /* Define structure for one recognized option (both single char and long name). 8 | * If short_open is '-' this is the last option. 9 | */ 10 | 11 | #ifndef RE2C_MBO_GETOPT_H_INCLUDE_GUARD_ 12 | #define RE2C_MBO_GETOPT_H_INCLUDE_GUARD_ 13 | 14 | namespace re2c 15 | { 16 | 17 | struct mbo_opt_struct { 18 | mbo_opt_struct(char _opt_char, int _need_param, const char *_opt_name) 19 | : opt_char(_opt_char), need_param(_need_param), opt_name(_opt_name) { 20 | } 21 | 22 | const char opt_char; 23 | const int need_param; 24 | const char *opt_name; 25 | }; 26 | 27 | int mbo_getopt(int argc, char *const *argv, const mbo_opt_struct *opts, char **optarg, int *optind, int show_err); 28 | 29 | } // end namespace re2c 30 | 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /perplex/token_type.h: -------------------------------------------------------------------------------- 1 | /* T O K E N _ T Y P E . H 2 | * BRL-CAD 3 | * 4 | * Copyright (c) 2011 United States Government as represented by 5 | * the U.S. Army Research Laboratory. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * 2. Redistributions in binary form must reproduce the above 15 | * copyright notice, this list of conditions and the following 16 | * disclaimer in the documentation and/or other materials provided 17 | * with the distribution. 18 | * 19 | * 3. The name of the author may not be used to endorse or promote 20 | * products derived from this software without specific prior written 21 | * permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 24 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 27 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 29 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 31 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | /** @file token_type.h 36 | * 37 | * Type to hold value of tokens passed from scanner to parser. 38 | * 39 | */ 40 | 41 | #ifndef TOKEN_TYPE_H 42 | #define TOKEN_TYPE_H 43 | 44 | typedef union YYSTYPE { 45 | char *string; 46 | } YYSTYPE; 47 | 48 | #endif 49 | 50 | /* 51 | * Local Variables: 52 | * tab-width: 8 53 | * mode: C 54 | * indent-tabs-mode: t 55 | * c-file-style: "stroustrup" 56 | * End: 57 | * ex: shiftwidth=4 tabstop=8 58 | */ 59 | -------------------------------------------------------------------------------- /re2c.dist: -------------------------------------------------------------------------------- 1 | SET(re2c_ignore_files 2 | CHANGELOG 3 | CMake 4 | README.in 5 | basics.h 6 | code.h 7 | code_names.h 8 | config.h.in 9 | config_w32.h.in 10 | configure.in 11 | dfa.h 12 | doc 13 | examples 14 | globals.h 15 | htdocs 16 | ins.h 17 | lessons 18 | mbo_getopt.h 19 | re2c_parser.h 20 | parser.yy 21 | re.h 22 | re2c.1.in 23 | re2c.spec.in 24 | run_tests.sh.in 25 | scanner.h 26 | scanner.re 27 | stream_lc.h 28 | substr.h 29 | test 30 | token.h 31 | ) 32 | -------------------------------------------------------------------------------- /re2c/basics.h: -------------------------------------------------------------------------------- 1 | /* $Id: basics.h 520 2006-05-25 13:31:06Z helly $ */ 2 | #ifndef _basics_h 3 | #define _basics_h 4 | 5 | #ifdef HAVE_CONFIG_H 6 | #include "config.h" 7 | #elif defined(_WIN32) 8 | #include "config_w32.h" 9 | #endif 10 | 11 | namespace re2c 12 | { 13 | 14 | #if SIZEOF_CHAR == 1 15 | typedef unsigned char byte; 16 | #elif SIZEOF_SHORT == 1 17 | typedef unsigned short byte; 18 | #elif SIZEOF_INT == 1 19 | typedef unsigned int byte; 20 | #elif SIZEOF_LONG == 1 21 | typedef unsigned long byte; 22 | #else 23 | typedef unsigned char byte; 24 | #endif 25 | 26 | #if SIZEOF_CHAR == 2 27 | typedef unsigned char word; 28 | #elif SIZEOF_SHORT == 2 29 | typedef unsigned short word; 30 | #elif SIZEOF_INT == 2 31 | typedef unsigned int word; 32 | #elif SIZEOF_LONG == 2 33 | typedef unsigned long word; 34 | #else 35 | typedef unsigned short word; 36 | #endif 37 | 38 | #if SIZEOF_CHAR == 4 39 | typedef unsigned char dword; 40 | #elif SIZEOF_SHORT == 4 41 | typedef unsigned short dword; 42 | #elif SIZEOF_INT == 4 43 | typedef unsigned int dword; 44 | #elif SIZEOF_LONG == 4 45 | typedef unsigned long dword; 46 | #else 47 | typedef unsigned long dword; 48 | #endif 49 | 50 | typedef unsigned int uint; 51 | typedef unsigned char uchar; 52 | typedef unsigned short ushort; 53 | typedef unsigned long ulong; 54 | 55 | } // end namespace re2c 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /re2c/code.h: -------------------------------------------------------------------------------- 1 | /* $Id: code.h 525 2006-05-25 13:32:49Z helly $ */ 2 | #ifndef _code_h 3 | #define _code_h 4 | 5 | #include "re.h" 6 | #include "dfa.h" 7 | 8 | namespace re2c 9 | { 10 | 11 | class BitMap 12 | { 13 | public: 14 | static BitMap *first; 15 | 16 | const Go *go; 17 | const State *on; 18 | const BitMap *next; 19 | uint i; 20 | uint m; 21 | 22 | public: 23 | static const BitMap *find(const Go*, const State*); 24 | static const BitMap *find(const State*); 25 | static void gen(std::ostream&, uint ind, uint, uint); 26 | static void stats(); 27 | BitMap(const Go*, const State*); 28 | ~BitMap(); 29 | 30 | #if defined(PEDANTIC) && (PEDANTIC>0) 31 | BitMap(const BitMap& oth) 32 | : go(oth.go) 33 | , on(oth.on) 34 | , next(oth.next) 35 | , i(oth.i) 36 | , m(oth.m) 37 | { 38 | } 39 | BitMap& operator = (const BitMap& oth) 40 | { 41 | new(this) BitMap(oth); 42 | return *this; 43 | } 44 | #endif 45 | }; 46 | 47 | #ifdef _MSC_VER 48 | # pragma warning(disable: 4355) /* 'this' : used in base member initializer list */ 49 | #endif 50 | 51 | } // end namespace re2c 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /re2c/code_names.h: -------------------------------------------------------------------------------- 1 | /* $Id: token.h 547 2006-05-25 13:40:35Z helly $ */ 2 | #ifndef _code_names_h 3 | #define _code_names_h 4 | 5 | #include 6 | #include 7 | 8 | namespace re2c 9 | { 10 | 11 | class CodeNames: public std::map 12 | { 13 | public: 14 | std::string& operator [] (const char * what); 15 | }; 16 | 17 | inline std::string& CodeNames::operator [] (const char * what) 18 | { 19 | CodeNames::iterator it = find(std::string(what)); 20 | 21 | if (it != end()) 22 | { 23 | return it->second; 24 | } 25 | else 26 | { 27 | return insert(std::make_pair(std::string(what), std::string(what))).first->second; 28 | } 29 | } 30 | 31 | } // end namespace re2c 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /re2c/configure.in: -------------------------------------------------------------------------------- 1 | AC_PREREQ([2.57]) 2 | AC_INIT(re2c, 0.13.5, re2c-general@lists.sourceforge.net) 3 | AM_INIT_AUTOMAKE(re2c, $PACKAGE_VERSION) 4 | AC_CONFIG_SRCDIR(actions.cc) 5 | AM_CONFIG_HEADER(config.h) 6 | 7 | AC_SUBST(PACKAGE_DATE, `date +'%d %b %Y'`) 8 | AC_SUBST(PACKAGE_VERSION) 9 | AC_SUBST(PACKAGE_NAME) 10 | AC_SUBST(PACKAGE_TARNAME) 11 | AC_SUBST(PACKAGE_RELEASE, ${PACKAGE_RELEASE:-1}) 12 | AC_SUBST(WINBUILDDIR, Release-2005) 13 | 14 | # Checks for programs. 15 | AC_PROG_YACC 16 | AC_PROG_CXX 17 | AC_PROG_CC 18 | AC_PROG_INSTALL 19 | 20 | if test "$GCC" = "yes"; then 21 | AC_MSG_CHECKING([Testing GCC version]) 22 | GCCVERSION=`$CXX -dumpversion 2>/dev/null` 23 | if test -z "$GCCVERSION"; then 24 | AC_MSG_ERROR([GCC version 3 or above required]) 25 | fi 26 | AC_MSG_RESULT([found version $GCCVERSION]) 27 | fi 28 | 29 | # Checks for libraries. 30 | 31 | # Checks for header files. 32 | AC_HEADER_STDC 33 | 34 | # We only rely on standard C/C++ headers. If we ever have a pressing need 35 | # for something non-standard, we should add a check for it here. 36 | # AC_CHECK_HEADERS([stddef.h stdlib.h string.h]) 37 | 38 | # Checks for typedefs, structures, and compiler characteristics. 39 | AC_HEADER_STDBOOL 40 | AC_C_CONST 41 | AC_C_INLINE 42 | AC_TYPE_SIZE_T 43 | AC_C_VOLATILE 44 | 45 | # Checks for library functions. 46 | AC_FUNC_MEMCMP 47 | AC_FUNC_MMAP 48 | AC_CHECK_FUNCS([memset munmap strdup strndup]) 49 | 50 | AC_CHECK_SIZEOF([char]) 51 | AC_CHECK_SIZEOF([short]) 52 | AC_CHECK_SIZEOF([int]) 53 | AC_CHECK_SIZEOF([long]) 54 | 55 | AC_CONFIG_FILES([\ 56 | Makefile \ 57 | README \ 58 | makerpm \ 59 | re2c.1 \ 60 | re2c.spec \ 61 | run_tests.sh \ 62 | config_w32.h \ 63 | htdocs/manual.html \ 64 | ]) 65 | AC_OUTPUT_COMMANDS([chmod +x makerpm run_tests.sh]) 66 | AC_OUTPUT 67 | -------------------------------------------------------------------------------- /re2c/doc/sample.bib: -------------------------------------------------------------------------------- 1 | @Article{Bumbulis94, 2 | author = {Peter Bumbulis and Donald D. Cowan}, 3 | title = {RE2C -- A More Versatile Scanner Generator}, 4 | journal = "ACM Letters on Programming Languages and Systems", 5 | volume = 2, 6 | number = "1--4", 7 | year = 1994, 8 | abstract = { 9 | It is usually claimed that lexical analysis routines are still coded by 10 | hand, despite the widespread availability of scanner generators, for 11 | efficiency reasons. While efficiency is a consideration, there exist 12 | freely available scanner generators such as GLA \cite{Gray88} that can 13 | generate scanners that are faster than most hand-coded ones. However, 14 | most generated scanners are tailored for a particular environment, and 15 | retargetting these scanners to other environments, if possible, is 16 | usually complex enough to make a hand-coded scanner more appealing. In 17 | this paper we describe RE2C, a scanner generator that not only generates 18 | scanners which are faster (and usually smaller) than those produced by 19 | any other scanner generator known to the authors, including GLA, but 20 | also adapt easily to any environment. 21 | } 22 | } 23 | @Article{Gray88, 24 | author = {Robert W. Gray}, 25 | title = {{$\gamma$-GLA} - {A} Generator for Lexical Analyzers That 26 | Programmers Can Use}, 27 | journal = {USENIX Conference Proceedings}, 28 | year = {1988}, 29 | month = {June}, 30 | pages = {147-160}, 31 | abstract = {Writing an efficient lexical analyzer for even a simple 32 | language is not a trivial task, and should not be done by hand. We 33 | describe GLA, a tool that generates very efficient scanners. These 34 | scanners do not use the conventional transition matrix, but instead 35 | use a few 128 element vectors. Scanning time is only slightly 36 | greater than the absolute minimum --- the time it takes to look at 37 | each character in a file. The GLA language allows simple, concise 38 | specification of scanners. Augmenting regular expressions with 39 | auxiliary scanners easily handles nasty problems such as C comments 40 | and C literal constants. We formalize the connection between token 41 | scanning and token processing by associating a processor with 42 | appropriate patterns. A library of canned descriptions simplifies the 43 | specification of commonly used language pieces --- such as, 44 | C\_IDENTIFIERS, C\_STRINGS, PASCAL\_COMMENTS, etc. Finally, carefully 45 | tuned lexical analysis support modules are provided for error 46 | handling, input buffering, storing identifiers in hash tables and 47 | manipulating denotations.} 48 | } 49 | -------------------------------------------------------------------------------- /re2c/examples/basemmap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #ifndef MAP_NORESERVE 8 | #define MAP_NORESERVE 0 9 | #endif 10 | 11 | volatile char ch; 12 | 13 | main(){ 14 | struct stat statbuf; 15 | uchar *buf; 16 | fstat(0, &statbuf); 17 | buf = mmap(NULL, statbuf.st_size, PROT_READ, MAP_SHARED|MAP_NORESERVE, 18 | 0, 0); 19 | if(buf != (uchar*)(-1)){ 20 | uchar *cur, *lim = &buf[statbuf.st_size]; 21 | for(cur = buf; buf != lim; ++cur){ 22 | ch = *cur; 23 | } 24 | munmap(buf, statbuf.st_size); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /re2c/examples/repeater.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define RET(n) printf("%d\n", n); return n 6 | 7 | int scan(char *s, int l){ 8 | char *p = s; 9 | char *q; 10 | #define YYCTYPE char 11 | #define YYCURSOR p 12 | #define YYLIMIT (s+l) 13 | #define YYMARKER q 14 | #define YYFILL(n) 15 | /*!re2c 16 | 'a'{1}"\n" {RET(1);} 17 | 'a'{2,3}"\n" {RET(2);} 18 | 'a'{6}"\n" {RET(4);} 19 | 'a'{4,}"\n" {RET(3);} 20 | [^aq]|"\n" {RET(0);} 21 | */ 22 | } 23 | 24 | #define do_scan(str) scan(str, strlen(str)) 25 | 26 | main() 27 | { 28 | do_scan("a\n"); 29 | do_scan("aa\n"); 30 | do_scan("aaa\n"); 31 | do_scan("aaaa\n"); 32 | do_scan("q"); 33 | do_scan("a"); 34 | do_scan("A\n"); 35 | do_scan("AA\n"); 36 | do_scan("aAa\n"); 37 | do_scan("AaaA\n"); 38 | do_scan("Q"); 39 | do_scan("AaaAa\n"); 40 | do_scan("AaaAaA\n"); 41 | do_scan("A"); 42 | do_scan("\n"); 43 | do_scan("0"); 44 | } 45 | -------------------------------------------------------------------------------- /re2c/examples/rexx/README: -------------------------------------------------------------------------------- 1 | Replacement modules for an existing REXX interpreter. Not standalone. 2 | -------------------------------------------------------------------------------- /re2c/examples/rexx/scanio.c: -------------------------------------------------------------------------------- 1 | uchar *ScanFill(uchar *cursor){ 2 | unsigned cnt = s->tok - s->bot; 3 | s->pos += cursor - s->mrk; 4 | if(cnt){ 5 | if(s->eot){ 6 | unsigned len = s->eot - s->tok; 7 | memcpy(s->bot, s->tok, len); 8 | s->eot = &s->bot[len]; 9 | if((len = s->lim - cursor) != 0) 10 | memcpy(s->eot, cursor, len); 11 | cursor = s->eot; 12 | s->lim = &cursor[len]; 13 | } else { 14 | memcpy(s->bot, s->tok, s->lim - s->tok); 15 | cursor -= cnt; 16 | s->lim -= cnt; 17 | } 18 | s->tok = s->bot; 19 | s->ptr -= cnt; 20 | } 21 | if((s->top - s->lim) < 512){ 22 | uchar *buf = (uchar*) malloc(((s->lim - s->bot) + 512)*sizeof(uchar)); 23 | memcpy(buf, s->bot, s->lim - s->bot); 24 | s->tok = buf; 25 | s->ptr = &buf[s->ptr - s->bot]; 26 | if(s->eot) 27 | s->eot = &buf[s->eot - s->bot]; 28 | cursor = &buf[cursor - s->bot]; 29 | s->lim = &buf[s->lim - s->bot]; 30 | s->top = &s->lim[512]; 31 | free(s->bot); 32 | s->bot = buf; 33 | } 34 | s->mrk = cursor; 35 | if(ScanCBIO.file){ 36 | if((cnt = read(ScanCBIO.u.f.fd, (char*) s->lim, 512)) != 512) 37 | memset(&s->lim[cnt], 0, 512 - cnt); 38 | s->lim += 512; 39 | } 40 | return cursor; 41 | } 42 | -------------------------------------------------------------------------------- /re2c/examples/sample.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | "print" {return PRINT;} 3 | [a-z]+ {return ID;} 4 | [0-9]+ {return DEC;} 5 | "0x" [0-9a-f]+ {return HEX;} 6 | [\000-\377] {return ERR;} 7 | */ 8 | -------------------------------------------------------------------------------- /re2c/examples/simple.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | char *scan(char *p){ 3 | char *q; 4 | #define YYCTYPE char 5 | #define YYCURSOR p 6 | #define YYLIMIT p 7 | #define YYMARKER q 8 | #define YYFILL(n) 9 | /*!re2c 10 | [0-9]+ {return YYCURSOR;} 11 | [\000-\377] {return NULL;} 12 | */ 13 | } 14 | -------------------------------------------------------------------------------- /re2c/ins.h: -------------------------------------------------------------------------------- 1 | /* $Id: ins.h 535 2006-05-25 13:36:14Z helly $ */ 2 | #ifndef _ins_h 3 | #define _ins_h 4 | 5 | #include "basics.h" 6 | 7 | namespace re2c 8 | { 9 | 10 | typedef unsigned short Char; 11 | 12 | const uint CHAR = 0; 13 | const uint GOTO = 1; 14 | const uint FORK = 2; 15 | const uint TERM = 3; 16 | const uint CTXT = 4; 17 | 18 | union Ins { 19 | 20 | struct 21 | { 22 | byte tag; 23 | byte marked; 24 | void *link; 25 | } 26 | 27 | i; 28 | 29 | struct 30 | { 31 | ushort value; 32 | ushort bump; 33 | void *link; 34 | } 35 | 36 | c; 37 | }; 38 | 39 | inline bool isMarked(Ins *i) 40 | { 41 | return i->i.marked != 0; 42 | } 43 | 44 | inline void mark(Ins *i) 45 | { 46 | i->i.marked = true; 47 | } 48 | 49 | inline void unmark(Ins *i) 50 | { 51 | i->i.marked = false; 52 | } 53 | 54 | } // end namespace re2c 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /re2c/lessons/001_upn_calculator/calc_002.re: -------------------------------------------------------------------------------- 1 | /* re2c lesson 001_upn_calculator, calc_002, (c) M. Boerger 2006 - 2007 */ 2 | /*!ignore:re2c 3 | 4 | - making use of YYFILL 5 | 6 | . Here we modified the scanner to not require strlen() on the call. Instead 7 | we compute limit on the fly. That is whenever more input is needed we 8 | search for the terminating \0 in the next n chars the scanner needs. 9 | . If there is not enough input we quit the scanner. 10 | . Note that in lesson_001 YYLIMIT was a character pointer computed only once. 11 | Here is of course also of type YYCTYPE but a variable that gets reevaluated 12 | by YYFILL(). 13 | . To make the code smaller we take advantage of the fact that our loop has no 14 | break so far. This allows us to use break here and have the code that is 15 | used for YYFILL() not contain the printf in every occurence. That way the 16 | generated code gets smaller. 17 | 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | int fill(char *p, int n, char **l) 25 | { 26 | while (*++p && n--) ; 27 | * l = p; 28 | return n <= 0; 29 | } 30 | 31 | int scan(char *s) 32 | { 33 | char *p = s; 34 | char *l = s; 35 | char *q = 0; 36 | #define YYCTYPE char 37 | #define YYCURSOR p 38 | #define YYLIMIT l 39 | #define YYMARKER q 40 | #define YYFILL(n) { if (!fill(p, n, &l)) break; } 41 | 42 | for(;;) 43 | { 44 | /*!re2c 45 | re2c:indent:top = 2; 46 | "0"[0-9]+ { printf("Oct\n"); continue; } 47 | [1-9][0-9]* { printf("Num\n"); continue; } 48 | "0" { printf("Num\n"); continue; } 49 | "+" { printf("+\n"); continue; } 50 | "-" { printf("+\n"); continue; } 51 | "\000" { printf("EOF\n"); return 0; } 52 | [^] { printf("ERR\n"); return 1; } 53 | */ 54 | } 55 | printf("OOD\n"); return 2; 56 | } 57 | 58 | int main(int argc, char **argv) 59 | { 60 | if (argc > 1) 61 | { 62 | return scan(argv[1]); 63 | } 64 | else 65 | { 66 | fprintf(stderr, "%s \n", argv[0]); 67 | return 0; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /re2c/lessons/001_upn_calculator/calc_003.re: -------------------------------------------------------------------------------- 1 | /* re2c lesson 001_upn_calculator, calc_003, (c) M. Boerger 2006 - 2007 */ 2 | /*!ignore:re2c 3 | 4 | - making use of YYFILL 5 | 6 | . Again provide the length of the input to generate the limit only once. Now 7 | we can use YYFILL() to detect the end and simply return since YYFILL() is 8 | only being used if the next scanner run might use more chars then YYLIMIT 9 | allows. 10 | . Note that we now use (s+l+2) instead of (s+l) as we did in lesson_001. In 11 | the first lesson we did not quit from YYFILL() and used a special rule to 12 | detect the end of input. Here we use the fact that we know the exact end 13 | of input and that this length does not include the terminating zero. Since 14 | YYLIMIT points to the first character behind the used buffer we use "+ 2". 15 | If we would use "+1" we could drop the "\000" rule but could no longer 16 | distinguish between end of input and out of data. 17 | 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | int scan(char *s, int l) 25 | { 26 | char *p = s; 27 | char *q = 0; 28 | #define YYCTYPE char 29 | #define YYCURSOR p 30 | #define YYLIMIT (s+l+2) 31 | #define YYMARKER q 32 | #define YYFILL(n) { printf("OOD\n"); return 2; } 33 | 34 | for(;;) 35 | { 36 | /*!re2c 37 | re2c:indent:top = 2; 38 | "0"[0-9]+ { printf("Oct\n"); continue; } 39 | [1-9][0-9]* { printf("Num\n"); continue; } 40 | "0" { printf("Num\n"); continue; } 41 | "+" { printf("+\n"); continue; } 42 | "-" { printf("+\n"); continue; } 43 | "\000" { printf("EOF\n"); return 0; } 44 | [^] { printf("ERR\n"); return 1; } 45 | */ 46 | } 47 | return 0; 48 | } 49 | 50 | int main(int argc, char **argv) 51 | { 52 | if (argc > 1) 53 | { 54 | return scan(argv[1], strlen(argv[1])); 55 | } 56 | else 57 | { 58 | fprintf(stderr, "%s \n", argv[0]); 59 | return 0; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /re2c/lessons/001_upn_calculator/calc_004.re: -------------------------------------------------------------------------------- 1 | /* re2c lesson 001_upn_calculator, calc_004, (c) M. Boerger 2006 - 2007 */ 2 | /*!ignore:re2c 3 | 4 | - making use of definitions 5 | . We provide complex rules as definitions. We can even have definitions made 6 | up from other definitions. And we could also use definitions as part of 7 | rules and not only as full rules as shown in this lesson. 8 | 9 | - showing the tokens 10 | . re2c does not store the beginning of a token on its own but we can easily 11 | do this by providing variable, in our case t, that is set to YYCURSOR on 12 | every loop. If we were not using a loop here the token, we could have used 13 | s instead of a new variable instead. 14 | . As we use the token for an output function that requires a terminating zero 15 | we copy the token. Alternatively we could store the end of the token, then 16 | replace it with a zero character and replace it after the token has been 17 | used. However that approach is not always acceptable. 18 | 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | char * tokendup(const char *t, const char *l) 26 | { 27 | size_t n = l -t + 1; 28 | char *r = (char*)malloc(n); 29 | 30 | memmove(r, t, n-1); 31 | r[n] = '\0'; 32 | return r; 33 | } 34 | 35 | int scan(char *s, int l) 36 | { 37 | char *p = s; 38 | char *q = 0; 39 | char *t; 40 | #define YYCTYPE char 41 | #define YYCURSOR p 42 | #define YYLIMIT (s+l+2) 43 | #define YYMARKER q 44 | #define YYFILL(n) { printf("OOD\n"); return 2; } 45 | 46 | for(;;) 47 | { 48 | t = p; 49 | /*!re2c 50 | re2c:indent:top = 2; 51 | 52 | DIGIT = [0-9] ; 53 | OCT = "0" DIGIT+ ; 54 | INT = "0" | ( [1-9] DIGIT* ) ; 55 | 56 | OCT { t = tokendup(t, p); printf("Oct: %s\n", t); free(t); continue; } 57 | INT { t = tokendup(t, p); printf("Num: %s\n", t); free(t); continue; } 58 | "+" { printf("+\n"); continue; } 59 | "-" { printf("+\n"); continue; } 60 | "\000" { printf("EOF\n"); return 0; } 61 | [^] { printf("ERR\n"); return 1; } 62 | */ 63 | } 64 | return 0; 65 | } 66 | 67 | int main(int argc, char **argv) 68 | { 69 | if (argc > 1) 70 | { 71 | return scan(argv[1], strlen(argv[1])); 72 | } 73 | else 74 | { 75 | fprintf(stderr, "%s \n", argv[0]); 76 | return 0; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /re2c/lessons/001_upn_calculator/windows/BuildAndRun.bat: -------------------------------------------------------------------------------- 1 | @echo OFF 2 | goto Start 3 | rem BuildAndRun.bat 06-Apr-15 lda 4 | rem Assumes re2c.exe findable with PATH or . or .. or ..\.. or $(RE2C_HOME) 5 | rem Assumes cl.exe findable with PATH or VcToolKit2003 installed 6 | 7 | :Start 8 | if exist %RE2C_HOME%\re2c.exe goto ProceedWithGenerate 9 | if exist .\re2c.exe set RE2C_HOME=. 10 | if exist ..\re2c.exe set RE2C_HOME=.. 11 | if exist ..\..\re2c.exe set RE2C_HOME=..\.. 12 | if exist ..\..\..\re2c.exe set RE2C_HOME=..\..\.. 13 | if exist ..\..\..\Release\re2c.exe set RE2C_HOME=..\..\..\Release 14 | if exist ..\..\..\Release-2005\re2c.exe set RE2C_HOME=..\..\..\Release-2005 15 | if not exist %RE2C_HOME%\re2c.exe goto ReportSetupError 16 | 17 | :ProceedWithGenerate 18 | set BASE_FILE_NAME=main 19 | %RE2C_HOME%\re2c -b -o%BASE_FILE_NAME%.c %BASE_FILE_NAME%.re 20 | rem echo ErrorLevel is set to %ERRORLEVEL% after re2c 21 | IF ERRORLEVEL 1 goto ReportRe2cError 22 | 23 | rem (to test) set path= 24 | cl 1>nul 2>nul 25 | IF ERRORLEVEL 1 goto AttemptToSetupCompiler 26 | goto ProceedWithCompile 27 | 28 | :AttemptToSetupCompiler 29 | echo ErrorLevel is set to %ERRORLEVEL% after blank cl command line 30 | call %VCToolkitInstallDir%\vcvars32.bat 1>nul 2>nul 31 | cl 1>nul 2>nul 32 | IF ERRORLEVEL 1 goto ReportClError 33 | 34 | :ProceedWithCompile 35 | cl -O2 /DNDEBUG /D_CONSOLE /DWIN32 %BASE_FILE_NAME%.c 36 | rem echo ErrorLevel is set to %ERRORLEVEL% after cl 37 | IF ERRORLEVEL 1 goto ReportClError 38 | %BASE_FILE_NAME% 39 | goto AllDone 40 | 41 | :ReportSetupError 42 | echo re2c.exe not found in ., .., ..\.., ..\..\.., ..\..\..\Release 43 | echo or ..\..\..\Release-2005 Environment variable RE2C_HOME invalid or not set? 44 | 45 | :ReportClError 46 | :ReportRe2cError 47 | :AllDone 48 | pause 49 | -------------------------------------------------------------------------------- /re2c/lessons/001_upn_calculator/windows/HiResTimer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file HiResTimer.h 3 | * @brief 4 | * @note 5 | */ 6 | 7 | #ifndef _HI_RES_TIMER_H_ 8 | #define _HI_RES_TIMER_H_ 9 | 10 | #ifdef WIN32 11 | #include // probably already done in stdafx.h 12 | static LARGE_INTEGER start; 13 | static LARGE_INTEGER stop; 14 | static LARGE_INTEGER freq; 15 | static _int64 elapsedCounts; 16 | static double elapsedMillis; 17 | static double elapsedMicros; 18 | static HANDLE processHandle; 19 | static DWORD prevPriorityClass; 20 | 21 | void HrtInit() 22 | { 23 | processHandle = GetCurrentProcess(); 24 | prevPriorityClass = GetPriorityClass(processHandle); 25 | QueryPerformanceFrequency(&freq); 26 | } 27 | 28 | void HrtStart() 29 | { 30 | QueryPerformanceCounter(&start); 31 | } 32 | 33 | void HrtSetPriority(DWORD priority) 34 | { 35 | int flag; 36 | prevPriorityClass = GetPriorityClass(processHandle); 37 | flag = SetPriorityClass(processHandle, priority); 38 | } 39 | 40 | void HrtResetPriority(void) 41 | { 42 | int flag = SetPriorityClass(processHandle, prevPriorityClass); 43 | } 44 | 45 | double HrtElapsedMillis() 46 | { 47 | QueryPerformanceCounter(&stop); 48 | elapsedCounts = (stop.QuadPart - start.QuadPart); 49 | elapsedMillis = ((elapsedCounts * 1000.0) / freq.QuadPart); 50 | return elapsedMillis; 51 | } 52 | 53 | #endif 54 | #endif -------------------------------------------------------------------------------- /re2c/lessons/001_upn_calculator/windows/TestRe2c-2005.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 9.00 2 | # Visual Studio 2005 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestRe2c", "TestRe2c-2005.vcproj", "{E2CEB3D0-066A-4C9A-B32C-B2197448A57A}" 4 | EndProject 5 | Global 6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 7 | Debug|Default = Debug|Default 8 | Release|Default = Release|Default 9 | EndGlobalSection 10 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 11 | {E2CEB3D0-066A-4C9A-B32C-B2197448A57A}.Debug|Default.ActiveCfg = Debug|Win32 12 | {E2CEB3D0-066A-4C9A-B32C-B2197448A57A}.Debug|Default.Build.0 = Debug|Win32 13 | {E2CEB3D0-066A-4C9A-B32C-B2197448A57A}.Release|Default.ActiveCfg = Release|Win32 14 | {E2CEB3D0-066A-4C9A-B32C-B2197448A57A}.Release|Default.Build.0 = Release|Win32 15 | EndGlobalSection 16 | GlobalSection(SolutionProperties) = preSolution 17 | HideSolutionNode = FALSE 18 | EndGlobalSection 19 | EndGlobal 20 | -------------------------------------------------------------------------------- /re2c/lessons/001_upn_calculator/windows/TestRe2c.dsp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stepcode/baffledCitrus/07421beb3b859db53669e8d0208ce27f81ecaec0/re2c/lessons/001_upn_calculator/windows/TestRe2c.dsp -------------------------------------------------------------------------------- /re2c/lessons/001_upn_calculator/windows/TestRe2c.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "TestRe2c"=.\TestRe2c.dsp - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /re2c/lessons/001_upn_calculator/windows/TestRe2c.ncb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stepcode/baffledCitrus/07421beb3b859db53669e8d0208ce27f81ecaec0/re2c/lessons/001_upn_calculator/windows/TestRe2c.ncb -------------------------------------------------------------------------------- /re2c/lessons/001_upn_calculator/windows/TestRe2c.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 7.00 2 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestRe2c", "TestRe2c.vcproj", "{BEC086F1-62CD-4BA7-8E17-367B825FA721}" 3 | EndProject 4 | Global 5 | GlobalSection(SolutionConfiguration) = preSolution 6 | ConfigName.0 = Debug 7 | ConfigName.1 = Release 8 | EndGlobalSection 9 | GlobalSection(ProjectDependencies) = postSolution 10 | EndGlobalSection 11 | GlobalSection(ProjectConfiguration) = postSolution 12 | {BEC086F1-62CD-4BA7-8E17-367B825FA721}.Debug.ActiveCfg = Debug|Win32 13 | {BEC086F1-62CD-4BA7-8E17-367B825FA721}.Debug.Build.0 = Debug|Win32 14 | {BEC086F1-62CD-4BA7-8E17-367B825FA721}.Release.ActiveCfg = Release|Win32 15 | {BEC086F1-62CD-4BA7-8E17-367B825FA721}.Release.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(ExtensibilityGlobals) = postSolution 18 | EndGlobalSection 19 | GlobalSection(ExtensibilityAddIns) = postSolution 20 | EndGlobalSection 21 | EndGlobal 22 | -------------------------------------------------------------------------------- /re2c/lessons/001_upn_calculator/windows/TestRe2c.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stepcode/baffledCitrus/07421beb3b859db53669e8d0208ce27f81ecaec0/re2c/lessons/001_upn_calculator/windows/TestRe2c.suo -------------------------------------------------------------------------------- /re2c/lessons/002_strip_comments/readme.txt: -------------------------------------------------------------------------------- 1 | re2c lesson 002_strip_comments, (c) M. Boerger 2006 2 | 3 | In this lesson you will learn how to use multiple scanner blocks and how to 4 | read the input from a file instead of a zero terminated string. In the end you 5 | will have a scanner that filters comments out of c source files but keeps re2c 6 | comments. 7 | 8 | The first scanner can be generated with: 9 | 10 | re2c -s -o t.c strip_001.s.re 11 | 12 | In the second step we will learn about YYMARKER that stores backtracking 13 | information. 14 | 15 | re2c -s -0 t.c strip_002.b.re 16 | 17 | The third step brings trailing contexts that are stored in YYCTXMARKER. We also 18 | change to use -b instead of -s option since the scanner gets more and more 19 | complex. 20 | 21 | re2c -b -0 t.c strip_002.b.re 22 | -------------------------------------------------------------------------------- /re2c/lessons/readme.txt: -------------------------------------------------------------------------------- 1 | re2c lessons, (c) M. Boerger 2006 2 | 3 | 001_upn_calculator 4 | 5 | This lesson gets you started with re2c. In the end you will have an easy 6 | RPN calculator for use at command line. 7 | 8 | You will learn about the basic interface of re2c when scanning input 9 | strings. How to detect the end of the input and use that to stop scanning 10 | in order to avoid problems. 11 | 12 | The lesson also contains a windows subdirectory to get you started in the 13 | Microsoft world. 14 | 15 | 002_strip_comments 16 | 17 | In this lesson you will learn how to use multiple scanner blocks and how 18 | to read the input from a file instead of a zero terminated string. In the 19 | end you will have a scanner that filters comments out of c source files 20 | but keeps re2c comments. 21 | -------------------------------------------------------------------------------- /re2c/mbo_getopt.h: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Marcus Boerger 3 | */ 4 | 5 | /* $Id: mbo_getopt.h 539 2006-05-25 13:37:38Z helly $ */ 6 | 7 | /* Define structure for one recognized option (both single char and long name). 8 | * If short_open is '-' this is the last option. 9 | */ 10 | 11 | #ifndef RE2C_MBO_GETOPT_H_INCLUDE_GUARD_ 12 | #define RE2C_MBO_GETOPT_H_INCLUDE_GUARD_ 13 | 14 | namespace re2c 15 | { 16 | 17 | struct mbo_opt_struct 18 | { 19 | mbo_opt_struct(char _opt_char, int _need_param, const char * _opt_name) 20 | : opt_char(_opt_char), need_param(_need_param), opt_name(_opt_name) 21 | { 22 | } 23 | 24 | const char opt_char; 25 | const int need_param; 26 | const char * opt_name; 27 | }; 28 | 29 | int mbo_getopt(int argc, char* const *argv, const mbo_opt_struct *opts, char **optarg, int *optind, int show_err); 30 | 31 | } // end namespace re2c 32 | 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /re2c/re2c.spec.in: -------------------------------------------------------------------------------- 1 | Summary: A tool for generating C-based recognizers from regular expressions 2 | Name: @PACKAGE_NAME@ 3 | Version: @PACKAGE_VERSION@ 4 | Release: @PACKAGE_RELEASE@ 5 | License: Public Domain 6 | Group: Development/Tools 7 | URL: http://re2c.org/ 8 | Source0: http://prdownloads.sourceforge.net/re2c/re2c-%{version}.tar.gz 9 | BuildRoot: %{_tmppath}/%{name}-%{version}-root 10 | 11 | %description 12 | re2c is a great tool for writing fast and flexible lexers. It has 13 | served many people well for many years and it deserves to be 14 | maintained more actively. re2c is on the order of 2-3 times faster 15 | than a flex based scanner, and its input model is much more 16 | flexible. 17 | 18 | %prep 19 | 20 | %setup -q 21 | 22 | %build 23 | ./configure \ 24 | --prefix=%{_prefix} 25 | make re2c 26 | #regenerate file scanner.cc 27 | rm -f scanner.cc 28 | ./re2c -b scanner.re > scanner.cc 29 | rm -f re2c scanner.o 30 | make 31 | 32 | %install 33 | rm -rf $RPM_BUILD_ROOT 34 | mkdir -p $RPM_BUILD_ROOT%{_bindir} 35 | install -m 0755 re2c $RPM_BUILD_ROOT%{_bindir} 36 | 37 | mkdir -p $RPM_BUILD_ROOT%{_mandir}/man1 38 | install -m 0755 re2c.1 $RPM_BUILD_ROOT%{_mandir}/man1 39 | 40 | %clean 41 | rm -rf $RPM_BUILD_ROOT 42 | 43 | %changelog 44 | * Sun Jan 04 2003 Marcus Boerger 45 | - Initial version. 46 | 47 | %files 48 | %defattr(-,root,root) 49 | %{_bindir}/re2c 50 | %{_mandir}/man1/re2c.1* 51 | 52 | %doc README examples doc/* lessons 53 | -------------------------------------------------------------------------------- /re2c/re2c_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef _parser_symbol_h 2 | #define _parser_symbol_h 3 | 4 | #include "scanner.h" 5 | #include "re.h" 6 | #include 7 | 8 | namespace re2c 9 | { 10 | 11 | class Symbol 12 | { 13 | public: 14 | 15 | RegExp* re; 16 | 17 | static Symbol *find(const SubStr&); 18 | static void ClearTable(); 19 | 20 | typedef std::map SymbolTable; 21 | 22 | const Str& GetName() const 23 | { 24 | return name; 25 | } 26 | 27 | protected: 28 | 29 | Symbol(const SubStr& str) 30 | : re(NULL) 31 | , name(str) 32 | { 33 | } 34 | 35 | private: 36 | 37 | static SymbolTable symbol_table; 38 | 39 | Str name; 40 | 41 | #if defined(PEDANTIC) && (PEDANTIC>0) 42 | Symbol(const Symbol& oth) 43 | : re(oth.re) 44 | , name(oth.name) 45 | { 46 | } 47 | Symbol& operator = (const Symbol& oth) 48 | { 49 | new(this) Symbol(oth); 50 | return *this; 51 | } 52 | #endif 53 | }; 54 | 55 | extern void parse(Scanner&, std::ostream&, std::ostream*); 56 | extern void parse_cleanup(); 57 | 58 | } // end namespace re2c 59 | 60 | union YYSTYPE { 61 | re2c::Symbol *symbol; 62 | re2c::RegExp *regexp; 63 | re2c::Token *token; 64 | char op; 65 | int number; 66 | re2c::ExtOp extop; 67 | re2c::Str *str; 68 | re2c::CondList *clist; 69 | }; 70 | 71 | void *ParseAlloc(void *(*mallocProc)(size_t)); 72 | void Parse(void *parser, int tokenID, YYSTYPE value); 73 | void ParseFree(void *parser, void (*freeProc)(void*)); 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /re2c/substr.cc: -------------------------------------------------------------------------------- 1 | /* $Id: substr.cc 860 2008-04-09 22:57:45Z nuno-lopes $ */ 2 | #include 3 | #include 4 | #include "substr.h" 5 | #include "globals.h" 6 | 7 | #ifndef HAVE_STRNDUP 8 | 9 | char *strndup(const char *str, size_t len) 10 | { 11 | char * ret = (char*)malloc(len + 1); 12 | 13 | memcpy(ret, str, len); 14 | ret[len] = '\0'; 15 | return ret; 16 | } 17 | 18 | #endif 19 | 20 | namespace re2c 21 | { 22 | 23 | void SubStr::out(std::ostream& o) const 24 | { 25 | o.write(str, len); 26 | } 27 | 28 | bool operator==(const SubStr &s1, const SubStr &s2) 29 | { 30 | return (bool) (s1.len == s2.len && memcmp(s1.str, s2.str, s1.len) == 0); 31 | } 32 | 33 | Str::Str(const SubStr& s) 34 | : SubStr(strndup(s.str, s.len), s.len) 35 | { 36 | ; 37 | } 38 | 39 | Str::Str(Str& s) 40 | : SubStr(s.str, s.len) 41 | { 42 | s.str = NULL; 43 | s.len = 0; 44 | } 45 | 46 | Str::Str(const char *s) 47 | : SubStr(strdup(s), strlen(s)) 48 | { 49 | ; 50 | } 51 | 52 | Str::Str() 53 | : SubStr((char*) NULL, 0) 54 | { 55 | ; 56 | } 57 | 58 | 59 | Str::~Str() 60 | { 61 | if (str) { 62 | free((void*)str); 63 | } 64 | str = NULL; 65 | len = 0; 66 | } 67 | 68 | } // end namespace re2c 69 | -------------------------------------------------------------------------------- /re2c/substr.h: -------------------------------------------------------------------------------- 1 | /* $Id: substr.h 860 2008-04-09 22:57:45Z nuno-lopes $ */ 2 | #ifndef _substr_h 3 | #define _substr_h 4 | 5 | #include 6 | #include 7 | #include "basics.h" 8 | 9 | namespace re2c 10 | { 11 | 12 | class SubStr 13 | { 14 | public: 15 | const char * str; 16 | const char * const org; 17 | uint len; 18 | 19 | public: 20 | friend bool operator==(const SubStr &, const SubStr &); 21 | SubStr(const uchar*, uint); 22 | SubStr(const char*, uint); 23 | SubStr(const char*); 24 | SubStr(const SubStr&); 25 | virtual ~SubStr(); 26 | void out(std::ostream&) const; 27 | std::string to_string() const; 28 | uint ofs() const; 29 | 30 | #ifdef PEDANTIC 31 | protected: 32 | SubStr& operator = (const SubStr& oth); 33 | #endif 34 | }; 35 | 36 | class Str: public SubStr 37 | { 38 | public: 39 | Str(const SubStr&); 40 | Str(Str&); 41 | Str(const char*); 42 | Str(); 43 | ~Str(); 44 | }; 45 | 46 | inline std::ostream& operator<<(std::ostream& o, const SubStr &s) 47 | { 48 | s.out(o); 49 | return o; 50 | } 51 | 52 | inline std::ostream& operator<<(std::ostream& o, const SubStr* s) 53 | { 54 | return o << *s; 55 | } 56 | 57 | inline SubStr::SubStr(const uchar *s, uint l) 58 | : str((char*)s), org((char*)s), len(l) 59 | { } 60 | 61 | inline SubStr::SubStr(const char *s, uint l) 62 | : str(s), org(s), len(l) 63 | { } 64 | 65 | inline SubStr::SubStr(const char *s) 66 | : str(s), org(s), len(strlen(s)) 67 | { } 68 | 69 | inline SubStr::SubStr(const SubStr &s) 70 | : str(s.str), org(s.str), len(s.len) 71 | { } 72 | 73 | inline SubStr::~SubStr() 74 | { } 75 | 76 | inline std::string SubStr::to_string() const 77 | { 78 | return str && len ? std::string(str, len) : std::string(); 79 | } 80 | 81 | inline uint SubStr::ofs() const 82 | { 83 | return str - org; 84 | } 85 | 86 | #ifdef PEDANTIC 87 | inline SubStr& SubStr::operator = (const SubStr& oth) 88 | { 89 | new(this) SubStr(oth); 90 | return *this; 91 | } 92 | #endif 93 | 94 | } // end namespace re2c 95 | 96 | #ifndef HAVE_STRNDUP 97 | 98 | char *strndup(const char *str, size_t len); 99 | 100 | #endif 101 | 102 | #if defined(_MSC_VER) && !defined(vsnprintf) 103 | #define vsnprintf _vsnprintf 104 | #endif 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /re2c/test/bug1054496.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define RET(n) printf("%d\n", n); return n 6 | #define TAG_EOI 0 7 | #define TAG_A 1 8 | #define TAG_TAG 2 9 | 10 | int scan(char *s, int l) 11 | { 12 | char *p = s; 13 | char *q; 14 | #define YYCTYPE char 15 | #define YYCURSOR p 16 | #define YYLIMIT (s+l) 17 | #define YYMARKER q 18 | #define YYFILL(n) 19 | cont: 20 | /*!re2c 21 | any = [\001-\377]; 22 | ' 2 | 3 | #define YYCTYPE unsigned char 4 | #define YYCURSOR cursor 5 | #define YYLIMIT cursor 6 | #define YYMARKER marker 7 | #define YYFILL(n) 8 | 9 | bool scan(const char *text) 10 | { 11 | YYCTYPE *start = (YYCTYPE *)text; 12 | YYCTYPE *cursor = (YYCTYPE *)text; 13 | YYCTYPE *marker = (YYCTYPE *)text; 14 | next: 15 | YYCTYPE *token = cursor; 16 | /*!re2c 17 | '(This file must be converted with BinHex 4.0)' 18 | { 19 | if (token == start || *(token - 1) == '\n') 20 | return true; else goto next; 21 | } 22 | [\001-\377] 23 | { goto next; } 24 | [\000] 25 | { return false; } 26 | */ 27 | return false; 28 | } 29 | 30 | #define do_scan(str, expect) \ 31 | res = scan(str) == expect ? 0 : 1; \ 32 | std::cerr << str << "\t-\t" << (res ? "fail" : "ok") << std::endl; \ 33 | result += res 34 | 35 | /*!max:re2c */ 36 | 37 | int main(int,void**) 38 | { 39 | int res, result = 0; 40 | do_scan("(This file must be converted with BinHex 4.0)", 1); 41 | do_scan("x(This file must be converted with BinHex 4.0)", 0); 42 | do_scan("(This file must be converted with BinHex 4.0)x", 1); 43 | do_scan("x(This file must be converted with BinHex 4.0)x", 0); 44 | 45 | return result; 46 | } 47 | -------------------------------------------------------------------------------- /re2c/test/bug1187785.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define RET(n) printf("%d\n", n); return n 6 | #define TAG_EOI 0 7 | #define TAG_A 1 8 | #define TAG_TAG 2 9 | 10 | int scan(char *s, int l) 11 | { 12 | char *p = s; 13 | char *q; 14 | #define YYCTYPE char 15 | #define YYCURSOR p 16 | #define YYLIMIT (s+l) 17 | #define YYMARKER q 18 | #define YYFILL(n) 19 | cont: 20 | /*!re2c 21 | any = [\000-\377]; 22 | (["] ([\000-\376]\["])+ ["]) { RET(1); } 23 | any { goto cont; } 24 | */ 25 | } 26 | 27 | #define do_scan(str) scan(str, strlen(str)) 28 | 29 | main() 30 | { 31 | do_scan("0"); 32 | } 33 | -------------------------------------------------------------------------------- /re2c/test/bug1297658.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct Scanner 6 | { 7 | Scanner(char *_inp) 8 | : inp(_inp), buf(NULL), ptr(NULL), len(0), siz(strlen(_inp)), line(0) 9 | { 10 | fill(0); 11 | cur = buf; 12 | } 13 | 14 | void fill(size_t n) 15 | { 16 | n++; 17 | buf = (char*)realloc(buf, len + n + 1); 18 | if ((len += n) > siz) 19 | { 20 | len = siz; 21 | } 22 | memcpy(buf, inp, len); 23 | buf[len] = '\0'; 24 | lim = buf + len; 25 | eof = buf + siz - 1; 26 | } 27 | 28 | char *inp; 29 | char *cur; 30 | char *buf; 31 | char *ptr; 32 | char *lim; 33 | char *eof; 34 | size_t len; 35 | size_t siz; 36 | size_t line; 37 | }; 38 | 39 | enum What 40 | { 41 | UNEXPECTED, 42 | FCON, 43 | EOI 44 | }; 45 | 46 | #define YYCTYPE char 47 | #define YYCURSOR s.cur 48 | #define YYLIMIT s.lim 49 | #define YYMARKER s.ptr 50 | #define YYFILL(n) s.fill(n) 51 | #define RET(n) return (n) 52 | 53 | int scan(Scanner &s) 54 | { 55 | std: 56 | 57 | /*!re2c 58 | 59 | ("0"* "." "e"? "L"?) | 60 | ("0"+ "." "e"? "L"?) 61 | { 62 | RET(FCON); 63 | } 64 | 65 | "\n" 66 | { 67 | s.line++; 68 | if(1||s.cur == s.eof) RET(EOI); 69 | goto std; 70 | } 71 | 72 | 73 | . 74 | { 75 | RET(UNEXPECTED); 76 | } 77 | */ 78 | } 79 | 80 | int main(int,char**) 81 | { 82 | Scanner s("\n0.eL\n00.eL\n"); 83 | 84 | std::cout << "RES(2): " << scan(s) << std::endl; 85 | std::cout << "RES(1): " << scan(s) << std::endl; 86 | std::cout << "RES(2): " << scan(s) << std::endl; 87 | std::cout << "RES(1): " << scan(s) << std::endl; 88 | std::cout << "RES(2): " << scan(s) << std::endl; 89 | std::cout << "RES(0): " << scan(s) << std::endl; 90 | } 91 | -------------------------------------------------------------------------------- /re2c/test/bug1390174.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "bug1390174.re" 3 | #include 4 | #include 5 | #include 6 | 7 | #define RET(n) return n 8 | 9 | int scan(const char *s, int l) { 10 | const char *p = s; 11 | const char *q; 12 | #define YYCTYPE char 13 | #define YYCURSOR p 14 | #define YYLIMIT (s+l) 15 | #define YYMARKER q 16 | #define YYFILL(n) 17 | 18 | #line 19 "" 19 | { 20 | YYCTYPE yych; 21 | 22 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 23 | yych = *YYCURSOR; 24 | switch (yych) { 25 | case '\n': goto yy4; 26 | case 'A': 27 | case 'a': goto yy2; 28 | default: goto yy6; 29 | } 30 | yy2: 31 | yych = *(YYMARKER = ++YYCURSOR); 32 | switch (yych) { 33 | case '\n': goto yy7; 34 | case 'A': 35 | case 'a': goto yy8; 36 | default: goto yy3; 37 | } 38 | yy3: 39 | #line 19 "bug1390174.re" 40 | {RET(0);} 41 | #line 42 "" 42 | yy4: 43 | ++YYCURSOR; 44 | yy5: 45 | #line 18 "bug1390174.re" 46 | {RET(1);} 47 | #line 48 "" 48 | yy6: 49 | yych = *++YYCURSOR; 50 | goto yy3; 51 | yy7: 52 | yych = *++YYCURSOR; 53 | goto yy5; 54 | yy8: 55 | ++YYCURSOR; 56 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 57 | yych = *YYCURSOR; 58 | switch (yych) { 59 | case '\n': goto yy7; 60 | case 'A': 61 | case 'a': goto yy8; 62 | default: goto yy10; 63 | } 64 | yy10: 65 | YYCURSOR = YYMARKER; 66 | goto yy3; 67 | } 68 | #line 20 "bug1390174.re" 69 | 70 | } 71 | 72 | void _do_scan(int exp, const char * str, int len) 73 | { 74 | int ret = scan(str, len); 75 | 76 | printf("%d %s %d\n", exp, exp == ret ? "==" : "!=", ret); 77 | } 78 | 79 | #define do_scan(exp, str) _do_scan(exp, str, sizeof(str) - 1) 80 | 81 | main() 82 | { 83 | do_scan(1, "a\n"); 84 | do_scan(1, "aa\n"); 85 | do_scan(1, "aaa\n"); 86 | do_scan(1, "aaaa\n"); 87 | do_scan(1, "\n"); 88 | 89 | do_scan(0, "q"); 90 | do_scan(0, "a"); 91 | } 92 | -------------------------------------------------------------------------------- /re2c/test/bug1390174.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define RET(n) return n 6 | 7 | int scan(const char *s, int l) { 8 | const char *p = s; 9 | const char *q; 10 | #define YYCTYPE char 11 | #define YYCURSOR p 12 | #define YYLIMIT (s+l) 13 | #define YYMARKER q 14 | #define YYFILL(n) 15 | /*!re2c 16 | any = [\000-\377]; 17 | 18 | 'a'{0,}"\n" {RET(1);} 19 | any {RET(0);} 20 | */ 21 | } 22 | 23 | void _do_scan(int exp, const char * str, int len) 24 | { 25 | int ret = scan(str, len); 26 | 27 | printf("%d %s %d\n", exp, exp == ret ? "==" : "!=", ret); 28 | } 29 | 30 | #define do_scan(exp, str) _do_scan(exp, str, sizeof(str) - 1) 31 | 32 | main() 33 | { 34 | do_scan(1, "a\n"); 35 | do_scan(1, "aa\n"); 36 | do_scan(1, "aaa\n"); 37 | do_scan(1, "aaaa\n"); 38 | do_scan(1, "\n"); 39 | 40 | do_scan(0, "q"); 41 | do_scan(0, "a"); 42 | } 43 | -------------------------------------------------------------------------------- /re2c/test/bug1454253.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define RET(n) return n 6 | 7 | size_t scan(const char *s, int l, char *r) 8 | { 9 | const char *p = s; 10 | const char *q; 11 | #define YYCTYPE char 12 | #define YYCURSOR p 13 | #define YYLIMIT (s+l) 14 | #define YYMARKER q 15 | #define YYFILL(n) 16 | 17 | while(1) 18 | { 19 | /*!re2c 20 | ALNUM = [0-9a-zA-Z]; 21 | ANY = [\001-\377]\"?"; 22 | EOF = '\000'; 23 | 24 | "?!" ALNUM* { 25 | *r++ = '1'; 26 | continue; 27 | } 28 | 29 | "?" ALNUM+ { 30 | *r++ = '2'; 31 | continue; 32 | } 33 | 34 | EOF { 35 | *r++ = '3'; 36 | *r++ = '\0'; 37 | return p - s; 38 | } 39 | 40 | ANY* { 41 | *r++ = '0'; 42 | *r++ = '\0'; 43 | return p - s; 44 | } 45 | */ 46 | } 47 | } 48 | 49 | void _do_scan(const char * str, size_t str_len, size_t scn_len, const char * exp, size_t exp_len) 50 | { 51 | char res[32], sp[32]; 52 | size_t res_len, inp_len; 53 | 54 | inp_len = scan(str, str_len, res); 55 | res_len = strlen(res); 56 | 57 | memset(sp, ' ', sizeof(sp)); 58 | sp[15 - str_len] = '\0'; 59 | 60 | printf("[%s](%2d/%2d)%s: %8s(%d) %s %8s(%d)\n", str, inp_len, scn_len, sp, 61 | res, res_len, 62 | inp_len != scn_len || exp_len != res_len || strncmp(exp, res, exp_len) ? "!=" : "==", 63 | exp, exp_len); 64 | } 65 | 66 | #define do_scan(str, scn_len, exp) _do_scan(str, sizeof(str) - 1, scn_len, exp, sizeof(exp) - 1) 67 | 68 | main() 69 | { 70 | do_scan("?1??", 2, "20"); 71 | do_scan("#", 1, "0"); 72 | do_scan("##", 2, "0"); 73 | do_scan("##?", 2, "0"); 74 | do_scan("##|", 3, "0"); 75 | do_scan("?!|", 3, "10"); 76 | do_scan("?!?1|", 5, "120"); 77 | do_scan("?!?a+", 5, "120"); 78 | do_scan("?2!1?2??", 4, "20"); 79 | do_scan("?1?2!1?2??", 6, "220"); 80 | do_scan("?1?2?!1?2??", 9, "22120"); 81 | do_scan("?1?2?!1?2?!", 12, "221213"); 82 | do_scan("?1?123?45??", 9, "2220"); 83 | do_scan("?1?123?45?!", 12, "22213"); 84 | } 85 | -------------------------------------------------------------------------------- /re2c/test/bug1454253.s.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define RET(n) return n 6 | 7 | size_t scan(const char *s, int l, char *r) 8 | { 9 | const char *p = s; 10 | const char *q; 11 | #define YYCTYPE char 12 | #define YYCURSOR p 13 | #define YYLIMIT (s+l) 14 | #define YYMARKER q 15 | #define YYFILL(n) 16 | 17 | while(1) 18 | { 19 | /*!re2c 20 | ALNUM = [0-9a-zA-Z]; 21 | ANY = [\001-\377]\"?"; 22 | EOF = '\000'; 23 | 24 | "?!" ALNUM* { 25 | *r++ = '1'; 26 | continue; 27 | } 28 | 29 | "?" ALNUM+ { 30 | *r++ = '2'; 31 | continue; 32 | } 33 | 34 | EOF { 35 | *r++ = '3'; 36 | *r++ = '\0'; 37 | return p - s; 38 | } 39 | 40 | ANY* { 41 | *r++ = '0'; 42 | *r++ = '\0'; 43 | return p - s; 44 | } 45 | */ 46 | } 47 | } 48 | 49 | void _do_scan(const char * str, size_t str_len, size_t scn_len, const char * exp, size_t exp_len) 50 | { 51 | char res[32], sp[32]; 52 | size_t res_len, inp_len; 53 | 54 | inp_len = scan(str, str_len, res); 55 | res_len = strlen(res); 56 | 57 | memset(sp, ' ', sizeof(sp)); 58 | sp[15 - str_len] = '\0'; 59 | 60 | printf("[%s](%2d/%2d)%s: %8s(%d) %s %8s(%d)\n", str, inp_len, scn_len, sp, 61 | res, res_len, 62 | inp_len != scn_len || exp_len != res_len || strncmp(exp, res, exp_len) ? "!=" : "==", 63 | exp, exp_len); 64 | } 65 | 66 | #define do_scan(str, scn_len, exp) _do_scan(str, sizeof(str) - 1, scn_len, exp, sizeof(exp) - 1) 67 | 68 | main() 69 | { 70 | do_scan("?1??", 2, "20"); 71 | do_scan("#", 1, "0"); 72 | do_scan("##", 2, "0"); 73 | do_scan("##?", 2, "0"); 74 | do_scan("##|", 3, "0"); 75 | do_scan("?!|", 3, "10"); 76 | do_scan("?!?1|", 5, "120"); 77 | do_scan("?!?a+", 5, "120"); 78 | do_scan("?2!1?2??", 4, "20"); 79 | do_scan("?1?2!1?2??", 6, "220"); 80 | do_scan("?1?2?!1?2??", 9, "22120"); 81 | do_scan("?1?2?!1?2?!", 12, "221213"); 82 | do_scan("?1?123?45??", 9, "2220"); 83 | do_scan("?1?123?45?!", 12, "22213"); 84 | } 85 | -------------------------------------------------------------------------------- /re2c/test/bug1454253b.s.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define RET(n) return n 6 | 7 | size_t scan(const char *s, int l, char *r) 8 | { 9 | const char *p = s; 10 | const char *q; 11 | #define YYCTYPE char 12 | #define YYCURSOR p 13 | #define YYLIMIT (s+l) 14 | #define YYMARKER q 15 | #define YYFILL(n) 16 | 17 | while(1) 18 | { 19 | /*!re2c 20 | ALNUM = [0-9a-zA-Z]; 21 | ANY = [\000-\377]; 22 | 23 | "?!" ALNUM* { 24 | *r++ = '1'; 25 | continue; 26 | } 27 | 28 | "?" ALNUM+ { 29 | *r++ = '2'; 30 | continue; 31 | } 32 | 33 | (ANY\"?") { 34 | *r++ = '0'; 35 | *r++ = '\0'; 36 | return p - s; 37 | } 38 | */ 39 | } 40 | } 41 | 42 | void _do_scan(const char * str, size_t str_len, size_t scn_len, const char * exp, size_t exp_len) 43 | { 44 | char res[32], sp[32]; 45 | size_t res_len, inp_len; 46 | 47 | inp_len = scan(str, str_len, res); 48 | res_len = strlen(res); 49 | 50 | memset(sp, ' ', sizeof(sp)); 51 | sp[15 - str_len] = '\0'; 52 | 53 | printf("[%s](%2d/%2d)%s: %8s(%d) %s %8s(%d)\n", str, inp_len, scn_len, sp, 54 | exp, exp_len, 55 | inp_len != scn_len || exp_len != res_len || strncmp(exp, res, exp_len) ? "!=" : "==", 56 | res, res_len); 57 | } 58 | 59 | #define do_scan(str, scn_len, exp) _do_scan(str, sizeof(str) - 1, scn_len, exp, sizeof(exp) - 1) 60 | 61 | main() 62 | { 63 | do_scan("?1??", 4, "20"); 64 | do_scan("#", 1, "0"); 65 | do_scan("##", 1, "0"); 66 | do_scan("##?", 1, "0"); 67 | do_scan("##|", 1, "0"); 68 | do_scan("?!|", 3, "10"); 69 | do_scan("?!?1|", 5, "120"); 70 | do_scan("?!?a+", 5, "120"); 71 | do_scan("?2!1?2??", 3, "20"); 72 | do_scan("?1?2!1?2??", 5, "220"); 73 | do_scan("?1?2?!1?2??", 11, "22120"); 74 | do_scan("?1?2?!1?2?!", 12, "221210"); 75 | do_scan("?1?123?45??", 11, "2220"); 76 | do_scan("?1?123?45?!", 12, "22210"); 77 | } 78 | -------------------------------------------------------------------------------- /re2c/test/bug1472770.b.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | #define YYCTYPE char 3 | #define YYCURSOR p 4 | #define YYLIMIT p 5 | #define YYMARKER q 6 | #define YYFILL(n) 7 | 8 | #include 9 | 10 | int scan(char *p) 11 | { 12 | int n = 0; 13 | char *q; 14 | 15 | printf("[--------------\n"); 16 | printf("%s\n", p); 17 | printf("]--------------\n"); 18 | start: 19 | /*!re2c 20 | [^\n\000]* '\n' 21 | { 22 | ++n; 23 | goto start; 24 | } 25 | [^\n\000]* '\000' 26 | { 27 | return n; 28 | } 29 | */ 30 | } 31 | 32 | int main(int argc, char **argv) 33 | { 34 | int n = 0; 35 | char *largv[4]; 36 | 37 | if (argc < 2) 38 | { 39 | argc = 4; 40 | argv = largv; 41 | argv[1] = ""; 42 | argv[2] = "1\n\n"; 43 | argv[3] = "1\n2\n"; 44 | } 45 | while(++n < argc) 46 | { 47 | printf("%d\n", scan(argv[n])); 48 | } 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /re2c/test/bug1472770.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "bug1472770.re" 3 | #define NULL ((char*) 0) 4 | #define YYCTYPE char 5 | #define YYCURSOR p 6 | #define YYLIMIT p 7 | #define YYMARKER q 8 | #define YYFILL(n) 9 | 10 | #include 11 | 12 | int scan(char *p) 13 | { 14 | int n = 0; 15 | char *q; 16 | 17 | printf("[--------------\n"); 18 | printf("%s\n", p); 19 | printf("]--------------\n"); 20 | start: 21 | 22 | #line 23 "" 23 | { 24 | YYCTYPE yych; 25 | goto yy0; 26 | yy1: 27 | ++YYCURSOR; 28 | yy0: 29 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 30 | yych = *YYCURSOR; 31 | switch (yych) { 32 | case 0x00: goto yy5; 33 | case '\n': goto yy3; 34 | default: goto yy1; 35 | } 36 | yy3: 37 | ++YYCURSOR; 38 | #line 21 "bug1472770.re" 39 | { 40 | ++n; 41 | goto start; 42 | } 43 | #line 44 "" 44 | yy5: 45 | ++YYCURSOR; 46 | #line 26 "bug1472770.re" 47 | { 48 | return n; 49 | } 50 | #line 51 "" 51 | } 52 | #line 29 "bug1472770.re" 53 | 54 | } 55 | 56 | int main(int argc, char **argv) 57 | { 58 | int n = 0; 59 | char *largv[4]; 60 | 61 | if (argc < 2) 62 | { 63 | argc = 4; 64 | argv = largv; 65 | argv[1] = ""; 66 | argv[2] = "1\n\n"; 67 | argv[3] = "1\n2\n"; 68 | } 69 | while(++n < argc) 70 | { 71 | printf("%d\n", scan(argv[n])); 72 | } 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /re2c/test/bug1472770.f.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "bug1472770.f.re" 3 | #define NULL ((char*) 0) 4 | #define YYCTYPE char 5 | #define YYCURSOR p 6 | #define YYLIMIT p 7 | #define YYMARKER q 8 | #define YYFILL(n) 9 | 10 | YYCTYPE yych; 11 | int yySavedState; 12 | 13 | #define YYGETSTATE() yySavedState 14 | #define YYSETSTATE(n) yySavedState = n; 15 | 16 | #include 17 | 18 | int scan(char *p) 19 | { 20 | int n = 0; 21 | char *q; 22 | 23 | printf("[--------------\n"); 24 | printf("%s\n", p); 25 | printf("]--------------\n"); 26 | start: 27 | 28 | #line 29 "" 29 | 30 | switch (YYGETSTATE()) { 31 | default: goto yy0; 32 | case 0: goto yyFillLabel0; 33 | } 34 | goto yy0; 35 | yy1: 36 | ++YYCURSOR; 37 | yy0: 38 | YYSETSTATE(0); 39 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 40 | yyFillLabel0: 41 | yych = *YYCURSOR; 42 | switch (yych) { 43 | case 0x00: goto yy5; 44 | case '\n': goto yy3; 45 | default: goto yy1; 46 | } 47 | yy3: 48 | ++YYCURSOR; 49 | #line 27 "bug1472770.f.re" 50 | { 51 | ++n; 52 | goto start; 53 | } 54 | #line 55 "" 55 | yy5: 56 | ++YYCURSOR; 57 | #line 32 "bug1472770.f.re" 58 | { 59 | return n; 60 | } 61 | #line 62 "" 62 | #line 35 "bug1472770.f.re" 63 | 64 | } 65 | 66 | int main(int argc, char **argv) 67 | { 68 | int n = 0; 69 | char *largv[4]; 70 | 71 | if (argc < 2) 72 | { 73 | argc = 4; 74 | argv = largv; 75 | argv[1] = ""; 76 | argv[2] = "1\n\n"; 77 | argv[3] = "1\n2\n"; 78 | } 79 | while(++n < argc) 80 | { 81 | printf("%d\n", scan(argv[n])); 82 | } 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /re2c/test/bug1472770.f.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | #define YYCTYPE char 3 | #define YYCURSOR p 4 | #define YYLIMIT p 5 | #define YYMARKER q 6 | #define YYFILL(n) 7 | 8 | YYCTYPE yych; 9 | int yySavedState; 10 | 11 | #define YYGETSTATE() yySavedState 12 | #define YYSETSTATE(n) yySavedState = n; 13 | 14 | #include 15 | 16 | int scan(char *p) 17 | { 18 | int n = 0; 19 | char *q; 20 | 21 | printf("[--------------\n"); 22 | printf("%s\n", p); 23 | printf("]--------------\n"); 24 | start: 25 | /*!re2c 26 | [^\n\000]* '\n' 27 | { 28 | ++n; 29 | goto start; 30 | } 31 | [^\n\000]* '\000' 32 | { 33 | return n; 34 | } 35 | */ 36 | } 37 | 38 | int main(int argc, char **argv) 39 | { 40 | int n = 0; 41 | char *largv[4]; 42 | 43 | if (argc < 2) 44 | { 45 | argc = 4; 46 | argv = largv; 47 | argv[1] = ""; 48 | argv[2] = "1\n\n"; 49 | argv[3] = "1\n2\n"; 50 | } 51 | while(++n < argc) 52 | { 53 | printf("%d\n", scan(argv[n])); 54 | } 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /re2c/test/bug1472770.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | #define YYCTYPE char 3 | #define YYCURSOR p 4 | #define YYLIMIT p 5 | #define YYMARKER q 6 | #define YYFILL(n) 7 | 8 | #include 9 | 10 | int scan(char *p) 11 | { 12 | int n = 0; 13 | char *q; 14 | 15 | printf("[--------------\n"); 16 | printf("%s\n", p); 17 | printf("]--------------\n"); 18 | start: 19 | /*!re2c 20 | [^\n\000]* '\n' 21 | { 22 | ++n; 23 | goto start; 24 | } 25 | [^\n\000]* '\000' 26 | { 27 | return n; 28 | } 29 | */ 30 | } 31 | 32 | int main(int argc, char **argv) 33 | { 34 | int n = 0; 35 | char *largv[4]; 36 | 37 | if (argc < 2) 38 | { 39 | argc = 4; 40 | argv = largv; 41 | argv[1] = ""; 42 | argv[2] = "1\n\n"; 43 | argv[3] = "1\n2\n"; 44 | } 45 | while(++n < argc) 46 | { 47 | printf("%d\n", scan(argv[n])); 48 | } 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /re2c/test/bug1472770.s.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "bug1472770.s.re" 3 | #define NULL ((char*) 0) 4 | #define YYCTYPE char 5 | #define YYCURSOR p 6 | #define YYLIMIT p 7 | #define YYMARKER q 8 | #define YYFILL(n) 9 | 10 | #include 11 | 12 | int scan(char *p) 13 | { 14 | int n = 0; 15 | char *q; 16 | 17 | printf("[--------------\n"); 18 | printf("%s\n", p); 19 | printf("]--------------\n"); 20 | start: 21 | 22 | #line 23 "" 23 | { 24 | YYCTYPE yych; 25 | goto yy0; 26 | yy1: 27 | ++YYCURSOR; 28 | yy0: 29 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 30 | yych = *YYCURSOR; 31 | if (yych <= 0x00) goto yy5; 32 | if (yych != '\n') goto yy1; 33 | ++YYCURSOR; 34 | #line 21 "bug1472770.s.re" 35 | { 36 | ++n; 37 | goto start; 38 | } 39 | #line 40 "" 40 | yy5: 41 | ++YYCURSOR; 42 | #line 26 "bug1472770.s.re" 43 | { 44 | return n; 45 | } 46 | #line 47 "" 47 | } 48 | #line 29 "bug1472770.s.re" 49 | 50 | } 51 | 52 | int main(int argc, char **argv) 53 | { 54 | int n = 0; 55 | char *largv[4]; 56 | 57 | if (argc < 2) 58 | { 59 | argc = 4; 60 | argv = largv; 61 | argv[1] = ""; 62 | argv[2] = "1\n\n"; 63 | argv[3] = "1\n2\n"; 64 | } 65 | while(++n < argc) 66 | { 67 | printf("%d\n", scan(argv[n])); 68 | } 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /re2c/test/bug1472770.s.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | #define YYCTYPE char 3 | #define YYCURSOR p 4 | #define YYLIMIT p 5 | #define YYMARKER q 6 | #define YYFILL(n) 7 | 8 | #include 9 | 10 | int scan(char *p) 11 | { 12 | int n = 0; 13 | char *q; 14 | 15 | printf("[--------------\n"); 16 | printf("%s\n", p); 17 | printf("]--------------\n"); 18 | start: 19 | /*!re2c 20 | [^\n\000]* '\n' 21 | { 22 | ++n; 23 | goto start; 24 | } 25 | [^\n\000]* '\000' 26 | { 27 | return n; 28 | } 29 | */ 30 | } 31 | 32 | int main(int argc, char **argv) 33 | { 34 | int n = 0; 35 | char *largv[4]; 36 | 37 | if (argc < 2) 38 | { 39 | argc = 4; 40 | argv = largv; 41 | argv[1] = ""; 42 | argv[2] = "1\n\n"; 43 | argv[3] = "1\n2\n"; 44 | } 45 | while(++n < argc) 46 | { 47 | printf("%d\n", scan(argv[n])); 48 | } 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /re2c/test/bug1479044.b.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | #define YYCTYPE char 3 | #define YYCURSOR p 4 | #define YYLIMIT p 5 | #define YYMARKER q 6 | #define YYFILL(n) 7 | 8 | #include 9 | 10 | char *scan281(char *p) 11 | { 12 | char *q; 13 | start: 14 | /*!re2c 15 | 16 | ( "adsl" | "adslppp" | "bdsl" | "cdsl" | "dslgw4pool" | "dslppp" | "edsl" | "fdsl" | "ldsl" | "pool" | "pppdsl" | "premiumC" | "vdsl" | "xsttldsl") [0-9a-k\-]+ ".".+ ".uswest.net" 17 | { 18 | return "dsl"; 19 | } 20 | 21 | ( "dhcp" | "dorms" | "rh" ).* "-" [0-9]+ "-" [0-9]+ "." .+ ".resnet.pitt.edu" 22 | { 23 | return "resnet"; 24 | } 25 | 26 | [0-9]+ "-" [0-9]+ "-" [0-9]+ "-" [0-9]+ "." ("dhcp" | .* "modem" | "bothell") .* ".washington.edu" 27 | { 28 | return "edu"; 29 | } 30 | 31 | [\001-\377] 32 | { 33 | goto start; 34 | } 35 | 36 | [\000] 37 | { 38 | return NULL; 39 | } 40 | */ 41 | } 42 | 43 | int main(int argc, char **argv) 44 | { 45 | int n = 0; 46 | char *largv[2]; 47 | 48 | if (argc < 2) 49 | { 50 | argc = 2; 51 | argv = largv; 52 | argv[1] = "D-128-208-46-51.dhcp4.washington.edu"; 53 | } 54 | while(++n < argc) 55 | { 56 | char *res = scan281(argv[n]); 57 | printf("%s\n", res ? res : ""); 58 | } 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /re2c/test/bug1479044.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | #define YYCTYPE char 3 | #define YYCURSOR p 4 | #define YYLIMIT p 5 | #define YYMARKER q 6 | #define YYFILL(n) 7 | 8 | #include 9 | 10 | char *scan281(char *p) 11 | { 12 | char *q; 13 | start: 14 | /*!re2c 15 | 16 | ( "adsl" | "adslppp" | "bdsl" | "cdsl" | "dslgw4pool" | "dslppp" | "edsl" | "fdsl" | "ldsl" | "pool" | "pppdsl" | "premiumC" | "vdsl" | "xsttldsl") [0-9a-k\-]+ ".".+ ".uswest.net" 17 | { 18 | return "dsl"; 19 | } 20 | 21 | ( "dhcp" | "dorms" | "rh" ).* "-" [0-9]+ "-" [0-9]+ "." .+ ".resnet.pitt.edu" 22 | { 23 | return "resnet"; 24 | } 25 | 26 | [0-9]+ "-" [0-9]+ "-" [0-9]+ "-" [0-9]+ "." ("dhcp" | .* "modem" | "bothell") .* ".washington.edu" 27 | { 28 | return "edu"; 29 | } 30 | 31 | [\001-\377] 32 | { 33 | goto start; 34 | } 35 | 36 | [\000] 37 | { 38 | return NULL; 39 | } 40 | */ 41 | } 42 | 43 | int main(int argc, char **argv) 44 | { 45 | int n = 0; 46 | char *largv[2]; 47 | 48 | if (argc < 2) 49 | { 50 | argc = 2; 51 | argv = largv; 52 | argv[1] = "D-128-208-46-51.dhcp4.washington.edu"; 53 | } 54 | while(++n < argc) 55 | { 56 | char *res = scan281(argv[n]); 57 | printf("%s\n", res ? res : ""); 58 | } 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /re2c/test/bug1479044.s.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | #define YYCTYPE char 3 | #define YYCURSOR p 4 | #define YYLIMIT p 5 | #define YYMARKER q 6 | #define YYFILL(n) 7 | 8 | #include 9 | 10 | char *scan281(char *p) 11 | { 12 | char *q; 13 | start: 14 | /*!re2c 15 | 16 | ( "adsl" | "adslppp" | "bdsl" | "cdsl" | "dslgw4pool" | "dslppp" | "edsl" | "fdsl" | "ldsl" | "pool" | "pppdsl" | "premiumC" | "vdsl" | "xsttldsl") [0-9a-k\-]+ ".".+ ".uswest.net" 17 | { 18 | return "dsl"; 19 | } 20 | 21 | ( "dhcp" | "dorms" | "rh" ).* "-" [0-9]+ "-" [0-9]+ "." .+ ".resnet.pitt.edu" 22 | { 23 | return "resnet"; 24 | } 25 | 26 | [0-9]+ "-" [0-9]+ "-" [0-9]+ "-" [0-9]+ "." ("dhcp" | .* "modem" | "bothell") .* ".washington.edu" 27 | { 28 | return "edu"; 29 | } 30 | 31 | [\001-\377] 32 | { 33 | goto start; 34 | } 35 | 36 | [\000] 37 | { 38 | return NULL; 39 | } 40 | */ 41 | } 42 | 43 | int main(int argc, char **argv) 44 | { 45 | int n = 0; 46 | char *largv[2]; 47 | 48 | if (argc < 2) 49 | { 50 | argc = 2; 51 | argv = largv; 52 | argv[1] = "D-128-208-46-51.dhcp4.washington.edu"; 53 | } 54 | while(++n < argc) 55 | { 56 | char *res = scan281(argv[n]); 57 | printf("%s\n", res ? res : ""); 58 | } 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /re2c/test/bug1528269.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stepcode/baffledCitrus/07421beb3b859db53669e8d0208ce27f81ecaec0/re2c/test/bug1528269.c -------------------------------------------------------------------------------- /re2c/test/bug1528269.re: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stepcode/baffledCitrus/07421beb3b859db53669e8d0208ce27f81ecaec0/re2c/test/bug1528269.re -------------------------------------------------------------------------------- /re2c/test/bug1529351.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 3, column 9: missing '}' 2 | -------------------------------------------------------------------------------- /re2c/test/bug1529351.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | "foo" { func(); { func(); } 4 | */ 5 | -------------------------------------------------------------------------------- /re2c/test/bug1682718.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "bug1682718.re" 3 | char *scan(char *p) 4 | { 5 | 6 | #line 7 "" 7 | { 8 | unsigned char yych; 9 | 10 | yych = (unsigned char)*p; 11 | switch (yych) { 12 | case '0': 13 | case '1': 14 | case '2': 15 | case '3': 16 | case '4': 17 | case '5': 18 | case '6': 19 | case '7': 20 | case '8': 21 | case '9': goto yy2; 22 | default: goto yy4; 23 | } 24 | yy2: 25 | ++p; 26 | yych = (unsigned char)*p; 27 | goto yy7; 28 | yy3: 29 | #line 9 "bug1682718.re" 30 | {return p;} 31 | #line 32 "" 32 | yy4: 33 | ++p; 34 | #line 10 "bug1682718.re" 35 | {return (char*)0;} 36 | #line 37 "" 37 | yy6: 38 | ++p; 39 | yych = (unsigned char)*p; 40 | yy7: 41 | switch (yych) { 42 | case '0': 43 | case '1': 44 | case '2': 45 | case '3': 46 | case '4': 47 | case '5': 48 | case '6': 49 | case '7': 50 | case '8': 51 | case '9': goto yy6; 52 | default: goto yy3; 53 | } 54 | } 55 | #line 11 "bug1682718.re" 56 | 57 | } 58 | 59 | -------------------------------------------------------------------------------- /re2c/test/bug1682718.is.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | char *scan(char *p) 3 | { 4 | 5 | { 6 | unsigned char yych; 7 | 8 | yych = (unsigned char)*p; 9 | if (yych <= '/') goto yy4; 10 | if (yych >= ':') goto yy4; 11 | ++p; 12 | yych = (unsigned char)*p; 13 | goto yy7; 14 | yy3: 15 | {return p;} 16 | yy4: 17 | ++p; 18 | {return (char*)0;} 19 | yy6: 20 | ++p; 21 | yych = (unsigned char)*p; 22 | yy7: 23 | if (yych <= '/') goto yy3; 24 | if (yych <= '9') goto yy6; 25 | goto yy3; 26 | } 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /re2c/test/bug1682718.is.re: -------------------------------------------------------------------------------- 1 | char *scan(char *p) 2 | { 3 | /*!re2c 4 | re2c:define:YYCTYPE = "unsigned char"; 5 | re2c:define:YYCURSOR = p; 6 | re2c:yyfill:enable = 0; 7 | re2c:yych:conversion = 1; 8 | re2c:indent:top = 1; 9 | [0-9]+ {return p;} 10 | [\000-\377] {return (char*)0;} 11 | */ 12 | } 13 | 14 | -------------------------------------------------------------------------------- /re2c/test/bug1682718.re: -------------------------------------------------------------------------------- 1 | char *scan(char *p) 2 | { 3 | /*!re2c 4 | re2c:define:YYCTYPE = "unsigned char"; 5 | re2c:define:YYCURSOR = p; 6 | re2c:yyfill:enable = 0; 7 | re2c:yych:conversion = 1; 8 | re2c:indent:top = 1; 9 | [0-9]+ {return p;} 10 | [\000-\377] {return (char*)0;} 11 | */ 12 | } 13 | 14 | -------------------------------------------------------------------------------- /re2c/test/bug1711240.eis.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | char scan(const unsigned char *s) 3 | { 4 | 5 | { 6 | YYCTYPE yych; 7 | 8 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 9 | yych = *YYCURSOR; 10 | if (yych <= '=') { 11 | if (yych == 0x07) goto yy5; 12 | goto yy7; 13 | } else { 14 | if (yych <= '"') goto yy3; 15 | if (yych <= 0xFF) goto yy7; 16 | } 17 | yy3: 18 | ++YYCURSOR; 19 | { 20 | return '"'; 21 | } 22 | yy5: 23 | ++YYCURSOR; 24 | { 25 | return '\x2F'; 26 | } 27 | yy7: 28 | ++YYCURSOR; 29 | { 30 | return '\0'; 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /re2c/test/bug1711240.eis.re: -------------------------------------------------------------------------------- 1 | char scan(const unsigned char *s) 2 | { 3 | /*!re2c 4 | '"' 5 | { 6 | return '"'; 7 | } 8 | '\x2F' 9 | { 10 | return '\x2F'; 11 | } 12 | '\x7F' 13 | { 14 | return '\x7F'; 15 | } 16 | [^] 17 | { 18 | return '\0'; 19 | } 20 | */ 21 | } 22 | -------------------------------------------------------------------------------- /re2c/test/casing-flags.i--case-insensitive.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | 3 | { 4 | YYCTYPE yych; 5 | 6 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 7 | yych = *YYCURSOR; 8 | switch (yych) { 9 | case 'A': 10 | case 'a': goto yy3; 11 | case 'B': 12 | case 'b': goto yy5; 13 | default: goto yy2; 14 | } 15 | yy2: 16 | yy3: 17 | ++YYCURSOR; 18 | {return 'a';} 19 | yy5: 20 | ++YYCURSOR; 21 | {return 'b';} 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /re2c/test/casing-flags.i--case-insensitive.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | "a" {return 'a';} 3 | 'b' {return 'b';} 4 | */ 5 | } 6 | -------------------------------------------------------------------------------- /re2c/test/casing-flags.i--case-inverted.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | 3 | { 4 | YYCTYPE yych; 5 | 6 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 7 | yych = *YYCURSOR; 8 | switch (yych) { 9 | case 'A': 10 | case 'a': goto yy3; 11 | case 'b': goto yy5; 12 | default: goto yy2; 13 | } 14 | yy2: 15 | yy3: 16 | ++YYCURSOR; 17 | {return 'a';} 18 | yy5: 19 | ++YYCURSOR; 20 | {return 'b';} 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /re2c/test/casing-flags.i--case-inverted.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | "a" {return 'a';} 3 | 'b' {return 'b';} 4 | */ 5 | } 6 | -------------------------------------------------------------------------------- /re2c/test/casing-flags.i.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | 3 | { 4 | YYCTYPE yych; 5 | 6 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 7 | yych = *YYCURSOR; 8 | switch (yych) { 9 | case 'B': 10 | case 'b': goto yy5; 11 | case 'a': goto yy3; 12 | default: goto yy2; 13 | } 14 | yy2: 15 | yy3: 16 | ++YYCURSOR; 17 | {return 'a';} 18 | yy5: 19 | ++YYCURSOR; 20 | {return 'b';} 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /re2c/test/casing-flags.i.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | "a" {return 'a';} 3 | 'b' {return 'b';} 4 | */ 5 | } 6 | -------------------------------------------------------------------------------- /re2c/test/cond_error_00.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 3, column 10: conditions are only allowed when using -c switch 2 | -------------------------------------------------------------------------------- /re2c/test/cond_error_00.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | "a" { } 4 | "b" { } 5 | 6 | */ 7 | -------------------------------------------------------------------------------- /re2c/test/cond_error_01.c.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 3, column 2: unnamed condition not supported 2 | -------------------------------------------------------------------------------- /re2c/test/cond_error_01.c.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | <> "a" { } 4 | 5 | */ 6 | -------------------------------------------------------------------------------- /re2c/test/cond_error_02.c.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 3, column 4: unnamed condition not supported 2 | -------------------------------------------------------------------------------- /re2c/test/cond_error_02.c.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | < > "a" { } 4 | 5 | */ 6 | -------------------------------------------------------------------------------- /re2c/test/cond_error_03.c.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 3, column 5: no expression specified 2 | -------------------------------------------------------------------------------- /re2c/test/cond_error_03.c.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | { } 4 | 5 | */ 6 | -------------------------------------------------------------------------------- /re2c/test/cond_error_04.c.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 3, column 2: unnamed condition not supported 2 | -------------------------------------------------------------------------------- /re2c/test/cond_error_04.c.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | <,> "a" { } 4 | 5 | */ 6 | -------------------------------------------------------------------------------- /re2c/test/cond_error_05.c.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 3, column 2: unnamed condition not supported 2 | -------------------------------------------------------------------------------- /re2c/test/cond_error_05.c.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | <+> "a" { } 4 | 5 | */ 6 | -------------------------------------------------------------------------------- /re2c/test/cond_error_06.c.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 3, column 2: unnamed condition not supported 2 | -------------------------------------------------------------------------------- /re2c/test/cond_error_06.c.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | "a" { } 4 | 5 | */ 6 | -------------------------------------------------------------------------------- /re2c/test/cond_error_07.c.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 3, column 4: syntax error 2 | -------------------------------------------------------------------------------- /re2c/test/cond_error_07.c.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | "a" { } 4 | 5 | */ 6 | -------------------------------------------------------------------------------- /re2c/test/cond_error_08.c.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 4, column 4: code to handle illegal condition already defined 2 | -------------------------------------------------------------------------------- /re2c/test/cond_error_08.c.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | <> { return 1; } 4 | <> { return 2; } 5 | 6 | */ 7 | -------------------------------------------------------------------------------- /re2c/test/cond_error_09.c.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 6, column 6: code to setup rule 'a' is already defined 2 | -------------------------------------------------------------------------------- /re2c/test/cond_error_09.c.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | "a" { return 1; } 4 | "b" { return 2; } 5 | { printf("foo"); } 6 | := printf("bar"); 7 | 8 | */ 9 | -------------------------------------------------------------------------------- /re2c/test/cond_error_10.c.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 6, column 1: setup for non existing rule 'c' found 2 | -------------------------------------------------------------------------------- /re2c/test/cond_error_10.c.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | "a" { return 1; } 4 | "b" { return 2; } 5 | { printf("foo"); } 6 | := printf("bar"); 7 | 8 | */ 9 | -------------------------------------------------------------------------------- /re2c/test/cond_error_11.c.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 7, column 1: setup for all rules with '*' not possible when all rules are setup explicitly 2 | -------------------------------------------------------------------------------- /re2c/test/cond_error_11.c.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | "a" { return 1; } 4 | "b" { return 2; } 5 | { printf("foo"); } 6 | := printf("bar"); 7 | := printf("baz"); 8 | 9 | */ 10 | -------------------------------------------------------------------------------- /re2c/test/condition_01.c.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "condition_01.c.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | switch (YYGETCONDITION()) { 8 | case yyca: goto yyc_a; 9 | case yycb: goto yyc_b; 10 | } 11 | /* *********************************** */ 12 | yyc_a: 13 | 14 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 15 | yych = *YYCURSOR; 16 | switch (yych) { 17 | case 'a': goto yy3; 18 | default: goto yy2; 19 | } 20 | yy2: 21 | yy3: 22 | yych = *++YYCURSOR; 23 | switch (yych) { 24 | case 'b': goto yy4; 25 | default: goto yy2; 26 | } 27 | yy4: 28 | ++YYCURSOR; 29 | #line 3 "condition_01.c.re" 30 | { } 31 | #line 32 "" 32 | /* *********************************** */ 33 | yyc_b: 34 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 35 | yych = *YYCURSOR; 36 | switch (yych) { 37 | case 'a': goto yy9; 38 | default: goto yy8; 39 | } 40 | yy8: 41 | yy9: 42 | yych = *++YYCURSOR; 43 | switch (yych) { 44 | case 'b': goto yy10; 45 | default: goto yy8; 46 | } 47 | yy10: 48 | ++YYCURSOR; 49 | #line 3 "condition_01.c.re" 50 | { } 51 | #line 52 "" 52 | } 53 | #line 5 "condition_01.c.re" 54 | 55 | -------------------------------------------------------------------------------- /re2c/test/condition_01.c.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | < a , b > "ab" { } 4 | 5 | */ 6 | -------------------------------------------------------------------------------- /re2c/test/condition_01a.c.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "condition_01a.c.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | switch (YYGETCONDITION()) { 8 | case yyca: goto yyc_a; 9 | case yycb: goto yyc_b; 10 | } 11 | /**** State a ***/ 12 | yyc_a: 13 | 14 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 15 | yych = *YYCURSOR; 16 | switch (yych) { 17 | case 'a': goto yy3; 18 | default: goto yy2; 19 | } 20 | yy2: 21 | yy3: 22 | yych = *++YYCURSOR; 23 | switch (yych) { 24 | case 'b': goto yy4; 25 | default: goto yy2; 26 | } 27 | yy4: 28 | ++YYCURSOR; 29 | #line 3 "condition_01a.c.re" 30 | { } 31 | #line 32 "" 32 | /**** State b ***/ 33 | yyc_b: 34 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 35 | yych = *YYCURSOR; 36 | switch (yych) { 37 | case 'a': goto yy9; 38 | default: goto yy8; 39 | } 40 | yy8: 41 | yy9: 42 | yych = *++YYCURSOR; 43 | switch (yych) { 44 | case 'b': goto yy10; 45 | default: goto yy8; 46 | } 47 | yy10: 48 | ++YYCURSOR; 49 | #line 3 "condition_01a.c.re" 50 | { } 51 | #line 52 "" 52 | } 53 | #line 5 "condition_01a.c.re" 54 | 55 | -------------------------------------------------------------------------------- /re2c/test/condition_01a.c.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | re2c:cond:divider = "/**** State @@ ***\/"; 3 | < a , b > "ab" { } 4 | 5 | */ 6 | -------------------------------------------------------------------------------- /re2c/test/condition_01b.c.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "condition_01b.c.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | switch (YYGETCONDITION()) { 8 | case yyca: goto yyc_a; 9 | case yycb: goto yyc_b; 10 | } 11 | yyc_a: 12 | 13 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 14 | yych = *YYCURSOR; 15 | switch (yych) { 16 | case 'a': goto yy3; 17 | default: goto yy2; 18 | } 19 | yy2: 20 | yy3: 21 | yych = *++YYCURSOR; 22 | switch (yych) { 23 | case 'b': goto yy4; 24 | default: goto yy2; 25 | } 26 | yy4: 27 | ++YYCURSOR; 28 | #line 3 "condition_01b.c.re" 29 | { } 30 | #line 31 "" 31 | yyc_b: 32 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 33 | yych = *YYCURSOR; 34 | switch (yych) { 35 | case 'a': goto yy9; 36 | default: goto yy8; 37 | } 38 | yy8: 39 | yy9: 40 | yych = *++YYCURSOR; 41 | switch (yych) { 42 | case 'b': goto yy10; 43 | default: goto yy8; 44 | } 45 | yy10: 46 | ++YYCURSOR; 47 | #line 3 "condition_01b.c.re" 48 | { } 49 | #line 50 "" 50 | } 51 | #line 5 "condition_01b.c.re" 52 | 53 | -------------------------------------------------------------------------------- /re2c/test/condition_01b.c.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | re2c:cond:divider = ; 3 | < a , b > "ab" { } 4 | 5 | */ 6 | -------------------------------------------------------------------------------- /re2c/test/condition_02.c.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "condition_02.c.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | switch (YYGETCONDITION()) { 8 | case yyc0: goto yyc_0; 9 | case yycr1: goto yyc_r1; 10 | case yycr2: goto yyc_r2; 11 | } 12 | /* *********************************** */ 13 | yyc_0: 14 | 15 | #line 3 "condition_02.c.re" 16 | { return NULL; } 17 | #line 18 "" 18 | /* *********************************** */ 19 | yyc_r1: 20 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 21 | yych = *YYCURSOR; 22 | switch (yych) { 23 | case 'a': goto yy6; 24 | case 'b': goto yy8; 25 | default: goto yy5; 26 | } 27 | yy5: 28 | yy6: 29 | ++YYCURSOR; 30 | #line 4 "condition_02.c.re" 31 | { return "a"; } 32 | #line 33 "" 33 | yy8: 34 | ++YYCURSOR; 35 | #line 5 "condition_02.c.re" 36 | { return "b"; } 37 | #line 38 "" 38 | /* *********************************** */ 39 | yyc_r2: 40 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 41 | yych = *YYCURSOR; 42 | switch (yych) { 43 | case 'b': goto yy13; 44 | default: goto yy12; 45 | } 46 | yy12: 47 | yy13: 48 | ++YYCURSOR; 49 | #line 5 "condition_02.c.re" 50 | { return "b"; } 51 | #line 52 "" 52 | } 53 | #line 7 "condition_02.c.re" 54 | 55 | -------------------------------------------------------------------------------- /re2c/test/condition_02.c.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | <> { return NULL; } 4 | "a" { return "a"; } 5 | "b" { return "b"; } 6 | 7 | */ 8 | -------------------------------------------------------------------------------- /re2c/test/condition_02.cg.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "condition_02.cg.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | static void *yyctable[3] = { 8 | &&yyc_0, 9 | &&yyc_r1, 10 | &&yyc_r2, 11 | }; 12 | goto *yyctable[YYGETCONDITION()]; 13 | /* *********************************** */ 14 | yyc_0: 15 | 16 | #line 3 "condition_02.cg.re" 17 | { return NULL; } 18 | #line 19 "" 19 | /* *********************************** */ 20 | yyc_r1: 21 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 22 | yych = *YYCURSOR; 23 | if (yych <= '`') goto yy5; 24 | if (yych <= 'a') goto yy6; 25 | if (yych <= 'b') goto yy8; 26 | yy5: 27 | yy6: 28 | ++YYCURSOR; 29 | #line 4 "condition_02.cg.re" 30 | { return "a"; } 31 | #line 32 "" 32 | yy8: 33 | ++YYCURSOR; 34 | #line 5 "condition_02.cg.re" 35 | { return "b"; } 36 | #line 37 "" 37 | /* *********************************** */ 38 | yyc_r2: 39 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 40 | yych = *YYCURSOR; 41 | if (yych == 'b') goto yy13; 42 | yy13: 43 | ++YYCURSOR; 44 | #line 5 "condition_02.cg.re" 45 | { return "b"; } 46 | #line 47 "" 47 | } 48 | #line 7 "condition_02.cg.re" 49 | 50 | -------------------------------------------------------------------------------- /re2c/test/condition_02.cg.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | <> { return NULL; } 4 | "a" { return "a"; } 5 | "b" { return "b"; } 6 | 7 | */ 8 | -------------------------------------------------------------------------------- /re2c/test/condition_03.cg.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "condition_03.cg.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | static void *yyctable[3] = { 8 | &&yyc_0, 9 | &&yyc_r1, 10 | &&yyc_r2, 11 | }; 12 | goto *yyctable[YYGETCONDITION()]; 13 | /* *********************************** */ 14 | yyc_0: 15 | 16 | #line 3 "condition_03.cg.re" 17 | { return NULL; } 18 | #line 19 "" 19 | /* *********************************** */ 20 | yyc_r1: 21 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 22 | yych = *YYCURSOR; 23 | if (yych <= '2') { 24 | if (yych <= '0') goto yy5; 25 | if (yych <= '1') goto yy8; 26 | goto yy6; 27 | } else { 28 | if (yych <= '`') goto yy5; 29 | if (yych <= 'a') goto yy10; 30 | if (yych <= 'b') goto yy12; 31 | } 32 | yy5: 33 | yy6: 34 | ++YYCURSOR; 35 | #line 5 "condition_03.cg.re" 36 | { return "2"; } 37 | #line 38 "" 38 | yy8: 39 | ++YYCURSOR; 40 | #line 4 "condition_03.cg.re" 41 | { return "1"; } 42 | #line 43 "" 43 | yy10: 44 | ++YYCURSOR; 45 | #line 6 "condition_03.cg.re" 46 | { return "a"; } 47 | #line 48 "" 48 | yy12: 49 | ++YYCURSOR; 50 | #line 7 "condition_03.cg.re" 51 | { return "b"; } 52 | #line 53 "" 53 | /* *********************************** */ 54 | yyc_r2: 55 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 56 | yych = *YYCURSOR; 57 | if (yych <= '2') { 58 | if (yych <= '0') goto yy16; 59 | if (yych <= '1') goto yy19; 60 | goto yy17; 61 | } else { 62 | if (yych == 'b') goto yy21; 63 | } 64 | yy16: 65 | yy17: 66 | ++YYCURSOR; 67 | #line 5 "condition_03.cg.re" 68 | { return "2"; } 69 | #line 70 "" 70 | yy19: 71 | ++YYCURSOR; 72 | #line 4 "condition_03.cg.re" 73 | { return "1"; } 74 | #line 75 "" 75 | yy21: 76 | ++YYCURSOR; 77 | #line 7 "condition_03.cg.re" 78 | { return "b"; } 79 | #line 80 "" 80 | } 81 | #line 9 "condition_03.cg.re" 82 | 83 | -------------------------------------------------------------------------------- /re2c/test/condition_03.cg.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | <> { return NULL; } 4 | <*> "1" { return "1"; } 5 | <*> "2" { return "2"; } 6 | "a" { return "a"; } 7 | "b" { return "b"; } 8 | 9 | */ 10 | -------------------------------------------------------------------------------- /re2c/test/condition_04.cg.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "condition_04.cg.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | static void *yyctable[2] = { 8 | &&yyc_r1, 9 | &&yyc_r2, 10 | }; 11 | goto *yyctable[YYGETCONDITION()]; 12 | /* *********************************** */ 13 | yyc_r1: 14 | 15 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 16 | yych = *YYCURSOR; 17 | if (yych <= '2') { 18 | if (yych <= '0') goto yy2; 19 | if (yych <= '1') goto yy5; 20 | goto yy3; 21 | } else { 22 | if (yych <= '`') goto yy2; 23 | if (yych <= 'a') goto yy7; 24 | if (yych <= 'b') goto yy9; 25 | } 26 | yy2: 27 | yy3: 28 | ++YYCURSOR; 29 | #line 4 "condition_04.cg.re" 30 | { return "2"; } 31 | #line 32 "" 32 | yy5: 33 | ++YYCURSOR; 34 | #line 3 "condition_04.cg.re" 35 | { return "1"; } 36 | #line 37 "" 37 | yy7: 38 | ++YYCURSOR; 39 | #line 5 "condition_04.cg.re" 40 | { return "a"; } 41 | #line 42 "" 42 | yy9: 43 | ++YYCURSOR; 44 | #line 6 "condition_04.cg.re" 45 | { return "b"; } 46 | #line 47 "" 47 | /* *********************************** */ 48 | yyc_r2: 49 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 50 | yych = *YYCURSOR; 51 | if (yych <= '2') { 52 | if (yych <= '0') goto yy13; 53 | if (yych <= '1') goto yy16; 54 | goto yy14; 55 | } else { 56 | if (yych == 'b') goto yy18; 57 | } 58 | yy13: 59 | yy14: 60 | ++YYCURSOR; 61 | #line 4 "condition_04.cg.re" 62 | { return "2"; } 63 | #line 64 "" 64 | yy16: 65 | ++YYCURSOR; 66 | #line 3 "condition_04.cg.re" 67 | { return "1"; } 68 | #line 69 "" 69 | yy18: 70 | ++YYCURSOR; 71 | #line 6 "condition_04.cg.re" 72 | { return "b"; } 73 | #line 74 "" 74 | } 75 | #line 8 "condition_04.cg.re" 76 | 77 | -------------------------------------------------------------------------------- /re2c/test/condition_04.cg.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | <*> "1" { return "1"; } 4 | <*> "2" { return "2"; } 5 | "a" { return "a"; } 6 | "b" { return "b"; } 7 | 8 | */ 9 | -------------------------------------------------------------------------------- /re2c/test/condition_05.cg.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define BSIZE 8192 6 | 7 | typedef struct Scanner 8 | { 9 | FILE *fp; 10 | unsigned char *cur, *tok, *lim, *eof; 11 | unsigned char buffer[BSIZE]; 12 | } Scanner; 13 | 14 | int fill(Scanner *s, int len) 15 | { 16 | if (!len) 17 | { 18 | s->cur = s->tok = s->lim = s->buffer; 19 | s->eof = 0; 20 | } 21 | if (!s->eof) 22 | { 23 | int got, cnt = s->tok - s->buffer; 24 | 25 | if (cnt > 0) 26 | { 27 | memcpy(s->buffer, s->tok, s->lim - s->tok); 28 | s->tok -= cnt; 29 | s->cur -= cnt; 30 | s->lim -= cnt; 31 | } 32 | cnt = BSIZE - cnt; 33 | if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt) 34 | { 35 | s->eof = &s->lim[got]; 36 | } 37 | s->lim += got; 38 | } 39 | else if (s->cur + len > s->eof) 40 | { 41 | return 0; /* not enough input data */ 42 | } 43 | return -1; 44 | } 45 | 46 | char scan(Scanner *s) 47 | { 48 | int cond = 1; 49 | 50 | fill(s, 0); 51 | 52 | for(;;) 53 | { 54 | s->tok = s->cur; 55 | /*!re2c 56 | 57 | re2c:define:YYCTYPE = "unsigned char"; 58 | re2c:define:YYCURSOR = s->cur; 59 | re2c:define:YYLIMIT = s->lim; 60 | re2c:define:YYMARKER = s->ptr; 61 | re2c:define:YYFILL@len = #; 62 | re2c:define:YYFILL:naked= 1; 63 | re2c:define:YYFILL = "{ if(fill(s, #) >= 0) break; }"; 64 | re2c:define:YYGETCONDITION = cond; 65 | re2c:define:YYGETCONDITION:naked = 1; 66 | re2c:yyfill:parameter = 0; 67 | re2c:indent:top = 2; 68 | 69 | "/*" 70 | { 71 | goto yyc_comment; 72 | } 73 | [^] 74 | { 75 | fputc(*s->tok, stdout); 76 | continue; 77 | } 78 | "*" "/" 79 | { 80 | continue; 81 | } 82 | [^] 83 | { 84 | goto yyc_comment; 85 | } 86 | 87 | */ 88 | } 89 | } 90 | 91 | int main(int argc, char **argv) 92 | { 93 | Scanner in; 94 | char c; 95 | 96 | if (argc != 2) 97 | { 98 | fprintf(stderr, "%s \n", argv[0]); 99 | return 1;; 100 | } 101 | 102 | memset((char*) &in, 0, sizeof(in)); 103 | 104 | if (!strcmp(argv[1], "-")) 105 | { 106 | in.fp = stdin; 107 | } 108 | else if ((in.fp = fopen(argv[1], "r")) == NULL) 109 | { 110 | fprintf(stderr, "Cannot open file '%s'\n", argv[1]); 111 | return 1; 112 | } 113 | 114 | scan(&in); 115 | 116 | if (in.fp != stdin) 117 | { 118 | fclose(in.fp); 119 | } 120 | return 0; 121 | } 122 | -------------------------------------------------------------------------------- /re2c/test/condition_05.cgitcondition_05.cgit.h.h: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | 3 | enum YYCONDTYPE { 4 | yycnormal, 5 | yyccomment, 6 | }; 7 | -------------------------------------------------------------------------------- /re2c/test/condition_05.cgitcondition_05.cgit.h.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define BSIZE 8192 6 | 7 | typedef struct Scanner 8 | { 9 | FILE *fp; 10 | unsigned char *cur, *tok, *lim, *eof; 11 | unsigned char buffer[BSIZE]; 12 | } Scanner; 13 | 14 | int fill(Scanner *s, int len) 15 | { 16 | if (!len) 17 | { 18 | s->cur = s->tok = s->lim = s->buffer; 19 | s->eof = 0; 20 | } 21 | if (!s->eof) 22 | { 23 | int got, cnt = s->tok - s->buffer; 24 | 25 | if (cnt > 0) 26 | { 27 | memcpy(s->buffer, s->tok, s->lim - s->tok); 28 | s->tok -= cnt; 29 | s->cur -= cnt; 30 | s->lim -= cnt; 31 | } 32 | cnt = BSIZE - cnt; 33 | if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt) 34 | { 35 | s->eof = &s->lim[got]; 36 | } 37 | s->lim += got; 38 | } 39 | else if (s->cur + len > s->eof) 40 | { 41 | return 0; /* not enough input data */ 42 | } 43 | return -1; 44 | } 45 | 46 | char scan(Scanner *s) 47 | { 48 | int cond = 1; 49 | 50 | fill(s, 0); 51 | 52 | for(;;) 53 | { 54 | s->tok = s->cur; 55 | /*!re2c 56 | 57 | re2c:define:YYCTYPE = "unsigned char"; 58 | re2c:define:YYCURSOR = s->cur; 59 | re2c:define:YYLIMIT = s->lim; 60 | re2c:define:YYMARKER = s->ptr; 61 | re2c:define:YYFILL@len = #; 62 | re2c:define:YYFILL:naked= 1; 63 | re2c:define:YYFILL = "{ if(fill(s, #) >= 0) break; }"; 64 | re2c:define:YYGETCONDITION = cond; 65 | re2c:define:YYGETCONDITION:naked = 1; 66 | re2c:yyfill:parameter = 0; 67 | re2c:indent:top = 2; 68 | 69 | "/*" 70 | { 71 | goto yyc_comment; 72 | } 73 | [^] 74 | { 75 | fputc(*s->tok, stdout); 76 | continue; 77 | } 78 | "*" "/" 79 | { 80 | continue; 81 | } 82 | [^] 83 | { 84 | goto yyc_comment; 85 | } 86 | 87 | */ 88 | } 89 | } 90 | 91 | int main(int argc, char **argv) 92 | { 93 | Scanner in; 94 | char c; 95 | 96 | if (argc != 2) 97 | { 98 | fprintf(stderr, "%s \n", argv[0]); 99 | return 1;; 100 | } 101 | 102 | memset((char*) &in, 0, sizeof(in)); 103 | 104 | if (!strcmp(argv[1], "-")) 105 | { 106 | in.fp = stdin; 107 | } 108 | else if ((in.fp = fopen(argv[1], "r")) == NULL) 109 | { 110 | fprintf(stderr, "Cannot open file '%s'\n", argv[1]); 111 | return 1; 112 | } 113 | 114 | scan(&in); 115 | 116 | if (in.fp != stdin) 117 | { 118 | fclose(in.fp); 119 | } 120 | return 0; 121 | } 122 | -------------------------------------------------------------------------------- /re2c/test/condition_05.cgtcondition_05.cgt.h.h: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 3 "condition_05.cgt.h" 3 | 4 | enum YYCONDTYPE { 5 | yycnormal, 6 | yyccomment, 7 | }; 8 | -------------------------------------------------------------------------------- /re2c/test/condition_05.cgtcondition_05.cgt.h.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define BSIZE 8192 6 | 7 | typedef struct Scanner 8 | { 9 | FILE *fp; 10 | unsigned char *cur, *tok, *lim, *eof; 11 | unsigned char buffer[BSIZE]; 12 | } Scanner; 13 | 14 | int fill(Scanner *s, int len) 15 | { 16 | if (!len) 17 | { 18 | s->cur = s->tok = s->lim = s->buffer; 19 | s->eof = 0; 20 | } 21 | if (!s->eof) 22 | { 23 | int got, cnt = s->tok - s->buffer; 24 | 25 | if (cnt > 0) 26 | { 27 | memcpy(s->buffer, s->tok, s->lim - s->tok); 28 | s->tok -= cnt; 29 | s->cur -= cnt; 30 | s->lim -= cnt; 31 | } 32 | cnt = BSIZE - cnt; 33 | if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt) 34 | { 35 | s->eof = &s->lim[got]; 36 | } 37 | s->lim += got; 38 | } 39 | else if (s->cur + len > s->eof) 40 | { 41 | return 0; /* not enough input data */ 42 | } 43 | return -1; 44 | } 45 | 46 | char scan(Scanner *s) 47 | { 48 | int cond = 1; 49 | 50 | fill(s, 0); 51 | 52 | for(;;) 53 | { 54 | s->tok = s->cur; 55 | /*!re2c 56 | 57 | re2c:define:YYCTYPE = "unsigned char"; 58 | re2c:define:YYCURSOR = s->cur; 59 | re2c:define:YYLIMIT = s->lim; 60 | re2c:define:YYMARKER = s->ptr; 61 | re2c:define:YYFILL@len = #; 62 | re2c:define:YYFILL:naked= 1; 63 | re2c:define:YYFILL = "{ if(fill(s, #) >= 0) break; }"; 64 | re2c:define:YYGETCONDITION = cond; 65 | re2c:define:YYGETCONDITION:naked = 1; 66 | re2c:yyfill:parameter = 0; 67 | re2c:indent:top = 2; 68 | 69 | "/*" 70 | { 71 | goto yyc_comment; 72 | } 73 | [^] 74 | { 75 | fputc(*s->tok, stdout); 76 | continue; 77 | } 78 | "*" "/" 79 | { 80 | continue; 81 | } 82 | [^] 83 | { 84 | goto yyc_comment; 85 | } 86 | 87 | */ 88 | } 89 | } 90 | 91 | int main(int argc, char **argv) 92 | { 93 | Scanner in; 94 | char c; 95 | 96 | if (argc != 2) 97 | { 98 | fprintf(stderr, "%s \n", argv[0]); 99 | return 1;; 100 | } 101 | 102 | memset((char*) &in, 0, sizeof(in)); 103 | 104 | if (!strcmp(argv[1], "-")) 105 | { 106 | in.fp = stdin; 107 | } 108 | else if ((in.fp = fopen(argv[1], "r")) == NULL) 109 | { 110 | fprintf(stderr, "Cannot open file '%s'\n", argv[1]); 111 | return 1; 112 | } 113 | 114 | scan(&in); 115 | 116 | if (in.fp != stdin) 117 | { 118 | fclose(in.fp); 119 | } 120 | return 0; 121 | } 122 | -------------------------------------------------------------------------------- /re2c/test/condition_05.cs.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define BSIZE 8192 6 | 7 | typedef struct Scanner 8 | { 9 | FILE *fp; 10 | unsigned char *cur, *tok, *lim, *eof; 11 | unsigned char buffer[BSIZE]; 12 | } Scanner; 13 | 14 | int fill(Scanner *s, int len) 15 | { 16 | if (!len) 17 | { 18 | s->cur = s->tok = s->lim = s->buffer; 19 | s->eof = 0; 20 | } 21 | if (!s->eof) 22 | { 23 | int got, cnt = s->tok - s->buffer; 24 | 25 | if (cnt > 0) 26 | { 27 | memcpy(s->buffer, s->tok, s->lim - s->tok); 28 | s->tok -= cnt; 29 | s->cur -= cnt; 30 | s->lim -= cnt; 31 | } 32 | cnt = BSIZE - cnt; 33 | if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt) 34 | { 35 | s->eof = &s->lim[got]; 36 | } 37 | s->lim += got; 38 | } 39 | else if (s->cur + len > s->eof) 40 | { 41 | return 0; /* not enough input data */ 42 | } 43 | return -1; 44 | } 45 | 46 | char scan(Scanner *s) 47 | { 48 | int cond = 1; 49 | 50 | fill(s, 0); 51 | 52 | for(;;) 53 | { 54 | s->tok = s->cur; 55 | /*!re2c 56 | 57 | re2c:define:YYCTYPE = "unsigned char"; 58 | re2c:define:YYCURSOR = s->cur; 59 | re2c:define:YYLIMIT = s->lim; 60 | re2c:define:YYMARKER = s->ptr; 61 | re2c:define:YYFILL@len = #; 62 | re2c:define:YYFILL:naked= 1; 63 | re2c:define:YYFILL = "{ if(fill(s, #) >= 0) break; }"; 64 | re2c:define:YYGETCONDITION = cond; 65 | re2c:define:YYGETCONDITION:naked = 1; 66 | re2c:yyfill:parameter = 0; 67 | re2c:indent:top = 2; 68 | 69 | "/*" 70 | { 71 | goto yyc_comment; 72 | } 73 | [^] 74 | { 75 | fputc(*s->tok, stdout); 76 | continue; 77 | } 78 | "*" "/" 79 | { 80 | continue; 81 | } 82 | [^] 83 | { 84 | goto yyc_comment; 85 | } 86 | 87 | */ 88 | } 89 | } 90 | 91 | int main(int argc, char **argv) 92 | { 93 | Scanner in; 94 | char c; 95 | 96 | if (argc != 2) 97 | { 98 | fprintf(stderr, "%s \n", argv[0]); 99 | return 1;; 100 | } 101 | 102 | memset((char*) &in, 0, sizeof(in)); 103 | 104 | if (!strcmp(argv[1], "-")) 105 | { 106 | in.fp = stdin; 107 | } 108 | else if ((in.fp = fopen(argv[1], "r")) == NULL) 109 | { 110 | fprintf(stderr, "Cannot open file '%s'\n", argv[1]); 111 | return 1; 112 | } 113 | 114 | scan(&in); 115 | 116 | if (in.fp != stdin) 117 | { 118 | fclose(in.fp); 119 | } 120 | return 0; 121 | } 122 | -------------------------------------------------------------------------------- /re2c/test/condition_07.cbi.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define BSIZE 8192 6 | 7 | typedef struct Scanner 8 | { 9 | FILE *fp; 10 | unsigned char *cur, *tok, *lim, *eof; 11 | unsigned char buffer[BSIZE]; 12 | } Scanner; 13 | 14 | int fill(Scanner *s, int len) 15 | { 16 | if (!len) 17 | { 18 | s->cur = s->tok = s->lim = s->buffer; 19 | s->eof = 0; 20 | } 21 | if (!s->eof) 22 | { 23 | int got, cnt = s->tok - s->buffer; 24 | 25 | if (cnt > 0) 26 | { 27 | memcpy(s->buffer, s->tok, s->lim - s->tok); 28 | s->tok -= cnt; 29 | s->cur -= cnt; 30 | s->lim -= cnt; 31 | } 32 | cnt = BSIZE - cnt; 33 | if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt) 34 | { 35 | s->eof = &s->lim[got]; 36 | } 37 | s->lim += got; 38 | } 39 | else if (s->cur + len > s->eof) 40 | { 41 | return 0; /* not enough input data */ 42 | } 43 | return -1; 44 | } 45 | 46 | void fputl(const char *s, size_t len, FILE *stream) 47 | { 48 | while(len-- > 0) 49 | { 50 | fputc(*s++, stream); 51 | } 52 | } 53 | 54 | /*!types:re2c */ 55 | 56 | void scan(Scanner *s) 57 | { 58 | int cond = EStateR1; 59 | 60 | fill(s, 0); 61 | 62 | for(;;) 63 | { 64 | s->tok = s->cur; 65 | /*!re2c 66 | 67 | re2c:define:YYCTYPE = "unsigned char"; 68 | re2c:define:YYCURSOR = s->cur; 69 | re2c:define:YYLIMIT = s->lim; 70 | re2c:define:YYMARKER = s->tok; 71 | re2c:define:YYFILL@len = #; 72 | re2c:define:YYFILL:naked= 1; 73 | re2c:define:YYFILL = "{ if(fill(s, #) >= 0) break; }"; 74 | re2c:define:YYGETCONDITION = cond; 75 | re2c:define:YYGETCONDITION:naked = 1; 76 | re2c:yyfill:parameter = 0; 77 | re2c:indent:top = 2; 78 | re2c:condenumprefix = EState; 79 | 80 | NUM = [0-9]; 81 | ALNUM = NUM|[a-zA-Z]; 82 | ANY = [^]; 83 | 84 | ALNUM+ 85 | { 86 | continue; 87 | } 88 | ANY 89 | { 90 | continue; 91 | } 92 | 93 | ALNUM+ 94 | { 95 | continue; 96 | } 97 | ANY 98 | { 99 | continue; 100 | } 101 | */ 102 | } 103 | } 104 | 105 | int main(int argc, char **argv) 106 | { 107 | Scanner in; 108 | char c; 109 | 110 | if (argc != 2) 111 | { 112 | fprintf(stderr, "%s \n", argv[0]); 113 | return 1;; 114 | } 115 | 116 | memset((char*) &in, 0, sizeof(in)); 117 | 118 | if (!strcmp(argv[1], "-")) 119 | { 120 | in.fp = stdin; 121 | } 122 | else if ((in.fp = fopen(argv[1], "r")) == NULL) 123 | { 124 | fprintf(stderr, "Cannot open file '%s'\n", argv[1]); 125 | return 1; 126 | } 127 | 128 | scan(&in); 129 | 130 | if (in.fp != stdin) 131 | { 132 | fclose(in.fp); 133 | } 134 | return 0; 135 | } 136 | -------------------------------------------------------------------------------- /re2c/test/condition_11.cg.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "condition_11.cg.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | static void *yyctable[3] = { 8 | &&yyc_0, 9 | &&yyc_r1, 10 | &&yyc_r2, 11 | }; 12 | goto *yyctable[YYGETCONDITION()]; 13 | /* *********************************** */ 14 | yyc_0: 15 | 16 | YYSETCONDITION(yycr1); 17 | #line 3 "condition_11.cg.re" 18 | { return NULL; } 19 | #line 20 "" 20 | /* *********************************** */ 21 | yyc_r1: 22 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 23 | yych = *YYCURSOR; 24 | if (yych <= '2') { 25 | if (yych <= '0') goto yy5; 26 | if (yych <= '1') goto yy8; 27 | goto yy6; 28 | } else { 29 | if (yych <= '`') goto yy5; 30 | if (yych <= 'a') goto yy10; 31 | if (yych <= 'b') goto yy12; 32 | } 33 | yy5: 34 | yy6: 35 | ++YYCURSOR; 36 | #line 5 "condition_11.cg.re" 37 | { return "2"; } 38 | #line 39 "" 39 | yy8: 40 | ++YYCURSOR; 41 | #line 4 "condition_11.cg.re" 42 | { return "1"; } 43 | #line 44 "" 44 | yy10: 45 | ++YYCURSOR; 46 | YYSETCONDITION(yycr2); 47 | #line 6 "condition_11.cg.re" 48 | { return "a"; } 49 | #line 50 "" 50 | yy12: 51 | ++YYCURSOR; 52 | YYSETCONDITION(yycr2); 53 | #line 7 "condition_11.cg.re" 54 | { return "b"; } 55 | #line 56 "" 56 | /* *********************************** */ 57 | yyc_r2: 58 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 59 | yych = *YYCURSOR; 60 | if (yych <= '2') { 61 | if (yych <= '0') goto yy16; 62 | if (yych <= '1') goto yy19; 63 | goto yy17; 64 | } else { 65 | if (yych == 'b') goto yy21; 66 | } 67 | yy16: 68 | yy17: 69 | ++YYCURSOR; 70 | YYSETCONDITION(yycr1); 71 | #line 5 "condition_11.cg.re" 72 | { return "2"; } 73 | #line 74 "" 74 | yy19: 75 | ++YYCURSOR; 76 | YYSETCONDITION(yycr1); 77 | #line 4 "condition_11.cg.re" 78 | { return "1"; } 79 | #line 80 "" 80 | yy21: 81 | ++YYCURSOR; 82 | #line 7 "condition_11.cg.re" 83 | { return "b"; } 84 | #line 85 "" 85 | } 86 | #line 9 "condition_11.cg.re" 87 | 88 | -------------------------------------------------------------------------------- /re2c/test/condition_11.cg.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | <> => r1 { return NULL; } 4 | <*> "1" => r1 { return "1"; } 5 | <*> "2" => r1 { return "2"; } 6 | "a" => r2 { return "a"; } 7 | "b" => r2 { return "b"; } 8 | 9 | */ 10 | -------------------------------------------------------------------------------- /re2c/test/condition_13.cg.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "condition_13.cg.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | static void *yyctable[3] = { 8 | &&yyc_0, 9 | &&yyc_r1, 10 | &&yyc_r2, 11 | }; 12 | goto *yyctable[YYGETCONDITION()]; 13 | /* *********************************** */ 14 | yyc_0: 15 | 16 | YYSETCONDITION(yycr1); 17 | #line 3 "condition_13.cg.re" 18 | goto yyc_r1; 19 | #line 20 "" 20 | /* *********************************** */ 21 | yyc_r1: 22 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 23 | yych = *YYCURSOR; 24 | if (yych <= '2') { 25 | if (yych <= '0') goto yy5; 26 | if (yych <= '1') goto yy8; 27 | goto yy6; 28 | } else { 29 | if (yych <= '`') goto yy5; 30 | if (yych <= 'a') goto yy10; 31 | if (yych <= 'b') goto yy12; 32 | } 33 | yy5: 34 | yy6: 35 | ++YYCURSOR; 36 | #line 5 "condition_13.cg.re" 37 | goto yyc_r1; 38 | #line 39 "" 39 | yy8: 40 | ++YYCURSOR; 41 | #line 4 "condition_13.cg.re" 42 | goto yyc_r1; 43 | #line 44 "" 44 | yy10: 45 | ++YYCURSOR; 46 | YYSETCONDITION(yycr2); 47 | #line 6 "condition_13.cg.re" 48 | goto yyc_r2; 49 | #line 50 "" 50 | yy12: 51 | ++YYCURSOR; 52 | YYSETCONDITION(yycr2); 53 | #line 7 "condition_13.cg.re" 54 | goto yyc_r2; 55 | #line 56 "" 56 | /* *********************************** */ 57 | yyc_r2: 58 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 59 | yych = *YYCURSOR; 60 | if (yych <= '2') { 61 | if (yych <= '0') goto yy16; 62 | if (yych <= '1') goto yy19; 63 | goto yy17; 64 | } else { 65 | if (yych == 'b') goto yy21; 66 | } 67 | yy16: 68 | yy17: 69 | ++YYCURSOR; 70 | YYSETCONDITION(yycr1); 71 | #line 5 "condition_13.cg.re" 72 | goto yyc_r1; 73 | #line 74 "" 74 | yy19: 75 | ++YYCURSOR; 76 | YYSETCONDITION(yycr1); 77 | #line 4 "condition_13.cg.re" 78 | goto yyc_r1; 79 | #line 80 "" 80 | yy21: 81 | ++YYCURSOR; 82 | #line 7 "condition_13.cg.re" 83 | goto yyc_r2; 84 | #line 85 "" 85 | } 86 | #line 9 "condition_13.cg.re" 87 | 88 | -------------------------------------------------------------------------------- /re2c/test/condition_13.cg.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | <> :=> r1 4 | <*> "1" :=> r1 5 | <*> "2" :=> r1 6 | "a" :=> r2 7 | "b" :=> r2 8 | 9 | */ 10 | -------------------------------------------------------------------------------- /re2c/test/config1.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | #define YYCTYPE char 3 | #define YYCURSOR p 4 | #define YYLIMIT p 5 | #define YYMARKER q 6 | #define YYFILL(n) 7 | 8 | char *scan0(char *p) 9 | { 10 | char *q; 11 | /*!re2c 12 | re2c:indent:top = 0; 13 | [0-9]+ { return YYCURSOR; } 14 | [\000-\377] { return NULL; } 15 | */ 16 | } 17 | 18 | char *scan1(char *p) 19 | { 20 | char *q; 21 | /*!re2c 22 | re2c:indent:top = 1; 23 | [0-9]+ { return YYCURSOR; } 24 | [\000-\377] { return NULL; } 25 | */ 26 | } 27 | 28 | char *scan(char *p) 29 | { 30 | char *q; 31 | /*!re2c 32 | [0-9]+ { return YYCURSOR; } 33 | [\000-\377] { return NULL; } 34 | */ 35 | } 36 | -------------------------------------------------------------------------------- /re2c/test/config10.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct Scanner 5 | { 6 | Scanner(char *txt) 7 | : cur(txt), lim(txt + strlen(txt)) 8 | { 9 | } 10 | 11 | char *cur; 12 | char *lim; 13 | char *ptr; 14 | char *ctx; 15 | char *tok; 16 | }; 17 | 18 | enum What 19 | { 20 | UNEXPECTED, 21 | KEYWORD, 22 | NUMBER, 23 | EOI 24 | }; 25 | 26 | char * tokens[] = { "UNEXPECTED", "KEYWORD", "NUMBER", "EOI" }; 27 | 28 | void fill() 29 | { 30 | } 31 | 32 | int scan(Scanner &s) 33 | { 34 | char *cursor = s.cur; 35 | 36 | if(cursor == s.lim) 37 | return EOI; 38 | 39 | std: 40 | s.tok = cursor; 41 | 42 | /*!re2c 43 | 44 | re2c:define:YYCTYPE = char; 45 | re2c:define:YYCURSOR = s.cur; 46 | re2c:define:YYLIMIT = s.lim; 47 | re2c:define:YYMARKER = s.ptr; 48 | re2c:define:YYCTXMARKER = s.ctx; 49 | re2c:define:YYFILL = "fill()"; 50 | 51 | re2c:yyfill:parameter = 0; 52 | re2c:variable:yych = curr; 53 | re2c:labelprefix = xx; 54 | 55 | ("a"|"b")/[1] { return KEYWORD; } 56 | ("a"|"b")/[0-9]+ { return KEYWORD; } 57 | [0-9]+ { return NUMBER; } 58 | 59 | [ \t\n] 60 | { 61 | if(s.cur == s.lim) 62 | return EOI; 63 | cursor = s.cur; 64 | goto std; 65 | } 66 | . 67 | { 68 | return UNEXPECTED; 69 | } 70 | */ 71 | } 72 | 73 | int main(int,char**) 74 | { 75 | Scanner s("a77 a1 b8 b1"); 76 | 77 | int t, n = 0; 78 | while ((t = scan(s)) != EOI) 79 | { 80 | std::cout << (++n) << ": " << tokens[t] << " = \""; std::cout.write(s.tok, s.cur-s.tok); std::cout << "\"" << std::endl; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /re2c/test/config2.s.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | #define YYCTYPE char 3 | #define YYCURSOR p 4 | #define YYLIMIT p 5 | #define YYMARKER q 6 | #define YYFILL(n) 7 | 8 | char *scan0(char *p) 9 | { 10 | char *q; 11 | /*!re2c 12 | re2c:indent:string = " "; 13 | [a] { return YYCURSOR; } 14 | [b] { return YYCURSOR; } 15 | [c] { return YYCURSOR; } 16 | [d] { return YYCURSOR; } 17 | [\000-\377] { return NULL; } 18 | */ 19 | } 20 | 21 | char *scan1(char *p) 22 | { 23 | char *q; 24 | /*!re2c 25 | re2c:indent:string = "\t"; 26 | [a] { return YYCURSOR; } 27 | [b] { return YYCURSOR; } 28 | [c] { return YYCURSOR; } 29 | [d] { return YYCURSOR; } 30 | [\000-\377] { return NULL; } 31 | */ 32 | } 33 | 34 | char *scan(char *p) 35 | { 36 | char *q; 37 | /*!re2c 38 | re2c:indent:string = ""; 39 | [a] { return YYCURSOR; } 40 | [b] { return YYCURSOR; } 41 | [c] { return YYCURSOR; } 42 | [d] { return YYCURSOR; } 43 | [\000-\377] { return NULL; } 44 | */ 45 | } 46 | -------------------------------------------------------------------------------- /re2c/test/config3.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | #define YYCTYPE char 3 | #define YYCURSOR p 4 | #define YYLIMIT p 5 | #define YYMARKER q 6 | #define YYFILL(n) 7 | 8 | char *scan0(char *p) 9 | { 10 | char *q; 11 | /*!re2c 12 | re2c:startlabel = 0; 13 | [0-9]+ { return YYCURSOR; } 14 | [\000-\377] { return NULL; } 15 | */ 16 | } 17 | 18 | char *scan1(char *p) 19 | { 20 | char *q; 21 | /*!re2c 22 | re2c:startlabel = 1; 23 | [0-9]+ { return YYCURSOR; } 24 | [\000-\377] { return NULL; } 25 | */ 26 | } 27 | 28 | char *scan2(char *p) 29 | { 30 | char *q; 31 | /*!re2c 32 | re2c:startlabel = "startLabel"; 33 | [0-9]+ { return YYCURSOR; } 34 | [\000-\377] { return NULL; } 35 | */ 36 | } 37 | 38 | char *scan(char *p) 39 | { 40 | char *q; 41 | /*!re2c 42 | re2c:startlabel = ; 43 | [0-9]+ { return YYCURSOR; } 44 | [\000-\377] { return NULL; } 45 | */ 46 | } 47 | -------------------------------------------------------------------------------- /re2c/test/config4a.f.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "config4a.f.re" 3 | #define NULL ((char*) 0) 4 | #define YYCTYPE char 5 | #define YYCURSOR p 6 | #define YYLIMIT p 7 | #define YYMARKER q 8 | #define YYFILL(n) 9 | 10 | char *scan(char *p) 11 | { 12 | char *q; 13 | 14 | #line 15 "" 15 | 16 | switch (YYGETSTATE()) { 17 | default: goto yy0; 18 | case 0: goto yyFillLabel0; 19 | case 1: goto yyFillLabel1; 20 | } 21 | yy0: 22 | YYSETSTATE(0); 23 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 24 | yyFillLabel0: 25 | yych = *YYCURSOR; 26 | switch (yych) { 27 | case '0': 28 | case '1': 29 | case '2': 30 | case '3': 31 | case '4': 32 | case '5': 33 | case '6': 34 | case '7': 35 | case '8': 36 | case '9': goto yy2; 37 | default: goto yy4; 38 | } 39 | yy2: 40 | ++YYCURSOR; 41 | yych = *YYCURSOR; 42 | goto yy7; 43 | yy3: 44 | #line 13 "config4a.f.re" 45 | { return YYCURSOR; } 46 | #line 47 "" 47 | yy4: 48 | ++YYCURSOR; 49 | #line 14 "config4a.f.re" 50 | { return NULL; } 51 | #line 52 "" 52 | yy6: 53 | ++YYCURSOR; 54 | YYSETSTATE(1); 55 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 56 | yyFillLabel1: 57 | yych = *YYCURSOR; 58 | yy7: 59 | switch (yych) { 60 | case '0': 61 | case '1': 62 | case '2': 63 | case '3': 64 | case '4': 65 | case '5': 66 | case '6': 67 | case '7': 68 | case '8': 69 | case '9': goto yy6; 70 | default: goto yy3; 71 | } 72 | #line 15 "config4a.f.re" 73 | 74 | } 75 | -------------------------------------------------------------------------------- /re2c/test/config4a.f.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | #define YYCTYPE char 3 | #define YYCURSOR p 4 | #define YYLIMIT p 5 | #define YYMARKER q 6 | #define YYFILL(n) 7 | 8 | char *scan(char *p) 9 | { 10 | char *q; 11 | /*!re2c 12 | re2c:state:abort = 0; 13 | [0-9]+ { return YYCURSOR; } 14 | [\000-\377] { return NULL; } 15 | */ 16 | } 17 | -------------------------------------------------------------------------------- /re2c/test/config4b.f.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "config4b.f.re" 3 | #define NULL ((char*) 0) 4 | #define YYCTYPE char 5 | #define YYCURSOR p 6 | #define YYLIMIT p 7 | #define YYMARKER q 8 | #define YYFILL(n) 9 | 10 | char *scan(char *p) 11 | { 12 | char *q; 13 | 14 | #line 15 "" 15 | 16 | switch (YYGETSTATE()) { 17 | default: abort(); 18 | case -1: goto yy0; 19 | case 0: goto yyFillLabel0; 20 | case 1: goto yyFillLabel1; 21 | } 22 | yy0: 23 | YYSETSTATE(0); 24 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 25 | yyFillLabel0: 26 | yych = *YYCURSOR; 27 | switch (yych) { 28 | case '0': 29 | case '1': 30 | case '2': 31 | case '3': 32 | case '4': 33 | case '5': 34 | case '6': 35 | case '7': 36 | case '8': 37 | case '9': goto yy2; 38 | default: goto yy4; 39 | } 40 | yy2: 41 | ++YYCURSOR; 42 | yych = *YYCURSOR; 43 | goto yy7; 44 | yy3: 45 | #line 13 "config4b.f.re" 46 | { return YYCURSOR; } 47 | #line 48 "" 48 | yy4: 49 | ++YYCURSOR; 50 | #line 14 "config4b.f.re" 51 | { return NULL; } 52 | #line 53 "" 53 | yy6: 54 | ++YYCURSOR; 55 | YYSETSTATE(1); 56 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 57 | yyFillLabel1: 58 | yych = *YYCURSOR; 59 | yy7: 60 | switch (yych) { 61 | case '0': 62 | case '1': 63 | case '2': 64 | case '3': 65 | case '4': 66 | case '5': 67 | case '6': 68 | case '7': 69 | case '8': 70 | case '9': goto yy6; 71 | default: goto yy3; 72 | } 73 | #line 15 "config4b.f.re" 74 | 75 | } 76 | -------------------------------------------------------------------------------- /re2c/test/config4b.f.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | #define YYCTYPE char 3 | #define YYCURSOR p 4 | #define YYLIMIT p 5 | #define YYMARKER q 6 | #define YYFILL(n) 7 | 8 | char *scan(char *p) 9 | { 10 | char *q; 11 | /*!re2c 12 | re2c:state:abort = 1; 13 | [0-9]+ { return YYCURSOR; } 14 | [\000-\377] { return NULL; } 15 | */ 16 | } 17 | -------------------------------------------------------------------------------- /re2c/test/config4c.f.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "config4c.f.re" 3 | #define NULL ((char*) 0) 4 | #define YYCTYPE char 5 | #define YYCURSOR p 6 | #define YYLIMIT p 7 | #define YYMARKER q 8 | #define YYFILL(n) 9 | 10 | char *scan(char *p) 11 | { 12 | char *q; 13 | 14 | #line 15 "" 15 | 16 | switch (YYGETSTATE()) { 17 | default: goto yy0; 18 | case 0: goto yyFillLabel0; 19 | case 1: goto yyFillLabel1; 20 | } 21 | start: 22 | yy0: 23 | YYSETSTATE(0); 24 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 25 | yyFillLabel0: 26 | yych = *YYCURSOR; 27 | switch (yych) { 28 | case '0': 29 | case '1': 30 | case '2': 31 | case '3': 32 | case '4': 33 | case '5': 34 | case '6': 35 | case '7': 36 | case '8': 37 | case '9': goto yy2; 38 | default: goto yy4; 39 | } 40 | yy2: 41 | ++YYCURSOR; 42 | yych = *YYCURSOR; 43 | goto yy7; 44 | yy3: 45 | #line 14 "config4c.f.re" 46 | { return YYCURSOR; } 47 | #line 48 "" 48 | yy4: 49 | ++YYCURSOR; 50 | #line 15 "config4c.f.re" 51 | { return NULL; } 52 | #line 53 "" 53 | yy6: 54 | ++YYCURSOR; 55 | YYSETSTATE(1); 56 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 57 | yyFillLabel1: 58 | yych = *YYCURSOR; 59 | yy7: 60 | switch (yych) { 61 | case '0': 62 | case '1': 63 | case '2': 64 | case '3': 65 | case '4': 66 | case '5': 67 | case '6': 68 | case '7': 69 | case '8': 70 | case '9': goto yy6; 71 | default: goto yy3; 72 | } 73 | #line 16 "config4c.f.re" 74 | 75 | } 76 | -------------------------------------------------------------------------------- /re2c/test/config4c.f.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | #define YYCTYPE char 3 | #define YYCURSOR p 4 | #define YYLIMIT p 5 | #define YYMARKER q 6 | #define YYFILL(n) 7 | 8 | char *scan(char *p) 9 | { 10 | char *q; 11 | /*!re2c 12 | re2c:startlabel = "start"; 13 | re2c:state:abort = 0; 14 | [0-9]+ { return YYCURSOR; } 15 | [\000-\377] { return NULL; } 16 | */ 17 | } 18 | -------------------------------------------------------------------------------- /re2c/test/config4d.f.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "config4d.f.re" 3 | #define NULL ((char*) 0) 4 | #define YYCTYPE char 5 | #define YYCURSOR p 6 | #define YYLIMIT p 7 | #define YYMARKER q 8 | #define YYFILL(n) 9 | 10 | char *scan(char *p) 11 | { 12 | char *q; 13 | 14 | #line 15 "" 15 | 16 | switch (YYGETSTATE()) { 17 | default: goto yy0; 18 | case 0: goto yyFillLabel0; 19 | case 1: goto yyFillLabel1; 20 | } 21 | yyNext: 22 | start: 23 | yy0: 24 | YYSETSTATE(0); 25 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 26 | yyFillLabel0: 27 | yych = *YYCURSOR; 28 | switch (yych) { 29 | case '0': 30 | case '1': 31 | case '2': 32 | case '3': 33 | case '4': 34 | case '5': 35 | case '6': 36 | case '7': 37 | case '8': 38 | case '9': goto yy2; 39 | default: goto yy4; 40 | } 41 | yy2: 42 | ++YYCURSOR; 43 | yych = *YYCURSOR; 44 | goto yy7; 45 | yy3: 46 | #line 15 "config4d.f.re" 47 | { return YYCURSOR; } 48 | #line 49 "" 49 | yy4: 50 | ++YYCURSOR; 51 | #line 16 "config4d.f.re" 52 | { return NULL; } 53 | #line 54 "" 54 | yy6: 55 | ++YYCURSOR; 56 | YYSETSTATE(1); 57 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 58 | yyFillLabel1: 59 | yych = *YYCURSOR; 60 | yy7: 61 | switch (yych) { 62 | case '0': 63 | case '1': 64 | case '2': 65 | case '3': 66 | case '4': 67 | case '5': 68 | case '6': 69 | case '7': 70 | case '8': 71 | case '9': goto yy6; 72 | default: goto yy3; 73 | } 74 | #line 17 "config4d.f.re" 75 | 76 | } 77 | -------------------------------------------------------------------------------- /re2c/test/config4d.f.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | #define YYCTYPE char 3 | #define YYCURSOR p 4 | #define YYLIMIT p 5 | #define YYMARKER q 6 | #define YYFILL(n) 7 | 8 | char *scan(char *p) 9 | { 10 | char *q; 11 | /*!re2c 12 | re2c:startlabel = "start"; 13 | re2c:state:abort = 0; 14 | re2c:state:nextlabel = 1; 15 | [0-9]+ { return YYCURSOR; } 16 | [\000-\377] { return NULL; } 17 | */ 18 | } 19 | -------------------------------------------------------------------------------- /re2c/test/config4e.f.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "config4e.f.re" 3 | #define NULL ((char*) 0) 4 | #define YYCTYPE char 5 | #define YYCURSOR p 6 | #define YYLIMIT p 7 | #define YYMARKER q 8 | #define YYFILL(n) 9 | 10 | char *scan(char *p) 11 | { 12 | char *q; 13 | 14 | #line 15 "" 15 | 16 | switch (YYGETSTATE()) { 17 | default: goto yy0; 18 | case 0: goto yyFillLabel0; 19 | case 1: goto yyFillLabel1; 20 | } 21 | yyNext: 22 | yy0: 23 | YYSETSTATE(0); 24 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 25 | yyFillLabel0: 26 | yych = *YYCURSOR; 27 | switch (yych) { 28 | case '0': 29 | case '1': 30 | case '2': 31 | case '3': 32 | case '4': 33 | case '5': 34 | case '6': 35 | case '7': 36 | case '8': 37 | case '9': goto yy2; 38 | default: goto yy4; 39 | } 40 | yy2: 41 | ++YYCURSOR; 42 | yych = *YYCURSOR; 43 | goto yy7; 44 | yy3: 45 | #line 15 "config4e.f.re" 46 | { return YYCURSOR; } 47 | #line 48 "" 48 | yy4: 49 | ++YYCURSOR; 50 | #line 16 "config4e.f.re" 51 | { return NULL; } 52 | #line 53 "" 53 | yy6: 54 | ++YYCURSOR; 55 | YYSETSTATE(1); 56 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 57 | yyFillLabel1: 58 | yych = *YYCURSOR; 59 | yy7: 60 | switch (yych) { 61 | case '0': 62 | case '1': 63 | case '2': 64 | case '3': 65 | case '4': 66 | case '5': 67 | case '6': 68 | case '7': 69 | case '8': 70 | case '9': goto yy6; 71 | default: goto yy3; 72 | } 73 | #line 17 "config4e.f.re" 74 | 75 | } 76 | -------------------------------------------------------------------------------- /re2c/test/config4e.f.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | #define YYCTYPE char 3 | #define YYCURSOR p 4 | #define YYLIMIT p 5 | #define YYMARKER q 6 | #define YYFILL(n) 7 | 8 | char *scan(char *p) 9 | { 10 | char *q; 11 | /*!re2c 12 | re2c:startlabel = "yyNext"; 13 | re2c:state:abort = 0; 14 | re2c:state:nextlabel = 0; 15 | [0-9]+ { return YYCURSOR; } 16 | [\000-\377] { return NULL; } 17 | */ 18 | } 19 | -------------------------------------------------------------------------------- /re2c/test/config4f.f.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "config4f.f.re" 3 | #define NULL ((char*) 0) 4 | #define YYCTYPE char 5 | #define YYCURSOR p 6 | #define YYLIMIT p 7 | #define YYMARKER q 8 | #define YYFILL(n) 9 | 10 | char *scan(char *p) 11 | { 12 | char *q; 13 | #line 13 "config4f.f.re" 14 | 15 | switch (YYGETSTATE()) { 16 | default: goto yy0; 17 | case 0: goto yyFillLabel0; 18 | case 1: goto yyFillLabel1; 19 | } 20 | 21 | // after getstate 22 | 23 | 24 | #line 25 "" 25 | 26 | yy0: 27 | YYSETSTATE(0); 28 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 29 | yyFillLabel0: 30 | yych = *YYCURSOR; 31 | switch (yych) { 32 | case '0': 33 | case '1': 34 | case '2': 35 | case '3': 36 | case '4': 37 | case '5': 38 | case '6': 39 | case '7': 40 | case '8': 41 | case '9': goto yy2; 42 | default: goto yy4; 43 | } 44 | yy2: 45 | ++YYCURSOR; 46 | yych = *YYCURSOR; 47 | goto yy7; 48 | yy3: 49 | #line 21 "config4f.f.re" 50 | { return YYCURSOR; } 51 | #line 52 "" 52 | yy4: 53 | ++YYCURSOR; 54 | #line 22 "config4f.f.re" 55 | { return NULL; } 56 | #line 57 "" 57 | yy6: 58 | ++YYCURSOR; 59 | YYSETSTATE(1); 60 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 61 | yyFillLabel1: 62 | yych = *YYCURSOR; 63 | yy7: 64 | switch (yych) { 65 | case '0': 66 | case '1': 67 | case '2': 68 | case '3': 69 | case '4': 70 | case '5': 71 | case '6': 72 | case '7': 73 | case '8': 74 | case '9': goto yy6; 75 | default: goto yy3; 76 | } 77 | #line 23 "config4f.f.re" 78 | 79 | } 80 | -------------------------------------------------------------------------------- /re2c/test/config4f.f.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | #define YYCTYPE char 3 | #define YYCURSOR p 4 | #define YYLIMIT p 5 | #define YYMARKER q 6 | #define YYFILL(n) 7 | 8 | char *scan(char *p) 9 | { 10 | char *q; 11 | /*!re2c 12 | re2c:indent:top = 1; 13 | */ 14 | /*!getstate:re2c */ 15 | 16 | // after getstate 17 | 18 | /*!re2c 19 | re2c:state:abort = 0; 20 | re2c:state:nextlabel = 0; 21 | [0-9]+ { return YYCURSOR; } 22 | [\000-\377] { return NULL; } 23 | */ 24 | } 25 | -------------------------------------------------------------------------------- /re2c/test/config4g.ifs.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #define NULL ((char*) 0) 3 | 4 | const unsigned char *scan(const unsigned char *p, unsigned int len, int *state) 5 | { 6 | unsigned char c; 7 | const unsigned char *q; 8 | const unsigned char * const e = p + len; 9 | 10 | switch (*state) { 11 | default: goto yy0; 12 | case 0: goto yyFillLabel0; 13 | case 1: goto yyFillLabel1; 14 | } 15 | 16 | 17 | yy0: 18 | *state = 0; 19 | if (p >= e) { 20 | return NULL; 21 | } 22 | yyFillLabel0: 23 | c = *p; 24 | if (c <= '/') goto yy4; 25 | if (c >= ':') goto yy4; 26 | ++p; 27 | c = *p; 28 | goto yy7; 29 | yy3: 30 | { return p; } 31 | yy4: 32 | ++p; 33 | { return NULL; } 34 | yy6: 35 | ++p; 36 | *state = 1; 37 | if (p >= e) { 38 | return NULL; 39 | } 40 | yyFillLabel1: 41 | c = *p; 42 | yy7: 43 | if (c <= '/') goto yy3; 44 | if (c <= '9') goto yy6; 45 | goto yy3; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /re2c/test/config4g.ifs.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | 3 | const unsigned char *scan(const unsigned char *p, unsigned int len, int *state) 4 | { 5 | unsigned char c; 6 | const unsigned char *q; 7 | const unsigned char * const e = p + len; 8 | /*!re2c 9 | re2c:variable:yych = c; 10 | re2c:indent:top = 1; 11 | re2c:state:abort = 0; 12 | re2c:state:nextlabel = 0; 13 | re2c:define:YYCTYPE = char; 14 | re2c:define:YYCURSOR = p; 15 | re2c:define:YYLIMIT = e; 16 | re2c:define:YYMARKER = q; 17 | re2c:yyfill:check = 0; 18 | re2c:define:YYFILL:naked = 1; 19 | re2c:define:YYFILL = "if (p >= e) {\n\t\treturn NULL;\n\t}"; 20 | re2c:define:YYSETSTATE = "*state = @;"; 21 | re2c:define:YYSETSTATE:naked = 1; 22 | re2c:define:YYSETSTATE@state = "@"; 23 | re2c:define:YYGETSTATE = "*state"; 24 | re2c:define:YYGETSTATE:naked = 1; 25 | */ 26 | /*!getstate:re2c */ 27 | /*!re2c 28 | [0-9]+ { return p; } 29 | [\000-\377] { return NULL; } 30 | */ 31 | } 32 | -------------------------------------------------------------------------------- /re2c/test/config5.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "config5.re" 3 | // ignored 4 | #line 7 "config5.re" 5 | // code 6 | 7 | #line 8 "" 8 | { 9 | YYCTYPE yych; 10 | 11 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 12 | yych = *YYCURSOR; 13 | switch (yych) { 14 | case 'a': goto yy2; 15 | default: goto yy4; 16 | } 17 | yy2: 18 | yych = *(YYMARKER = ++YYCURSOR); 19 | switch (yych) { 20 | case 'b': goto yy5; 21 | default: goto yy3; 22 | } 23 | yy3: 24 | #line 11 "config5.re" 25 | { return 0; } 26 | #line 27 "" 27 | yy4: 28 | yych = *++YYCURSOR; 29 | goto yy3; 30 | yy5: 31 | ++YYCURSOR; 32 | if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); 33 | yych = *YYCURSOR; 34 | switch (yych) { 35 | case 'b': goto yy5; 36 | case 'c': goto yy8; 37 | default: goto yy7; 38 | } 39 | yy7: 40 | YYCURSOR = YYMARKER; 41 | goto yy3; 42 | yy8: 43 | yych = *++YYCURSOR; 44 | switch (yych) { 45 | case 'c': goto yy9; 46 | default: goto yy7; 47 | } 48 | yy9: 49 | yych = *++YYCURSOR; 50 | switch (yych) { 51 | case 'c': goto yy10; 52 | default: goto yy7; 53 | } 54 | yy10: 55 | ++YYCURSOR; 56 | #line 10 "config5.re" 57 | { return 1; } 58 | #line 59 "" 59 | } 60 | #line 13 "config5.re" 61 | 62 | // ignored 63 | #line 20 "config5.re" 64 | // max 65 | #define YYMAXFILL 3 66 | #line 26 "config5.re" 67 | // eof 68 | -------------------------------------------------------------------------------- /re2c/test/config5.re: -------------------------------------------------------------------------------- 1 | // ignored 2 | /*!ignore:re2c 3 | 4 | Ignored... 5 | 6 | */ 7 | // code 8 | /*!re2c 9 | 10 | [a][b]+ "ccc" { return 1; } 11 | [\000-\377] { return 0; } 12 | 13 | */ 14 | // ignored 15 | /*!ignore:re2c 16 | 17 | Ignored... 18 | 19 | */ 20 | // max 21 | /*!max:re2c 22 | 23 | Ignored... 24 | 25 | */ 26 | // eof 27 | -------------------------------------------------------------------------------- /re2c/test/config6.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "config6.re" 3 | #include 4 | #include 5 | #include 6 | 7 | int scan(char *s) 8 | { 9 | char *p = s; 10 | 11 | #define YYCTYPE char 12 | #define YYCURSOR p 13 | 14 | for(;;) 15 | { 16 | 17 | #line 18 "" 18 | { 19 | YYCTYPE yych; 20 | 21 | yych = *YYCURSOR; 22 | switch (yych) { 23 | case 0x00: goto yy10; 24 | case '+': goto yy6; 25 | case '-': goto yy8; 26 | case '0': goto yy2; 27 | case '1': 28 | case '2': 29 | case '3': 30 | case '4': 31 | case '5': 32 | case '6': 33 | case '7': 34 | case '8': 35 | case '9': goto yy4; 36 | default: goto yy12; 37 | } 38 | yy2: 39 | ++YYCURSOR; 40 | switch ((yych = *YYCURSOR)) { 41 | case '0': 42 | case '1': 43 | case '2': 44 | case '3': 45 | case '4': 46 | case '5': 47 | case '6': 48 | case '7': 49 | case '8': 50 | case '9': goto yy16; 51 | default: goto yy3; 52 | } 53 | yy3: 54 | #line 20 "config6.re" 55 | { printf("Num\n"); continue; } 56 | #line 57 "" 57 | yy4: 58 | ++YYCURSOR; 59 | yych = *YYCURSOR; 60 | goto yy15; 61 | yy5: 62 | #line 19 "config6.re" 63 | { printf("Num\n"); continue; } 64 | #line 65 "" 65 | yy6: 66 | ++YYCURSOR; 67 | #line 21 "config6.re" 68 | { printf("+\n"); continue; } 69 | #line 70 "" 70 | yy8: 71 | ++YYCURSOR; 72 | #line 22 "config6.re" 73 | { printf("-\n"); continue; } 74 | #line 75 "" 75 | yy10: 76 | ++YYCURSOR; 77 | #line 23 "config6.re" 78 | { printf("EOF\n"); return 0; } 79 | #line 80 "" 80 | yy12: 81 | ++YYCURSOR; 82 | #line 24 "config6.re" 83 | { printf("ERR\n"); return 1; } 84 | #line 85 "" 85 | yy14: 86 | ++YYCURSOR; 87 | yych = *YYCURSOR; 88 | yy15: 89 | switch (yych) { 90 | case '0': 91 | case '1': 92 | case '2': 93 | case '3': 94 | case '4': 95 | case '5': 96 | case '6': 97 | case '7': 98 | case '8': 99 | case '9': goto yy14; 100 | default: goto yy5; 101 | } 102 | yy16: 103 | ++YYCURSOR; 104 | yych = *YYCURSOR; 105 | switch (yych) { 106 | case '0': 107 | case '1': 108 | case '2': 109 | case '3': 110 | case '4': 111 | case '5': 112 | case '6': 113 | case '7': 114 | case '8': 115 | case '9': goto yy16; 116 | default: goto yy18; 117 | } 118 | yy18: 119 | #line 18 "config6.re" 120 | { printf("Oct\n"); continue; } 121 | #line 122 "" 122 | } 123 | #line 25 "config6.re" 124 | 125 | } 126 | } 127 | 128 | int main(int argc, char **argv) 129 | { 130 | if (argc > 1) 131 | { 132 | return scan(argv[1]); 133 | } 134 | else 135 | { 136 | fprintf(stderr, "%s \n", argv[0]); 137 | return 1; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /re2c/test/config6.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int scan(char *s) 6 | { 7 | char *p = s; 8 | 9 | #define YYCTYPE char 10 | #define YYCURSOR p 11 | 12 | for(;;) 13 | { 14 | /*!re2c 15 | re2c:indent:top = 2; 16 | re2c:yyfill:enable = 0; 17 | 18 | "0"[0-9]+ { printf("Oct\n"); continue; } 19 | [1-9][0-9]* { printf("Num\n"); continue; } 20 | "0" { printf("Num\n"); continue; } 21 | "+" { printf("+\n"); continue; } 22 | "-" { printf("-\n"); continue; } 23 | "\000" { printf("EOF\n"); return 0; } 24 | [^] { printf("ERR\n"); return 1; } 25 | */ 26 | } 27 | } 28 | 29 | int main(int argc, char **argv) 30 | { 31 | if (argc > 1) 32 | { 33 | return scan(argv[1]); 34 | } 35 | else 36 | { 37 | fprintf(stderr, "%s \n", argv[0]); 38 | return 1; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /re2c/test/config7a.g.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "config7a.g.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | 8 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 9 | yych = *YYCURSOR; 10 | if (yych <= 'E') { 11 | if (yych <= '@') goto yy4; 12 | if (yych >= 'E') goto yy4; 13 | } else { 14 | if (yych <= 'G') goto yy2; 15 | if (yych <= '`') goto yy4; 16 | if (yych >= 'h') goto yy4; 17 | } 18 | yy2: 19 | ++YYCURSOR; 20 | #line 10 "config7a.g.re" 21 | { return 1; } 22 | #line 23 "" 23 | yy4: 24 | ++YYCURSOR; 25 | #line 12 "config7a.g.re" 26 | { return -1; } 27 | #line 28 "" 28 | } 29 | #line 14 "config7a.g.re" 30 | 31 | -------------------------------------------------------------------------------- /re2c/test/config7a.g.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | re2c:cgoto:threshold = 8; 4 | 5 | a = [aA]; 6 | b = [bB]; 7 | c = [cC]; 8 | d = [dD]; 9 | 10 | (a|b|c|d|"e"|'f'|[gG]) { return 1; } 11 | 12 | .|"\n" { return -1; } 13 | 14 | */ 15 | -------------------------------------------------------------------------------- /re2c/test/config7b.g.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "config7b.g.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | 8 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 9 | yych = *YYCURSOR; 10 | { 11 | static void *yytarget[256] = { 12 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 13 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 14 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 15 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 16 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 17 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 18 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 19 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 20 | &&yy4, &&yy2, &&yy2, &&yy2, &&yy2, &&yy4, &&yy2, &&yy2, 21 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 22 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 23 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 24 | &&yy4, &&yy2, &&yy2, &&yy2, &&yy2, &&yy2, &&yy2, &&yy2, 25 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 26 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 27 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 28 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 29 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 30 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 31 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 32 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 33 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 34 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 35 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 36 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 37 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 38 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 39 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 40 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 41 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 42 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, 43 | &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4, &&yy4 44 | }; 45 | goto *yytarget[yych]; 46 | } 47 | yy2: 48 | ++YYCURSOR; 49 | #line 10 "config7b.g.re" 50 | { return 1; } 51 | #line 52 "" 52 | yy4: 53 | ++YYCURSOR; 54 | #line 12 "config7b.g.re" 55 | { return -1; } 56 | #line 57 "" 57 | } 58 | #line 14 "config7b.g.re" 59 | 60 | -------------------------------------------------------------------------------- /re2c/test/config7b.g.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | re2c:cgoto:threshold = 7; 4 | 5 | a = [aA]; 6 | b = [bB]; 7 | c = [cC]; 8 | d = [dD]; 9 | 10 | (a|b|c|d|"e"|'f'|[gG]) { return 1; } 11 | 12 | .|"\n" { return -1; } 13 | 14 | */ 15 | -------------------------------------------------------------------------------- /re2c/test/config8.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct Scanner 5 | { 6 | Scanner(char *txt) 7 | : cur(txt), lim(txt + strlen(txt)) 8 | { 9 | } 10 | 11 | char *cur; 12 | char *lim; 13 | char *ptr; 14 | char *ctx; 15 | char *tok; 16 | }; 17 | 18 | enum What 19 | { 20 | UNEXPECTED, 21 | KEYWORD, 22 | NUMBER, 23 | EOI 24 | }; 25 | 26 | char * tokens[] = { "UNEXPECTED", "KEYWORD", "NUMBER", "EOI" }; 27 | 28 | void fill(int) 29 | { 30 | } 31 | 32 | int scan(Scanner &s) 33 | { 34 | char *cursor = s.cur; 35 | 36 | if(cursor == s.lim) 37 | return EOI; 38 | 39 | std: 40 | s.tok = cursor; 41 | 42 | /*!re2c 43 | 44 | re2c:define:YYCTYPE = char; 45 | re2c:define:YYCURSOR = s.cur; 46 | re2c:define:YYLIMIT = s.lim; 47 | re2c:define:YYMARKER = s.ptr; 48 | re2c:define:YYCTXMARKER = s.ctx; 49 | re2c:define:YYFILL = fill; 50 | 51 | re2c:variable:yych = curr; 52 | re2c:labelprefix = xx; 53 | 54 | ("a"|"b")/[1] { return KEYWORD; } 55 | ("a"|"b")/[0-9]+ { return KEYWORD; } 56 | [0-9]+ { return NUMBER; } 57 | 58 | [ \t\n] 59 | { 60 | if(s.cur == s.lim) 61 | return EOI; 62 | cursor = s.cur; 63 | goto std; 64 | } 65 | . 66 | { 67 | return UNEXPECTED; 68 | } 69 | */ 70 | } 71 | 72 | int main(int,char**) 73 | { 74 | Scanner s("a77 a1 b8 b1"); 75 | 76 | int t, n = 0; 77 | while ((t = scan(s)) != EOI) 78 | { 79 | std::cout << (++n) << ": " << tokens[t] << " = \""; std::cout.write(s.tok, s.cur-s.tok); std::cout << "\"" << std::endl; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /re2c/test/config9.b.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct Scanner 5 | { 6 | Scanner(char *txt) 7 | : cur(txt), lim(txt + strlen(txt)) 8 | { 9 | } 10 | 11 | char *cur; 12 | char *lim; 13 | char *ptr; 14 | char *ctx; 15 | char *tok; 16 | }; 17 | 18 | enum What 19 | { 20 | UNEXPECTED, 21 | KEYWORD, 22 | NUMBER, 23 | EOI 24 | }; 25 | 26 | char * tokens[] = { "UNEXPECTED", "KEYWORD", "NUMBER", "EOI" }; 27 | 28 | void fill(int) 29 | { 30 | } 31 | 32 | int scan(Scanner &s) 33 | { 34 | char *cursor = s.cur; 35 | 36 | if(cursor == s.lim) 37 | return EOI; 38 | 39 | std: 40 | s.tok = cursor; 41 | 42 | /*!re2c 43 | 44 | re2c:define:YYCTYPE = "unsigned char"; 45 | re2c:define:YYCURSOR = s.cur; 46 | re2c:define:YYLIMIT = s.lim; 47 | re2c:define:YYMARKER = s.ptr; 48 | re2c:define:YYCTXMARKER = s.ctx; 49 | re2c:define:YYFILL = fill; 50 | 51 | re2c:variable:yych = curr; 52 | re2c:labelprefix = xx; 53 | 54 | re2c:yych:conversion = 1; 55 | 56 | ("a"|"b")/[1] { return KEYWORD; } 57 | ("a"|"b")/[0-9]+ { return KEYWORD; } 58 | [0-9]+ { return NUMBER; } 59 | 60 | [ \t\n] 61 | { 62 | if(s.cur == s.lim) 63 | return EOI; 64 | cursor = s.cur; 65 | goto std; 66 | } 67 | . 68 | { 69 | return UNEXPECTED; 70 | } 71 | */ 72 | } 73 | 74 | int main(int,char**) 75 | { 76 | Scanner s("a77 a1 b8 b1"); 77 | 78 | int t, n = 0; 79 | while ((t = scan(s)) != EOI) 80 | { 81 | std::cout << (++n) << ": " << tokens[t] << " = \""; std::cout.write(s.tok, s.cur-s.tok); std::cout << "\"" << std::endl; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /re2c/test/ctx.b.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct Scanner 5 | { 6 | Scanner(char *txt) 7 | : cur(txt), lim(txt + strlen(txt)) 8 | { 9 | } 10 | 11 | char *cur; 12 | char *lim; 13 | char *ptr; 14 | char *ctx; 15 | char *tok; 16 | }; 17 | 18 | #define YYCTYPE char 19 | #define YYCURSOR s.cur 20 | #define YYLIMIT s.lim 21 | #define YYMARKER s.ptr 22 | #define YYCTXMARKER s.ctx 23 | #define YYFILL(n) 24 | 25 | enum What 26 | { 27 | UNEXPECTED, 28 | KEYWORD, 29 | NUMBER, 30 | EOI 31 | }; 32 | 33 | char * tokens[] = { "UNEXPECTED", "KEYWORD", "NUMBER", "EOI" }; 34 | 35 | 36 | int scan(Scanner &s) 37 | { 38 | YYCTYPE *cursor = s.cur; 39 | 40 | if(cursor == s.lim) 41 | return EOI; 42 | 43 | std: 44 | s.tok = cursor; 45 | 46 | /*!re2c 47 | 48 | ("a"|"b")/[1] { return KEYWORD; } 49 | ("a"|"b")/[0-9]+ { return KEYWORD; } 50 | [0-9]+ { return NUMBER; } 51 | 52 | [ \t\n] 53 | { 54 | if(s.cur == s.lim) 55 | return EOI; 56 | cursor = s.cur; 57 | goto std; 58 | } 59 | . 60 | { 61 | return UNEXPECTED; 62 | } 63 | */ 64 | } 65 | 66 | /*!max:re2c */ 67 | 68 | int main(int,char**) 69 | { 70 | Scanner s("a77 a1 b8 b1"); 71 | 72 | int t, n = 0; 73 | while ((t = scan(s)) != EOI) 74 | { 75 | std::cout << (++n) << ": " << tokens[t] << " = \""; std::cout.write(s.tok, s.cur-s.tok); std::cout << "\"" << std::endl; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /re2c/test/ctx.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct Scanner 5 | { 6 | Scanner(char *txt) 7 | : cur(txt), lim(txt + strlen(txt)) 8 | { 9 | } 10 | 11 | char *cur; 12 | char *lim; 13 | char *ptr; 14 | char *ctx; 15 | char *tok; 16 | }; 17 | 18 | #define YYCTYPE char 19 | #define YYCURSOR s.cur 20 | #define YYLIMIT s.lim 21 | #define YYMARKER s.ptr 22 | #define YYCTXMARKER s.ctx 23 | #define YYFILL(n) 24 | 25 | enum What 26 | { 27 | UNEXPECTED, 28 | KEYWORD, 29 | NUMBER, 30 | EOI 31 | }; 32 | 33 | char * tokens[] = { "UNEXPECTED", "KEYWORD", "NUMBER", "EOI" }; 34 | 35 | 36 | int scan(Scanner &s) 37 | { 38 | YYCTYPE *cursor = s.cur; 39 | 40 | if(cursor == s.lim) 41 | return EOI; 42 | 43 | std: 44 | s.tok = cursor; 45 | 46 | /*!re2c 47 | 48 | ("a"|"b")/[1] { return KEYWORD; } 49 | ("a"|"b")/[0-9]+ { return KEYWORD; } 50 | [0-9]+ { return NUMBER; } 51 | 52 | [ \t\n] 53 | { 54 | if(s.cur == s.lim) 55 | return EOI; 56 | cursor = s.cur; 57 | goto std; 58 | } 59 | . 60 | { 61 | return UNEXPECTED; 62 | } 63 | */ 64 | } 65 | 66 | /*!max:re2c */ 67 | 68 | int main(int,char**) 69 | { 70 | Scanner s("a77 a1 b8 b1"); 71 | 72 | int t, n = 0; 73 | while ((t = scan(s)) != EOI) 74 | { 75 | std::cout << (++n) << ": " << tokens[t] << " = \""; std::cout.write(s.tok, s.cur-s.tok); std::cout << "\"" << std::endl; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /re2c/test/ctx.s.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct Scanner 5 | { 6 | Scanner(char *txt) 7 | : cur(txt), lim(txt + strlen(txt)) 8 | { 9 | } 10 | 11 | char *cur; 12 | char *lim; 13 | char *ptr; 14 | char *ctx; 15 | char *tok; 16 | }; 17 | 18 | #define YYCTYPE char 19 | #define YYCURSOR s.cur 20 | #define YYLIMIT s.lim 21 | #define YYMARKER s.ptr 22 | #define YYCTXMARKER s.ctx 23 | #define YYFILL(n) 24 | 25 | enum What 26 | { 27 | UNEXPECTED, 28 | KEYWORD, 29 | NUMBER, 30 | EOI 31 | }; 32 | 33 | char * tokens[] = { "UNEXPECTED", "KEYWORD", "NUMBER", "EOI" }; 34 | 35 | 36 | int scan(Scanner &s) 37 | { 38 | YYCTYPE *cursor = s.cur; 39 | 40 | if(cursor == s.lim) 41 | return EOI; 42 | 43 | std: 44 | s.tok = cursor; 45 | 46 | /*!re2c 47 | 48 | ("a"|"b")/[1] { return KEYWORD; } 49 | ("a"|"b")/[0-9]+ { return KEYWORD; } 50 | [0-9]+ { return NUMBER; } 51 | 52 | [ \t\n] 53 | { 54 | if(s.cur == s.lim) 55 | return EOI; 56 | cursor = s.cur; 57 | goto std; 58 | } 59 | . 60 | { 61 | return UNEXPECTED; 62 | } 63 | */ 64 | } 65 | 66 | /*!max:re2c */ 67 | 68 | int main(int,char**) 69 | { 70 | Scanner s("a77 a1 b8 b1"); 71 | 72 | int t, n = 0; 73 | while ((t = scan(s)) != EOI) 74 | { 75 | std::cout << (++n) << ": " << tokens[t] << " = \""; std::cout.write(s.tok, s.cur-s.tok); std::cout << "\"" << std::endl; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /re2c/test/cvsignore.b.re: -------------------------------------------------------------------------------- 1 | 2 | #define YYFILL(n) if (cursor >= limit) break; 3 | #define YYCTYPE char 4 | #define YYCURSOR cursor 5 | #define YYLIMIT limit 6 | #define YYMARKER marker 7 | 8 | /*!re2c 9 | any = (.|"\n"); 10 | value = (":" (.\"$")+)?; 11 | cvsdat = "Date"; 12 | cvsid = "Id"; 13 | cvslog = "Log"; 14 | cvsrev = "Revision"; 15 | cvssrc = "Source"; 16 | */ 17 | 18 | #define APPEND(text) \ 19 | append(output, outsize, text, sizeof(text) - sizeof(YYCTYPE)) 20 | 21 | inline void append(YYCTYPE *output, size_t & outsize, const YYCTYPE * text, size_t len) 22 | { 23 | memcpy(output + outsize, text, len); 24 | outsize += (len / sizeof(YYCTYPE)); 25 | } 26 | 27 | void scan(YYCTYPE *pText, size_t *pSize, int *pbChanged) 28 | { 29 | // rule 30 | // scan lines 31 | // find $ in lines 32 | // compact $: .. $ to $$ 33 | 34 | YYCTYPE *output; 35 | const YYCTYPE *cursor, *limit, *marker; 36 | 37 | cursor = marker = output = *pText; 38 | 39 | size_t insize = *pSize; 40 | size_t outsize = 0; 41 | 42 | limit = cursor + insize; 43 | 44 | while(1) { 45 | loop: 46 | /*!re2c 47 | 48 | "$" cvsdat value "$" { APPEND(L"$" L"Date$"); goto loop; } 49 | "$" cvsid value "$" { APPEND(L"$" L"Id$"); goto loop; } 50 | "$" cvslog value "$" { APPEND(L"$" L"Log$"); goto loop; } 51 | "$" cvsrev value "$" { APPEND(L"$" L"Revision$"); goto loop; } 52 | "$" cvssrc value "$" { APPEND(L"$" L"Source$"); goto loop; } 53 | any { output[outsize++] = cursor[-1]; if (cursor >= limit) break; goto loop; } 54 | 55 | */ 56 | } 57 | output[outsize] = '\0'; 58 | 59 | // set the new size 60 | *pSize = outsize; 61 | 62 | *pbChanged = (insize == outsize) ? 0 : 1; 63 | } 64 | -------------------------------------------------------------------------------- /re2c/test/cvsignore.re: -------------------------------------------------------------------------------- 1 | 2 | #define YYFILL(n) if (cursor >= limit) break; 3 | #define YYCTYPE char 4 | #define YYCURSOR cursor 5 | #define YYLIMIT limit 6 | #define YYMARKER marker 7 | 8 | /*!re2c 9 | any = (.|"\n"); 10 | value = (":" (.\"$")+)?; 11 | cvsdat = "Date"; 12 | cvsid = "Id"; 13 | cvslog = "Log"; 14 | cvsrev = "Revision"; 15 | cvssrc = "Source"; 16 | */ 17 | 18 | #define APPEND(text) \ 19 | append(output, outsize, text, sizeof(text) - sizeof(YYCTYPE)) 20 | 21 | inline void append(YYCTYPE *output, size_t & outsize, const YYCTYPE * text, size_t len) 22 | { 23 | memcpy(output + outsize, text, len); 24 | outsize += (len / sizeof(YYCTYPE)); 25 | } 26 | 27 | void scan(YYCTYPE *pText, size_t *pSize, int *pbChanged) 28 | { 29 | // rule 30 | // scan lines 31 | // find $ in lines 32 | // compact $: .. $ to $$ 33 | 34 | YYCTYPE *output; 35 | const YYCTYPE *cursor, *limit, *marker; 36 | 37 | cursor = marker = output = *pText; 38 | 39 | size_t insize = *pSize; 40 | size_t outsize = 0; 41 | 42 | limit = cursor + insize; 43 | 44 | while(1) { 45 | loop: 46 | /*!re2c 47 | 48 | "$" cvsdat value "$" { APPEND(L"$" L"Date$"); goto loop; } 49 | "$" cvsid value "$" { APPEND(L"$" L"Id$"); goto loop; } 50 | "$" cvslog value "$" { APPEND(L"$" L"Log$"); goto loop; } 51 | "$" cvsrev value "$" { APPEND(L"$" L"Revision$"); goto loop; } 52 | "$" cvssrc value "$" { APPEND(L"$" L"Source$"); goto loop; } 53 | any { output[outsize++] = cursor[-1]; if (cursor >= limit) break; goto loop; } 54 | 55 | */ 56 | } 57 | output[outsize] = '\0'; 58 | 59 | // set the new size 60 | *pSize = outsize; 61 | 62 | *pbChanged = (insize == outsize) ? 0 : 1; 63 | } 64 | -------------------------------------------------------------------------------- /re2c/test/cvsignore.s.re: -------------------------------------------------------------------------------- 1 | 2 | #define YYFILL(n) if (cursor >= limit) break; 3 | #define YYCTYPE char 4 | #define YYCURSOR cursor 5 | #define YYLIMIT limit 6 | #define YYMARKER marker 7 | 8 | /*!re2c 9 | any = (.|"\n"); 10 | value = (":" (.\"$")+)?; 11 | cvsdat = "Date"; 12 | cvsid = "Id"; 13 | cvslog = "Log"; 14 | cvsrev = "Revision"; 15 | cvssrc = "Source"; 16 | */ 17 | 18 | #define APPEND(text) \ 19 | append(output, outsize, text, sizeof(text) - sizeof(YYCTYPE)) 20 | 21 | inline void append(YYCTYPE *output, size_t & outsize, const YYCTYPE * text, size_t len) 22 | { 23 | memcpy(output + outsize, text, len); 24 | outsize += (len / sizeof(YYCTYPE)); 25 | } 26 | 27 | void scan(YYCTYPE *pText, size_t *pSize, int *pbChanged) 28 | { 29 | // rule 30 | // scan lines 31 | // find $ in lines 32 | // compact $: .. $ to $$ 33 | 34 | YYCTYPE *output; 35 | const YYCTYPE *cursor, *limit, *marker; 36 | 37 | cursor = marker = output = *pText; 38 | 39 | size_t insize = *pSize; 40 | size_t outsize = 0; 41 | 42 | limit = cursor + insize; 43 | 44 | while(1) { 45 | loop: 46 | /*!re2c 47 | 48 | "$" cvsdat value "$" { APPEND(L"$" L"Date$"); goto loop; } 49 | "$" cvsid value "$" { APPEND(L"$" L"Id$"); goto loop; } 50 | "$" cvslog value "$" { APPEND(L"$" L"Log$"); goto loop; } 51 | "$" cvsrev value "$" { APPEND(L"$" L"Revision$"); goto loop; } 52 | "$" cvssrc value "$" { APPEND(L"$" L"Source$"); goto loop; } 53 | any { output[outsize++] = cursor[-1]; if (cursor >= limit) break; goto loop; } 54 | 55 | */ 56 | } 57 | output[outsize] = '\0'; 58 | 59 | // set the new size 60 | *pSize = outsize; 61 | 62 | *pbChanged = (insize == outsize) ? 0 : 1; 63 | } 64 | -------------------------------------------------------------------------------- /re2c/test/cvsignore.u.re: -------------------------------------------------------------------------------- 1 | 2 | #define YYFILL(n) if (cursor >= limit) break; 3 | #define YYCTYPE unsigned int 4 | #define YYCURSOR cursor 5 | #define YYLIMIT limit 6 | #define YYMARKER marker 7 | 8 | /*!re2c 9 | any = (.|"\n"); 10 | value = (":" (.\"$")+)?; 11 | cvsdat = "Date"; 12 | cvsid = "Id"; 13 | cvslog = "Log"; 14 | cvsrev = "Revision"; 15 | cvssrc = "Source"; 16 | */ 17 | 18 | #define APPEND(text) \ 19 | append(output, outsize, text, sizeof(text) - sizeof(YYCTYPE)) 20 | 21 | inline void append(YYCTYPE *output, size_t & outsize, const YYCTYPE * text, size_t len) 22 | { 23 | memcpy(output + outsize, text, len); 24 | outsize += (len / sizeof(YYCTYPE)); 25 | } 26 | 27 | void scan(YYCTYPE *pText, size_t *pSize, int *pbChanged) 28 | { 29 | // rule 30 | // scan lines 31 | // find $ in lines 32 | // compact $: .. $ to $$ 33 | 34 | YYCTYPE *output; 35 | const YYCTYPE *cursor, *limit, *marker; 36 | 37 | cursor = marker = output = *pText; 38 | 39 | size_t insize = *pSize; 40 | size_t outsize = 0; 41 | 42 | limit = cursor + insize; 43 | 44 | while(1) { 45 | loop: 46 | /*!re2c 47 | 48 | "$" cvsdat value "$" { APPEND(L"$" L"Date$"); goto loop; } 49 | "$" cvsid value "$" { APPEND(L"$" L"Id$"); goto loop; } 50 | "$" cvslog value "$" { APPEND(L"$" L"Log$"); goto loop; } 51 | "$" cvsrev value "$" { APPEND(L"$" L"Revision$"); goto loop; } 52 | "$" cvssrc value "$" { APPEND(L"$" L"Source$"); goto loop; } 53 | any { output[outsize++] = cursor[-1]; if (cursor >= limit) break; goto loop; } 54 | 55 | */ 56 | } 57 | output[outsize] = '\0'; 58 | 59 | // set the new size 60 | *pSize = outsize; 61 | 62 | *pbChanged = (insize == outsize) ? 0 : 1; 63 | } 64 | -------------------------------------------------------------------------------- /re2c/test/cvsignore.ub.re: -------------------------------------------------------------------------------- 1 | 2 | #define YYFILL(n) if (cursor >= limit) break; 3 | #define YYCTYPE unsigned int 4 | #define YYCURSOR cursor 5 | #define YYLIMIT limit 6 | #define YYMARKER marker 7 | 8 | /*!re2c 9 | any = (.|"\n"); 10 | value = (":" (.\"$")+)?; 11 | cvsdat = "Date"; 12 | cvsid = "Id"; 13 | cvslog = "Log"; 14 | cvsrev = "Revision"; 15 | cvssrc = "Source"; 16 | */ 17 | 18 | #define APPEND(text) \ 19 | append(output, outsize, text, sizeof(text) - sizeof(YYCTYPE)) 20 | 21 | inline void append(YYCTYPE *output, size_t & outsize, const YYCTYPE * text, size_t len) 22 | { 23 | memcpy(output + outsize, text, len); 24 | outsize += (len / sizeof(YYCTYPE)); 25 | } 26 | 27 | void scan(YYCTYPE *pText, size_t *pSize, int *pbChanged) 28 | { 29 | // rule 30 | // scan lines 31 | // find $ in lines 32 | // compact $: .. $ to $$ 33 | 34 | YYCTYPE *output; 35 | const YYCTYPE *cursor, *limit, *marker; 36 | 37 | cursor = marker = output = *pText; 38 | 39 | size_t insize = *pSize; 40 | size_t outsize = 0; 41 | 42 | limit = cursor + insize; 43 | 44 | while(1) { 45 | loop: 46 | /*!re2c 47 | 48 | "$" cvsdat value "$" { APPEND(L"$" L"Date$"); goto loop; } 49 | "$" cvsid value "$" { APPEND(L"$" L"Id$"); goto loop; } 50 | "$" cvslog value "$" { APPEND(L"$" L"Log$"); goto loop; } 51 | "$" cvsrev value "$" { APPEND(L"$" L"Revision$"); goto loop; } 52 | "$" cvssrc value "$" { APPEND(L"$" L"Source$"); goto loop; } 53 | any { output[outsize++] = cursor[-1]; if (cursor >= limit) break; goto loop; } 54 | 55 | */ 56 | } 57 | output[outsize] = '\0'; 58 | 59 | // set the new size 60 | *pSize = outsize; 61 | 62 | *pbChanged = (insize == outsize) ? 0 : 1; 63 | } 64 | -------------------------------------------------------------------------------- /re2c/test/cvsignore.w.re: -------------------------------------------------------------------------------- 1 | 2 | #define YYFILL(n) if (cursor >= limit) break; 3 | #define YYCTYPE unsigned short 4 | #define YYCURSOR cursor 5 | #define YYLIMIT limit 6 | #define YYMARKER marker 7 | 8 | /*!re2c 9 | any = (.|"\n"); 10 | value = (":" (.\"$")+)?; 11 | cvsdat = "Date"; 12 | cvsid = "Id"; 13 | cvslog = "Log"; 14 | cvsrev = "Revision"; 15 | cvssrc = "Source"; 16 | */ 17 | 18 | #define APPEND(text) \ 19 | append(output, outsize, text, sizeof(text) - sizeof(YYCTYPE)) 20 | 21 | inline void append(YYCTYPE *output, size_t & outsize, const YYCTYPE * text, size_t len) 22 | { 23 | memcpy(output + outsize, text, len); 24 | outsize += (len / sizeof(YYCTYPE)); 25 | } 26 | 27 | void scan(YYCTYPE *pText, size_t *pSize, int *pbChanged) 28 | { 29 | // rule 30 | // scan lines 31 | // find $ in lines 32 | // compact $: .. $ to $$ 33 | 34 | YYCTYPE *output; 35 | const YYCTYPE *cursor, *limit, *marker; 36 | 37 | cursor = marker = output = *pText; 38 | 39 | size_t insize = *pSize; 40 | size_t outsize = 0; 41 | 42 | limit = cursor + insize; 43 | 44 | while(1) { 45 | loop: 46 | /*!re2c 47 | 48 | "$" cvsdat value "$" { APPEND(L"$" L"Date$"); goto loop; } 49 | "$" cvsid value "$" { APPEND(L"$" L"Id$"); goto loop; } 50 | "$" cvslog value "$" { APPEND(L"$" L"Log$"); goto loop; } 51 | "$" cvsrev value "$" { APPEND(L"$" L"Revision$"); goto loop; } 52 | "$" cvssrc value "$" { APPEND(L"$" L"Source$"); goto loop; } 53 | any { output[outsize++] = cursor[-1]; if (cursor >= limit) break; goto loop; } 54 | 55 | */ 56 | } 57 | output[outsize] = '\0'; 58 | 59 | // set the new size 60 | *pSize = outsize; 61 | 62 | *pbChanged = (insize == outsize) ? 0 : 1; 63 | } 64 | -------------------------------------------------------------------------------- /re2c/test/cvsignore.wb.re: -------------------------------------------------------------------------------- 1 | 2 | #define YYFILL(n) if (cursor >= limit) break; 3 | #define YYCTYPE unsigned short 4 | #define YYCURSOR cursor 5 | #define YYLIMIT limit 6 | #define YYMARKER marker 7 | 8 | /*!re2c 9 | any = (.|"\n"); 10 | value = (":" (.\"$")+)?; 11 | cvsdat = "Date"; 12 | cvsid = "Id"; 13 | cvslog = "Log"; 14 | cvsrev = "Revision"; 15 | cvssrc = "Source"; 16 | */ 17 | 18 | #define APPEND(text) \ 19 | append(output, outsize, text, sizeof(text) - sizeof(YYCTYPE)) 20 | 21 | inline void append(YYCTYPE *output, size_t & outsize, const YYCTYPE * text, size_t len) 22 | { 23 | memcpy(output + outsize, text, len); 24 | outsize += (len / sizeof(YYCTYPE)); 25 | } 26 | 27 | void scan(YYCTYPE *pText, size_t *pSize, int *pbChanged) 28 | { 29 | // rule 30 | // scan lines 31 | // find $ in lines 32 | // compact $: .. $ to $$ 33 | 34 | YYCTYPE *output; 35 | const YYCTYPE *cursor, *limit, *marker; 36 | 37 | cursor = marker = output = *pText; 38 | 39 | size_t insize = *pSize; 40 | size_t outsize = 0; 41 | 42 | limit = cursor + insize; 43 | 44 | while(1) { 45 | loop: 46 | /*!re2c 47 | 48 | "$" cvsdat value "$" { APPEND(L"$" L"Date$"); goto loop; } 49 | "$" cvsid value "$" { APPEND(L"$" L"Id$"); goto loop; } 50 | "$" cvslog value "$" { APPEND(L"$" L"Log$"); goto loop; } 51 | "$" cvsrev value "$" { APPEND(L"$" L"Revision$"); goto loop; } 52 | "$" cvssrc value "$" { APPEND(L"$" L"Source$"); goto loop; } 53 | any { output[outsize++] = cursor[-1]; if (cursor >= limit) break; goto loop; } 54 | 55 | */ 56 | } 57 | output[outsize] = '\0'; 58 | 59 | // set the new size 60 | *pSize = outsize; 61 | 62 | *pbChanged = (insize == outsize) ? 0 : 1; 63 | } 64 | -------------------------------------------------------------------------------- /re2c/test/dot.D.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | 3 | digraph re2c { 4 | 5 | 6 | 1 -> 2 [label="a"] 7 | 1 -> 4 [label="e"] 8 | 1 -> 5 [label=default] 9 | 2 -> 10 [label="b"] 10 | 2 -> 3 [label=default] 11 | 3 [label="dot.D.re:8"]; 12 | 4 -> 6 [label="f"] 13 | 4 -> 3 [label=default] 14 | 5 -> 3 15 | 6 -> 8 [label="g"] 16 | 6 -> 7 [label=default] 17 | 7 -> 3 18 | 8 -> 9 19 | 9 [label="dot.D.re:7"]; 20 | 10 -> 11 [label="c"] 21 | 10 -> 7 [label=default] 22 | 11 -> 12 23 | 12 [label="dot.D.re:6"]; 24 | } 25 | -------------------------------------------------------------------------------- /re2c/test/dot.D.re: -------------------------------------------------------------------------------- 1 | int main(){ 2 | printf("some code that will be stripped"); 3 | 4 | /*!re2c 5 | 6 | "abc" { return 1; } 7 | "efg" { return 2; } 8 | [^] { return 3; } 9 | 10 | */ 11 | 12 | printf("here too"); 13 | } 14 | -------------------------------------------------------------------------------- /re2c/test/dot_conditions.Dc.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | 3 | digraph re2c { 4 | 5 | 0 -> state1 [label="state=state1"] 6 | 0 -> state2 [label="state=state2"] 7 | /* *********************************** */ 8 | state1 -> 1 9 | 10 | 1 -> 3 [label="a"] 11 | 1 -> 4 [label="f"] 12 | 1 -> 2 [label=default] 13 | 3 -> 8 [label="b"] 14 | 3 -> 2 [label=default] 15 | 4 -> 5 [label="o"] 16 | 4 -> 2 [label=default] 17 | 5 -> 6 [label="o"] 18 | 5 -> 2 [label=default] 19 | 6 -> 7 20 | 7 [label="dot_conditions.Dc.re:8"]; 21 | 8 -> 9 [label="c"] 22 | 8 -> 2 [label=default] 23 | 9 -> 10 24 | 10 [label="dot_conditions.Dc.re:6"]; 25 | /* *********************************** */ 26 | state2 -> 12 27 | 12 -> 14 [label="a"] 28 | 12 -> 13 [label=default] 29 | 14 -> 15 [label="b"] 30 | 14 -> 13 [label=default] 31 | 15 -> 16 [label="c"] 32 | 15 -> 13 [label=default] 33 | 16 -> 17 34 | 17 [label="dot_conditions.Dc.re:7"]; 35 | } 36 | -------------------------------------------------------------------------------- /re2c/test/dot_conditions.Dc.re: -------------------------------------------------------------------------------- 1 | int main() { 2 | printf("some code that will be stripped"); 3 | 4 | /*!re2c 5 | 6 | "abc" { return 1; } 7 | "abc" { return 2; } 8 | "foo" { return 3; } 9 | 10 | */ 11 | 12 | printf("here too\n"); 13 | } 14 | -------------------------------------------------------------------------------- /re2c/test/error1.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 18, column 5: illegal closure form, use '{n}', '{n,}', '{n,m}' where n and m are numbers 2 | -------------------------------------------------------------------------------- /re2c/test/error1.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define RET(n) return n 6 | 7 | int scan(const char *s, int l) { 8 | const char *p = s; 9 | const char *q; 10 | #define YYCTYPE char 11 | #define YYCURSOR p 12 | #define YYLIMIT (s+l) 13 | #define YYMARKER q 14 | #define YYFILL(n) 15 | /*!re2c 16 | any = [\000-\377]; 17 | 18 | 'a'{,}"\n" {RET(1);} 19 | any {RET(0);} 20 | */ 21 | } 22 | -------------------------------------------------------------------------------- /re2c/test/error10.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 2, column 6: Illegal unicode character, eight hexadecimal digits are required 2 | -------------------------------------------------------------------------------- /re2c/test/error10.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | [\U00900000YY] {} 3 | */ 4 | -------------------------------------------------------------------------------- /re2c/test/error11.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 2, column 9: Illegal unicode character, non hexadecimal digit found 2 | -------------------------------------------------------------------------------- /re2c/test/error11.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | [\U00000ZZZYY] {} 3 | */ 4 | -------------------------------------------------------------------------------- /re2c/test/error12.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 3, column 17: trailing contexts are not allowed in named definitions 2 | -------------------------------------------------------------------------------- /re2c/test/error12.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | DEF1 = ("a"|"b")/[1] ; 4 | DEF2 = ("a"|"b")/[0-9]+ ; 5 | 6 | DEF1 { return KEYWORD; } 7 | DEF2 { return KEYWORD; } 8 | [0-9]+ { return NUMBER; } 9 | 10 | [^] { return UNEXPECTED; } 11 | 12 | */ 13 | -------------------------------------------------------------------------------- /re2c/test/error13.1.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "error13.1.re" 3 | #define YYMAXFILL 1 4 | 5 | re2c: error: line 3, column 1: found scanner block after YYMAXFILL declaration 6 | -------------------------------------------------------------------------------- /re2c/test/error13.1.re: -------------------------------------------------------------------------------- 1 | /*!max:re2c */ 2 | 3 | /*!re2c 4 | "ABC" { return 1; } 5 | "ABD" { return 2; } 6 | [^] { return 0; } 7 | */ 8 | -------------------------------------------------------------------------------- /re2c/test/error13.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "error13.re" 3 | #define YYMAXFILL 3 4 | 5 | 6 | #line 7 "" 7 | { 8 | YYCTYPE yych; 9 | 10 | if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); 11 | yych = *YYCURSOR; 12 | switch (yych) { 13 | case 'A': goto yy2; 14 | default: goto yy4; 15 | } 16 | yy2: 17 | yych = *(YYMARKER = ++YYCURSOR); 18 | switch (yych) { 19 | case 'B': goto yy5; 20 | default: goto yy3; 21 | } 22 | yy3: 23 | #line 6 "error13.re" 24 | { return 0; } 25 | #line 26 "" 26 | yy4: 27 | yych = *++YYCURSOR; 28 | goto yy3; 29 | yy5: 30 | yych = *++YYCURSOR; 31 | switch (yych) { 32 | case 'C': goto yy7; 33 | case 'D': goto yy9; 34 | default: goto yy6; 35 | } 36 | yy6: 37 | YYCURSOR = YYMARKER; 38 | goto yy3; 39 | yy7: 40 | ++YYCURSOR; 41 | #line 4 "error13.re" 42 | { return 1; } 43 | #line 44 "" 44 | yy9: 45 | ++YYCURSOR; 46 | #line 5 "error13.re" 47 | { return 2; } 48 | #line 49 "" 49 | } 50 | #line 7 "error13.re" 51 | 52 | -------------------------------------------------------------------------------- /re2c/test/error13.re: -------------------------------------------------------------------------------- 1 | /*!max:re2c */ 2 | 3 | /*!re2c 4 | "ABC" { return 1; } 5 | "ABD" { return 2; } 6 | [^] { return 0; } 7 | */ 8 | -------------------------------------------------------------------------------- /re2c/test/error14.1.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "error14.1.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | 8 | if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); 9 | yych = *YYCURSOR; 10 | switch (yych) { 11 | case 'A': goto yy2; 12 | default: goto yy4; 13 | } 14 | yy2: 15 | yych = *(YYMARKER = ++YYCURSOR); 16 | switch (yych) { 17 | case 'B': goto yy5; 18 | default: goto yy3; 19 | } 20 | yy3: 21 | #line 4 "error14.1.re" 22 | { return 0; } 23 | #line 24 "" 24 | yy4: 25 | yych = *++YYCURSOR; 26 | goto yy3; 27 | yy5: 28 | yych = *++YYCURSOR; 29 | switch (yych) { 30 | case 'C': goto yy7; 31 | case 'D': goto yy9; 32 | default: goto yy6; 33 | } 34 | yy6: 35 | YYCURSOR = YYMARKER; 36 | goto yy3; 37 | yy7: 38 | ++YYCURSOR; 39 | #line 2 "error14.1.re" 40 | { return 1; } 41 | #line 42 "" 42 | yy9: 43 | ++YYCURSOR; 44 | #line 3 "error14.1.re" 45 | { return 2; } 46 | #line 47 "" 47 | } 48 | #line 5 "error14.1.re" 49 | 50 | 51 | #define YYMAXFILL 3 52 | 53 | re2c: error: line 9, column 1: cannot generate YYMAXFILL twice 54 | -------------------------------------------------------------------------------- /re2c/test/error14.1.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | "ABC" { return 1; } 3 | "ABD" { return 2; } 4 | [^] { return 0; } 5 | */ 6 | 7 | /*!max:re2c */ 8 | 9 | /*!max:re2c */ 10 | -------------------------------------------------------------------------------- /re2c/test/error14.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 9, column 1: cannot generate YYMAXFILL twice 2 | -------------------------------------------------------------------------------- /re2c/test/error14.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | "ABC" { return 1; } 3 | "ABD" { return 2; } 4 | [^] { return 0; } 5 | */ 6 | 7 | /*!max:re2c */ 8 | 9 | /*!max:re2c */ 10 | -------------------------------------------------------------------------------- /re2c/test/error2.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 18, column 5: illegal closure form, use '{n}', '{n,}', '{n,m}' where n and m are numbers 2 | -------------------------------------------------------------------------------- /re2c/test/error2.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define RET(n) return n 6 | 7 | int scan(const char *s, int l) { 8 | const char *p = s; 9 | const char *q; 10 | #define YYCTYPE char 11 | #define YYCURSOR p 12 | #define YYLIMIT (s+l) 13 | #define YYMARKER q 14 | #define YYFILL(n) 15 | /*!re2c 16 | any = [\000-\377]; 17 | 18 | 'a'{0,b}"\n" {RET(1);} 19 | any {RET(0);} 20 | */ 21 | } 22 | -------------------------------------------------------------------------------- /re2c/test/error3.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 18, column 5: unexpected character: ']' 2 | -------------------------------------------------------------------------------- /re2c/test/error3.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define RET(n) return n 6 | 7 | int scan(const char *s, int l) { 8 | const char *p = s; 9 | const char *q; 10 | #define YYCTYPE char 11 | #define YYCURSOR p 12 | #define YYLIMIT (s+l) 13 | #define YYMARKER q 14 | #define YYFILL(n) 15 | /*!re2c 16 | any = [\000-\377]; 17 | 18 | [a]] {RET(1);} 19 | any {RET(0);} 20 | */ 21 | } 22 | -------------------------------------------------------------------------------- /re2c/test/error4.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 2, column 5: Illegal hexadecimal character code, two hexadecimal digits are required 2 | -------------------------------------------------------------------------------- /re2c/test/error4.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | [\x0] {} 3 | */ 4 | -------------------------------------------------------------------------------- /re2c/test/error5.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 2, column 5: Illegal hexadecimal character code 2 | -------------------------------------------------------------------------------- /re2c/test/error5.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | [\x0ZYY] {} 3 | */ 4 | -------------------------------------------------------------------------------- /re2c/test/error6.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 2, column 7: Illegal hexadecimal character code, four hexadecimal digits are required 2 | -------------------------------------------------------------------------------- /re2c/test/error6.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | [\X123] {} 3 | */ 4 | -------------------------------------------------------------------------------- /re2c/test/error7.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 2, column 3: Illegal octal character code, first digit must be 0 thru 3 2 | -------------------------------------------------------------------------------- /re2c/test/error7.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | [\400YY] {} 3 | */ 4 | -------------------------------------------------------------------------------- /re2c/test/error8.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 2, column 4: Illegal octal character code, non octal digit found 2 | -------------------------------------------------------------------------------- /re2c/test/error8.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | [\090YY] {} 3 | */ 4 | -------------------------------------------------------------------------------- /re2c/test/error9.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 2, column 5: Illegal octal character code, non octal digit found 2 | -------------------------------------------------------------------------------- /re2c/test/error9.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | [\009YY] {} 3 | */ 4 | -------------------------------------------------------------------------------- /re2c/test/flex-01.i.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 6, column 1: curly braces for names only allowed with -F switch 2 | -------------------------------------------------------------------------------- /re2c/test/flex-01.i.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | F1 = "a"; 4 | F2 = "b"; 5 | 6 | {F1} { return "a"; } 7 | {F2} { return "b"; } 8 | 9 | */ 10 | -------------------------------------------------------------------------------- /re2c/test/flex-01.iF.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | 3 | { 4 | YYCTYPE yych; 5 | 6 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 7 | yych = *YYCURSOR; 8 | switch (yych) { 9 | case 'a': goto yy3; 10 | case 'b': goto yy5; 11 | default: goto yy2; 12 | } 13 | yy2: 14 | yy3: 15 | ++YYCURSOR; 16 | { return "a"; } 17 | yy5: 18 | ++YYCURSOR; 19 | { return "b"; } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /re2c/test/flex-01.iF.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | F1 = "a"; 4 | F2 = "b"; 5 | 6 | {F1} { return "a"; } 7 | {F2} { return "b"; } 8 | 9 | */ 10 | -------------------------------------------------------------------------------- /re2c/test/input1.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "input1.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | 8 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 9 | yych = *YYCURSOR; 10 | switch (yych) { 11 | case 'a': goto yy2; 12 | default: goto yy4; 13 | } 14 | yy2: 15 | yych = *(YYMARKER = ++YYCURSOR); 16 | switch (yych) { 17 | case 'b': goto yy5; 18 | default: goto yy3; 19 | } 20 | yy3: 21 | #line 4 "input1.re" 22 | { return 0; } 23 | #line 24 "" 24 | yy4: 25 | yych = *++YYCURSOR; 26 | goto yy3; 27 | yy5: 28 | ++YYCURSOR; 29 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 30 | yych = *YYCURSOR; 31 | switch (yych) { 32 | case 'b': goto yy5; 33 | case 'c': goto yy8; 34 | default: goto yy7; 35 | } 36 | yy7: 37 | YYCURSOR = YYMARKER; 38 | goto yy3; 39 | yy8: 40 | yych = *++YYCURSOR; 41 | switch (yych) { 42 | case 'c': goto yy9; 43 | default: goto yy7; 44 | } 45 | yy9: 46 | ++YYCURSOR; 47 | #line 3 "input1.re" 48 | { return 1; } 49 | #line 50 "" 50 | } 51 | #line 6 "input1.re" 52 | 53 | -------------------------------------------------------------------------------- /re2c/test/input1.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | [a][b]+ "cc" { return 1; } 4 | [\000-\377] { return 0; } 5 | 6 | */ 7 | -------------------------------------------------------------------------------- /re2c/test/input10.b.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "input10.b.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | 8 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 9 | yych = *YYCURSOR; 10 | if (yych <= 'E') { 11 | if (yych <= '@') goto yy4; 12 | if (yych >= 'E') goto yy4; 13 | } else { 14 | if (yych <= 'G') goto yy2; 15 | if (yych <= '`') goto yy4; 16 | if (yych >= 'h') goto yy4; 17 | } 18 | yy2: 19 | ++YYCURSOR; 20 | #line 8 "input10.b.re" 21 | { return 1; } 22 | #line 23 "" 23 | yy4: 24 | ++YYCURSOR; 25 | #line 10 "input10.b.re" 26 | { return -1; } 27 | #line 28 "" 28 | } 29 | #line 12 "input10.b.re" 30 | 31 | -------------------------------------------------------------------------------- /re2c/test/input10.b.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | a = [aA]; 4 | b = [bB]; 5 | c = [cC]; 6 | d = [dD]; 7 | 8 | (a|b|c|d|"e"|'f'|[gG]) { return 1; } 9 | 10 | .|"\n" { return -1; } 11 | 12 | */ 13 | -------------------------------------------------------------------------------- /re2c/test/input10.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "input10.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | 8 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 9 | yych = *YYCURSOR; 10 | switch (yych) { 11 | case 'A': 12 | case 'B': 13 | case 'C': 14 | case 'D': 15 | case 'F': 16 | case 'G': 17 | case 'a': 18 | case 'b': 19 | case 'c': 20 | case 'd': 21 | case 'e': 22 | case 'f': 23 | case 'g': goto yy2; 24 | default: goto yy4; 25 | } 26 | yy2: 27 | ++YYCURSOR; 28 | #line 8 "input10.re" 29 | { return 1; } 30 | #line 31 "" 31 | yy4: 32 | ++YYCURSOR; 33 | #line 10 "input10.re" 34 | { return -1; } 35 | #line 36 "" 36 | } 37 | #line 12 "input10.re" 38 | 39 | -------------------------------------------------------------------------------- /re2c/test/input10.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | a = [aA]; 4 | b = [bB]; 5 | c = [cC]; 6 | d = [dD]; 7 | 8 | (a|b|c|d|"e"|'f'|[gG]) { return 1; } 9 | 10 | .|"\n" { return -1; } 11 | 12 | */ 13 | -------------------------------------------------------------------------------- /re2c/test/input10.s.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "input10.s.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | 8 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 9 | yych = *YYCURSOR; 10 | if (yych <= 'E') { 11 | if (yych <= '@') goto yy4; 12 | if (yych >= 'E') goto yy4; 13 | } else { 14 | if (yych <= 'G') goto yy2; 15 | if (yych <= '`') goto yy4; 16 | if (yych >= 'h') goto yy4; 17 | } 18 | yy2: 19 | ++YYCURSOR; 20 | #line 8 "input10.s.re" 21 | { return 1; } 22 | #line 23 "" 23 | yy4: 24 | ++YYCURSOR; 25 | #line 10 "input10.s.re" 26 | { return -1; } 27 | #line 28 "" 28 | } 29 | #line 12 "input10.s.re" 30 | 31 | -------------------------------------------------------------------------------- /re2c/test/input10.s.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | a = [aA]; 4 | b = [bB]; 5 | c = [cC]; 6 | d = [dD]; 7 | 8 | (a|b|c|d|"e"|'f'|[gG]) { return 1; } 9 | 10 | .|"\n" { return -1; } 11 | 12 | */ 13 | -------------------------------------------------------------------------------- /re2c/test/input11.b.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | re2c:yybm:hex = 1; 4 | 5 | letter = [a-zA-Z]; 6 | digit = [0-9]; 7 | number = "0" | ("-"? [1-9] digit*); 8 | name = letter (letter|digit)*; 9 | config = "re2c:" (letter|"_") (letter|digit|"_"|":")*; 10 | 11 | config { return 0; } 12 | name { return 1; } 13 | number { return 2; } 14 | 15 | .|"\n" { return -1; } 16 | 17 | */ 18 | -------------------------------------------------------------------------------- /re2c/test/input11.i.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | letter = [a-zA-Z]; 4 | digit = [0-9]; 5 | number = "0" | ("-"? [1-9] digit*); 6 | name = letter (letter|digit)*; 7 | config = "re2c:" (letter|"_") (letter|digit|"_"|":")*; 8 | 9 | config { return 0; } 10 | name { return 1; } 11 | number { return 2; } 12 | 13 | .|"\n" { return -1; } 14 | 15 | */ 16 | -------------------------------------------------------------------------------- /re2c/test/input11.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | letter = [a-zA-Z]; 4 | digit = [0-9]; 5 | number = "0" | ("-"? [1-9] digit*); 6 | name = letter (letter|digit)*; 7 | config = "re2c:" (letter|"_") (letter|digit|"_"|":")*; 8 | 9 | config { return 0; } 10 | name { return 1; } 11 | number { return 2; } 12 | 13 | .|"\n" { return -1; } 14 | 15 | */ 16 | -------------------------------------------------------------------------------- /re2c/test/input11.s.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | letter = [a-zA-Z]; 4 | digit = [0-9]; 5 | number = "0" | ("-"? [1-9] digit*); 6 | name = letter (letter|digit)*; 7 | config = "re2c:" (letter|"_") (letter|digit|"_"|":")*; 8 | 9 | config { return 0; } 10 | name { return 1; } 11 | number { return 2; } 12 | 13 | .|"\n" { return -1; } 14 | 15 | */ 16 | -------------------------------------------------------------------------------- /re2c/test/input12.boinput12.c.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "input12.boinput12.c.re" 3 | 4 | #line 5 "input12.c" 5 | { 6 | YYCTYPE yych; 7 | static const unsigned char yybm[] = { 8 | 0, 0, 0, 0, 0, 0, 0, 0, 9 | 0, 0, 0, 0, 0, 0, 0, 0, 10 | 0, 0, 0, 0, 0, 0, 0, 0, 11 | 0, 0, 0, 0, 0, 0, 0, 0, 12 | 0, 0, 0, 0, 0, 0, 0, 0, 13 | 0, 0, 0, 0, 0, 0, 0, 0, 14 | 0, 0, 0, 0, 0, 0, 0, 0, 15 | 0, 0, 0, 0, 0, 0, 0, 0, 16 | 0, 0, 0, 0, 0, 0, 0, 0, 17 | 0, 0, 0, 0, 0, 0, 0, 0, 18 | 0, 0, 0, 0, 0, 0, 0, 0, 19 | 0, 0, 0, 0, 0, 0, 0, 0, 20 | 0, 128, 0, 0, 0, 0, 0, 0, 21 | 0, 0, 0, 0, 0, 0, 0, 0, 22 | 0, 0, 0, 0, 0, 0, 0, 0, 23 | 0, 0, 0, 0, 0, 0, 0, 0, 24 | 0, 0, 0, 0, 0, 0, 0, 0, 25 | 0, 0, 0, 0, 0, 0, 0, 0, 26 | 0, 0, 0, 0, 0, 0, 0, 0, 27 | 0, 0, 0, 0, 0, 0, 0, 0, 28 | 0, 0, 0, 0, 0, 0, 0, 0, 29 | 0, 0, 0, 0, 0, 0, 0, 0, 30 | 0, 0, 0, 0, 0, 0, 0, 0, 31 | 0, 0, 0, 0, 0, 0, 0, 0, 32 | 0, 0, 0, 0, 0, 0, 0, 0, 33 | 0, 0, 0, 0, 0, 0, 0, 0, 34 | 0, 0, 0, 0, 0, 0, 0, 0, 35 | 0, 0, 0, 0, 0, 0, 0, 0, 36 | 0, 0, 0, 0, 0, 0, 0, 0, 37 | 0, 0, 0, 0, 0, 0, 0, 0, 38 | 0, 0, 0, 0, 0, 0, 0, 0, 39 | 0, 0, 0, 0, 0, 0, 0, 0, 40 | }; 41 | 42 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 43 | yych = *YYCURSOR; 44 | if (yybm[0+yych] & 128) { 45 | goto yy3; 46 | } 47 | yy2: 48 | yy3: 49 | ++YYCURSOR; 50 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 51 | yych = *YYCURSOR; 52 | if (yybm[0+yych] & 128) { 53 | goto yy3; 54 | } 55 | if (yych != 'b') goto yy2; 56 | yych = *++YYCURSOR; 57 | if (yych != 'b') goto yy2; 58 | ++YYCURSOR; 59 | #line 3 "input12.boinput12.c.re" 60 | { return 1; } 61 | #line 62 "input12.c" 62 | } 63 | #line 5 "input12.boinput12.c.re" 64 | 65 | -------------------------------------------------------------------------------- /re2c/test/input12.boinput12.c.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | [a]+ "bb" { return 1; } 4 | 5 | */ 6 | -------------------------------------------------------------------------------- /re2c/test/input12.oinput12.c.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "input12.oinput12.c.re" 3 | 4 | #line 5 "input12.c" 5 | { 6 | YYCTYPE yych; 7 | 8 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 9 | yych = *YYCURSOR; 10 | switch (yych) { 11 | case 'a': goto yy3; 12 | default: goto yy2; 13 | } 14 | yy2: 15 | yy3: 16 | ++YYCURSOR; 17 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 18 | yych = *YYCURSOR; 19 | switch (yych) { 20 | case 'a': goto yy3; 21 | case 'b': goto yy5; 22 | default: goto yy2; 23 | } 24 | yy5: 25 | yych = *++YYCURSOR; 26 | switch (yych) { 27 | case 'b': goto yy6; 28 | default: goto yy2; 29 | } 30 | yy6: 31 | ++YYCURSOR; 32 | #line 3 "input12.oinput12.c.re" 33 | { return 1; } 34 | #line 35 "input12.c" 35 | } 36 | #line 5 "input12.oinput12.c.re" 37 | 38 | -------------------------------------------------------------------------------- /re2c/test/input12.oinput12.c.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | [a]+ "bb" { return 1; } 4 | 5 | */ 6 | -------------------------------------------------------------------------------- /re2c/test/input13.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "input13.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | 8 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 9 | yych = *YYCURSOR; 10 | switch (yych) { 11 | case 'a': goto yy2; 12 | case 'b': goto yy4; 13 | case 'c': goto yy6; 14 | case 'd': goto yy8; 15 | default: goto yy10; 16 | } 17 | yy2: 18 | ++YYCURSOR; 19 | #line 8 "input13.re" 20 | { return 'a'; } 21 | #line 22 "" 22 | yy4: 23 | ++YYCURSOR; 24 | #line 9 "input13.re" 25 | { return 'b'; } 26 | #line 27 "" 27 | yy6: 28 | ++YYCURSOR; 29 | #line 10 "input13.re" 30 | { return 'c'; } 31 | #line 32 "" 32 | yy8: 33 | ++YYCURSOR; 34 | #line 11 "input13.re" 35 | { return 'd'; } 36 | #line 37 "" 37 | yy10: 38 | ++YYCURSOR; 39 | #line 12 "input13.re" 40 | { return '\0'; } 41 | #line 42 "" 42 | } 43 | #line 14 "input13.re" 44 | 45 | -------------------------------------------------------------------------------- /re2c/test/input13.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | space_ = "a"; 4 | _space = "b"; 5 | s_pace = "c"; 6 | _ = "d"; 7 | 8 | space_ { return 'a'; } 9 | _space { return 'b'; } 10 | s_pace { return 'c'; } 11 | _ { return 'd'; } 12 | [^] { return '\0'; } 13 | 14 | */ 15 | -------------------------------------------------------------------------------- /re2c/test/input2.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "input2.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | 8 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 9 | yych = *YYCURSOR; 10 | switch (yych) { 11 | case 'a': goto yy3; 12 | default: goto yy2; 13 | } 14 | yy2: 15 | yy3: 16 | ++YYCURSOR; 17 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 18 | yych = *YYCURSOR; 19 | switch (yych) { 20 | case 'a': goto yy3; 21 | case 'b': goto yy5; 22 | default: goto yy2; 23 | } 24 | yy5: 25 | yych = *++YYCURSOR; 26 | switch (yych) { 27 | case 'b': goto yy6; 28 | default: goto yy2; 29 | } 30 | yy6: 31 | ++YYCURSOR; 32 | #line 3 "input2.re" 33 | { return 1; } 34 | #line 35 "" 35 | } 36 | #line 5 "input2.re" 37 | 38 | -------------------------------------------------------------------------------- /re2c/test/input2.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | [a]+ "bb" { return 1; } 4 | 5 | */ 6 | -------------------------------------------------------------------------------- /re2c/test/input3.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "input3.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | 8 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 9 | yych = *YYCURSOR; 10 | switch (yych) { 11 | case 'a': goto yy3; 12 | default: goto yy2; 13 | } 14 | yy2: 15 | yy3: 16 | ++YYCURSOR; 17 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 18 | yych = *YYCURSOR; 19 | switch (yych) { 20 | case 'a': goto yy3; 21 | case 'b': goto yy5; 22 | default: goto yy2; 23 | } 24 | yy5: 25 | yych = *++YYCURSOR; 26 | switch (yych) { 27 | case 'b': goto yy6; 28 | default: goto yy2; 29 | } 30 | yy6: 31 | ++YYCURSOR; 32 | #line 3 "input3.re" 33 | { return 1; } 34 | #line 35 "" 35 | } 36 | #line 5 "input3.re" 37 | 38 | -------------------------------------------------------------------------------- /re2c/test/input3.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | "a" [a]* "bb" { return 1; } 4 | 5 | */ 6 | -------------------------------------------------------------------------------- /re2c/test/input4.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "input4.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | 8 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 9 | yych = *YYCURSOR; 10 | goto yy3; 11 | #line 3 "input4.re" 12 | { return 0; } 13 | #line 14 "" 14 | yy3: 15 | ++YYCURSOR; 16 | #line 4 "input4.re" 17 | { return 1; } 18 | #line 19 "" 19 | } 20 | #line 7 "input4.re" 21 | 22 | -------------------------------------------------------------------------------- /re2c/test/input4.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | [] { return 0; } 4 | [^] { return 1; } 5 | [\000-\377] { return 2; } 6 | 7 | */ 8 | -------------------------------------------------------------------------------- /re2c/test/input5.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "input5.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | 8 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 9 | yych = *YYCURSOR; 10 | switch (yych) { 11 | case 'a': goto yy2; 12 | default: goto yy4; 13 | } 14 | yy2: 15 | ++YYCURSOR; 16 | #line 3 "input5.re" 17 | { return 0; } 18 | #line 19 "" 19 | yy4: 20 | ++YYCURSOR; 21 | #line 4 "input5.re" 22 | { return 1; } 23 | #line 24 "" 24 | } 25 | #line 6 "input5.re" 26 | 27 | -------------------------------------------------------------------------------- /re2c/test/input5.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | [a] { return 0; } 4 | [^a] { return 1; } 5 | 6 | */ 7 | -------------------------------------------------------------------------------- /re2c/test/input6.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "input6.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | 8 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 9 | yych = *YYCURSOR; 10 | goto yy3; 11 | #line 3 "input6.re" 12 | { return 0; } 13 | #line 14 "" 14 | yy3: 15 | ++YYCURSOR; 16 | #line 4 "input6.re" 17 | { return 1; } 18 | #line 19 "" 19 | } 20 | #line 6 "input6.re" 21 | 22 | -------------------------------------------------------------------------------- /re2c/test/input6.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | []/[] { return 0; } 4 | [\000-\377] { return 1; } 5 | 6 | */ 7 | -------------------------------------------------------------------------------- /re2c/test/input7.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "input7.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | 8 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 9 | yych = *YYCURSOR; 10 | switch (yych) { 11 | case '\n': goto yy4; 12 | default: goto yy2; 13 | } 14 | yy2: 15 | ++YYCURSOR; 16 | #line 5 "input7.re" 17 | { return 0; } 18 | #line 19 "" 19 | yy4: 20 | ++YYCURSOR; 21 | #line 6 "input7.re" 22 | { return 1; } 23 | #line 24 "" 24 | } 25 | #line 8 "input7.re" 26 | 27 | -------------------------------------------------------------------------------- /re2c/test/input7.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | any = [\000-\377]; 4 | 5 | . { return 0; } 6 | any { return 1; } 7 | 8 | */ 9 | -------------------------------------------------------------------------------- /re2c/test/input8.b.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "input8.b.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | unsigned int yyaccept = 0; 8 | 9 | if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4); 10 | yych = *YYCURSOR; 11 | if (yych == '\n') goto yy4; 12 | yyaccept = 0; 13 | yych = *(YYMARKER = ++YYCURSOR); 14 | if (yych <= 0x00) goto yy6; 15 | if (yych != '\n') goto yy8; 16 | yy3: 17 | #line 6 "input8.b.re" 18 | { return 1; } 19 | #line 20 "" 20 | yy4: 21 | ++YYCURSOR; 22 | #line 7 "input8.b.re" 23 | { return 2; } 24 | #line 25 "" 25 | yy6: 26 | yyaccept = 1; 27 | yych = *(YYMARKER = ++YYCURSOR); 28 | if (yych <= 0x00) goto yy10; 29 | if (yych != '\n') goto yy11; 30 | yy7: 31 | #line 5 "input8.b.re" 32 | { return 0; } 33 | #line 34 "" 34 | yy8: 35 | yych = *++YYCURSOR; 36 | if (yych <= 0x00) goto yy10; 37 | if (yych != '\n') goto yy11; 38 | yy9: 39 | YYCURSOR = YYMARKER; 40 | if (yyaccept <= 0) { 41 | goto yy3; 42 | } else { 43 | goto yy7; 44 | } 45 | yy10: 46 | yych = *++YYCURSOR; 47 | if (yych <= 0x00) goto yy12; 48 | goto yy7; 49 | yy11: 50 | yych = *++YYCURSOR; 51 | if (yych >= 0x01) goto yy9; 52 | yy12: 53 | ++YYCURSOR; 54 | yych = *YYCURSOR; 55 | goto yy7; 56 | } 57 | #line 9 "input8.b.re" 58 | 59 | -------------------------------------------------------------------------------- /re2c/test/input8.b.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | any = [\000-\377]; 4 | 5 | .{1,3}"\000" { return 0; } 6 | . { return 1; } 7 | any { return 2; } 8 | 9 | */ 10 | -------------------------------------------------------------------------------- /re2c/test/input8.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "input8.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | unsigned int yyaccept = 0; 8 | 9 | if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4); 10 | yych = *YYCURSOR; 11 | switch (yych) { 12 | case '\n': goto yy4; 13 | default: goto yy2; 14 | } 15 | yy2: 16 | yyaccept = 0; 17 | yych = *(YYMARKER = ++YYCURSOR); 18 | switch (yych) { 19 | case 0x00: goto yy6; 20 | case '\n': goto yy3; 21 | default: goto yy8; 22 | } 23 | yy3: 24 | #line 6 "input8.re" 25 | { return 1; } 26 | #line 27 "" 27 | yy4: 28 | ++YYCURSOR; 29 | #line 7 "input8.re" 30 | { return 2; } 31 | #line 32 "" 32 | yy6: 33 | yyaccept = 1; 34 | yych = *(YYMARKER = ++YYCURSOR); 35 | switch (yych) { 36 | case 0x00: goto yy10; 37 | case '\n': goto yy7; 38 | default: goto yy11; 39 | } 40 | yy7: 41 | #line 5 "input8.re" 42 | { return 0; } 43 | #line 44 "" 44 | yy8: 45 | yych = *++YYCURSOR; 46 | switch (yych) { 47 | case 0x00: goto yy10; 48 | case '\n': goto yy9; 49 | default: goto yy11; 50 | } 51 | yy9: 52 | YYCURSOR = YYMARKER; 53 | switch (yyaccept) { 54 | case 0: goto yy3; 55 | case 1: goto yy7; 56 | } 57 | yy10: 58 | yych = *++YYCURSOR; 59 | if (yych <= 0x00) goto yy12; 60 | goto yy7; 61 | yy11: 62 | yych = *++YYCURSOR; 63 | if (yych >= 0x01) goto yy9; 64 | yy12: 65 | ++YYCURSOR; 66 | yych = *YYCURSOR; 67 | goto yy7; 68 | } 69 | #line 9 "input8.re" 70 | 71 | -------------------------------------------------------------------------------- /re2c/test/input8.g.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "input8.g.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | unsigned int yyaccept = 0; 8 | 9 | if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4); 10 | yych = *YYCURSOR; 11 | if (yych == '\n') goto yy4; 12 | yyaccept = 0; 13 | yych = *(YYMARKER = ++YYCURSOR); 14 | if (yych <= 0x00) goto yy6; 15 | if (yych != '\n') goto yy8; 16 | yy3: 17 | #line 6 "input8.g.re" 18 | { return 1; } 19 | #line 20 "" 20 | yy4: 21 | ++YYCURSOR; 22 | #line 7 "input8.g.re" 23 | { return 2; } 24 | #line 25 "" 25 | yy6: 26 | yyaccept = 1; 27 | yych = *(YYMARKER = ++YYCURSOR); 28 | if (yych <= 0x00) goto yy10; 29 | if (yych != '\n') goto yy11; 30 | yy7: 31 | #line 5 "input8.g.re" 32 | { return 0; } 33 | #line 34 "" 34 | yy8: 35 | yych = *++YYCURSOR; 36 | if (yych <= 0x00) goto yy10; 37 | if (yych != '\n') goto yy11; 38 | yy9: 39 | YYCURSOR = YYMARKER; 40 | if (yyaccept <= 0) { 41 | goto yy3; 42 | } else { 43 | goto yy7; 44 | } 45 | yy10: 46 | yych = *++YYCURSOR; 47 | if (yych <= 0x00) goto yy12; 48 | goto yy7; 49 | yy11: 50 | yych = *++YYCURSOR; 51 | if (yych >= 0x01) goto yy9; 52 | yy12: 53 | ++YYCURSOR; 54 | yych = *YYCURSOR; 55 | goto yy7; 56 | } 57 | #line 9 "input8.g.re" 58 | 59 | -------------------------------------------------------------------------------- /re2c/test/input8.g.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | any = [\000-\377]; 4 | 5 | .{1,3}"\000" { return 0; } 6 | . { return 1; } 7 | any { return 2; } 8 | 9 | */ 10 | -------------------------------------------------------------------------------- /re2c/test/input8.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | any = [\000-\377]; 4 | 5 | .{1,3}"\000" { return 0; } 6 | . { return 1; } 7 | any { return 2; } 8 | 9 | */ 10 | -------------------------------------------------------------------------------- /re2c/test/input9.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "input9.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | 8 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 9 | yych = *YYCURSOR; 10 | switch (yych) { 11 | case 0x00: goto yy2; 12 | case 0x01: goto yy4; 13 | case 0x02: goto yy16; 14 | case 0x07: goto yy6; 15 | case 0x08: goto yy8; 16 | case ' ': goto yy18; 17 | case '4': goto yy20; 18 | case '@': goto yy10; 19 | case 'S': goto yy12; 20 | case 0xAB: goto yy22; 21 | case 0xCD: goto yy24; 22 | case 0xEE: goto yy14; 23 | default: goto yy26; 24 | } 25 | yy2: 26 | ++YYCURSOR; 27 | #line 5 "input9.re" 28 | { return 1; } 29 | #line 30 "" 30 | yy4: 31 | ++YYCURSOR; 32 | #line 6 "input9.re" 33 | { return 2; } 34 | #line 35 "" 35 | yy6: 36 | ++YYCURSOR; 37 | #line 7 "input9.re" 38 | { return 3; } 39 | #line 40 "" 40 | yy8: 41 | ++YYCURSOR; 42 | #line 8 "input9.re" 43 | { return 4; } 44 | #line 45 "" 45 | yy10: 46 | ++YYCURSOR; 47 | #line 9 "input9.re" 48 | { return 5; } 49 | #line 50 "" 50 | yy12: 51 | ++YYCURSOR; 52 | #line 10 "input9.re" 53 | { return 6; } 54 | #line 55 "" 55 | yy14: 56 | ++YYCURSOR; 57 | switch ((yych = *YYCURSOR)) { 58 | case '7': goto yy27; 59 | default: goto yy15; 60 | } 61 | yy15: 62 | #line 18 "input9.re" 63 | { return 0; } 64 | #line 65 "" 65 | yy16: 66 | ++YYCURSOR; 67 | #line 13 "input9.re" 68 | { return 8; } 69 | #line 70 "" 70 | yy18: 71 | ++YYCURSOR; 72 | #line 14 "input9.re" 73 | { return 9; } 74 | #line 75 "" 75 | yy20: 76 | ++YYCURSOR; 77 | #line 15 "input9.re" 78 | { return 10; } 79 | #line 80 "" 80 | yy22: 81 | ++YYCURSOR; 82 | #line 16 "input9.re" 83 | { return 11; } 84 | #line 85 "" 85 | yy24: 86 | ++YYCURSOR; 87 | #line 17 "input9.re" 88 | { return 12; } 89 | #line 90 "" 90 | yy26: 91 | yych = *++YYCURSOR; 92 | goto yy15; 93 | yy27: 94 | ++YYCURSOR; 95 | #line 11 "input9.re" 96 | { return 7; } 97 | #line 98 "" 98 | } 99 | #line 20 "input9.re" 100 | 101 | -------------------------------------------------------------------------------- /re2c/test/input9.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | 3 | any = [\000-\377]; 4 | 5 | "\000" { return 1; } 6 | "\001" { return 2; } 7 | "\007" { return 3; } 8 | "\010" { return 4; } 9 | "\100" { return 5; } 10 | "\123" { return 6; } 11 | "\3567" { return 7; } 12 | 13 | "\x02" { return 8; } 14 | "\x20" { return 9; } 15 | "\x34" { return 10; } 16 | "\xab" { return 11; } 17 | "\xCD" { return 12; } 18 | any { return 0; } 19 | 20 | */ 21 | -------------------------------------------------------------------------------- /re2c/test/line-01.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "line-01.re" 3 | const char* scan(unsigned char* in) 4 | { 5 | 6 | #line 7 "" 7 | { 8 | YYCTYPE yych; 9 | 10 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 11 | yych = *YYCURSOR; 12 | switch (yych) { 13 | case '\n': goto yy2; 14 | case 'a': goto yy3; 15 | case 'b': goto yy5; 16 | case 'c': goto yy7; 17 | case 'd': goto yy9; 18 | default: goto yy11; 19 | } 20 | yy2: 21 | yy3: 22 | ++YYCURSOR; 23 | #line 1 "a" 24 | { 25 | return "a"; 26 | } 27 | #line 28 "" 28 | yy5: 29 | ++YYCURSOR; 30 | #line 2 "b" 31 | { 32 | return "b"; 33 | } 34 | #line 35 "" 35 | yy7: 36 | ++YYCURSOR; 37 | #line 5 "b" 38 | { 39 | return "c"; 40 | } 41 | #line 42 "" 42 | yy9: 43 | ++YYCURSOR; 44 | #line 2 "d" 45 | { 46 | return "d"; 47 | } 48 | #line 49 "" 49 | yy11: 50 | ++YYCURSOR; 51 | #line 6 "d" 52 | { 53 | return "."; 54 | } 55 | #line 56 "" 56 | } 57 | #line 1 "e" 58 | 59 | } 60 | -------------------------------------------------------------------------------- /re2c/test/line-01.re: -------------------------------------------------------------------------------- 1 | const char* scan(unsigned char* in) 2 | { 3 | /*!re2c 4 | 5 | #line 1 "a" 6 | "a" { 7 | return "a"; 8 | } 9 | #line 2 "b" 10 | "b" { 11 | return "b"; 12 | } 13 | "c" { 14 | return "c"; 15 | } 16 | #line 1 "d" 17 | 18 | "d" { 19 | return "d"; 20 | } 21 | 22 | . { 23 | return "."; 24 | } 25 | #line 1 "e" 26 | */ 27 | } 28 | -------------------------------------------------------------------------------- /re2c/test/overflow-2.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 2, column 8219: can't find symbol 2 | -------------------------------------------------------------------------------- /re2c/test/overflow-3.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 2, column 8219: can't find symbol 2 | -------------------------------------------------------------------------------- /re2c/test/overflow-4.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "overflow-4.re" 3 | 4 | #line 5 "" 5 | { 6 | YYCTYPE yych; 7 | 8 | if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3); 9 | yych = *YYCURSOR; 10 | switch (yych) { 11 | case 'b': goto yy3; 12 | default: goto yy2; 13 | } 14 | yy2: 15 | yy3: 16 | yych = *++YYCURSOR; 17 | switch (yych) { 18 | case 'l': goto yy4; 19 | default: goto yy2; 20 | } 21 | yy4: 22 | yych = *++YYCURSOR; 23 | switch (yych) { 24 | case 'a': goto yy5; 25 | default: goto yy2; 26 | } 27 | yy5: 28 | ++YYCURSOR; 29 | #line 4 "overflow-4.re" 30 | { return "bla"; } 31 | #line 32 "" 32 | } 33 | #line 6 "overflow-4.re" 34 | -------------------------------------------------------------------------------- /re2c/test/push.fs.re: -------------------------------------------------------------------------------- 1 | uint32_t push() 2 | { 3 | // The scanner starts here 4 | #define YYLIMIT limit 5 | #define YYCURSOR cursor 6 | #define YYMARKER marker 7 | #define YYCTYPE uint8_t 8 | 9 | #define SKIP(x) { start = cursor; goto yy0; } 10 | #define SEND(x) { send(x); SKIP(); } 11 | #define YYFILL(n) { goto fill; } 12 | 13 | #define YYGETSTATE() state 14 | #define YYSETSTATE(x) { state = (x); } 15 | 16 | start: 17 | 18 | /*!re2c 19 | re2c:startlabel = 1; 20 | eol = "\n"; 21 | eof = "\000"; 22 | digit = [0-9]; 23 | integer = digit+; 24 | alpha = [A-Za-z_]; 25 | any = [\000-\377]; 26 | space = [ \h\t\v\f\r]; 27 | 28 | "if" { SEND(kIf); } 29 | "for" { SEND(kFor); } 30 | "else" { SEND(kElse); } 31 | "goto" { SEND(kGoto); } 32 | "break" { SEND(kBreak); } 33 | "while" { SEND(kWhile); } 34 | "return" { SEND(kReturn); } 35 | alpha (alpha|digit)* { SEND(kIdentifier); } 36 | integer { SEND(kDecimalConstant);} 37 | 38 | "=" { SEND(kEqual); } 39 | "(" { SEND(kLeftParen); } 40 | ")" { SEND(kRightParen); } 41 | "-" { SEND(kMinus); } 42 | "+" { SEND(kPlus); } 43 | "*" { SEND(kStar); } 44 | "/" { SEND(kSlash); } 45 | 46 | eol { SKIP(); } 47 | space { SKIP(); } 48 | eof { send(kEOF); return 1; } 49 | any { SEND(kUnknown); } 50 | */ 51 | 52 | fill: 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /re2c/test/repeat-00.cgi.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 5, column 1: found 'reules:re2c' block without -r flag 2 | -------------------------------------------------------------------------------- /re2c/test/repeat-00.cgi.re: -------------------------------------------------------------------------------- 1 | // multiples scanners 2 | 3 | void scan(unsigned char* in) 4 | { 5 | /*!rules:re2c 6 | 7 | <*> "1" { return "1"; } 8 | <*> "2" { return "2"; } 9 | "a" { return "a"; } 10 | "b" { return "b"; } 11 | */ 12 | 13 | /*!use:re2c 14 | 15 | re2c:define:YYCTYPE = 'unsigned char'; 16 | 17 | 18 | 19 | 20 | 21 | 22 | */ 23 | } 24 | 25 | void scan(unsigned short* in) 26 | { 27 | /*!use:re2c 28 | 29 | 30 | 31 | 32 | 33 | 34 | */ 35 | } 36 | 37 | void scan(unsigned int* in) 38 | { 39 | /*!use:re2c 40 | 41 | 42 | 43 | 44 | 45 | 46 | */ 47 | } 48 | 49 | -------------------------------------------------------------------------------- /re2c/test/repeat-01.cgir.re: -------------------------------------------------------------------------------- 1 | // multiple scanners 2 | 3 | /*!types:re2c */ 4 | 5 | void scan(unsigned char* in) 6 | { 7 | /*!rules:re2c 8 | 9 | <*> "1" { return "1"; } 10 | <*> "2" { return "2"; } 11 | "a" { return "a"; } 12 | "b" { return "b"; } 13 | *//*!use:re2c 14 | 15 | re2c:define:YYCTYPE = 'unsigned char'; 16 | 17 | 18 | 19 | 20 | 21 | 22 | */ 23 | } 24 | 25 | void scan(unsigned short* in) 26 | { 27 | /*!use:re2c 28 | 29 | 30 | 31 | 32 | 33 | 34 | */ 35 | } 36 | 37 | void scan(unsigned int* in) 38 | { 39 | /*!use:re2c 40 | 41 | 42 | 43 | 44 | 45 | 46 | */ 47 | } 48 | 49 | -------------------------------------------------------------------------------- /re2c/test/repeat-02.cgir.re: -------------------------------------------------------------------------------- 1 | // multiple scanners 2 | 3 | /*!types:re2c */ 4 | 5 | void scan(unsigned char* in) 6 | { 7 | /*!rules:re2c 8 | 9 | <*> "1" { return "1"; } 10 | <*> "2" { return "2"; } 11 | "a" { return "a"; } 12 | "b" { return "b"; } 13 | *//*!use:re2c 14 | 15 | re2c:define:YYCTYPE = 'unsigned char'; 16 | re2c:define:YYFILL = 'fill1'; 17 | re2c:define:YYCURSOR = 'cursor1'; 18 | re2c:define:YYLIMIT = 'limit1'; 19 | 20 | */ 21 | } 22 | 23 | void scan(unsigned short* in) 24 | { 25 | /*!use:re2c 26 | 27 | re2c:define:YYCTYPE = 'unsigned short'; 28 | re2c:define:YYFILL = 'fill2'; 29 | re2c:define:YYCURSOR = 'cursor2'; 30 | re2c:define:YYLIMIT = 'limit2'; 31 | 32 | */ 33 | } 34 | 35 | void scan(unsigned int* in) 36 | { 37 | /*!use:re2c 38 | 39 | re2c:define:YYCTYPE = 'unsigned int'; 40 | re2c:define:YYFILL = 'fill3'; 41 | re2c:define:YYCURSOR = 'cursor3'; 42 | re2c:define:YYLIMIT = 'limit3'; 43 | 44 | */ 45 | } 46 | 47 | -------------------------------------------------------------------------------- /re2c/test/repeat-03.cgir.re: -------------------------------------------------------------------------------- 1 | // multiple scanners 2 | 3 | /*!types:re2c */ 4 | 5 | void scan(unsigned char* in) 6 | { 7 | /*!rules:re2c 8 | 9 | <*> "a" { return "a"; } 10 | <*> . { return "."; } 11 | "b" { return "b"; } 12 | "c" { return "c"; } 13 | 14 | *//*!use:re2c 15 | 16 | "1" { return "1"; } 17 | 18 | */ 19 | 20 | } 21 | 22 | void scan(unsigned short* in) 23 | { 24 | /*!use:re2c 25 | 26 | "2" { return "2"; } 27 | 28 | */ 29 | } 30 | -------------------------------------------------------------------------------- /re2c/test/repeat-04.cgir.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 20, column 1: cannot have a second 'rules:re2c' block 2 | -------------------------------------------------------------------------------- /re2c/test/repeat-04.cgir.re: -------------------------------------------------------------------------------- 1 | // multiple scanners, error 2 | 3 | /*!types:re2c */ 4 | 5 | void scan(unsigned char* in) 6 | { 7 | /*!rules:re2c 8 | 9 | <*> "1" { return "1"; } 10 | <*> "2" { return "2"; } 11 | "a" { return "a"; } 12 | "b" { return "b"; } 13 | 14 | *//*!use:re2c 15 | 16 | re2c:define:YYCTYPE = 'unsigned char'; 17 | 18 | */ 19 | /* Next block is not possible */ 20 | /*!rules:re2c 21 | */ 22 | } 23 | -------------------------------------------------------------------------------- /re2c/test/repeat-05.cgir.c: -------------------------------------------------------------------------------- 1 | re2c: error: line 7, column 1: found standard 're2c' block while using -r flag 2 | -------------------------------------------------------------------------------- /re2c/test/repeat-05.cgir.re: -------------------------------------------------------------------------------- 1 | // multiple scanners, error 2 | 3 | /*!types:re2c */ 4 | 5 | void scan(unsigned char* in) 6 | { 7 | /*!re2c re2c not allowed 8 | */ 9 | } 10 | -------------------------------------------------------------------------------- /re2c/test/repeat-06.gir.re: -------------------------------------------------------------------------------- 1 | // multiple scanners, additional rules, no char width change 2 | 3 | void scan(unsigned char* in) 4 | { 5 | /*!rules:re2c 6 | 7 | "a" := return "a"; 8 | "b" := return "b"; 9 | "c" := return "c"; 10 | "d" := return "d"; 11 | 12 | re2c:indent:top = 1; 13 | 14 | *//*!use:re2c 15 | 16 | re2c:define:YYCTYPE = 'unsigned char'; 17 | re2c:define:YYFILL = 'fill1'; 18 | re2c:define:YYCURSOR = 'cursor1'; 19 | re2c:define:YYLIMIT = 'limit1'; 20 | 21 | "1" := return "1"; 22 | . := return "."; 23 | 24 | */ 25 | } 26 | 27 | void scan(unsigned short* in) 28 | { 29 | /*!use:re2c 30 | 31 | re2c:define:YYCTYPE = 'unsigned short'; 32 | re2c:define:YYFILL = 'fill2'; 33 | re2c:define:YYCURSOR = 'cursor2'; 34 | re2c:define:YYLIMIT = 'limit2'; 35 | 36 | "2" := return "2"; 37 | . := return "."; 38 | 39 | */ 40 | } 41 | 42 | void scan(unsigned int* in) 43 | { 44 | /*!use:re2c 45 | 46 | re2c:define:YYCTYPE = 'unsigned int'; 47 | re2c:define:YYFILL = 'fill3'; 48 | re2c:define:YYCURSOR = 'cursor3'; 49 | re2c:define:YYLIMIT = 'limit3'; 50 | 51 | "3" := return "3"; 52 | . := return "."; 53 | 54 | */ 55 | } 56 | -------------------------------------------------------------------------------- /re2c/test/repeat-07.gir.re: -------------------------------------------------------------------------------- 1 | // multiple scanners, additional rules, char width change 2 | 3 | void scan(unsigned char* in) 4 | { 5 | /*!rules:re2c 6 | 7 | "a" := return "a"; 8 | "b" := return "b"; 9 | "c" := return "c"; 10 | "d" := return "d"; 11 | 12 | re2c:indent:top = 1; 13 | 14 | *//*!use:re2c 15 | 16 | re2c:flags:u = 0; 17 | re2c:flags:w = 0; 18 | 19 | re2c:define:YYCTYPE = 'unsigned char'; 20 | re2c:define:YYFILL = 'fill1'; 21 | re2c:define:YYCURSOR = 'cursor1'; 22 | re2c:define:YYLIMIT = 'limit1'; 23 | 24 | "1" := return "1"; 25 | . := return "."; 26 | 27 | */ 28 | } 29 | 30 | void scan(unsigned short* in) 31 | { 32 | /*!use:re2c 33 | 34 | re2c:flags:u = 0; 35 | re2c:flags:w = 1; 36 | 37 | re2c:define:YYCTYPE = 'unsigned short'; 38 | re2c:define:YYFILL = 'fill2'; 39 | re2c:define:YYCURSOR = 'cursor2'; 40 | re2c:define:YYLIMIT = 'limit2'; 41 | 42 | "2" := return "2"; 43 | . := return "."; 44 | 45 | */ 46 | } 47 | 48 | void scan(unsigned int* in) 49 | { 50 | /*!use:re2c 51 | 52 | re2c:flags:u = 1; 53 | re2c:flags:w = 1; 54 | 55 | re2c:define:YYCTYPE = 'unsigned int'; 56 | re2c:define:YYFILL = 'fill3'; 57 | re2c:define:YYCURSOR = 'cursor3'; 58 | re2c:define:YYLIMIT = 'limit3'; 59 | 60 | "3" := return "3"; 61 | . := return "."; 62 | 63 | */ 64 | } 65 | -------------------------------------------------------------------------------- /re2c/test/repeater.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define RET(n) return n 6 | 7 | int scan(const char *s, int l){ 8 | const char *p = s; 9 | const char *q; 10 | #define YYCTYPE char 11 | #define YYCURSOR p 12 | #define YYLIMIT (s+l) 13 | #define YYMARKER q 14 | #define YYFILL(n) 15 | /*!re2c 16 | any = [\000-\377]; 17 | 18 | 'a'{1}"\n" {RET(1);} 19 | 'a'{2,3}"\n" {RET(2);} 20 | 'a'{6}"\n" {RET(3);} 21 | 'a'{4,}"\n" {RET(4);} 22 | [^aq\n] {RET(5);} 23 | any {RET(0);} 24 | */ 25 | } 26 | 27 | void _do_scan(int exp, const char * str, int len) 28 | { 29 | int ret = scan(str, len); 30 | 31 | printf("%d %s %d\n", exp, exp == ret ? "==" : "!=", ret); 32 | } 33 | 34 | #define do_scan(exp, str) _do_scan(exp, str, sizeof(str) - 1) 35 | 36 | main() 37 | { 38 | do_scan(1, "a\n"); 39 | do_scan(2, "aa\n"); 40 | do_scan(2, "aaa\n"); 41 | do_scan(4, "aaaa\n"); 42 | do_scan(0, "q"); 43 | do_scan(0, "a"); 44 | do_scan(1, "A\n"); 45 | do_scan(2, "AA\n"); 46 | do_scan(2, "aAa\n"); 47 | do_scan(4, "AaaA\n"); 48 | do_scan(5, "Q"); 49 | do_scan(4, "AaaAa\n"); 50 | do_scan(3, "AaaAaA\n"); 51 | do_scan(5, "A"); 52 | do_scan(0, "\n"); 53 | do_scan(5, "0"); 54 | do_scan(0, "a"); 55 | do_scan(0, "q"); 56 | do_scan(5, "x"); 57 | } 58 | -------------------------------------------------------------------------------- /re2c/test/sample.re: -------------------------------------------------------------------------------- 1 | /*!re2c 2 | "print" {return PRINT;} 3 | [a-z]+ {return ID;} 4 | [0-9]+ {return DEC;} 5 | "0x" [0-9a-f]+ {return HEX;} 6 | [\000-\377] {return ERR;} 7 | */ 8 | -------------------------------------------------------------------------------- /re2c/test/simple.c: -------------------------------------------------------------------------------- 1 | /* Generated by re2c */ 2 | #line 1 "simple.re" 3 | #define NULL ((char*) 0) 4 | char *scan(char *p){ 5 | char *q; 6 | #define YYCTYPE char 7 | #define YYCURSOR p 8 | #define YYLIMIT p 9 | #define YYMARKER q 10 | #define YYFILL(n) 11 | 12 | #line 13 "" 13 | { 14 | YYCTYPE yych; 15 | 16 | if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); 17 | yych = *YYCURSOR; 18 | switch (yych) { 19 | case '0': 20 | case '1': 21 | case '2': 22 | case '3': 23 | case '4': 24 | case '5': 25 | case '6': 26 | case '7': 27 | case '8': 28 | case '9': goto yy2; 29 | default: goto yy4; 30 | } 31 | yy2: 32 | ++YYCURSOR; 33 | yych = *YYCURSOR; 34 | goto yy7; 35 | yy3: 36 | #line 10 "simple.re" 37 | {return YYCURSOR;} 38 | #line 39 "" 39 | yy4: 40 | ++YYCURSOR; 41 | #line 11 "simple.re" 42 | {return NULL;} 43 | #line 44 "" 44 | yy6: 45 | ++YYCURSOR; 46 | if (YYLIMIT <= YYCURSOR) YYFILL(1); 47 | yych = *YYCURSOR; 48 | yy7: 49 | switch (yych) { 50 | case '0': 51 | case '1': 52 | case '2': 53 | case '3': 54 | case '4': 55 | case '5': 56 | case '6': 57 | case '7': 58 | case '8': 59 | case '9': goto yy6; 60 | default: goto yy3; 61 | } 62 | } 63 | #line 12 "simple.re" 64 | 65 | } 66 | -------------------------------------------------------------------------------- /re2c/test/simple.re: -------------------------------------------------------------------------------- 1 | #define NULL ((char*) 0) 2 | char *scan(char *p){ 3 | char *q; 4 | #define YYCTYPE char 5 | #define YYCURSOR p 6 | #define YYLIMIT p 7 | #define YYMARKER q 8 | #define YYFILL(n) 9 | /*!re2c 10 | [0-9]+ {return YYCURSOR;} 11 | [\000-\377] {return NULL;} 12 | */ 13 | } 14 | -------------------------------------------------------------------------------- /re2c/test/yyaccept_missing.bci.re: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define YYGETCONDITION() yy_state 6 | #define YYSETCONDITION(s) yy_state = s 7 | #define YYCTYPE char 8 | #define YYCURSOR p 9 | #define YYLIMIT (s+l) 10 | #define YYMARKER q 11 | #define YYFILL(n) 12 | 13 | #define STATE(name) yyc##name 14 | 15 | static enum YYCONDTYPE yy_state; 16 | 17 | /*!types:re2c */ 18 | 19 | int scan(char *s, int l) 20 | { 21 | char *p = s; 22 | char *q = 0; 23 | char *t; 24 | 25 | for(;;) 26 | { 27 | t = p; 28 | /*!re2c 29 | re2c:indent:top = 2; 30 | 31 | TABS_AND_SPACES = [ \t]*; 32 | LITERAL_DOLLAR = "$"[a-zA-Z]; 33 | 34 | LITERAL_DOLLAR { 35 | printf("FOUND %s\n", t); 36 | continue; 37 | } 38 | 39 | LITERAL_DOLLAR+ { 40 | printf("Found $ or $\\\n"); 41 | continue; 42 | } 43 | 44 | TABS_AND_SPACES { 45 | YYSETCONDITION(STATE(INITIAL)); 46 | printf("Found spaces\n"); 47 | } 48 | 49 | "\000" { printf("EOF\n"); return 0; } 50 | [^] { printf("ERR\n"); return 1; } 51 | 52 | */ 53 | } 54 | } 55 | 56 | int main(int argc, char **argv) 57 | { 58 | if (argc > 1) 59 | { 60 | return scan(argv[1], strlen(argv[1])); 61 | } 62 | else 63 | { 64 | fprintf(stderr, "%s \n", argv[0]); 65 | return 1; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /re2c/token.h: -------------------------------------------------------------------------------- 1 | /* $Id: token.h 858 2008-04-03 20:53:44Z helly $ */ 2 | #ifndef _token_h 3 | #define _token_h 4 | 5 | #include "substr.h" 6 | #include "stream_lc.h" 7 | 8 | namespace re2c 9 | { 10 | 11 | class Token 12 | { 13 | public: 14 | const Str text; 15 | const std::string newcond; 16 | const std::string source; 17 | uint line; 18 | const bool autogen; 19 | 20 | public: 21 | Token(const SubStr&, const file_info&); 22 | Token(const SubStr&, const std::string&, uint); 23 | Token(const Token*, const file_info&, const Str*); 24 | Token(const Token*, const std::string&, uint, const Str*); 25 | Token(const Token& oth); 26 | ~Token(); 27 | }; 28 | 29 | inline Token::Token(const SubStr& t, const file_info& fi) 30 | : text(t) 31 | , newcond() 32 | , source(fi.fname) 33 | , line(fi.ln->get_line()) 34 | , autogen(false) 35 | { 36 | ; 37 | } 38 | 39 | inline Token::Token(const SubStr& t, const std::string& s, uint l) 40 | : text(t) 41 | , newcond() 42 | , source(s) 43 | , line(l) 44 | , autogen(false) 45 | { 46 | ; 47 | } 48 | 49 | inline Token::Token(const Token* t, const file_info& fi, const Str *c) 50 | : text(t ? t->text.to_string().c_str() : "") 51 | , newcond(c ? c->to_string() : "") 52 | , source(t ? t->source : fi.fname) 53 | , line(t ? t->line : fi.ln->get_line()) 54 | , autogen(t == NULL) 55 | { 56 | ; 57 | } 58 | 59 | inline Token::Token(const Token* t, const std::string& s, uint l, const Str *c) 60 | : text(t ? t->text.to_string().c_str() : "") 61 | , newcond(c ? c->to_string() : "") 62 | , source(s) 63 | , line(l) 64 | , autogen(t == NULL) 65 | { 66 | ; 67 | } 68 | 69 | inline Token::Token(const Token& oth) 70 | : text(oth.text.to_string().c_str()) 71 | , newcond(oth.newcond) 72 | , source(oth.source) 73 | , line(oth.line) 74 | , autogen(oth.autogen) 75 | { 76 | ; 77 | } 78 | 79 | inline Token::~Token() 80 | { 81 | } 82 | 83 | } // end namespace re2c 84 | 85 | #endif 86 | --------------------------------------------------------------------------------