├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── LICENSE ├── Makefile.in ├── README.md ├── configure ├── configure.ac ├── doc ├── CMakeLists.txt ├── Internals.txt ├── Makefile.in ├── yaep++-1.html ├── yaep++.dvi ├── yaep++.html ├── yaep++.info ├── yaep++.pdf ├── yaep++.ps ├── yaep++.sgml.in ├── yaep++.txt ├── yaep-1.html ├── yaep.dvi ├── yaep.html ├── yaep.info ├── yaep.pdf ├── yaep.ps ├── yaep.sgml.in ├── yaep.txt ├── yaep_part++.sgml.in └── yaep_part.sgml.in ├── install-sh ├── src ├── CMakeLists.txt ├── ChangeLog ├── Makefile.in ├── allocate.c ├── allocate.h ├── hashtab.c ├── hashtab.cpp ├── hashtab.h ├── objstack.c ├── objstack.cpp ├── objstack.h ├── sgramm.y ├── vlobject.c ├── vlobject.cpp ├── vlobject.h ├── yaep.c ├── yaep.cpp └── yaep.h └── test ├── C++ ├── CMakeLists.txt ├── Makefile.in ├── common.h ├── test06.cpp ├── test07.cpp ├── test08.cpp ├── test09.cpp ├── test10.cpp ├── test11.cpp ├── test12.cpp ├── test13.cpp ├── test14.cpp ├── test15.cpp ├── test16.cpp ├── test17.cpp ├── test18.cpp ├── test19.cpp ├── test20.cpp ├── test21.cpp ├── test22.cpp ├── test23.cpp ├── test24.cpp ├── test25.cpp ├── test26.cpp ├── test27.cpp ├── test28.cpp ├── test29.cpp ├── test30.cpp ├── test31.cpp ├── test32.cpp ├── test33.cpp ├── test34.cpp ├── test35.cpp ├── test36.cpp ├── test37.cpp ├── test38.cpp ├── test39.cpp ├── test40.cpp ├── test41.cpp ├── test42.cpp ├── test43.cpp ├── test44.cpp ├── test45.cpp ├── test46.cpp ├── test47.cpp ├── test48.cpp └── test49.cpp ├── C ├── CMakeLists.txt ├── Makefile.in ├── common.h ├── test06.c ├── test07.c ├── test08.c ├── test09.c ├── test10.c ├── test11.c ├── test12.c ├── test13.c ├── test14.c ├── test15.c ├── test16.c ├── test17.c ├── test18.c ├── test19.c ├── test20.c ├── test21.c ├── test22.c ├── test23.c ├── test24.c ├── test25.c ├── test26.c ├── test27.c ├── test28.c ├── test29.c ├── test30.c ├── test31.c ├── test32.c ├── test33.c ├── test34.c ├── test35.c ├── test36.c ├── test37.c ├── test38.c ├── test39.c ├── test40.c ├── test41.c ├── test42.c ├── test43.c ├── test44.c ├── test45.c ├── test46.c ├── test47.c ├── test48.c └── test49.c ├── CMakeLists.txt ├── Makefile.in ├── ansic.h ├── ansic.l ├── compare_parsers ├── CMakeLists.txt ├── ansic.y ├── compare_parsers.sh.in ├── test.i ├── test.y ├── test1.i ├── test_common.c ├── test_yaep.c ├── test_yyparse.c └── whole_gcc_test.i ├── test.i ├── test01.out ├── test01a.out ├── test02.out ├── test02a.out ├── test03.out ├── test03a.out ├── test03b.out ├── test04.out ├── test04a.out ├── test04b.out ├── test05.out ├── test05a.out ├── test06.out ├── test07.out ├── test08.out ├── test09.out ├── test10.out ├── test11.out ├── test12.out ├── test13.out ├── test14.out ├── test15.out ├── test16.out ├── test17.out ├── test18.out ├── test19.out ├── test20.out ├── test21.out ├── test22.out ├── test23.out ├── test24.out ├── test25.out ├── test26.out ├── test27.out ├── test28.out ├── test29.out ├── test30.out ├── test31.out ├── test32.out ├── test33.out ├── test34.out ├── test35.out ├── test36.out ├── test37.out ├── test38.out ├── test39.out ├── test40.out ├── test42.out ├── test43.out ├── test44.out ├── test45.rout ├── test46.rout ├── test47.rout ├── test48.out ├── test49.out ├── ticker.c ├── ticker.cpp └── ticker.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Editor files 2 | *~ 3 | *.sw[op] 4 | 5 | # Build directories 6 | /build* 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # YAEP (Yet Another Earley Parser) 2 | # 3 | # Copyright (c) 1997-2018 Vladimir Makarov 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a 6 | # copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included 14 | # in all copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | language: cpp 25 | 26 | matrix: 27 | include: 28 | - os: linux 29 | compiler: gcc 30 | - os: osx 31 | compiler: gcc 32 | - os: linux 33 | compiler: clang 34 | - os: osx 35 | compiler: clang 36 | 37 | script: 38 | - mkdir build 39 | - cd build 40 | - cmake -DCMAKE_BUILD_TYPE=Debug .. 41 | - make 42 | - make test 43 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # YAEP (Yet Another Earley Parser) 2 | # 3 | # Copyright (c) 1997-2018 Vladimir Makarov 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a 6 | # copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included 14 | # in all copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | cmake_minimum_required( VERSION 3.0 ) 25 | 26 | project( yaep ) 27 | enable_testing() 28 | 29 | set( CMAKE_C_STANDARD 90 ) 30 | set( CMAKE_CXX_STANDARD 11 ) 31 | 32 | include( GNUInstallDirs ) 33 | 34 | add_subdirectory( src ) 35 | add_subdirectory( test ) 36 | add_subdirectory( doc ) 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YAEP (Yet Another Earley Parser) 2 | 3 | Copyright (c) 1997-2018 Vladimir Makarov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a 6 | copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | dnl Process this file with autoconf to produce a configure script. 2 | AC_INIT(src/yaep.c) 3 | 4 | dnl Checks for programs. 5 | AC_PROG_AWK 6 | dnl Try C++ before C because configure reports cros-compiler for CXX sometimes. 7 | AC_PROG_CXX 8 | AC_PROG_CC 9 | AC_PROG_CPP 10 | AC_PROG_INSTALL 11 | AC_PROG_MAKE_SET 12 | AC_PROG_RANLIB 13 | AC_PROG_YACC 14 | AC_PROG_LEX 15 | AC_PROG_SED 16 | AC_PROG_EGREP 17 | 18 | AC_AIX 19 | AC_FUNC_GETMNTENT 20 | AC_ISC_POSIX 21 | AC_MINIX 22 | AC_STDC_HEADERS 23 | AC_HAVE_HEADERS(string.h) 24 | 25 | AC_ALLOCA 26 | AC_CONST 27 | 28 | AC_CHECK_LIB(m, log) 29 | 30 | dnl Checks for header files. 31 | AC_CHECK_HEADERS(assert.h limits.h errno.h float.h time.h dlfcn.h unistd.h sys/time.h) 32 | 33 | dnl Checks for typedefs, structures, and compiler characteristics. 34 | AC_C_CONST 35 | AC_C_INLINE 36 | AC_TYPE_SIZE_T 37 | AC_CHECK_SIZEOF(size_t) 38 | AC_CHECK_SIZEOF(char *) 39 | dnl There is no clock_t `sys/types.h', or `stdlib.h' or `stddef.h' on Linux 40 | dnl I think checking time.h will be sufficient. 41 | dnl AC_CHECK_TYPES([clock_t], [], AC_DEFINE([clock_t], [long], [])) 42 | 43 | dnl Checks for library functions. 44 | AC_TYPE_SIGNAL 45 | AC_CHECK_FUNCS(setitimer sigaction sigemptyset) 46 | 47 | AC_SUBST(YAEPLIB) 48 | AC_SUBST(YAEPDIR) 49 | YAEPLIB=yaep 50 | YAEPDIR=../src 51 | 52 | AC_SUBST(C_DEBUG_DEFINE) 53 | if test x$yaep_debug = x; then 54 | C_DEBUG_DEFINE=-DNDEBUG 55 | else 56 | CFLAGS=-g3 57 | AC_MSG_CHECKING([whether CC supports -g3]) 58 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], 59 | [AC_MSG_RESULT([yes])] 60 | [g3=yes], 61 | [AC_MSG_RESULT([no])] 62 | ) 63 | 64 | if test "$g3" = yes; then 65 | CFLAGS='-O0 -g3' 66 | CXXFLAGS='-O0 -g3' 67 | else 68 | CFLAGS='-O0 -g' 69 | CXXFLAGS='-O0 -g' 70 | fi 71 | C_DEBUG_DEFINE= 72 | fi 73 | 74 | AC_SUBST(GCC_FPIC) 75 | AC_SUBST(LIB_SUFFIX) 76 | AC_SUBST(MAKELIB) 77 | AC_SUBST(AFTER_MAKELIB) 78 | 79 | system=`uname`.`uname -r` 80 | 81 | if test "$GCC" = yes && test x$yaep_debug = x; then 82 | my_save_cflags="$CFLAGS" 83 | CFLAGS=-Ofast 84 | AC_MSG_CHECKING([whether CC supports -Ofast]) 85 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], 86 | [AC_MSG_RESULT([yes])] 87 | [fast=yes], 88 | [AC_MSG_RESULT([no])] 89 | ) 90 | CFLAGS="$my_save_cflags" 91 | if test "$fast" = yes; then 92 | CFLAGS="`echo $CFLAGS|sed s/-O2//` -Ofast" 93 | CXXFLAGS="`echo $CXXFLAGS|sed s/-O2//` -Ofast" 94 | else 95 | CFLAGS="`echo $CFLAGS|sed s/-O2//` -O3" 96 | CXXFLAGS="`echo $CXXFLAGS|sed s/-O2//` -O3" 97 | fi 98 | 99 | system=`uname -m` 100 | case $system in 101 | i386*|i486*|i586*|i686*) 102 | CFLAGS="$CFLAGS -fomit-frame-pointer" 103 | CXXFLAGS="$CXXFLAGS -fomit-frame-pointer" 104 | ;; 105 | *) 106 | ;; 107 | esac 108 | fi 109 | 110 | output_files="Makefile doc/Makefile src/Makefile test/Makefile test/C/Makefile test/C++/Makefile test/compare_parsers/compare_parsers.sh" 111 | 112 | AC_OUTPUT($output_files) 113 | -------------------------------------------------------------------------------- /doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # YAEP (Yet Another Earley Parser) 2 | # 3 | # Copyright (c) 1997-2018 Vladimir Makarov 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a 6 | # copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included 14 | # in all copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | set( DOCFILES 25 | Internals.txt 26 | yaep-1.html 27 | yaep.dvi 28 | yaep.html 29 | yaep.info 30 | yaep.pdf 31 | yaep.ps 32 | yaep.txt 33 | yaep++-1.html 34 | yaep++.dvi 35 | yaep++.html 36 | yaep++.info 37 | yaep++.pdf 38 | yaep++.ps 39 | yaep++.txt 40 | ) 41 | install( FILES ${DOCFILES} DESTINATION "${CMAKE_INSTALL_DOCDIR}" ) 42 | -------------------------------------------------------------------------------- /doc/Internals.txt: -------------------------------------------------------------------------------- 1 | Here are some YAEP implementation details: 2 | 3 | * All numbers below are given for our biggest C test (GCC as one file). 4 | 5 | 1. *Earley set* representation is very compact and only *set core* 6 | pointer and vector of *distances* for start situations of the set core. 7 | 2. The distances are *relative*, not absolute. The distance vector 8 | is stored in *one exemplar*. In average, the distance vector is reused 9 | 22 times. 10 | 3. The same Earley sets are represented in *one exemplar* and parser list 11 | consists of only pointers to the sets. In average one set occurs 20 times. 12 | 4. The *situation* is mostly a triple (rule, the dot place in the rule, 13 | optional possible lookahead). In other words, the situation is the set 14 | tuple in original Earley algorithm but without distances. The same 15 | situation is stored in *one exemplar* and only a pointer to it is used. 16 | 5. The *set core* is set of situations which can occur during YAEP work. 17 | 6. *Start situations* in the set core are situations produced by Earley 18 | Scanningand Completion passes excluding situations added by the 19 | completion pass from processing rules with empty right hand side. 20 | 7. Start situations and their distances *define* all the rest situations 21 | and their distances created by predictor pass and completer pass 22 | processing rules with empty right hand side. 23 | 8. More dynamic programming. There are a lot of repeated parsing parts 24 | in the input. We build *map* (Earley set, input token, lookahead) 25 | -> a few possible Earley sets (currently 3 sets) and try to reuse a set 26 | from a map. In 70% cases, the reuse is successful. 27 | 9. We *do use lookahead* and it speeds up the parser in almost 2 times. 28 | Which is opposite to researches showed the lookahead usage has little 29 | practical effect on the parsing efficiency. 30 | 10. We *don't use PEP* (Practical Earley Parser algorithm). It would 31 | complicate the implementation much and, in my estimation, could give 32 | only a few percent speedup for our tests. 33 | 11. We *don't use Leo Joop's approach*. Using right recursion creates 34 | the same number of start situations in overall as using the left 35 | recursion. Simply Earley set corresponding to the end of right recursion 36 | contains a lot of start situations (created by the completer). 37 | * Moreover, using the right recursion considerably improves reuse 38 | of a set from the map (see 8). For example, parsing 1M token list 39 | described by a grammar with the *right* recursion takes only 40 | *0.14s vs 1.05s* for a grammar described with the *left* recursion. 41 | Usage of the right recursion also results in *3 times* less 42 | memory consumption. 43 | 44 | -------------------------------------------------------------------------------- /doc/Makefile.in: -------------------------------------------------------------------------------- 1 | all test install uninstall clean realclean distclean TAGS dist-copy dist: 2 | @echo "+++++ Please use only top level Makefile" 3 | -------------------------------------------------------------------------------- /doc/yaep++.dvi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vnmakarov/yaep/7aba93e1b49b3f1db0e20ba7d4e4158e2a0a8bb9/doc/yaep++.dvi -------------------------------------------------------------------------------- /doc/yaep++.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | YAEP (Yet Another Earley Parser) - C++ interface 6 | 7 | 8 | 9 | 10 | 11 | Next 12 | Previous 13 | Contents 14 |
15 |

YAEP (Yet Another Earley Parser) - C++ interface

16 | 17 |

Vladimir Makarov, vmakarov@gcc.gnu.org

Oct 10, 2015 18 |
19 | This document describes YAEP (Yet Another Earley Parser) written in C/C++. 20 |
21 |

22 |

1. YAEP

23 | 24 |
25 | Next 26 | Previous 27 | Contents 28 | 29 | 30 | -------------------------------------------------------------------------------- /doc/yaep++.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vnmakarov/yaep/7aba93e1b49b3f1db0e20ba7d4e4158e2a0a8bb9/doc/yaep++.pdf -------------------------------------------------------------------------------- /doc/yaep++.sgml.in: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | YAEP (Yet Another Earley Parser) - C++ interface 7 | <author>Vladimir Makarov, <tt>vmakarov@gcc.gnu.org</tt> 8 | <date>Oct 10, 2015 9 | <abstract> 10 | This document describes YAEP (Yet Another Earley Parser) written in C/C++. 11 | </abstract> 12 | %%% 13 | </article> 14 | -------------------------------------------------------------------------------- /doc/yaep.dvi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vnmakarov/yaep/7aba93e1b49b3f1db0e20ba7d4e4158e2a0a8bb9/doc/yaep.dvi -------------------------------------------------------------------------------- /doc/yaep.html: -------------------------------------------------------------------------------- 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> 2 | <HTML> 3 | <HEAD> 4 | <META NAME="GENERATOR" CONTENT="LinuxDoc-Tools 0.9.66"> 5 | <TITLE>YAEP (Yet Another Earley Parser) - C interface 6 | 7 | 8 | 9 | 10 | 11 | Next 12 | Previous 13 | Contents 14 |
15 |

YAEP (Yet Another Earley Parser) - C interface

16 | 17 |

Vladimir Makarov, vmakarov@gcc.gnu.org

Oct 10, 2015 18 |
19 | This document describes YAEP (Yet Another Earley Parser) written in C/C++. 20 |
21 |

22 |

1. YAEP

23 | 24 |
25 | Next 26 | Previous 27 | Contents 28 | 29 | 30 | -------------------------------------------------------------------------------- /doc/yaep.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vnmakarov/yaep/7aba93e1b49b3f1db0e20ba7d4e4158e2a0a8bb9/doc/yaep.pdf -------------------------------------------------------------------------------- /doc/yaep.sgml.in: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | YAEP (Yet Another Earley Parser) - C interface 7 | <author>Vladimir Makarov, <tt>vmakarov@gcc.gnu.org</tt> 8 | <date>Oct 10, 2015 9 | <abstract> 10 | This document describes YAEP (Yet Another Earley Parser) written in C/C++. 11 | </abstract> 12 | %%% 13 | </article> 14 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # YAEP (Yet Another Earley Parser) 2 | # 3 | # Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a 6 | # copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included 14 | # in all copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | # Generate sources from yacc first 25 | find_package( BISON REQUIRED ) 26 | bison_target( sgramm sgramm.y ${CMAKE_CURRENT_BINARY_DIR}/sgramm.c ) 27 | if( NOT ${BISON_sgramm_DEFINED} ) 28 | message( FATAL_ERROR "Failed to add rule for sgramm.c" ) 29 | endif() 30 | add_custom_target( sgramm_c DEPENDS ${BISON_sgramm_OUTPUTS} ) # FIXME: yaep.c includes sgramm.c directly, so we need a custom target 31 | 32 | # Now build libraries 33 | include_directories( 34 | ${CMAKE_CURRENT_BINARY_DIR} 35 | ) 36 | 37 | # C 38 | set( YAEP_LIB ${PROJECT_NAME} ) 39 | if( UNIX ) 40 | set( YAEP_LIB_STATIC ${YAEP_LIB} ) 41 | else() 42 | set( YAEP_LIB_STATIC "${YAEP_LIB}_static" ) 43 | endif() 44 | set( YAEP_LIB_SOURCES 45 | allocate.c 46 | hashtab.c 47 | objstack.c 48 | vlobject.c 49 | yaep.c 50 | ) 51 | add_library( yaep_static STATIC ${YAEP_LIB_SOURCES} ) 52 | add_dependencies( yaep_static sgramm_c ) # FIXME: yaep.c includes sgramm.c directly; would be cleaner if sgramm was its own object 53 | set_target_properties( yaep_static PROPERTIES OUTPUT_NAME ${YAEP_LIB_STATIC} ) 54 | 55 | # C++ 56 | set( YAEPXX_LIB "${PROJECT_NAME}++" ) 57 | if( UNIX ) 58 | set( YAEPXX_LIB_STATIC ${YAEPXX_LIB} ) 59 | else() 60 | set( YAEPXX_LIB_STATIC "${YAEPXX_LIB}_static" ) 61 | endif() 62 | set( YAEPXX_LIB_SOURCES 63 | allocate.c 64 | hashtab.cpp 65 | objstack.cpp 66 | vlobject.cpp 67 | yaep.cpp 68 | ) 69 | add_library( yaep++_static STATIC ${YAEPXX_LIB_SOURCES} ) 70 | add_dependencies( yaep++_static sgramm_c ) # FIXME: yaep.cpp includes sgramm.c via yaep.c; would be cleaner if sgramm was its own object 71 | set_target_properties( yaep++_static PROPERTIES OUTPUT_NAME ${YAEPXX_LIB_STATIC} ) 72 | 73 | # Install 74 | set( YAEP_INCLUDE 75 | yaep.h 76 | ) 77 | install( TARGETS yaep_static yaep++_static DESTINATION ${CMAKE_INSTALL_LIBDIR} ) 78 | install( FILES ${YAEP_INCLUDE} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}" ) 79 | 80 | # Build test binaries from the same sources 81 | add_executable( yaep_test ${YAEP_LIB_SOURCES} ) 82 | add_executable( yaep++_test ${YAEPXX_LIB_SOURCES} ) 83 | set_target_properties( yaep_test yaep++_test PROPERTIES COMPILE_FLAGS "-DYAEP_TEST -DYAEP_DEBUG" ) 84 | -------------------------------------------------------------------------------- /src/ChangeLog: -------------------------------------------------------------------------------- 1 | 2018-11-02 Vladimir Makarov <vmakarov@gcc.gnu.org> 2 | 3 | * src/yape.c (traverse_pruned_translation): Process next alt node 4 | from the start again. 5 | 6 | 2018-11-02 Vladimir Makarov <vmakarov@gcc.gnu.org> 7 | 8 | * src/compare_parsers.tst.in: Remove mentioning ammunition. Print 9 | better messages. 10 | (set_sgrammar): Fix typo in OS_CREATE call. 11 | 12 | 2018-10-21 Vladimir Makarov <vmakarov@gcc.gnu.org> 13 | 14 | * allocate.[ch]: Use GNU style format. 15 | * compare_parsers.tst.in: Ditto. 16 | * hashtab.{c,cpp}: Ditto. 17 | * objstack.{c,h,cpp}: Ditto. 18 | * sgramm.y: Ditto. 19 | * vlobject.{c,h,cpp}: Ditto. 20 | * yaep.{c,cpp}: Ditto. 21 | * yaep[++].tst.in: Ditto. 22 | 23 | 2018-10-21 Vladimir Makarov <vmakarov@gcc.gnu.org> 24 | 25 | * src/compare_parsers.tst.in: Add forward func decls. Remove old 26 | C style func decls. 27 | * src/yaep.tst.in: Ditto. 28 | 29 | 2018-10-21 Alexander Klauer 30 | 31 | * Merge: https://github.com/vnmakarov/yaep/pull/16 32 | 33 | 2016-11-04 Vladimir Makarov <vmakarov@gcc.gnu.org> 34 | 35 | * Makefile.in (install, uninstall): Process allocate.h. 36 | 37 | 2015-10-06 Vladimir Makarov <vmakarov@gcc.gnu.org> 38 | 39 | * compare_parsers.tst.in: Use YAEPLIB and YAEPDIR. 40 | 41 | 2015-10-06 Vladimir Makarov <vmakarov@gcc.gnu.org> 42 | 43 | * ChangeLog.YAEP: Start. 44 | * yaep.c (struct sit_dist, first_free_sit_dist_index): Remove. 45 | (sit_dist_vlo, sit_dist_vec_check_vlo): Ditto. 46 | (sit_dist_set_init, empty_sit_dist_set, sit_dist_insert): Rewrite 47 | for new (sit, dist) set implementation. 48 | (sit_dist_set_fin): Ditto. 49 | (make_parse): Add more debug printing. 50 | * compare_parsers.tst.in: Move from MSTA/compare.tst. Add 51 | checking MSTA. Add big test. 52 | * yaep_part.sgml.in, yaep_part++.sgml.in: New. 53 | * whole_gcc_test.i: New. 54 | 55 | -------------------------------------------------------------------------------- /src/Makefile.in: -------------------------------------------------------------------------------- 1 | all test install uninstall clean realclean distclean TAGS dist-copy dist: 2 | @echo "+++++ Please use only top level Makefile" 3 | -------------------------------------------------------------------------------- /test/C++/test06.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include<cstdio> 28 | #include <stdlib.h> 29 | 30 | #include"common.h" 31 | #include "yaep.h" 32 | 33 | static const char *input = "a+a*(a*a+a)"; 34 | 35 | static const char *description = 36 | "\n" 37 | "TERM;\n" 38 | "E : T # 0\n" 39 | " | E '+' T # plus (0 2)\n" 40 | " ;\n" 41 | "T : F # 0\n" 42 | " | T '*' F # mult (0 2)\n" 43 | " ;\n" 44 | "F : 'a' # 0\n" 45 | " | '(' E ')' # 1\n" 46 | " ;\n" 47 | ; 48 | 49 | int 50 | main (void) 51 | { 52 | yaep *e; 53 | struct yaep_tree_node *root; 54 | int ambiguous_p; 55 | 56 | test_input = input; 57 | e = new yaep (); 58 | if (e == NULL) 59 | { 60 | fprintf (stderr, "yaep::yaep: No memory\n"); 61 | exit (1); 62 | } 63 | if (e->parse (test_read_token, test_syntax_error, test_parse_alloc, NULL, 64 | &root, &ambiguous_p)) 65 | { 66 | fprintf (stderr, "yaep parse: %s\n", e->error_message ()); 67 | exit (1); 68 | } 69 | delete e; 70 | exit (0); 71 | } 72 | -------------------------------------------------------------------------------- /test/C++/test07.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include<cstdio> 28 | #include <stdlib.h> 29 | 30 | #include"common.h" 31 | #include "yaep.h" 32 | 33 | static const char *input = "a+a*(a*a+a)"; 34 | 35 | static const char *description = 36 | "\n" 37 | "TERM;\n" 38 | "E : T # 0\n" 39 | " | E '+' T # plus (0 2)\n" 40 | " ;\n" 41 | "T : F # 0\n" 42 | " | T '*' F # mult (0 2)\n" 43 | " ;\n" 44 | "F : 'a' # 0\n" 45 | " | '(' E ')' # 1\n" 46 | " ;\n" 47 | ; 48 | 49 | int 50 | main (void) 51 | { 52 | yaep *e; 53 | struct yaep_tree_node *root; 54 | int ambiguous_p; 55 | 56 | test_input = input; 57 | e = new yaep (); 58 | if (e == NULL) 59 | { 60 | fprintf (stderr, "yaep::yaep: No memory\n"); 61 | exit (1); 62 | } 63 | if (e->parse_grammar (0, description) != 0) 64 | { 65 | fprintf (stderr, "%s\n", e->error_message ()); 66 | exit (1); 67 | } 68 | if (e->parse_grammar (1, description) != 0) 69 | { 70 | fprintf (stderr, "%s\n", e->error_message ()); 71 | exit (1); 72 | } 73 | if (e->parse (test_read_token, test_syntax_error, test_parse_alloc, NULL, 74 | &root, &ambiguous_p)) 75 | { 76 | fprintf (stderr, "yaep parse: %s\n", e->error_message ()); 77 | exit (1); 78 | } 79 | delete e; 80 | exit (0); 81 | } 82 | -------------------------------------------------------------------------------- /test/C++/test08.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "TERM 1\n" 36 | "E : T # 0\n" 37 | " | E '+' T # plus (0 2)\n" 38 | " ;\n" 39 | "T : F # 0\n" 40 | " | T '*' F # mult (0 2)\n" 41 | " ;\n" 42 | "F : 'a' # 0\n" 43 | " | '(' E ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int 48 | main (void) 49 | { 50 | test_standard_parse (input, description); 51 | exit (0); 52 | } 53 | -------------------------------------------------------------------------------- /test/C++/test09.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "TERM;\n" 36 | "error : T # 0\n" 37 | " | E '+' T # plus (0 2)\n" 38 | " ;\n" 39 | "T : F # 0\n" 40 | " | T '*' F # mult (0 2)\n" 41 | " ;\n" 42 | "F : 'a' # 0\n" 43 | " | '(' E ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int 48 | main (void) 49 | { 50 | test_standard_parse (input, description); 51 | exit (0); 52 | } 53 | -------------------------------------------------------------------------------- /test/C++/test10.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "TERM ident=11 ident=10;\n" 36 | "E : T # 0\n" 37 | " | E '+' T # plus (0 2)\n" 38 | " ;\n" 39 | "T : F # 0\n" 40 | " | T '*' F # mult (0 2)\n" 41 | " ;\n" 42 | "F : 'a' # 0\n" 43 | " | '(' E ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int 48 | main (void) 49 | { 50 | test_standard_parse (input, description); 51 | exit (0); 52 | } 53 | -------------------------------------------------------------------------------- /test/C++/test11.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "TERM ident=10 i=10;\n" 36 | "E : T # 0\n" 37 | " | E '+' T # plus (0 2)\n" 38 | " ;\n" 39 | "T : F # 0\n" 40 | " | T '*' F # mult (0 2)\n" 41 | " ;\n" 42 | "F : 'a' # 0\n" 43 | " | '(' E ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int 48 | main (void) 49 | { 50 | test_standard_parse (input, description); 51 | exit (0); 52 | } 53 | -------------------------------------------------------------------------------- /test/C++/test12.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = "TERM;\n"; 34 | 35 | int 36 | main (void) 37 | { 38 | test_standard_parse (input, description); 39 | exit (0); 40 | } 41 | -------------------------------------------------------------------------------- /test/C++/test13.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = "TERM ident; ident : ;\n"; 34 | 35 | int 36 | main (void) 37 | { 38 | test_standard_parse (input, description); 39 | exit (0); 40 | } 41 | -------------------------------------------------------------------------------- /test/C++/test14.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "TERM;\n" 36 | "E : T # 1\n" 37 | " | E '+' T # plus (0 2)\n" 38 | " ;\n" 39 | "T : F # 0\n" 40 | " | T '*' F # mult (0 2)\n" 41 | " ;\n" 42 | "F : 'a' # 0\n" 43 | " | '(' E ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int 48 | main (void) 49 | { 50 | test_standard_parse (input, description); 51 | exit (0); 52 | } 53 | -------------------------------------------------------------------------------- /test/C++/test15.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "TERM;\n" 36 | "E : T # 0\n" 37 | " | E '+' T # plus (0 0)\n" 38 | " ;\n" 39 | "T : F # 0\n" 40 | " | T '*' F # mult (0 2)\n" 41 | " ;\n" 42 | "F : 'a' # 0\n" 43 | " | '(' E ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int 48 | main (void) 49 | { 50 | test_standard_parse (input, description); 51 | exit (0); 52 | } 53 | -------------------------------------------------------------------------------- /test/C++/test16.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : T # 0\n" 36 | " | E '+' T # plus (0 0)\n" 37 | " ;\n" 38 | "T : F # 0\n" 39 | " | T '*' F # mult (0 2)\n" 40 | " ;\n" 41 | "F : 'a' # 0\n" 42 | " | '(' E ')' # 1\n" 43 | " ;\n" 44 | ; 45 | 46 | int 47 | main (void) 48 | { 49 | test_standard_parse (input, description); 50 | exit (0); 51 | } 52 | -------------------------------------------------------------------------------- /test/C++/test17.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : 'a' E\n" 36 | " | E '+'\n" 37 | " ;\n" 38 | ; 39 | 40 | int 41 | main (int argc, char **argv) 42 | { 43 | test_complex_parse (input, description, 0, 0, 0, 0, argc, argv); 44 | exit (0); 45 | } 46 | -------------------------------------------------------------------------------- /test/C++/test18.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "E : A O O\n" 35 | " | E 'a'\n" 36 | " | 'b'\n" 37 | " |\n" 38 | " ;\n" 39 | "\n" 40 | "A : O O N\n" 41 | " ;\n" 42 | "\n" 43 | "N : O E E O\n" 44 | " ;\n" 45 | "\n" 46 | "O :\n" 47 | " ;\n" 48 | ; 49 | 50 | int 51 | main (void) 52 | { 53 | test_standard_parse (input, description); 54 | exit (0); 55 | } 56 | -------------------------------------------------------------------------------- /test/C++/test19.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+b)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "TERM;\n" 36 | "E : T # 0\n" 37 | " | E '+' T # plus (0 2)\n" 38 | " ;\n" 39 | "T : F # 0\n" 40 | " | T '*' F # mult (0 2)\n" 41 | " ;\n" 42 | "F : 'a' # 0\n" 43 | " | '(' E ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int 48 | main (void) 49 | { 50 | test_standard_parse (input, description); 51 | exit (0); 52 | } 53 | -------------------------------------------------------------------------------- /test/C++/test20.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : T # 0\n" 36 | " | E '+' T # plus (0 2)\n" 37 | " ;\n" 38 | "T : F # 0\n" 39 | " | T '*' F # mult (0 2)\n" 40 | " ;\n" 41 | "F : 'a' # 0\n" 42 | " | '(' E ')' # 1\n" 43 | " ;\n" 44 | "G : 'a' # 0\n" 45 | " ;\n" 46 | ; 47 | 48 | int 49 | main (void) 50 | { 51 | test_standard_parse (input, description); 52 | exit (0); 53 | } 54 | -------------------------------------------------------------------------------- /test/C++/test22.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | /* The following variable is the current number of next input grammar 32 | terminal. */ 33 | static int nterm; 34 | 35 | /* The following function imported by YAEP (see comments in the interface file). */ 36 | const char * 37 | read_terminal (int *code) 38 | { 39 | nterm++; 40 | switch (nterm) 41 | { 42 | case 1: *code = 'a'; return "a"; 43 | case 2: *code = '+'; return "+"; 44 | case 3: *code = '*'; return "*"; 45 | case 4: *code = '('; return "("; 46 | case 5: *code = ')'; return ")"; 47 | default: return NULL; 48 | } 49 | } 50 | 51 | /* The following variable is the current number of next rule grammar 52 | terminal. */ 53 | static int nrule; 54 | 55 | /* The following function imported by YAEP (see comments in the interface file). */ 56 | const char * 57 | read_rule (const char ***rhs, const char **anode, int *anode_cost, int **transl) 58 | { 59 | static const char *rhs_1 [] = {"T", NULL}; 60 | static int tr_1 [] = {0, -1}; 61 | static const char *rhs_2 [] = {"E", "+", "T", NULL}; 62 | static int tr_2 [] = {0, 2, -1}; 63 | static const char *rhs_3 [] = {"F", NULL}; 64 | static int tr_3 [] = {0, -1}; 65 | static const char *rhs_4 [] = {"T", "*", "F", NULL}; 66 | static int tr_4 [] = {0, 2, -1}; 67 | static const char *rhs_5 [] = {"a", NULL}; 68 | static int tr_5 [] = {0, -1}; 69 | static const char *rhs_6 [] = {"(", "E", ")", NULL}; 70 | static int tr_6 [] = {1, -1}; 71 | 72 | nrule++; 73 | switch (nrule) 74 | { 75 | case 1: *rhs = rhs_1; *anode = NULL; *anode_cost = 0; *transl = tr_1; 76 | return "$S"; 77 | case 2: *rhs = rhs_2; *anode = "plus"; *anode_cost = 0; *transl = tr_2; 78 | return "E"; 79 | case 3: *rhs = rhs_3; *anode = NULL; *anode_cost = 0; *transl = tr_3; 80 | return "T"; 81 | case 4: *rhs = rhs_4; *anode = "mult"; *anode_cost = 0; *transl = tr_4; 82 | return "T"; 83 | case 5: *rhs = rhs_5; *anode = NULL; *anode_cost = 0; *transl = tr_5; 84 | return "F"; 85 | case 6: *rhs = rhs_6; *anode = NULL; *anode_cost = 0; *transl = tr_6; 86 | return "F"; 87 | default: return NULL; 88 | } 89 | } 90 | 91 | static const char *input = "a+a*(a*a+a)"; 92 | 93 | int 94 | main (void) 95 | { 96 | test_standard_read (input, read_terminal, read_rule); 97 | exit (0); 98 | } 99 | -------------------------------------------------------------------------------- /test/C++/test25.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | /* The following variable is the current number of next input grammar 32 | terminal. */ 33 | static int nterm; 34 | 35 | /* The following function imported by YAEP (see comments in the interface file). */ 36 | const char * 37 | read_terminal (int *code) 38 | { 39 | nterm++; 40 | switch (nterm) 41 | { 42 | case 1: *code = -2; return "a"; 43 | case 2: *code = '+'; return "+"; 44 | case 3: *code = '*'; return "*"; 45 | case 4: *code = '('; return "("; 46 | case 5: *code = ')'; return ")"; 47 | default: return NULL; 48 | } 49 | } 50 | 51 | /* The following variable is the current number of next rule grammar 52 | terminal. */ 53 | static int nrule; 54 | 55 | /* The following function imported by YAEP (see comments in the interface file). */ 56 | const char * 57 | read_rule (const char ***rhs, const char **anode, int *anode_cost, int **transl) 58 | { 59 | static const char *rhs_1 [] = {"T", NULL}; 60 | static int tr_1 [] = {0, -1}; 61 | static const char *rhs_2 [] = {"E", "+", "T", NULL}; 62 | static int tr_2 [] = {0, 2, -1}; 63 | static const char *rhs_3 [] = {"F", NULL}; 64 | static int tr_3 [] = {0, -1}; 65 | static const char *rhs_4 [] = {"T", "*", "F", NULL}; 66 | static int tr_4 [] = {0, 2, -1}; 67 | static const char *rhs_5 [] = {"a", NULL}; 68 | static int tr_5 [] = {0, -1}; 69 | static const char *rhs_6 [] = {"(", "E", ")", NULL}; 70 | static int tr_6 [] = {1, -1}; 71 | 72 | nrule++; 73 | switch (nrule) 74 | { 75 | case 1: *rhs = rhs_1; *anode = NULL; *anode_cost = 0; *transl = tr_1; 76 | return "E"; 77 | case 2: *rhs = rhs_2; *anode = "plus"; *anode_cost = 0; *transl = tr_2; 78 | return "E"; 79 | case 3: *rhs = rhs_3; *anode = NULL; *anode_cost = 0; *transl = tr_3; 80 | return "T"; 81 | case 4: *rhs = rhs_4; *anode = "mult"; *anode_cost = 0; *transl = tr_4; 82 | return "T"; 83 | case 5: *rhs = rhs_5; *anode = NULL; *anode_cost = 0; *transl = tr_5; 84 | return "F"; 85 | case 6: *rhs = rhs_6; *anode = NULL; *anode_cost = 0; *transl = tr_6; 86 | return "F"; 87 | default: return NULL; 88 | } 89 | } 90 | 91 | static const char *input = "a+a*(a*a+a)"; 92 | 93 | int 94 | main (void) 95 | { 96 | test_standard_read (input, read_terminal, read_rule); 97 | exit (0); 98 | } 99 | -------------------------------------------------------------------------------- /test/C++/test26.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | /* The following variable is the current number of next input grammar 32 | terminal. */ 33 | static int nterm; 34 | 35 | /* The following function imported by YAEP (see comments in the interface file). */ 36 | const char * 37 | read_terminal (int *code) 38 | { 39 | nterm++; 40 | switch (nterm) 41 | { 42 | case 1: *code = 'a'; return "a"; 43 | case 2: *code = '+'; return "+"; 44 | case 3: *code = '*'; return "*"; 45 | case 4: *code = '('; return "("; 46 | case 5: *code = ')'; return ")"; 47 | default: return NULL; 48 | } 49 | } 50 | 51 | /* The following variable is the current number of next rule grammar 52 | terminal. */ 53 | static int nrule; 54 | 55 | /* The following function imported by YAEP (see comments in the interface file). */ 56 | const char * 57 | read_rule (const char ***rhs, const char **anode, int *anode_cost, int **transl) 58 | { 59 | static const char *rhs_1 [] = {"T", NULL}; 60 | static int tr_1 [] = {0, 0, -1}; 61 | static const char *rhs_2 [] = {"E", "+", "T", NULL}; 62 | static int tr_2 [] = {0, 2, -1}; 63 | static const char *rhs_3 [] = {"F", NULL}; 64 | static int tr_3 [] = {0, -1}; 65 | static const char *rhs_4 [] = {"T", "*", "F", NULL}; 66 | static int tr_4 [] = {0, 2, -1}; 67 | static const char *rhs_5 [] = {"a", NULL}; 68 | static int tr_5 [] = {0, -1}; 69 | static const char *rhs_6 [] = {"(", "E", ")", NULL}; 70 | static int tr_6 [] = {1, -1}; 71 | 72 | nrule++; 73 | switch (nrule) 74 | { 75 | case 1: *rhs = rhs_1; *anode = NULL; *anode_cost = 0; *transl = tr_1; 76 | return "E"; 77 | case 2: *rhs = rhs_2; *anode = "plus"; *anode_cost = 0; *transl = tr_2; 78 | return "E"; 79 | case 3: *rhs = rhs_3; *anode = NULL; *anode_cost = 0; *transl = tr_3; 80 | return "T"; 81 | case 4: *rhs = rhs_4; *anode = "mult"; *anode_cost = 0; *transl = tr_4; 82 | return "T"; 83 | case 5: *rhs = rhs_5; *anode = NULL; *anode_cost = 0; *transl = tr_5; 84 | return "F"; 85 | case 6: *rhs = rhs_6; *anode = NULL; *anode_cost = 0; *transl = tr_6; 86 | return "F"; 87 | default: return NULL; 88 | } 89 | } 90 | 91 | static const char *input = "a+a*(a*a+a)"; 92 | 93 | int 94 | main (void) 95 | { 96 | test_standard_read (input, read_terminal, read_rule); 97 | exit (0); 98 | } 99 | -------------------------------------------------------------------------------- /test/C++/test27.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : T # 0\n" 36 | " | E '+' T # plus (0 2)\n" 37 | " ;\n" 38 | "T : F # 0\n" 39 | " | T '*' F # mult (0 2)\n" 40 | " ;\n" 41 | "F : 'a' # 0\n" 42 | " | '(' E ')' # 1\n" 43 | " ;\n" 44 | ; 45 | 46 | int 47 | main (void) 48 | { 49 | test_standard_parse (input, description); 50 | exit (0); 51 | } 52 | -------------------------------------------------------------------------------- /test/C++/test28.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : T # 0\n" 36 | " | E '+' T # plus (0 2)\n" 37 | " ;\n" 38 | "T : F # 0\n" 39 | " | T '*' F # mult (0 2)\n" 40 | " ;\n" 41 | "F : 'a' # 0\n" 42 | " | '(' E ')' # 1\n" 43 | " | '(' error ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int 48 | main (int argc, char **argv) 49 | { 50 | test_complex_parse (input, description, 1, 0, 0, 0, argc, argv); 51 | exit (0); 52 | } 53 | -------------------------------------------------------------------------------- /test/C++/test29.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : T # 0\n" 36 | " | E '+' T # plus (0 2)\n" 37 | " ;\n" 38 | "T : F # 0\n" 39 | " | T '*' F # mult (0 2)\n" 40 | " ;\n" 41 | "F : 'a' # 0\n" 42 | " | '(' E ')' # 1\n" 43 | " | '(' error ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int 48 | main (int argc, char **argv) 49 | { 50 | test_complex_parse (input, description, 1, 0, 0, 0, argc, argv); 51 | exit (0); 52 | } 53 | -------------------------------------------------------------------------------- /test/C++/test30.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : E '+' E # plus (0 2)\n" 36 | " | E '*' E # mult (0 2)\n" 37 | " | 'a' # 0\n" 38 | " | '(' E ')' # 1\n" 39 | " ;\n" 40 | ; 41 | 42 | int 43 | main (int argc, char **argv) 44 | { 45 | test_complex_parse (input, description, 1, 1, 0, 0, argc, argv); 46 | exit (0); 47 | } 48 | -------------------------------------------------------------------------------- /test/C++/test31.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : E '+' E # plus (0 2)\n" 36 | " | E '*' E # mult (0 2)\n" 37 | " | 'a' # 0\n" 38 | " | '(' E ')' # 1\n" 39 | " ;\n" 40 | ; 41 | 42 | int 43 | main (int argc, char **argv) 44 | { 45 | test_complex_parse (input, description, 0, 1, 0, 0, argc, argv); 46 | exit (0); 47 | } 48 | -------------------------------------------------------------------------------- /test/C++/test32.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : E '+' E # plus (0 2)\n" 36 | " | E '*' E # mult (0 2)\n" 37 | " | 'a' # 0\n" 38 | " | '(' E ')' # 1\n" 39 | " | '(' error ')' # 1\n" 40 | " ;\n" 41 | ; 42 | 43 | int 44 | main (int argc, char **argv) 45 | { 46 | test_complex_parse (input, description, 1, 1, 0, 0, argc, argv); 47 | exit (0); 48 | } 49 | -------------------------------------------------------------------------------- /test/C++/test33.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : E '+' E # plus (0 2)\n" 36 | " | E '*' E # mult (0 2)\n" 37 | " | 'a' # 0\n" 38 | " | '(' E ')' # 1\n" 39 | " ;\n" 40 | ; 41 | 42 | int 43 | main (int argc, char **argv) 44 | { 45 | test_complex_parse (input, description, 0, 0, 0, 0, argc, argv); 46 | exit (0); 47 | } 48 | -------------------------------------------------------------------------------- /test/C++/test34.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : E '+' E # plus (0 2)\n" 36 | " | E '*' E # mult (0 2)\n" 37 | " | 'a' # 0\n" 38 | " | '(' E ')' # 1\n" 39 | " | '(' error ')' # 1\n" 40 | " ;\n" 41 | ; 42 | 43 | int 44 | main (int argc, char **argv) 45 | { 46 | test_complex_parse (input, description, 0, 1, 0, 0, argc, argv); 47 | exit (0); 48 | } 49 | -------------------------------------------------------------------------------- /test/C++/test35.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : T # 0\n" 36 | " | E '+' T # plus (0 2)\n" 37 | " ;\n" 38 | "T : F # 0\n" 39 | " | T '*' F # mult (0 2)\n" 40 | " ;\n" 41 | "F : 'a' # 0\n" 42 | " | '(' E ')' # 1\n" 43 | " ;\n" 44 | ; 45 | 46 | int 47 | main (int argc, char **argv) 48 | { 49 | test_complex_parse (input, description, 0, 0, 0, 0, argc, argv); 50 | exit (0); 51 | } 52 | -------------------------------------------------------------------------------- /test/C++/test36.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*)+(*a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : T # 0\n" 36 | " | E '+' T # plus (0 2)\n" 37 | " ;\n" 38 | "T : F # 0\n" 39 | " | T '*' F # mult (0 2)\n" 40 | " ;\n" 41 | "F : 'a' # 0\n" 42 | " | '(' E ')' # 1\n" 43 | " | '(' error ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int 48 | main (int argc, char **argv) 49 | { 50 | test_complex_parse (input, description, 0, 0, 0, 0, argc, argv); 51 | exit (0); 52 | } 53 | -------------------------------------------------------------------------------- /test/C++/test37.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*)+(*a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : T # 0\n" 36 | " | E '+' T # plus (0 2)\n" 37 | " ;\n" 38 | "T : F # 0\n" 39 | " | T '*' F # mult (0 2)\n" 40 | " ;\n" 41 | "F : 'a' # 0\n" 42 | " | '(' E ')' # 1\n" 43 | " | '(' error ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int 48 | main (int argc, char **argv) 49 | { 50 | test_complex_parse (input, description, 0, 0, 0, 4, argc, argv); 51 | exit (0); 52 | } 53 | -------------------------------------------------------------------------------- /test/C++/test38.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*)+(*a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : T # 0\n" 36 | " | E '+' T # plus (0 2)\n" 37 | "T : F # 0\n" 38 | " | T '*' F # mult (0 2)\n" 39 | "F : 'a' # 0\n" 40 | " | '(' E ')' # 1\n" 41 | " | '(' error ')' # 1\n" 42 | ; 43 | 44 | int 45 | main (int argc, char **argv) 46 | { 47 | test_complex_parse (input, description, 0, 0, 0, 4, argc, argv); 48 | exit (0); 49 | } 50 | -------------------------------------------------------------------------------- /test/C++/test39.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+b*c+d"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : E '+' E # plus (0 2)\n" 36 | " | E '*' E # mult (0 2)\n" 37 | " | 'a' # 0\n" 38 | " | 'b' # 0\n" 39 | " | 'c' # 0\n" 40 | " | 'd' # 0\n" 41 | " | '(' E ')' # 1\n" 42 | " ;\n" 43 | ; 44 | 45 | int 46 | main (int argc, char **argv) 47 | { 48 | test_complex_parse (input, description, 0, 1, 0, 0, argc, argv); 49 | exit (0); 50 | } 51 | -------------------------------------------------------------------------------- /test/C++/test40.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+b*c+a"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : E '+' E # plus (0 2)\n" 36 | " | E '*' E # mult (0 2)\n" 37 | " | 'a' # 0\n" 38 | " | 'b' # 0\n" 39 | " | 'c' # 0\n" 40 | " | 'd' # 0\n" 41 | " | '(' E ')' # 1\n" 42 | " ;\n" 43 | ; 44 | 45 | int 46 | main (int argc, char **argv) 47 | { 48 | test_complex_parse (input, description, 0, 1, 0, 0, argc, argv); 49 | exit (0); 50 | } 51 | -------------------------------------------------------------------------------- /test/C++/test42.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+(a*a+a)*a"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : E '+' E # plus (- 2)\n" 36 | " | E '*' E # mult (0 -)\n" 37 | " | 'a' # 0\n" 38 | " | '(' E ')' # 1\n" 39 | " ;\n" 40 | ; 41 | 42 | int 43 | main (int argc, char **argv) 44 | { 45 | test_complex_parse (input, description, 1, 1, 0, 0, argc, argv); 46 | exit (0); 47 | } 48 | -------------------------------------------------------------------------------- /test/C++/test43.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+b*c+d"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : E '+' E # plus (- 2)\n" 36 | " | E '*' E # mult (0 -)\n" 37 | " | E '*' E # mult (0 2)\n" 38 | " | 'a' # 0\n" 39 | " | 'b' # 0\n" 40 | " | 'c' # 0\n" 41 | " | 'd' # 0\n" 42 | " | '(' E ')' # 1\n" 43 | " ;\n" 44 | ; 45 | 46 | int 47 | main (int argc, char **argv) 48 | { 49 | test_complex_parse (input, description, 0, 1, 0, 0, argc, argv); 50 | exit (0); 51 | } 52 | -------------------------------------------------------------------------------- /test/C++/test44.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | /* The following variable is the current number of next input grammar 32 | terminal. */ 33 | static int nterm; 34 | 35 | /* The following function imported by YAEP (see comments in the interface file). */ 36 | const char * 37 | read_terminal (int *code) 38 | { 39 | nterm++; 40 | switch (nterm) 41 | { 42 | case 1: *code = 'a'; return "a"; 43 | case 2: *code = '+'; return "+"; 44 | case 3: *code = '*'; return "*"; 45 | case 4: *code = '('; return "("; 46 | case 5: *code = ')'; return ")"; 47 | default: return NULL; 48 | } 49 | } 50 | 51 | /* The following variable is the current number of next rule grammar 52 | terminal. */ 53 | static int nrule; 54 | 55 | /* The following function imported by YAEP (see comments in the interface file). */ 56 | const char * 57 | read_rule (const char ***rhs, const char **anode, int *anode_cost, int **transl) 58 | { 59 | static const char *rhs_1 [] = {"T", NULL}; 60 | static int tr_1 [] = {0, -1}; 61 | static const char *rhs_2 [] = {"E", "+", "T", NULL}; 62 | static int tr_2 [] = {0, 2, -1}; 63 | static const char *rhs_3 [] = {"F", NULL}; 64 | static int tr_3 [] = {0, -1}; 65 | static const char *rhs_4 [] = {"T", "*", "F", NULL}; 66 | static int tr_4 [] = {0, 2, -1}; 67 | static const char *rhs_5 [] = {"a", NULL}; 68 | static int tr_5 [] = {0, -1}; 69 | static const char *rhs_6 [] = {"(", "E", ")", NULL}; 70 | static int tr_6 [] = {1, -1}; 71 | 72 | nrule++; 73 | switch (nrule) 74 | { 75 | case 1: *rhs = rhs_1; *anode = NULL; *anode_cost = 0; *transl = tr_1; 76 | return "E"; 77 | case 2: *rhs = rhs_2; *anode = "plus"; *anode_cost = -1; *transl = tr_2; 78 | return "E"; 79 | case 3: *rhs = rhs_3; *anode = NULL; *anode_cost = 0; *transl = tr_3; 80 | return "T"; 81 | case 4: *rhs = rhs_4; *anode = "mult"; *anode_cost = 0; *transl = tr_4; 82 | return "T"; 83 | case 5: *rhs = rhs_5; *anode = NULL; *anode_cost = 0; *transl = tr_5; 84 | return "F"; 85 | case 6: *rhs = rhs_6; *anode = NULL; *anode_cost = 0; *transl = tr_6; 86 | return "F"; 87 | default: return NULL; 88 | } 89 | } 90 | 91 | static const char *input = "a+a*(a*a+a)"; 92 | 93 | int 94 | main (void) 95 | { 96 | test_standard_read (input, read_terminal, read_rule); 97 | exit (0); 98 | } 99 | -------------------------------------------------------------------------------- /test/C++/test45.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+((a*a)+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : V '+' V # add 1 (0 2)\n" 36 | " | V '*' V # mult 1 (0 2)\n" 37 | " | V '+' '(' V '*' V ')' # madd 1 (0 3 5)\n" 38 | " | '(' V '*' V ')' '+' V # madd 1 (6 1 3)\n" 39 | " ;\n" 40 | "V : 'a' # 0\n" 41 | " | '(' E ')' # 1\n" 42 | " ;\n" 43 | ; 44 | 45 | int 46 | main (int argc, char **argv) 47 | { 48 | test_complex_parse (input, description, 1, 1, 1, 0, argc, argv); 49 | exit (0); 50 | } 51 | -------------------------------------------------------------------------------- /test/C++/test46.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+((a*a)+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : V '+' V # add 1 (0 2)\n" 36 | " | V '*' V # mult 1 (0 2)\n" 37 | " | V '+' '(' V '*' V ')' # madd 2 (0 3 5)\n" 38 | " | '(' V '*' V ')' '+' V # madd 2 (6 1 3)\n" 39 | " ;\n" 40 | "V : 'a' # 0\n" 41 | " | '(' E ')' # 1\n" 42 | " ;\n" 43 | ; 44 | 45 | int 46 | main (int argc, char **argv) 47 | { 48 | test_complex_parse (input, description, 0, 1, 1, 0, argc, argv); 49 | exit (0); 50 | } 51 | -------------------------------------------------------------------------------- /test/C++/test47.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+((a*a)+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : V '+' V # add 1 (0 2)\n" 36 | " | V '*' V # mult 1 (0 2)\n" 37 | " | V '+' '(' V '*' V ')' # madd 1 (0 3 5)\n" 38 | " | '(' V '*' V ')' '+' V # madd 1 (6 1 3)\n" 39 | " ;\n" 40 | "V : 'a' # 0\n" 41 | " | '(' E ')' # 1\n" 42 | " ;\n" 43 | ; 44 | 45 | int 46 | main (int argc, char **argv) 47 | { 48 | test_complex_parse (input, description, 1, 1, 1, 0, argc, argv); 49 | exit (0); 50 | } 51 | -------------------------------------------------------------------------------- /test/C++/test48.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "spc; "; 32 | 33 | static const char *description = 34 | "\n" 35 | "P : 's' sp st sp # prog (2)\n" 36 | "st : 'p' sp p_list sp ';' # print (2)\n" 37 | "p_list : 'c' sp p_list # string (0 2)\n" 38 | " | # -\n" 39 | "sp : ' '\n" 40 | " |\n" 41 | ; 42 | 43 | int 44 | main (int argc, char **argv) 45 | { 46 | test_complex_parse (input, description, 1, 0, 0, 0, argc, argv); 47 | exit (0); 48 | } 49 | -------------------------------------------------------------------------------- /test/C++/test49.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "s"; 32 | 33 | static const char *description = 34 | "\n" 35 | "P : 's' opt # prog (1)\n" 36 | "opt : # opt (-)\n" 37 | "opt : 'c' # optc (-)" 38 | ; 39 | 40 | int 41 | main (int argc, char **argv) 42 | { 43 | test_complex_parse (input, description, 1, 0, 0, 0, argc, argv); 44 | exit (0); 45 | } 46 | -------------------------------------------------------------------------------- /test/C/test06.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include<stdio.h> 28 | #include <stdlib.h> 29 | 30 | #include"common.h" 31 | #include "yaep.h" 32 | 33 | static const char *input = "a+a*(a*a+a)"; 34 | 35 | static const char *description = 36 | "\n" 37 | "TERM;\n" 38 | "E : T # 0\n" 39 | " | E '+' T # plus (0 2)\n" 40 | " ;\n" 41 | "T : F # 0\n" 42 | " | T '*' F # mult (0 2)\n" 43 | " ;\n" 44 | "F : 'a' # 0\n" 45 | " | '(' E ')' # 1\n" 46 | " ;\n" 47 | ; 48 | 49 | int main (void) 50 | { 51 | struct grammar *g; 52 | struct yaep_tree_node *root; 53 | int ambiguous_p; 54 | 55 | if ((g = yaep_create_grammar ()) == NULL) 56 | { 57 | fprintf (stderr, "yaep_create_grammar: No memory\n"); 58 | exit (1); 59 | } 60 | if ( yaep_parse( g, test_read_token, test_syntax_error, test_parse_alloc, test_parse_free, &root, &ambiguous_p ) ) { 61 | fprintf (stderr, "yaep parse: %s\n", yaep_error_message (g)); 62 | exit (1); 63 | } 64 | yaep_free_grammar (g); 65 | exit (0); 66 | } 67 | -------------------------------------------------------------------------------- /test/C/test07.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include<stdio.h> 28 | #include <stdlib.h> 29 | 30 | #include"common.h" 31 | #include "yaep.h" 32 | 33 | static const char *input = "a+a*(a*a+a)"; 34 | 35 | static const char *description = 36 | "\n" 37 | "TERM;\n" 38 | "E : T # 0\n" 39 | " | E '+' T # plus (0 2)\n" 40 | " ;\n" 41 | "T : F # 0\n" 42 | " | T '*' F # mult (0 2)\n" 43 | " ;\n" 44 | "F : 'a' # 0\n" 45 | " | '(' E ')' # 1\n" 46 | " ;\n" 47 | ; 48 | 49 | int main (void) 50 | { 51 | struct grammar *g; 52 | struct yaep_tree_node *root; 53 | int ambiguous_p; 54 | 55 | if ((g = yaep_create_grammar ()) == NULL) 56 | { 57 | fprintf (stderr, "yaep_create_grammar: No memory\n"); 58 | exit (1); 59 | } 60 | if (yaep_parse_grammar (g, 0, description) != 0) 61 | { 62 | fprintf (stderr, "%s\n", yaep_error_message (g)); 63 | exit (1); 64 | } 65 | if (yaep_parse_grammar (g, 1, description) != 0) 66 | { 67 | fprintf (stderr, "%s\n", yaep_error_message (g)); 68 | exit (1); 69 | } 70 | if ( yaep_parse( g, test_read_token, test_syntax_error, test_parse_alloc, test_parse_free, &root, &ambiguous_p ) ) { 71 | fprintf (stderr, "yaep parse: %s\n", yaep_error_message (g)); 72 | exit (1); 73 | } 74 | yaep_free_grammar (g); 75 | exit (0); 76 | } 77 | -------------------------------------------------------------------------------- /test/C/test08.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "TERM 1\n" 36 | "E : T # 0\n" 37 | " | E '+' T # plus (0 2)\n" 38 | " ;\n" 39 | "T : F # 0\n" 40 | " | T '*' F # mult (0 2)\n" 41 | " ;\n" 42 | "F : 'a' # 0\n" 43 | " | '(' E ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int main (void) 48 | { 49 | test_standard_parse (); 50 | exit (0); 51 | } 52 | -------------------------------------------------------------------------------- /test/C/test09.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "TERM;\n" 36 | "error : T # 0\n" 37 | " | E '+' T # plus (0 2)\n" 38 | " ;\n" 39 | "T : F # 0\n" 40 | " | T '*' F # mult (0 2)\n" 41 | " ;\n" 42 | "F : 'a' # 0\n" 43 | " | '(' E ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int main (void) 48 | { 49 | test_standard_parse (); 50 | exit (0); 51 | } 52 | -------------------------------------------------------------------------------- /test/C/test10.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "TERM ident=11 ident=10;\n" 36 | "E : T # 0\n" 37 | " | E '+' T # plus (0 2)\n" 38 | " ;\n" 39 | "T : F # 0\n" 40 | " | T '*' F # mult (0 2)\n" 41 | " ;\n" 42 | "F : 'a' # 0\n" 43 | " | '(' E ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int main (void) 48 | { 49 | test_standard_parse (); 50 | exit (0); 51 | } 52 | -------------------------------------------------------------------------------- /test/C/test11.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "TERM ident=10 i=10;\n" 36 | "E : T # 0\n" 37 | " | E '+' T # plus (0 2)\n" 38 | " ;\n" 39 | "T : F # 0\n" 40 | " | T '*' F # mult (0 2)\n" 41 | " ;\n" 42 | "F : 'a' # 0\n" 43 | " | '(' E ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int main (void) 48 | { 49 | test_standard_parse (); 50 | exit (0); 51 | } 52 | -------------------------------------------------------------------------------- /test/C/test12.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = "TERM;\n"; 34 | 35 | int main (void) 36 | { 37 | test_standard_parse (); 38 | exit (0); 39 | } 40 | -------------------------------------------------------------------------------- /test/C/test13.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = "TERM ident; ident : ;\n"; 34 | 35 | int main (void) 36 | { 37 | test_standard_parse (); 38 | exit (0); 39 | } 40 | -------------------------------------------------------------------------------- /test/C/test14.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "TERM;\n" 36 | "E : T # 1\n" 37 | " | E '+' T # plus (0 2)\n" 38 | " ;\n" 39 | "T : F # 0\n" 40 | " | T '*' F # mult (0 2)\n" 41 | " ;\n" 42 | "F : 'a' # 0\n" 43 | " | '(' E ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int main (void) 48 | { 49 | test_standard_parse (); 50 | exit (0); 51 | } 52 | -------------------------------------------------------------------------------- /test/C/test15.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "TERM;\n" 36 | "E : T # 0\n" 37 | " | E '+' T # plus (0 0)\n" 38 | " ;\n" 39 | "T : F # 0\n" 40 | " | T '*' F # mult (0 2)\n" 41 | " ;\n" 42 | "F : 'a' # 0\n" 43 | " | '(' E ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int main (void) 48 | { 49 | test_standard_parse (); 50 | exit (0); 51 | } 52 | -------------------------------------------------------------------------------- /test/C/test16.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : T # 0\n" 36 | " | E '+' T # plus (0 0)\n" 37 | " ;\n" 38 | "T : F # 0\n" 39 | " | T '*' F # mult (0 2)\n" 40 | " ;\n" 41 | "F : 'a' # 0\n" 42 | " | '(' E ')' # 1\n" 43 | " ;\n" 44 | ; 45 | 46 | int main (void) 47 | { 48 | test_standard_parse (); 49 | exit (0); 50 | } 51 | -------------------------------------------------------------------------------- /test/C/test17.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : 'a' E\n" 36 | " | E '+'\n" 37 | " ;\n" 38 | ; 39 | 40 | int main (int argc, char **argv) 41 | { 42 | test_complex_parse (0, 0, 0, 0, argc, argv); 43 | exit (0); 44 | } 45 | -------------------------------------------------------------------------------- /test/C/test18.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "E : A O O\n" 35 | " | E 'a'\n" 36 | " | 'b'\n" 37 | " |\n" 38 | " ;\n" 39 | "\n" 40 | "A : O O N\n" 41 | " ;\n" 42 | "\n" 43 | "N : O E E O\n" 44 | " ;\n" 45 | "\n" 46 | "O :\n" 47 | " ;\n" 48 | ; 49 | 50 | int main (void) 51 | { 52 | test_standard_parse (); 53 | exit (0); 54 | } 55 | -------------------------------------------------------------------------------- /test/C/test19.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+b)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "TERM;\n" 36 | "E : T # 0\n" 37 | " | E '+' T # plus (0 2)\n" 38 | " ;\n" 39 | "T : F # 0\n" 40 | " | T '*' F # mult (0 2)\n" 41 | " ;\n" 42 | "F : 'a' # 0\n" 43 | " | '(' E ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int main (void) 48 | { 49 | test_standard_parse (); 50 | exit (0); 51 | } 52 | -------------------------------------------------------------------------------- /test/C/test20.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : T # 0\n" 36 | " | E '+' T # plus (0 2)\n" 37 | " ;\n" 38 | "T : F # 0\n" 39 | " | T '*' F # mult (0 2)\n" 40 | " ;\n" 41 | "F : 'a' # 0\n" 42 | " | '(' E ')' # 1\n" 43 | " ;\n" 44 | "G : 'a' # 0\n" 45 | " ;\n" 46 | ; 47 | 48 | int main (void) 49 | { 50 | test_standard_parse (); 51 | exit (0); 52 | } 53 | -------------------------------------------------------------------------------- /test/C/test22.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | /* The following variable is the current number of next input grammar 32 | terminal. */ 33 | static int nterm; 34 | 35 | /* The following function imported by YAEP (see comments in the interface file). */ 36 | const char * 37 | read_terminal (int *code) 38 | { 39 | nterm++; 40 | switch (nterm) 41 | { 42 | case 1: *code = 'a'; return "a"; 43 | case 2: *code = '+'; return "+"; 44 | case 3: *code = '*'; return "*"; 45 | case 4: *code = '('; return "("; 46 | case 5: *code = ')'; return ")"; 47 | default: return NULL; 48 | } 49 | } 50 | 51 | /* The following variable is the current number of next rule grammar 52 | terminal. */ 53 | static int nrule; 54 | 55 | /* The following function imported by YAEP (see comments in the interface file). */ 56 | const char * 57 | read_rule (const char ***rhs, const char **anode, int *anode_cost, int **transl) 58 | { 59 | static const char *rhs_1 [] = {"T", NULL}; 60 | static int tr_1 [] = {0, -1}; 61 | static const char *rhs_2 [] = {"E", "+", "T", NULL}; 62 | static int tr_2 [] = {0, 2, -1}; 63 | static const char *rhs_3 [] = {"F", NULL}; 64 | static int tr_3 [] = {0, -1}; 65 | static const char *rhs_4 [] = {"T", "*", "F", NULL}; 66 | static int tr_4 [] = {0, 2, -1}; 67 | static const char *rhs_5 [] = {"a", NULL}; 68 | static int tr_5 [] = {0, -1}; 69 | static const char *rhs_6 [] = {"(", "E", ")", NULL}; 70 | static int tr_6 [] = {1, -1}; 71 | 72 | nrule++; 73 | switch (nrule) 74 | { 75 | case 1: *rhs = rhs_1; *anode = NULL; *anode_cost = 0; *transl = tr_1; 76 | return "$S"; 77 | case 2: *rhs = rhs_2; *anode = "plus"; *anode_cost = 0; *transl = tr_2; 78 | return "E"; 79 | case 3: *rhs = rhs_3; *anode = NULL; *anode_cost = 0; *transl = tr_3; 80 | return "T"; 81 | case 4: *rhs = rhs_4; *anode = "mult"; *anode_cost = 0; *transl = tr_4; 82 | return "T"; 83 | case 5: *rhs = rhs_5; *anode = NULL; *anode_cost = 0; *transl = tr_5; 84 | return "F"; 85 | case 6: *rhs = rhs_6; *anode = NULL; *anode_cost = 0; *transl = tr_6; 86 | return "F"; 87 | default: return NULL; 88 | } 89 | } 90 | 91 | static const char *input = "a+a*(a*a+a)"; 92 | 93 | int main (void) 94 | { 95 | test_standard_read (read_terminal, read_rule); 96 | exit (0); 97 | } 98 | -------------------------------------------------------------------------------- /test/C/test23.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | /* The following variable is the current number of next input grammar 32 | terminal. */ 33 | static int nterm; 34 | 35 | /* The following function imported by YAEP (see comments in the interface file). */ 36 | const char * 37 | read_terminal (int *code) 38 | { 39 | nterm++; 40 | switch (nterm) 41 | { 42 | case 1: *code = 'a'; return "a"; 43 | case 2: *code = '+'; return "+"; 44 | case 3: *code = '*'; return "*"; 45 | case 4: *code = '('; return "("; 46 | case 5: *code = ')'; return ")"; 47 | case 6: *code = 'e'; return "$eof"; 48 | default: return NULL; 49 | } 50 | } 51 | 52 | /* The following variable is the current number of next rule grammar 53 | terminal. */ 54 | static int nrule; 55 | 56 | /* The following function imported by YAEP (see comments in the interface file). */ 57 | const char * 58 | read_rule (const char ***rhs, const char **anode, int *anode_cost, int **transl) 59 | { 60 | static const char *rhs_1 [] = {"T", NULL}; 61 | static int tr_1 [] = {0, -1}; 62 | static const char *rhs_2 [] = {"E", "+", "T", NULL}; 63 | static int tr_2 [] = {0, 2, -1}; 64 | static const char *rhs_3 [] = {"F", NULL}; 65 | static int tr_3 [] = {0, -1}; 66 | static const char *rhs_4 [] = {"T", "*", "F", NULL}; 67 | static int tr_4 [] = {0, 2, -1}; 68 | static const char *rhs_5 [] = {"a", NULL}; 69 | static int tr_5 [] = {0, -1}; 70 | static const char *rhs_6 [] = {"(", "E", ")", NULL}; 71 | static int tr_6 [] = {1, -1}; 72 | 73 | nrule++; 74 | switch (nrule) 75 | { 76 | case 1: *rhs = rhs_1; *anode = NULL; *anode_cost = 0; *transl = tr_1; 77 | return "E"; 78 | case 2: *rhs = rhs_2; *anode = "plus"; *anode_cost = 0; *transl = tr_2; 79 | return "E"; 80 | case 3: *rhs = rhs_3; *anode = NULL; *anode_cost = 0; *transl = tr_3; 81 | return "T"; 82 | case 4: *rhs = rhs_4; *anode = "mult"; *anode_cost = 0; *transl = tr_4; 83 | return "T"; 84 | case 5: *rhs = rhs_5; *anode = NULL; *anode_cost = 0; *transl = tr_5; 85 | return "F"; 86 | case 6: *rhs = rhs_6; *anode = NULL; *anode_cost = 0; *transl = tr_6; 87 | return "F"; 88 | default: return NULL; 89 | } 90 | } 91 | 92 | static const char *input = "a+a*(a*a+a)"; 93 | 94 | int main (void) 95 | { 96 | test_standard_read (read_terminal, read_rule); 97 | exit (0); 98 | } 99 | -------------------------------------------------------------------------------- /test/C/test24.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | /* The following variable is the current number of next input grammar 32 | terminal. */ 33 | static int nterm; 34 | 35 | /* The following function imported by YAEP (see comments in the interface file). */ 36 | const char * 37 | read_terminal (int *code) 38 | { 39 | nterm++; 40 | switch (nterm) 41 | { 42 | case 1: *code = 'a'; return "a"; 43 | case 2: *code = '+'; return "+"; 44 | case 3: *code = '*'; return "*"; 45 | case 4: *code = '('; return "("; 46 | case 5: *code = ')'; return ")"; 47 | case 6: *code = 'a'; return "a"; 48 | default: return NULL; 49 | } 50 | } 51 | 52 | /* The following variable is the current number of next rule grammar 53 | terminal. */ 54 | static int nrule; 55 | 56 | /* The following function imported by YAEP (see comments in the interface file). */ 57 | const char * 58 | read_rule (const char ***rhs, const char **anode, int *anode_cost, int **transl) 59 | { 60 | static const char *rhs_1 [] = {"T", NULL}; 61 | static int tr_1 [] = {0, -1}; 62 | static const char *rhs_2 [] = {"E", "+", "T", NULL}; 63 | static int tr_2 [] = {0, 2, -1}; 64 | static const char *rhs_3 [] = {"F", NULL}; 65 | static int tr_3 [] = {0, -1}; 66 | static const char *rhs_4 [] = {"T", "*", "F", NULL}; 67 | static int tr_4 [] = {0, 2, -1}; 68 | static const char *rhs_5 [] = {"a", NULL}; 69 | static int tr_5 [] = {0, -1}; 70 | static const char *rhs_6 [] = {"(", "E", ")", NULL}; 71 | static int tr_6 [] = {1, -1}; 72 | 73 | nrule++; 74 | switch (nrule) 75 | { 76 | case 1: *rhs = rhs_1; *anode = NULL; *anode_cost = 0; *transl = tr_1; 77 | return "E"; 78 | case 2: *rhs = rhs_2; *anode = "plus"; *anode_cost = 0; *transl = tr_2; 79 | return "E"; 80 | case 3: *rhs = rhs_3; *anode = NULL; *anode_cost = 0; *transl = tr_3; 81 | return "T"; 82 | case 4: *rhs = rhs_4; *anode = "mult"; *anode_cost = 0; *transl = tr_4; 83 | return "T"; 84 | case 5: *rhs = rhs_5; *anode = NULL; *anode_cost = 0; *transl = tr_5; 85 | return "F"; 86 | case 6: *rhs = rhs_6; *anode = NULL; *anode_cost = 0; *transl = tr_6; 87 | return "F"; 88 | default: return NULL; 89 | } 90 | } 91 | 92 | static const char *input = "a+a*(a*a+a)"; 93 | 94 | int main (void) 95 | { 96 | test_standard_read (read_terminal, read_rule); 97 | exit (0); 98 | } 99 | -------------------------------------------------------------------------------- /test/C/test25.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | /* The following variable is the current number of next input grammar 32 | terminal. */ 33 | static int nterm; 34 | 35 | /* The following function imported by YAEP (see comments in the interface file). */ 36 | const char * 37 | read_terminal (int *code) 38 | { 39 | nterm++; 40 | switch (nterm) 41 | { 42 | case 1: *code = -2; return "a"; 43 | case 2: *code = '+'; return "+"; 44 | case 3: *code = '*'; return "*"; 45 | case 4: *code = '('; return "("; 46 | case 5: *code = ')'; return ")"; 47 | default: return NULL; 48 | } 49 | } 50 | 51 | /* The following variable is the current number of next rule grammar 52 | terminal. */ 53 | static int nrule; 54 | 55 | /* The following function imported by YAEP (see comments in the interface file). */ 56 | const char * 57 | read_rule (const char ***rhs, const char **anode, int *anode_cost, int **transl) 58 | { 59 | static const char *rhs_1 [] = {"T", NULL}; 60 | static int tr_1 [] = {0, -1}; 61 | static const char *rhs_2 [] = {"E", "+", "T", NULL}; 62 | static int tr_2 [] = {0, 2, -1}; 63 | static const char *rhs_3 [] = {"F", NULL}; 64 | static int tr_3 [] = {0, -1}; 65 | static const char *rhs_4 [] = {"T", "*", "F", NULL}; 66 | static int tr_4 [] = {0, 2, -1}; 67 | static const char *rhs_5 [] = {"a", NULL}; 68 | static int tr_5 [] = {0, -1}; 69 | static const char *rhs_6 [] = {"(", "E", ")", NULL}; 70 | static int tr_6 [] = {1, -1}; 71 | 72 | nrule++; 73 | switch (nrule) 74 | { 75 | case 1: *rhs = rhs_1; *anode = NULL; *anode_cost = 0; *transl = tr_1; 76 | return "E"; 77 | case 2: *rhs = rhs_2; *anode = "plus"; *anode_cost = 0; *transl = tr_2; 78 | return "E"; 79 | case 3: *rhs = rhs_3; *anode = NULL; *anode_cost = 0; *transl = tr_3; 80 | return "T"; 81 | case 4: *rhs = rhs_4; *anode = "mult"; *anode_cost = 0; *transl = tr_4; 82 | return "T"; 83 | case 5: *rhs = rhs_5; *anode = NULL; *anode_cost = 0; *transl = tr_5; 84 | return "F"; 85 | case 6: *rhs = rhs_6; *anode = NULL; *anode_cost = 0; *transl = tr_6; 86 | return "F"; 87 | default: return NULL; 88 | } 89 | } 90 | 91 | static const char *input = "a+a*(a*a+a)"; 92 | 93 | int main (void) 94 | { 95 | test_standard_read (read_terminal, read_rule); 96 | exit (0); 97 | } 98 | -------------------------------------------------------------------------------- /test/C/test26.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | /* The following variable is the current number of next input grammar 32 | terminal. */ 33 | static int nterm; 34 | 35 | /* The following function imported by YAEP (see comments in the interface file). */ 36 | const char * 37 | read_terminal (int *code) 38 | { 39 | nterm++; 40 | switch (nterm) 41 | { 42 | case 1: *code = 'a'; return "a"; 43 | case 2: *code = '+'; return "+"; 44 | case 3: *code = '*'; return "*"; 45 | case 4: *code = '('; return "("; 46 | case 5: *code = ')'; return ")"; 47 | default: return NULL; 48 | } 49 | } 50 | 51 | /* The following variable is the current number of next rule grammar 52 | terminal. */ 53 | static int nrule; 54 | 55 | /* The following function imported by YAEP (see comments in the interface file). */ 56 | const char * 57 | read_rule (const char ***rhs, const char **anode, int *anode_cost, int **transl) 58 | { 59 | static const char *rhs_1 [] = {"T", NULL}; 60 | static int tr_1 [] = {0, 0, -1}; 61 | static const char *rhs_2 [] = {"E", "+", "T", NULL}; 62 | static int tr_2 [] = {0, 2, -1}; 63 | static const char *rhs_3 [] = {"F", NULL}; 64 | static int tr_3 [] = {0, -1}; 65 | static const char *rhs_4 [] = {"T", "*", "F", NULL}; 66 | static int tr_4 [] = {0, 2, -1}; 67 | static const char *rhs_5 [] = {"a", NULL}; 68 | static int tr_5 [] = {0, -1}; 69 | static const char *rhs_6 [] = {"(", "E", ")", NULL}; 70 | static int tr_6 [] = {1, -1}; 71 | 72 | nrule++; 73 | switch (nrule) 74 | { 75 | case 1: *rhs = rhs_1; *anode = NULL; *anode_cost = 0; *transl = tr_1; 76 | return "E"; 77 | case 2: *rhs = rhs_2; *anode = "plus"; *anode_cost = 0; *transl = tr_2; 78 | return "E"; 79 | case 3: *rhs = rhs_3; *anode = NULL; *anode_cost = 0; *transl = tr_3; 80 | return "T"; 81 | case 4: *rhs = rhs_4; *anode = "mult"; *anode_cost = 0; *transl = tr_4; 82 | return "T"; 83 | case 5: *rhs = rhs_5; *anode = NULL; *anode_cost = 0; *transl = tr_5; 84 | return "F"; 85 | case 6: *rhs = rhs_6; *anode = NULL; *anode_cost = 0; *transl = tr_6; 86 | return "F"; 87 | default: return NULL; 88 | } 89 | } 90 | 91 | static const char *input = "a+a*(a*a+a)"; 92 | 93 | int main (void) 94 | { 95 | test_standard_read (read_terminal, read_rule); 96 | exit (0); 97 | } 98 | -------------------------------------------------------------------------------- /test/C/test27.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : T # 0\n" 36 | " | E '+' T # plus (0 2)\n" 37 | " ;\n" 38 | "T : F # 0\n" 39 | " | T '*' F # mult (0 2)\n" 40 | " ;\n" 41 | "F : 'a' # 0\n" 42 | " | '(' E ')' # 1\n" 43 | " ;\n" 44 | ; 45 | 46 | int main (void) 47 | { 48 | test_standard_parse (); 49 | exit (0); 50 | } 51 | -------------------------------------------------------------------------------- /test/C/test28.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : T # 0\n" 36 | " | E '+' T # plus (0 2)\n" 37 | " ;\n" 38 | "T : F # 0\n" 39 | " | T '*' F # mult (0 2)\n" 40 | " ;\n" 41 | "F : 'a' # 0\n" 42 | " | '(' E ')' # 1\n" 43 | " | '(' error ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int main (int argc, char **argv) 48 | { 49 | test_complex_parse (1, 0, 0, 0, argc, argv); 50 | exit (0); 51 | } 52 | -------------------------------------------------------------------------------- /test/C/test29.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : T # 0\n" 36 | " | E '+' T # plus (0 2)\n" 37 | " ;\n" 38 | "T : F # 0\n" 39 | " | T '*' F # mult (0 2)\n" 40 | " ;\n" 41 | "F : 'a' # 0\n" 42 | " | '(' E ')' # 1\n" 43 | " | '(' error ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int main (int argc, char **argv) 48 | { 49 | test_complex_parse (1, 0, 0, 0, argc, argv); 50 | exit (0); 51 | } 52 | -------------------------------------------------------------------------------- /test/C/test30.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : E '+' E # plus (0 2)\n" 36 | " | E '*' E # mult (0 2)\n" 37 | " | 'a' # 0\n" 38 | " | '(' E ')' # 1\n" 39 | " ;\n" 40 | ; 41 | 42 | int main (int argc, char **argv) 43 | { 44 | test_complex_parse (1, 1, 0, 0, argc, argv); 45 | exit (0); 46 | } 47 | -------------------------------------------------------------------------------- /test/C/test31.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : E '+' E # plus (0 2)\n" 36 | " | E '*' E # mult (0 2)\n" 37 | " | 'a' # 0\n" 38 | " | '(' E ')' # 1\n" 39 | " ;\n" 40 | ; 41 | 42 | int main (int argc, char **argv) 43 | { 44 | test_complex_parse (0, 1, 0, 0, argc, argv); 45 | exit (0); 46 | } 47 | -------------------------------------------------------------------------------- /test/C/test32.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(*a+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : E '+' E # plus (0 2)\n" 36 | " | E '*' E # mult (0 2)\n" 37 | " | 'a' # 0\n" 38 | " | '(' E ')' # 1\n" 39 | " | '(' error ')' # 1\n" 40 | " ;\n" 41 | ; 42 | 43 | int main (int argc, char **argv) 44 | { 45 | test_complex_parse (1, 1, 0, 0, argc, argv); 46 | exit (0); 47 | } 48 | -------------------------------------------------------------------------------- /test/C/test33.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : E '+' E # plus (0 2)\n" 36 | " | E '*' E # mult (0 2)\n" 37 | " | 'a' # 0\n" 38 | " | '(' E ')' # 1\n" 39 | " ;\n" 40 | ; 41 | 42 | int main (int argc, char **argv) 43 | { 44 | test_complex_parse (0, 0, 0, 0, argc, argv); 45 | exit (0); 46 | } 47 | -------------------------------------------------------------------------------- /test/C/test34.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : E '+' E # plus (0 2)\n" 36 | " | E '*' E # mult (0 2)\n" 37 | " | 'a' # 0\n" 38 | " | '(' E ')' # 1\n" 39 | " | '(' error ')' # 1\n" 40 | " ;\n" 41 | ; 42 | 43 | int main (int argc, char **argv) 44 | { 45 | test_complex_parse (0, 1, 0, 0, argc, argv); 46 | exit (0); 47 | } 48 | -------------------------------------------------------------------------------- /test/C/test35.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : T # 0\n" 36 | " | E '+' T # plus (0 2)\n" 37 | " ;\n" 38 | "T : F # 0\n" 39 | " | T '*' F # mult (0 2)\n" 40 | " ;\n" 41 | "F : 'a' # 0\n" 42 | " | '(' E ')' # 1\n" 43 | " ;\n" 44 | ; 45 | 46 | int main (int argc, char **argv) 47 | { 48 | test_complex_parse (0, 0, 0, 0, argc, argv); 49 | exit (0); 50 | } 51 | -------------------------------------------------------------------------------- /test/C/test36.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*)+(*a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : T # 0\n" 36 | " | E '+' T # plus (0 2)\n" 37 | " ;\n" 38 | "T : F # 0\n" 39 | " | T '*' F # mult (0 2)\n" 40 | " ;\n" 41 | "F : 'a' # 0\n" 42 | " | '(' E ')' # 1\n" 43 | " | '(' error ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int main (int argc, char **argv) 48 | { 49 | test_complex_parse (0, 0, 0, 0, argc, argv); 50 | exit (0); 51 | } 52 | -------------------------------------------------------------------------------- /test/C/test37.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*)+(*a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : T # 0\n" 36 | " | E '+' T # plus (0 2)\n" 37 | " ;\n" 38 | "T : F # 0\n" 39 | " | T '*' F # mult (0 2)\n" 40 | " ;\n" 41 | "F : 'a' # 0\n" 42 | " | '(' E ')' # 1\n" 43 | " | '(' error ')' # 1\n" 44 | " ;\n" 45 | ; 46 | 47 | int main (int argc, char **argv) 48 | { 49 | test_complex_parse (0, 0, 0, 4, argc, argv); 50 | exit (0); 51 | } 52 | -------------------------------------------------------------------------------- /test/C/test38.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+a*(a*)+(*a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : T # 0\n" 36 | " | E '+' T # plus (0 2)\n" 37 | "T : F # 0\n" 38 | " | T '*' F # mult (0 2)\n" 39 | "F : 'a' # 0\n" 40 | " | '(' E ')' # 1\n" 41 | " | '(' error ')' # 1\n" 42 | ; 43 | 44 | int main (int argc, char **argv) 45 | { 46 | test_complex_parse (0, 0, 0, 4, argc, argv); 47 | exit (0); 48 | } 49 | -------------------------------------------------------------------------------- /test/C/test39.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+b*c+d"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : E '+' E # plus (0 2)\n" 36 | " | E '*' E # mult (0 2)\n" 37 | " | 'a' # 0\n" 38 | " | 'b' # 0\n" 39 | " | 'c' # 0\n" 40 | " | 'd' # 0\n" 41 | " | '(' E ')' # 1\n" 42 | " ;\n" 43 | ; 44 | 45 | int main (int argc, char **argv) 46 | { 47 | test_complex_parse (0, 1, 0, 0, argc, argv); 48 | exit (0); 49 | } 50 | -------------------------------------------------------------------------------- /test/C/test40.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+b*c+a"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : E '+' E # plus (0 2)\n" 36 | " | E '*' E # mult (0 2)\n" 37 | " | 'a' # 0\n" 38 | " | 'b' # 0\n" 39 | " | 'c' # 0\n" 40 | " | 'd' # 0\n" 41 | " | '(' E ')' # 1\n" 42 | " ;\n" 43 | ; 44 | 45 | int main (int argc, char **argv) 46 | { 47 | test_complex_parse (0, 1, 0, 0, argc, argv); 48 | exit (0); 49 | } 50 | -------------------------------------------------------------------------------- /test/C/test42.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+(a*a+a)*a"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : E '+' E # plus (- 2)\n" 36 | " | E '*' E # mult (0 -)\n" 37 | " | 'a' # 0\n" 38 | " | '(' E ')' # 1\n" 39 | " ;\n" 40 | ; 41 | 42 | int main (int argc, char **argv) 43 | { 44 | test_complex_parse (1, 1, 0, 0, argc, argv); 45 | exit (0); 46 | } 47 | -------------------------------------------------------------------------------- /test/C/test43.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+b*c+d"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : E '+' E # plus (- 2)\n" 36 | " | E '*' E # mult (0 -)\n" 37 | " | E '*' E # mult (0 2)\n" 38 | " | 'a' # 0\n" 39 | " | 'b' # 0\n" 40 | " | 'c' # 0\n" 41 | " | 'd' # 0\n" 42 | " | '(' E ')' # 1\n" 43 | " ;\n" 44 | ; 45 | 46 | int main (int argc, char **argv) 47 | { 48 | test_complex_parse (0, 1, 0, 0, argc, argv); 49 | exit (0); 50 | } 51 | -------------------------------------------------------------------------------- /test/C/test44.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | /* The following variable is the current number of next input grammar 32 | terminal. */ 33 | static int nterm; 34 | 35 | /* The following function imported by YAEP (see comments in the interface file). */ 36 | const char * 37 | read_terminal (int *code) 38 | { 39 | nterm++; 40 | switch (nterm) 41 | { 42 | case 1: *code = 'a'; return "a"; 43 | case 2: *code = '+'; return "+"; 44 | case 3: *code = '*'; return "*"; 45 | case 4: *code = '('; return "("; 46 | case 5: *code = ')'; return ")"; 47 | default: return NULL; 48 | } 49 | } 50 | 51 | /* The following variable is the current number of next rule grammar 52 | terminal. */ 53 | static int nrule; 54 | 55 | /* The following function imported by YAEP (see comments in the interface file). */ 56 | const char * 57 | read_rule (const char ***rhs, const char **anode, int *anode_cost, int **transl) 58 | { 59 | static const char *rhs_1 [] = {"T", NULL}; 60 | static int tr_1 [] = {0, -1}; 61 | static const char *rhs_2 [] = {"E", "+", "T", NULL}; 62 | static int tr_2 [] = {0, 2, -1}; 63 | static const char *rhs_3 [] = {"F", NULL}; 64 | static int tr_3 [] = {0, -1}; 65 | static const char *rhs_4 [] = {"T", "*", "F", NULL}; 66 | static int tr_4 [] = {0, 2, -1}; 67 | static const char *rhs_5 [] = {"a", NULL}; 68 | static int tr_5 [] = {0, -1}; 69 | static const char *rhs_6 [] = {"(", "E", ")", NULL}; 70 | static int tr_6 [] = {1, -1}; 71 | 72 | nrule++; 73 | switch (nrule) 74 | { 75 | case 1: *rhs = rhs_1; *anode = NULL; *anode_cost = 0; *transl = tr_1; 76 | return "E"; 77 | case 2: *rhs = rhs_2; *anode = "plus"; *anode_cost = -1; *transl = tr_2; 78 | return "E"; 79 | case 3: *rhs = rhs_3; *anode = NULL; *anode_cost = 0; *transl = tr_3; 80 | return "T"; 81 | case 4: *rhs = rhs_4; *anode = "mult"; *anode_cost = 0; *transl = tr_4; 82 | return "T"; 83 | case 5: *rhs = rhs_5; *anode = NULL; *anode_cost = 0; *transl = tr_5; 84 | return "F"; 85 | case 6: *rhs = rhs_6; *anode = NULL; *anode_cost = 0; *transl = tr_6; 86 | return "F"; 87 | default: return NULL; 88 | } 89 | } 90 | 91 | static const char *input = "a+a*(a*a+a)"; 92 | 93 | int main (void) 94 | { 95 | test_standard_read (read_terminal, read_rule); 96 | exit (0); 97 | } 98 | -------------------------------------------------------------------------------- /test/C/test45.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+((a*a)+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : V '+' V # add 1 (0 2)\n" 36 | " | V '*' V # mult 1 (0 2)\n" 37 | " | V '+' '(' V '*' V ')' # madd 1 (0 3 5)\n" 38 | " | '(' V '*' V ')' '+' V # madd 1 (6 1 3)\n" 39 | " ;\n" 40 | "V : 'a' # 0\n" 41 | " | '(' E ')' # 1\n" 42 | " ;\n" 43 | ; 44 | 45 | int main (int argc, char **argv) 46 | { 47 | test_complex_parse (1, 1, 1, 0, argc, argv); 48 | exit (0); 49 | } 50 | -------------------------------------------------------------------------------- /test/C/test46.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+((a*a)+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : V '+' V # add 1 (0 2)\n" 36 | " | V '*' V # mult 1 (0 2)\n" 37 | " | V '+' '(' V '*' V ')' # madd 2 (0 3 5)\n" 38 | " | '(' V '*' V ')' '+' V # madd 2 (6 1 3)\n" 39 | " ;\n" 40 | "V : 'a' # 0\n" 41 | " | '(' E ')' # 1\n" 42 | " ;\n" 43 | ; 44 | 45 | int main (int argc, char **argv) 46 | { 47 | test_complex_parse (0, 1, 1, 0, argc, argv); 48 | exit (0); 49 | } 50 | -------------------------------------------------------------------------------- /test/C/test47.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "a+((a*a)+a)"; 32 | 33 | static const char *description = 34 | "\n" 35 | "E : V '+' V # add 1 (0 2)\n" 36 | " | V '*' V # mult 1 (0 2)\n" 37 | " | V '+' '(' V '*' V ')' # madd 1 (0 3 5)\n" 38 | " | '(' V '*' V ')' '+' V # madd 1 (6 1 3)\n" 39 | " ;\n" 40 | "V : 'a' # 0\n" 41 | " | '(' E ')' # 1\n" 42 | " ;\n" 43 | ; 44 | 45 | int main (int argc, char **argv) 46 | { 47 | test_complex_parse (1, 1, 1, 0, argc, argv); 48 | exit (0); 49 | } 50 | -------------------------------------------------------------------------------- /test/C/test48.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "spc; "; 32 | 33 | static const char *description = 34 | "\n" 35 | "P : 's' sp st sp # prog (2)\n" 36 | "st : 'p' sp p_list sp ';' # print (2)\n" 37 | "p_list : 'c' sp p_list # string (0 2)\n" 38 | " | # -\n" 39 | "sp : ' '\n" 40 | " |\n" 41 | ; 42 | 43 | int main (int argc, char **argv) 44 | { 45 | test_complex_parse (1, 0, 0, 0, argc, argv); 46 | exit (0); 47 | } 48 | -------------------------------------------------------------------------------- /test/C/test49.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include <stdlib.h> 28 | 29 | #include"common.h" 30 | 31 | static const char *input = "s"; 32 | 33 | static const char *description = 34 | "\n" 35 | "P : 's' opt # prog (1)\n" 36 | "opt : # opt (-)\n" 37 | "opt : 'c' # optc (-)" 38 | ; 39 | 40 | int main (int argc, char **argv) 41 | { 42 | test_complex_parse (1, 0, 0, 0, argc, argv); 43 | exit (0); 44 | } 45 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # YAEP (Yet Another Earley Parser) 2 | # 3 | # Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a 6 | # copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included 14 | # in all copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | set( TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}" ) 25 | 26 | include_directories( 27 | ${PROJECT_SOURCE_DIR}/src 28 | ${CMAKE_CURRENT_SOURCE_DIR} 29 | ) 30 | 31 | # ANSI-C tokenizer 32 | find_package( FLEX ) 33 | if( FLEX_FOUND ) 34 | flex_target( flex_ansic ansic.l "${CMAKE_CURRENT_BINARY_DIR}/ansic.c" ) 35 | add_custom_target( ansic_c DEPENDS ${FLEX_flex_ansic_OUTPUTS} ) # for direct #includes 36 | else() 37 | message( WARNING "(f)lex not found; needed for all ANSI-C tests" ) 38 | endif() 39 | 40 | # Ticker library 41 | add_library( ticker STATIC ticker.c ) 42 | add_library( ticker++ STATIC ticker.cpp ) 43 | 44 | # Test subdirectories 45 | add_subdirectory( C ) 46 | add_subdirectory( C++ ) 47 | add_subdirectory( compare_parsers ) 48 | -------------------------------------------------------------------------------- /test/Makefile.in: -------------------------------------------------------------------------------- 1 | all test install uninstall clean realclean distclean TAGS dist-copy dist: 2 | @echo "+++++ Please use only top level Makefile" 3 | -------------------------------------------------------------------------------- /test/ansic.h: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #ifndef YAEP_TEST_ANSIC_H_ 28 | #define YAEP_TEST_ANSIC_H_ 29 | 30 | #define IDENTIFIER 1000 31 | #define SIGNED 2000 32 | #define CONST 3000 33 | #define INLINE 4000 34 | #define AUTO 5000 35 | #define BREAK 6000 36 | #define CASE 7000 37 | #define CHAR 8000 38 | #define CONTINUE 9000 39 | #define DEFAULT 1001 40 | #define DO 2001 41 | #define DOUBLE 3001 42 | #define ELSE 4001 43 | #define ENUM 5001 44 | #define EXTERN 6001 45 | #define FLOAT 7001 46 | #define FOR 8001 47 | #define GOTO 9001 48 | #define IF 1002 49 | #define INT 2002 50 | #define LONG 3002 51 | #define REGISTER 4002 52 | #define RETURN 5002 53 | #define SHORT 6002 54 | #define SIZEOF 7002 55 | #define STATIC 8002 56 | #define STRUCT 9002 57 | #define SWITCH 1003 58 | #define TYPEDEF 2003 59 | #define UNION 3003 60 | #define UNSIGNED 4003 61 | #define VOID 5003 62 | #define VOLATILE 6003 63 | #define WHILE 7003 64 | #define CONSTANT 8003 65 | #define STRING_LITERAL 9003 66 | #define RIGHT_ASSIGN 1004 67 | #define LEFT_ASSIGN 2004 68 | #define ADD_ASSIGN 3004 69 | #define SUB_ASSIGN 4004 70 | #define MUL_ASSIGN 5004 71 | #define DIV_ASSIGN 6004 72 | #define MOD_ASSIGN 7004 73 | #define AND_ASSIGN 8004 74 | #define XOR_ASSIGN 9004 75 | #define OR_ASSIGN 1005 76 | #define RIGHT_OP 2007 77 | #define LEFT_OP 3005 78 | #define INC_OP 4005 79 | #define DEC_OP 5005 80 | #define PTR_OP 6005 81 | #define AND_OP 7005 82 | #define OR_OP 8005 83 | #define LE_OP 9005 84 | #define GE_OP 1006 85 | #define EQ_OP 2006 86 | #define NE_OP 3006 87 | #define ELIPSIS 4006 88 | #define RESTRICT 5006 89 | #define _BOOL 6006 90 | #define _COMPLEX 7006 91 | #define _IMAGINARY 8006 92 | 93 | struct lex { 94 | short code; 95 | short column; 96 | int line; 97 | const char *id; 98 | struct lex *next; 99 | }; 100 | 101 | extern int column; 102 | extern int line; 103 | 104 | extern int yylex (void); 105 | extern char *get_yytext (void); 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /test/compare_parsers/test_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | YAEP (Yet Another Earley Parser) 3 | 4 | Copyright (c) 1997-2018 Vladimir Makarov <vmakarov@gcc.gnu.org> 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | */ 26 | 27 | #define YAEP_TEST_ANSIC_H_ /* FIXME: avoid inclusion of ansic.h via ansic.c */ 28 | 29 | struct lex { 30 | short code; 31 | short column; 32 | int line; 33 | const char *id; 34 | struct lex *next; 35 | }; 36 | 37 | static os_t lexs; 38 | static struct lex *list; 39 | static struct lex *curr = NULL; 40 | 41 | static int column = 0; 42 | static int line = 1; 43 | 44 | static hash_table_t table; 45 | 46 | static unsigned 47 | hash (hash_table_entry_t el) 48 | { 49 | const char *id = (char *) el; 50 | unsigned result, i; 51 | 52 | for (result = i = 0;*id++ != '\0'; i++) 53 | result += ((unsigned char) *id << (i % CHAR_BIT)); 54 | return result; 55 | } 56 | 57 | static int 58 | eq (hash_table_entry_t el1, hash_table_entry_t el2) 59 | { 60 | return strcmp ((char *) el1, (char *) el2) == 0; 61 | } 62 | 63 | static void initiate_typedefs( YaepAllocator * alloc ) { 64 | table = create_hash_table( alloc, 50000, hash, eq ); 65 | } 66 | 67 | /* Now we ignore level */ 68 | static 69 | void add_typedef (const char *id, int level) 70 | { 71 | hash_table_entry_t *entry_ptr; 72 | 73 | assert (level == 0); 74 | entry_ptr = find_hash_table_entry (table, id, 1); 75 | if (*entry_ptr == NULL) 76 | *entry_ptr = (hash_table_entry_t) id; 77 | else 78 | assert (strcmp (id, *entry_ptr) == 0); 79 | #ifdef DEBUG 80 | fprintf (stderr, "add typedef %s\n", id); 81 | #endif 82 | } 83 | 84 | #ifdef __GNUC__ 85 | inline 86 | #endif 87 | static 88 | int find_typedef (const char *id, int level) 89 | { 90 | hash_table_entry_t *entry_ptr; 91 | 92 | entry_ptr = find_hash_table_entry (table, id, 0); 93 | #ifdef DEBUG 94 | if (*entry_ptr != NULL) 95 | fprintf (stderr, "found typedef %s\n", id); 96 | #endif 97 | return *entry_ptr != NULL; 98 | } 99 | -------------------------------------------------------------------------------- /test/test01.out: -------------------------------------------------------------------------------- 1 | Use description 2 | -------------------------------------------------------------------------------- /test/test01a.out: -------------------------------------------------------------------------------- 1 | Use functions 2 | -------------------------------------------------------------------------------- /test/test02.out: -------------------------------------------------------------------------------- 1 | Use description 2 | Grammar: #terms = 7, #nonterms = 4, #rules = 8, rules size = 24 3 | Input: #tokens = 12, #unique situations = 22 4 | #terminal sets = 30, their size = 240 5 | #unique set cores = 10, #their start situations = 25 6 | #parent indexes for some non start situations = 0 7 | #unique set dist. vects = 10, their length = 25 8 | #unique sets = 11, #their start situations = 26 9 | #unique triples (set, term, lookahead) = 12, goto successes=0 10 | #pairs(set core, symb) = 38, their trans+reduce vects length = 43 11 | #unique transition vectors = 12, their length = 16 12 | #unique reduce vectors = 3, their length = 3 13 | #term nodes = 5, #abstract nodes = 4 14 | #alternative nodes = 0, #all nodes = 9 15 | -------------------------------------------------------------------------------- /test/test02a.out: -------------------------------------------------------------------------------- 1 | Use functions 2 | Grammar: #terms = 7, #nonterms = 4, #rules = 8, rules size = 24 3 | Input: #tokens = 12, #unique situations = 22 4 | #terminal sets = 30, their size = 240 5 | #unique set cores = 10, #their start situations = 25 6 | #parent indexes for some non start situations = 0 7 | #unique set dist. vects = 10, their length = 25 8 | #unique sets = 11, #their start situations = 26 9 | #unique triples (set, term, lookahead) = 12, goto successes=0 10 | #pairs(set core, symb) = 38, their trans+reduce vects length = 43 11 | #unique transition vectors = 12, their length = 16 12 | #unique reduce vectors = 3, their length = 3 13 | #term nodes = 5, #abstract nodes = 4 14 | #alternative nodes = 0, #all nodes = 9 15 | -------------------------------------------------------------------------------- /test/test03.out: -------------------------------------------------------------------------------- 1 | Use description 2 | Grammar: #terms = 7, #nonterms = 4, #rules = 8, rules size = 24 3 | Input: #tokens = 12, #unique situations = 22 4 | #terminal sets = 8, their size = 64 5 | #unique set cores = 11, #their start situations = 42 6 | #parent indexes for some non start situations = 0 7 | #unique set dist. vects = 11, their length = 42 8 | #unique sets = 12, #their start situations = 43 9 | #unique triples (set, term, lookahead) = 12, goto successes=0 10 | #pairs(set core, symb) = 55, their trans+reduce vects length = 60 11 | #unique transition vectors = 12, their length = 16 12 | #unique reduce vectors = 3, their length = 3 13 | #term nodes = 5, #abstract nodes = 4 14 | #alternative nodes = 0, #all nodes = 9 15 | -------------------------------------------------------------------------------- /test/test03a.out: -------------------------------------------------------------------------------- 1 | Use functions 2 | Grammar: #terms = 7, #nonterms = 4, #rules = 8, rules size = 24 3 | Input: #tokens = 12, #unique situations = 22 4 | #terminal sets = 8, their size = 64 5 | #unique set cores = 11, #their start situations = 42 6 | #parent indexes for some non start situations = 0 7 | #unique set dist. vects = 11, their length = 42 8 | #unique sets = 12, #their start situations = 43 9 | #unique triples (set, term, lookahead) = 12, goto successes=0 10 | #pairs(set core, symb) = 55, their trans+reduce vects length = 60 11 | #unique transition vectors = 12, their length = 16 12 | #unique reduce vectors = 3, their length = 3 13 | #term nodes = 5, #abstract nodes = 4 14 | #alternative nodes = 0, #all nodes = 9 15 | -------------------------------------------------------------------------------- /test/test03b.out: -------------------------------------------------------------------------------- 1 | Use functions 2 | Grammar: #terms = 7, #nonterms = 4, #rules = 8, rules size = 24 3 | Input: #tokens = 12, #unique situations = 22 4 | #terminal sets = 8, their size = 64 5 | #unique set cores = 11, #their start situations = 42 6 | #parent indexes for some non start situations = 0 7 | #unique set dist. vects = 11, their length = 42 8 | #unique sets = 12, #their start situations = 43 9 | #unique triples (set, term, lookahead) = 12, goto successes=0 10 | #pairs(set core, symb) = 55, their trans+reduce vects length = 60 11 | #unique transition vectors = 12, their length = 16 12 | #unique reduce vectors = 3, their length = 3 13 | #term nodes = 5, #abstract nodes = 4 14 | #alternative nodes = 0, #all nodes = 9 15 | -------------------------------------------------------------------------------- /test/test04.out: -------------------------------------------------------------------------------- 1 | Use description 2 | Grammar: #terms = 7, #nonterms = 4, #rules = 8, rules size = 24 3 | Input: #tokens = 12, #unique situations = 45 4 | #terminal sets = 71, their size = 568 5 | #unique set cores = 13, #their start situations = 30 6 | #parent indexes for some non start situations = 0 7 | #unique set dist. vects = 10, their length = 25 8 | #unique sets = 13, #their start situations = 30 9 | #unique triples (set, term, lookahead) = 12, goto successes=0 10 | #pairs(set core, symb) = 48, their trans+reduce vects length = 54 11 | #unique transition vectors = 12, their length = 16 12 | #unique reduce vectors = 3, their length = 3 13 | #term nodes = 5, #abstract nodes = 4 14 | #alternative nodes = 0, #all nodes = 9 15 | -------------------------------------------------------------------------------- /test/test04a.out: -------------------------------------------------------------------------------- 1 | Use functions 2 | -------------------------------------------------------------------------------- /test/test04b.out: -------------------------------------------------------------------------------- 1 | Use functions 2 | -------------------------------------------------------------------------------- /test/test05.out: -------------------------------------------------------------------------------- 1 | Use description 2 | Translation: 3 | 0: ABSTRACT: plus ( 1 2 ) 4 | 1: TERMINAL: code=97, repr='a' 5 | 2: ABSTRACT: mult ( 3 4 ) 6 | 3: TERMINAL: code=97, repr='a' 7 | 4: ABSTRACT: plus ( 5 6 ) 8 | 5: ABSTRACT: mult ( 7 8 ) 9 | 7: TERMINAL: code=97, repr='a' 10 | 8: TERMINAL: code=97, repr='a' 11 | 6: TERMINAL: code=97, repr='a' 12 | 13 | Grammar: #terms = 7, #nonterms = 4, #rules = 8, rules size = 24 14 | Input: #tokens = 12, #unique situations = 22 15 | #terminal sets = 30, their size = 240 16 | #unique set cores = 10, #their start situations = 25 17 | #parent indexes for some non start situations = 0 18 | #unique set dist. vects = 10, their length = 25 19 | #unique sets = 11, #their start situations = 26 20 | #unique triples (set, term, lookahead) = 12, goto successes=0 21 | #pairs(set core, symb) = 38, their trans+reduce vects length = 43 22 | #unique transition vectors = 12, their length = 16 23 | #unique reduce vectors = 3, their length = 3 24 | #term nodes = 5, #abstract nodes = 4 25 | #alternative nodes = 0, #all nodes = 9 26 | -------------------------------------------------------------------------------- /test/test05a.out: -------------------------------------------------------------------------------- 1 | Use functions 2 | Translation: 3 | 0: ABSTRACT: plus ( 1 2 ) 4 | 1: TERMINAL: code=97, repr=a 5 | 2: ABSTRACT: mult ( 3 4 ) 6 | 3: TERMINAL: code=97, repr=a 7 | 4: ABSTRACT: plus ( 5 6 ) 8 | 5: ABSTRACT: mult ( 7 8 ) 9 | 7: TERMINAL: code=97, repr=a 10 | 8: TERMINAL: code=97, repr=a 11 | 6: TERMINAL: code=97, repr=a 12 | 13 | Grammar: #terms = 7, #nonterms = 4, #rules = 8, rules size = 24 14 | Input: #tokens = 12, #unique situations = 22 15 | #terminal sets = 30, their size = 240 16 | #unique set cores = 10, #their start situations = 25 17 | #parent indexes for some non start situations = 0 18 | #unique set dist. vects = 10, their length = 25 19 | #unique sets = 11, #their start situations = 26 20 | #unique triples (set, term, lookahead) = 12, goto successes=0 21 | #pairs(set core, symb) = 38, their trans+reduce vects length = 43 22 | #unique transition vectors = 12, their length = 16 23 | #unique reduce vectors = 3, their length = 3 24 | #term nodes = 5, #abstract nodes = 4 25 | #alternative nodes = 0, #all nodes = 9 26 | -------------------------------------------------------------------------------- /test/test06.out: -------------------------------------------------------------------------------- 1 | yaep parse: undefined or bad grammar 2 | -------------------------------------------------------------------------------- /test/test07.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vnmakarov/yaep/7aba93e1b49b3f1db0e20ba7d4e4158e2a0a8bb9/test/test07.out -------------------------------------------------------------------------------- /test/test08.out: -------------------------------------------------------------------------------- 1 | description syntax error on ln 2 2 | -------------------------------------------------------------------------------- /test/test09.out: -------------------------------------------------------------------------------- 1 | term `error' in the left hand side of rule 2 | -------------------------------------------------------------------------------- /test/test10.out: -------------------------------------------------------------------------------- 1 | term ident described repeatedly with different code 2 | -------------------------------------------------------------------------------- /test/test11.out: -------------------------------------------------------------------------------- 1 | repeated code 10 in term `i' 2 | -------------------------------------------------------------------------------- /test/test12.out: -------------------------------------------------------------------------------- 1 | grammar does not contains rules 2 | -------------------------------------------------------------------------------- /test/test13.out: -------------------------------------------------------------------------------- 1 | term `ident' in the left hand side of rule 2 | -------------------------------------------------------------------------------- /test/test14.out: -------------------------------------------------------------------------------- 1 | translation symbol number 1 in rule for `E' is out of range 2 | -------------------------------------------------------------------------------- /test/test15.out: -------------------------------------------------------------------------------- 1 | repeated translation symbol number 0 in rule for `E' 2 | -------------------------------------------------------------------------------- /test/test16.out: -------------------------------------------------------------------------------- 1 | repeated translation symbol number 0 in rule for `E' 2 | -------------------------------------------------------------------------------- /test/test17.out: -------------------------------------------------------------------------------- 1 | nonterm `E' does not derive any term string 2 | -------------------------------------------------------------------------------- /test/test18.out: -------------------------------------------------------------------------------- 1 | nonterm `E' can derive only itself (grammar with loops) 2 | -------------------------------------------------------------------------------- /test/test19.out: -------------------------------------------------------------------------------- 1 | yaep parse: invalid token code 98 2 | -------------------------------------------------------------------------------- /test/test20.out: -------------------------------------------------------------------------------- 1 | nonterm `G' is not accessible from axiom 2 | -------------------------------------------------------------------------------- /test/test21.out: -------------------------------------------------------------------------------- 1 | do not use fixed name `error' 2 | -------------------------------------------------------------------------------- /test/test22.out: -------------------------------------------------------------------------------- 1 | do not use fixed name `$S' 2 | -------------------------------------------------------------------------------- /test/test23.out: -------------------------------------------------------------------------------- 1 | do not use fixed name `$eof' 2 | -------------------------------------------------------------------------------- /test/test24.out: -------------------------------------------------------------------------------- 1 | repeated declaration of term `a' 2 | -------------------------------------------------------------------------------- /test/test25.out: -------------------------------------------------------------------------------- 1 | term `a' has negative code 2 | -------------------------------------------------------------------------------- /test/test26.out: -------------------------------------------------------------------------------- 1 | rule for `E' has incorrect translation 2 | -------------------------------------------------------------------------------- /test/test27.out: -------------------------------------------------------------------------------- 1 | Syntax error on token 7:ignore 10 tokens starting with token = 0 2 | -------------------------------------------------------------------------------- /test/test28.out: -------------------------------------------------------------------------------- 1 | Syntax error on token 7:ignore 4 tokens starting with token = 5 2 | Translation: 3 | 0: ABSTRACT: plus ( 1 2 ) 4 | 1: TERMINAL: code=97, repr='a' 5 | 2: ABSTRACT: mult ( 3 4 ) 6 | 3: TERMINAL: code=97, repr='a' 7 | 4: ERROR 8 | 9 | -------------------------------------------------------------------------------- /test/test29.out: -------------------------------------------------------------------------------- 1 | Syntax error on token 5:ignore 4 tokens starting with token = 5 2 | Translation: 3 | 0: ABSTRACT: plus ( 1 2 ) 4 | 1: TERMINAL: code=97, repr='a' 5 | 2: ABSTRACT: mult ( 3 4 ) 6 | 3: TERMINAL: code=97, repr='a' 7 | 4: ERROR 8 | 9 | -------------------------------------------------------------------------------- /test/test30.out: -------------------------------------------------------------------------------- 1 | Translation: 2 | 0: ABSTRACT: mult ( 1 2 ) 3 | 1: ABSTRACT: plus ( 3 4 ) 4 | 3: TERMINAL: code=97, repr='a' 5 | 4: TERMINAL: code=97, repr='a' 6 | 2: ABSTRACT: plus ( 5 6 ) 7 | 5: ABSTRACT: mult ( 7 8 ) 8 | 7: TERMINAL: code=97, repr='a' 9 | 8: TERMINAL: code=97, repr='a' 10 | 6: TERMINAL: code=97, repr='a' 11 | 12 | -------------------------------------------------------------------------------- /test/test31.out: -------------------------------------------------------------------------------- 1 | Translation: 2 | 0: ALTERNATIVE: node=1, next=2 3 | 1: ABSTRACT: plus ( 3 4 ) 4 | 3: TERMINAL: code=97, repr='a' 5 | 4: ABSTRACT: mult ( 5 6 ) 6 | 5: TERMINAL: code=97, repr='a' 7 | 6: ALTERNATIVE: node=7, next=8 8 | 7: ABSTRACT: mult ( 9 10 ) 9 | 9: TERMINAL: code=97, repr='a' 10 | 10: ABSTRACT: plus ( 11 12 ) 11 | 11: TERMINAL: code=97, repr='a' 12 | 12: TERMINAL: code=97, repr='a' 13 | 8: ALTERNATIVE: node=13, next=nil 14 | 13: ABSTRACT: plus ( 14 12 ) 15 | 14: ABSTRACT: mult ( 9 11 ) 16 | 2: ALTERNATIVE: node=15, next=nil 17 | 15: ABSTRACT: mult ( 16 17 ) 18 | 16: ABSTRACT: plus ( 3 5 ) 19 | 17: ALTERNATIVE: node=7, next=18 20 | 18: ALTERNATIVE: node=13, next=nil 21 | 22 | -------------------------------------------------------------------------------- /test/test32.out: -------------------------------------------------------------------------------- 1 | Syntax error on token 5:ignore 4 tokens starting with token = 5 2 | Translation: 3 | 0: ABSTRACT: mult ( 1 2 ) 4 | 1: ABSTRACT: plus ( 3 4 ) 5 | 3: TERMINAL: code=97, repr='a' 6 | 4: TERMINAL: code=97, repr='a' 7 | 2: ERROR 8 | 9 | -------------------------------------------------------------------------------- /test/test33.out: -------------------------------------------------------------------------------- 1 | Syntax error on token 7:ignore 10 tokens starting with token = 0 2 | Translation: 3 | 0: EMPTY 4 | 5 | -------------------------------------------------------------------------------- /test/test34.out: -------------------------------------------------------------------------------- 1 | Syntax error on token 7:ignore 4 tokens starting with token = 5 2 | Translation: 3 | 0: ALTERNATIVE: node=1, next=2 4 | 1: ABSTRACT: plus ( 3 4 ) 5 | 3: TERMINAL: code=97, repr='a' 6 | 4: ABSTRACT: mult ( 5 6 ) 7 | 5: TERMINAL: code=97, repr='a' 8 | 6: ERROR 9 | 2: ALTERNATIVE: node=7, next=nil 10 | 7: ABSTRACT: mult ( 8 6 ) 11 | 8: ABSTRACT: plus ( 3 5 ) 12 | 13 | -------------------------------------------------------------------------------- /test/test35.out: -------------------------------------------------------------------------------- 1 | Syntax error on token 7 2 | -------------------------------------------------------------------------------- /test/test36.out: -------------------------------------------------------------------------------- 1 | Syntax error on token 7:ignore 2 tokens starting with token = 5 2 | Syntax error on token 10:ignore 2 tokens starting with token = 10 3 | Translation: 4 | 0: ABSTRACT: plus ( 1 2 ) 5 | 1: ABSTRACT: plus ( 3 4 ) 6 | 3: TERMINAL: code=97, repr='a' 7 | 4: ABSTRACT: mult ( 5 2 ) 8 | 5: TERMINAL: code=97, repr='a' 9 | 2: ERROR 10 | 11 | -------------------------------------------------------------------------------- /test/test37.out: -------------------------------------------------------------------------------- 1 | Syntax error on token 7:ignore 4 tokens starting with token = 5 2 | Translation: 3 | 0: ABSTRACT: plus ( 1 2 ) 4 | 1: ABSTRACT: plus ( 3 4 ) 5 | 3: TERMINAL: code=97, repr='a' 6 | 4: ABSTRACT: mult ( 5 2 ) 7 | 5: TERMINAL: code=97, repr='a' 8 | 2: ERROR 9 | 10 | -------------------------------------------------------------------------------- /test/test38.out: -------------------------------------------------------------------------------- 1 | Syntax error on token 7:ignore 4 tokens starting with token = 5 2 | Translation: 3 | 0: ABSTRACT: plus ( 1 2 ) 4 | 1: ABSTRACT: plus ( 3 4 ) 5 | 3: TERMINAL: code=97, repr='a' 6 | 4: ABSTRACT: mult ( 5 2 ) 7 | 5: TERMINAL: code=97, repr='a' 8 | 2: ERROR 9 | 10 | -------------------------------------------------------------------------------- /test/test39.out: -------------------------------------------------------------------------------- 1 | Translation: 2 | 0: ALTERNATIVE: node=1, next=2 3 | 1: ABSTRACT: plus ( 3 4 ) 4 | 3: TERMINAL: code=97, repr='a' 5 | 4: ALTERNATIVE: node=5, next=6 6 | 5: ABSTRACT: mult ( 7 8 ) 7 | 7: TERMINAL: code=98, repr='b' 8 | 8: ABSTRACT: plus ( 9 10 ) 9 | 9: TERMINAL: code=99, repr='c' 10 | 10: TERMINAL: code=100, repr='d' 11 | 6: ALTERNATIVE: node=11, next=nil 12 | 11: ABSTRACT: plus ( 12 10 ) 13 | 12: ABSTRACT: mult ( 7 9 ) 14 | 2: ALTERNATIVE: node=13, next=14 15 | 13: ABSTRACT: mult ( 15 8 ) 16 | 15: ABSTRACT: plus ( 3 7 ) 17 | 14: ALTERNATIVE: node=16, next=nil 18 | 16: ABSTRACT: plus ( 17 10 ) 19 | 17: ALTERNATIVE: node=18, next=19 20 | 18: ABSTRACT: plus ( 3 12 ) 21 | 19: ALTERNATIVE: node=20, next=nil 22 | 20: ABSTRACT: mult ( 15 9 ) 23 | 24 | -------------------------------------------------------------------------------- /test/test40.out: -------------------------------------------------------------------------------- 1 | Translation: 2 | 0: ALTERNATIVE: node=1, next=2 3 | 1: ABSTRACT: plus ( 3 4 ) 4 | 3: TERMINAL: code=97, repr='a' 5 | 4: ALTERNATIVE: node=5, next=6 6 | 5: ABSTRACT: mult ( 7 8 ) 7 | 7: TERMINAL: code=98, repr='b' 8 | 8: ABSTRACT: plus ( 9 10 ) 9 | 9: TERMINAL: code=99, repr='c' 10 | 10: TERMINAL: code=97, repr='a' 11 | 6: ALTERNATIVE: node=11, next=nil 12 | 11: ABSTRACT: plus ( 12 10 ) 13 | 12: ABSTRACT: mult ( 7 9 ) 14 | 2: ALTERNATIVE: node=13, next=14 15 | 13: ABSTRACT: mult ( 15 8 ) 16 | 15: ABSTRACT: plus ( 3 7 ) 17 | 14: ALTERNATIVE: node=16, next=nil 18 | 16: ABSTRACT: plus ( 17 10 ) 19 | 17: ALTERNATIVE: node=18, next=19 20 | 18: ABSTRACT: plus ( 3 12 ) 21 | 19: ALTERNATIVE: node=20, next=nil 22 | 20: ABSTRACT: mult ( 15 9 ) 23 | 24 | -------------------------------------------------------------------------------- /test/test42.out: -------------------------------------------------------------------------------- 1 | Translation: 2 | 0: ABSTRACT: mult ( 1 2 ) 3 | 1: ABSTRACT: plus ( 2 3 ) 4 | 2: EMPTY 5 | 3: ABSTRACT: plus ( 2 4 ) 6 | 4: TERMINAL: code=97, repr='a' 7 | 8 | -------------------------------------------------------------------------------- /test/test43.out: -------------------------------------------------------------------------------- 1 | Translation: 2 | 0: ALTERNATIVE: node=1, next=2 3 | 1: ABSTRACT: plus ( 3 4 ) 4 | 3: EMPTY 5 | 4: ALTERNATIVE: node=5, next=6 6 | 5: ABSTRACT: mult ( 7 3 ) 7 | 7: TERMINAL: code=98, repr='b' 8 | 6: ALTERNATIVE: node=8, next=9 9 | 8: ABSTRACT: mult ( 7 10 ) 10 | 10: ABSTRACT: plus ( 3 11 ) 11 | 11: TERMINAL: code=100, repr='d' 12 | 9: ALTERNATIVE: node=12, next=nil 13 | 12: ABSTRACT: plus ( 3 11 ) 14 | 2: ALTERNATIVE: node=13, next=14 15 | 13: ABSTRACT: mult ( 15 3 ) 16 | 15: ABSTRACT: plus ( 3 7 ) 17 | 14: ALTERNATIVE: node=16, next=17 18 | 16: ABSTRACT: mult ( 15 10 ) 19 | 17: ALTERNATIVE: node=18, next=nil 20 | 18: ABSTRACT: plus ( 3 11 ) 21 | 22 | -------------------------------------------------------------------------------- /test/test44.out: -------------------------------------------------------------------------------- 1 | translation for `E' has negative cost 2 | -------------------------------------------------------------------------------- /test/test45.rout: -------------------------------------------------------------------------------- 1 | Translation: 2 | 0: ABSTRACT: add \( 1 2 \) 3 | 1: TERMINAL: code=97, repr='a' 4 | 2: ABSTRACT: madd \( 3 4 5 \) 5 | 3: TERMINAL: code=97, repr='a' 6 | 4: TERMINAL: code=97, repr='a' 7 | 5: TERMINAL: code=97, repr='a' 8 | 9 | AMBIGUOUS Grammar:.* 10 | cost = 2 11 | -------------------------------------------------------------------------------- /test/test46.rout: -------------------------------------------------------------------------------- 1 | Translation: 2 | 0: ABSTRACT: add \( 1 2 \) 3 | 1: TERMINAL: code=97, repr='a' 4 | 2: ALTERNATIVE: node=3, next=4 5 | 3: ABSTRACT: madd \( 5 6 7 \) 6 | 5: TERMINAL: code=97, repr='a' 7 | 6: TERMINAL: code=97, repr='a' 8 | 7: TERMINAL: code=97, repr='a' 9 | 4: ALTERNATIVE: node=8, next=nil 10 | 8: ABSTRACT: add \( 9 5 \) 11 | 9: ABSTRACT: mult \( 6 7 \) 12 | 13 | AMBIGUOUS Grammar:.* 14 | cost = 3 15 | -------------------------------------------------------------------------------- /test/test47.rout: -------------------------------------------------------------------------------- 1 | Translation: 2 | 0: ABSTRACT: add \( 1 2 \) 3 | 1: TERMINAL: code=97, repr='a' 4 | 2: ABSTRACT: madd \( 3 4 5 \) 5 | 3: TERMINAL: code=97, repr='a' 6 | 4: TERMINAL: code=97, repr='a' 7 | 5: TERMINAL: code=97, repr='a' 8 | 9 | AMBIGUOUS Grammar:.* 10 | cost = 2 11 | -------------------------------------------------------------------------------- /test/test48.out: -------------------------------------------------------------------------------- 1 | Translation: 2 | 0: ABSTRACT: prog ( 1 ) 3 | 1: ABSTRACT: print ( 2 ) 4 | 2: ABSTRACT: string ( 3 4 ) 5 | 3: TERMINAL: code=99, repr='c' 6 | 4: EMPTY 7 | 8 | -------------------------------------------------------------------------------- /test/test49.out: -------------------------------------------------------------------------------- 1 | Translation: 2 | 0: ABSTRACT: prog ( 1 ) 3 | 1: ABSTRACT: opt ( 2 ) 4 | 2: EMPTY 5 | 6 | --------------------------------------------------------------------------------