1
0
mirror of https://git.savannah.gnu.org/git/gperf.git synced 2025-12-02 21:19:24 +00:00

Initial revision

This commit is contained in:
Bruno Haible
2000-08-19 06:20:11 +00:00
commit 501ee3e640
107 changed files with 30411 additions and 0 deletions

232
tests/Makefile.in Normal file
View File

@@ -0,0 +1,232 @@
# Makefile for gperf/tests
# Copyright (C) 1989, 1992, 1993, 1995, 1998 Free Software Foundation, Inc.
# written by Douglas C. Schmidt (schmidt@ics.uci.edu)
#
# This file is part of GNU GPERF.
#
# GNU GPERF is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 1, or (at your option)
# any later version.
#
# GNU GPERF is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU GPERF; see the file COPYING. If not, write to the Free
# Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA.
#### Start of system configuration section. ####
# Directories used by "make":
srcdir = @srcdir@
# Programs used by "make":
# C compiler
CC = @CC@
CFLAGS = @CFLAGS@
CPP = @CPP@
# C++ compiler
CXX = @CXX@
CXXFLAGS = @CXXFLAGS@
CXXCPP = @CXXCPP@
# Other
MV = mv
LN = ln
RM = rm -f
@SET_MAKE@
#### End of system configuration section. ####
SHELL = /bin/sh
VPATH = $(srcdir)
GPERF = ../src/gperf
all :
install : all
installdirs :
uninstall :
check : check-link-c check-link-c++ check-c check-ada check-modula3 check-pascal check-test
@true
extracheck : @CHECK_LANG_SYNTAX@
@true
check-link-c: force
@echo "performing some tests of the perfect hash generator"
$(CC) -c $(CFLAGS) $(srcdir)/test.c
$(GPERF) -p -c -l -S1 -o $(srcdir)/c.gperf > cinset.c
$(CC) $(CFLAGS) -o cout cinset.c test.o
check-link-c++: force
check-c:
@echo "testing ANSI C reserved words, all items should be found in the set"
./cout -v < $(srcdir)/c.gperf > c.out
diff $(srcdir)/c.exp c.out
check-ada:
$(GPERF) -k1,4,'$$' $(srcdir)/ada.gperf > adainset.c
# double '$$' is only there since make gets confused; program wants only 1 '$'
$(CC) $(CFLAGS) -o aout adainset.c test.o
@echo "testing Ada reserved words, all items should be found in the set"
./aout -v < $(srcdir)/ada.gperf > ada-res.out
diff $(srcdir)/ada-res.exp ada-res.out
$(GPERF) -p -D -k1,'$$' -s 2 -o $(srcdir)/adadefs.gperf > preinset.c
$(CC) $(CFLAGS) -o preout preinset.c test.o
@echo "testing Ada predefined words, all items should be found in the set"
./preout -v < $(srcdir)/adadefs.gperf > ada-pred.out
diff $(srcdir)/ada-pred.exp ada-pred.out
check-modula3:
$(GPERF) -k1,2,'$$' -o $(srcdir)/modula3.gperf > m3inset.c
$(CC) $(CFLAGS) -o m3out m3inset.c test.o
@echo "testing Modula3 reserved words, all items should be found in the set"
./m3out -v < $(srcdir)/modula3.gperf > modula.out
diff $(srcdir)/modula.exp modula.out
check-pascal:
$(GPERF) -o -S2 -p < $(srcdir)/pascal.gperf > pinset.c
$(CC) $(CFLAGS) -o pout pinset.c test.o
@echo "testing Pascal reserved words, all items should be found in the set"
./pout -v < $(srcdir)/pascal.gperf > pascal.out
diff $(srcdir)/pascal.exp pascal.out
# these next 5 are demos that show off the generated code
check-test:
$(GPERF) -p -j1 -g -o -t -N is_reserved_word -k1,3,'$$' < $(srcdir)/c-parse.gperf > test-1.out
diff $(srcdir)/test-1.exp test-1.out
$(GPERF) -n -k1-8 -l < $(srcdir)/modula2.gperf > test-2.out
diff $(srcdir)/test-2.exp test-2.out
$(GPERF) -p -j 1 -o -a -C -g -t -k1,4,$$ < $(srcdir)/gplus.gperf > test-3.out
diff $(srcdir)/test-3.exp test-3.out
$(GPERF) -D -p -t < $(srcdir)/c-parse.gperf > test-4.out
diff $(srcdir)/test-4.exp test-4.out
$(GPERF) -g -o -j1 -t -p -N is_reserved_word < $(srcdir)/gpc.gperf > test-5.out
diff $(srcdir)/test-5.exp test-5.out
# prints out the help message
-$(GPERF) -h > test-6.out 2>&1
diff $(srcdir)/test-6.exp test-6.out
@echo "only if, do, for, case, goto, else, while, and return should be found "
./aout -v < $(srcdir)/c.gperf > test-7.out
diff $(srcdir)/test-7.exp test-7.out
# The following validates valid language syntax with different parameters.
# Works only with gcc and g++, and only on platforms where "gcc -ansi" is
# usable. (There are still platforms where gcc-2.8.0's fixincludes does not
# work well enough.)
VALIDATE = CC='$(CC)' CFLAGS='$(CFLAGS)' CXX='$(CXX)' CXXFLAGS='$(CXXFLAGS)' GPERF='$(GPERF)' ./validate
check-lang-syntax : force
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -c
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -C
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -E
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -G
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -G -C
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -G -E
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -l
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -D
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -D -l
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -S 10
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -S 10 -c
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -S 10 -C
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -S 10 -E
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -S 10 -G
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -S 10 -l
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -S 10 -D
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -S 10 -D -l
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -S 1000
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -C
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -l
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -D
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -D -l
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -S 10
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -S 10 -C
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -S 10 -l
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -S 10 -D
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -S 10 -D -l
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -p -S 1000
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -K key_name
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -H hash_function_name
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest1.gperf -W word_list_name
sed -e 's,in_word_set,lookup_function_name,g' < jstest1.gperf > tmp-jstest1.gperf && \
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 tmp-jstest1.gperf -N lookup_function_name
sed -e 's,Perfect_Hash,class_name,g' < jstest1.gperf > tmp-jstest1.gperf && \
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 tmp-jstest1.gperf -Z class_name
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -c
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -C
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -E
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -G
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -G -C
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -G -E
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -l
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -D
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -D -l
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -S 10
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -S 10 -c
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -S 10 -C
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -S 10 -E
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -S 10 -G
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -S 10 -l
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -S 10 -D
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -S 10 -D -l
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -S 1000
sed -e 's,name,key_name,g' < jstest2.gperf > tmp-jstest2.gperf && \
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 tmp-jstest2.gperf -t -p -K key_name
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 jstest2.gperf -t -p -H hash_function_name
sed -e 's,in_word_set,lookup_function_name,g' < jstest2.gperf > tmp-jstest2.gperf && \
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 tmp-jstest2.gperf -t -p -N lookup_function_name
sed -e 's,Perfect_Hash,class_name,g' < jstest2.gperf > tmp-jstest2.gperf && \
$(VALIDATE) KR-C,C,ANSI-C,C++ -k1,2 tmp-jstest2.gperf -t -p -Z class_name
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -c
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -C
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -E
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -G
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -G -C
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -G -E
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -l
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -D
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -D -l
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -S 10
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -S 10 -c
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -S 10 -C
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -S 10 -E
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -S 10 -G
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -S 10 -l
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -S 10 -D
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -S 10 -D -l
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -S 1000
sed -e 's,name,key_name,g' < jstest3.gperf > tmp-jstest3.gperf && \
$(VALIDATE) C,ANSI-C,C++ -k1,2 tmp-jstest3.gperf -t -p -K key_name
$(VALIDATE) C,ANSI-C,C++ -k1,2 jstest3.gperf -t -p -H hash_function_name
sed -e 's,in_word_set,lookup_function_name,g' < jstest3.gperf > tmp-jstest3.gperf && \
$(VALIDATE) C,ANSI-C,C++ -k1,2 tmp-jstest3.gperf -t -p -N lookup_function_name
sed -e 's,Perfect_Hash,class_name,g' < jstest3.gperf > tmp-jstest3.gperf && \
$(VALIDATE) C,ANSI-C,C++ -k1,2 tmp-jstest3.gperf -t -p -Z class_name
mostlyclean : clean
clean : force
$(RM) *.o core *inset.c output.* *.out aout cout m3out pout preout tmp-* valitest*
distclean : clean
$(RM) config.status config.log config.cache Makefile
maintainer-clean : distclean
force :

54
tests/ada-pred.exp Normal file
View File

@@ -0,0 +1,54 @@
in word set boolean
in word set character
in word set constraint_error
in word set false
in word set float
in word set integer
in word set natural
in word set numeric_error
in word set positive
in word set program_error
in word set storage_error
in word set string
in word set tasking_error
in word set true
in word set address
in word set aft
in word set base
in word set callable
in word set constrained
in word set count
in word set delta
in word set digits
in word set emax
in word set epsilon
in word set first
in word set firstbit
in word set fore
in word set image
in word set large
in word set last
in word set lastbit
in word set length
in word set machine_emax
in word set machine_emin
in word set machine_mantissa
in word set machine_overflows
in word set machine_radix
in word set machine_rounds
in word set mantissa
in word set pos
in word set position
in word set pred
in word set range
in word set safe_emax
in word set safe_large
in word set safe_small
in word set size
in word set small
in word set storage_size
in word set succ
in word set terminated
in word set val
in word set value
in word set width

63
tests/ada-res.exp Normal file
View File

@@ -0,0 +1,63 @@
in word set else
in word set exit
in word set terminate
in word set type
in word set raise
in word set range
in word set reverse
in word set declare
in word set end
in word set record
in word set exception
in word set not
in word set then
in word set return
in word set separate
in word set select
in word set digits
in word set renames
in word set subtype
in word set elsif
in word set function
in word set for
in word set package
in word set procedure
in word set private
in word set while
in word set when
in word set new
in word set entry
in word set delay
in word set case
in word set constant
in word set at
in word set abort
in word set accept
in word set and
in word set delta
in word set access
in word set abs
in word set pragma
in word set array
in word set use
in word set out
in word set do
in word set others
in word set of
in word set or
in word set all
in word set limited
in word set loop
in word set null
in word set task
in word set in
in word set is
in word set if
in word set rem
in word set mod
in word set begin
in word set body
in word set xor
in word set goto
in word set generic
in word set with

63
tests/ada.gperf Normal file
View File

@@ -0,0 +1,63 @@
else
exit
terminate
type
raise
range
reverse
declare
end
record
exception
not
then
return
separate
select
digits
renames
subtype
elsif
function
for
package
procedure
private
while
when
new
entry
delay
case
constant
at
abort
accept
and
delta
access
abs
pragma
array
use
out
do
others
of
or
all
limited
loop
null
task
in
is
if
rem
mod
begin
body
xor
goto
generic
with

54
tests/adadefs.gperf Normal file
View File

@@ -0,0 +1,54 @@
boolean
character
constraint_error
false
float
integer
natural
numeric_error
positive
program_error
storage_error
string
tasking_error
true
address
aft
base
callable
constrained
count
delta
digits
emax
epsilon
first
firstbit
fore
image
large
last
lastbit
length
machine_emax
machine_emin
machine_mantissa
machine_overflows
machine_radix
machine_rounds
mantissa
pos
position
pred
range
safe_emax
safe_large
safe_small
size
small
storage_size
succ
terminated
val
value
width

47
tests/c++.gperf Normal file
View File

@@ -0,0 +1,47 @@
asm
auto
break
case
catch
char
class
const
continue
default
delete
do
double
else
enum
extern
float
for
friend
goto
if
inline
int
long
new
operator
overload
private
protected
public
register
return
short
signed
sizeof
static
struct
switch
template
this
typedef
union
unsigned
virtual
void
volatile
while

56
tests/c-parse.gperf Normal file
View File

@@ -0,0 +1,56 @@
%{
/* Command-line: gperf -p -j1 -i 1 -g -o -t -N is_reserved_word -k1,3,$ c-parse.gperf */
%}
struct resword { char *name; short token; enum rid rid; };
%%
__alignof, ALIGNOF, NORID
__alignof__, ALIGNOF, NORID
__asm, ASM, NORID
__asm__, ASM, NORID
__attribute, ATTRIBUTE, NORID
__attribute__, ATTRIBUTE, NORID
__const, TYPE_QUAL, RID_CONST
__const__, TYPE_QUAL, RID_CONST
__inline, SCSPEC, RID_INLINE
__inline__, SCSPEC, RID_INLINE
__signed, TYPESPEC, RID_SIGNED
__signed__, TYPESPEC, RID_SIGNED
__typeof, TYPEOF, NORID
__typeof__, TYPEOF, NORID
__volatile, TYPE_QUAL, RID_VOLATILE
__volatile__, TYPE_QUAL, RID_VOLATILE
asm, ASM, NORID
auto, SCSPEC, RID_AUTO
break, BREAK, NORID
case, CASE, NORID
char, TYPESPEC, RID_CHAR
const, TYPE_QUAL, RID_CONST
continue, CONTINUE, NORID
default, DEFAULT, NORID
do, DO, NORID
double, TYPESPEC, RID_DOUBLE
else, ELSE, NORID
enum, ENUM, NORID
extern, SCSPEC, RID_EXTERN
float, TYPESPEC, RID_FLOAT
for, FOR, NORID
goto, GOTO, NORID
if, IF, NORID
inline, SCSPEC, RID_INLINE
int, TYPESPEC, RID_INT
long, TYPESPEC, RID_LONG
register, SCSPEC, RID_REGISTER
return, RETURN, NORID
short, TYPESPEC, RID_SHORT
signed, TYPESPEC, RID_SIGNED
sizeof, SIZEOF, NORID
static, SCSPEC, RID_STATIC
struct, STRUCT, NORID
switch, SWITCH, NORID
typedef, SCSPEC, RID_TYPEDEF
typeof, TYPEOF, NORID
union, UNION, NORID
unsigned, TYPESPEC, RID_UNSIGNED
void, TYPESPEC, RID_VOID
volatile, TYPE_QUAL, RID_VOLATILE
while, WHILE, NORID

32
tests/c.exp Normal file
View File

@@ -0,0 +1,32 @@
in word set if
in word set do
in word set int
in word set for
in word set case
in word set char
in word set auto
in word set goto
in word set else
in word set long
in word set void
in word set enum
in word set float
in word set short
in word set union
in word set break
in word set while
in word set const
in word set double
in word set static
in word set extern
in word set struct
in word set return
in word set sizeof
in word set switch
in word set signed
in word set typedef
in word set default
in word set unsigned
in word set continue
in word set register
in word set volatile

32
tests/c.gperf Normal file
View File

@@ -0,0 +1,32 @@
if
do
int
for
case
char
auto
goto
else
long
void
enum
float
short
union
break
while
const
double
static
extern
struct
return
sizeof
switch
signed
typedef
default
unsigned
continue
register
volatile

1214
tests/configure vendored Executable file

File diff suppressed because it is too large Load Diff

45
tests/configure.in Normal file
View File

@@ -0,0 +1,45 @@
dnl autoconf configuration for gperf/tests
dnl Copyright (C) 1998 Free Software Foundation, Inc.
dnl written by Douglas C. Schmidt (schmidt@ics.uci.edu)
dnl
dnl This file is part of GNU GPERF.
dnl
dnl GNU GPERF is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 1, or (at your option)
dnl any later version.
dnl
dnl GNU GPERF is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with GNU GPERF; see the file COPYING. If not, write to the
dnl Free Software Foundation, 59 Temple Place - Suite 330, Boston,
dnl MA 02111-1307, USA.
AC_INIT(c-parse.gperf)
AC_PROG_MAKE_SET
dnl
dnl checks for programs
dnl
AC_PROG_CC
dnl sets variable CC
AC_PROG_CPP
dnl sets variable CPP
AC_PROG_CXX
dnl sets variable CXX
AC_PROG_CXXCPP
dnl sets variable CXXCPP
if test $ac_cv_prog_gcc = yes -a $ac_cv_prog_gxx = yes; then
CHECK_LANG_SYNTAX='check-lang-syntax'
else
CHECK_LANG_SYNTAX=''
fi
AC_SUBST(CHECK_LANG_SYNTAX)
dnl
dnl That's it.
dnl
AC_OUTPUT(Makefile)

48
tests/gpc.gperf Normal file
View File

@@ -0,0 +1,48 @@
%{
/* ISO Pascal 7185 reserved words.
*
* For GNU Pascal compiler (GPC) by jtv@hut.fi
*
* run this through the Doug Schmidt's gperf program
* with command
* gperf -g -o -j1 -t -p -N is_reserved_word
*
*/
%}
struct resword { char *name; short token; short iclass;};
%%
And, AND, PASCAL_ISO
Array, ARRAY, PASCAL_ISO
Begin, BEGIN_, PASCAL_ISO
Case, CASE, PASCAL_ISO
Const, CONST, PASCAL_ISO
Div, DIV, PASCAL_ISO
Do, DO, PASCAL_ISO
Downto, DOWNTO, PASCAL_ISO
Else, ELSE, PASCAL_ISO
End, END, PASCAL_ISO
File, FILE_, PASCAL_ISO
For, FOR, PASCAL_ISO
Function, FUNCTION, PASCAL_ISO
Goto, GOTO, PASCAL_ISO
If, IF, PASCAL_ISO
In, IN, PASCAL_ISO
Label, LABEL, PASCAL_ISO
Mod, MOD, PASCAL_ISO
Nil, NIL, PASCAL_ISO
Not, NOT, PASCAL_ISO
Of, OF, PASCAL_ISO
Or, OR, PASCAL_ISO
Packed, PACKED, PASCAL_ISO
Procedure, PROCEDURE, PASCAL_ISO
Program,PROGRAM,PASCAL_ISO
Record, RECORD, PASCAL_ISO
Repeat, REPEAT, PASCAL_ISO
Set, SET, PASCAL_ISO
Then, THEN, PASCAL_ISO
To, TO, PASCAL_ISO
Type, TYPE, PASCAL_ISO
Until, UNTIL, PASCAL_ISO
Var, VAR, PASCAL_ISO
While, WHILE, PASCAL_ISO
With, WITH, PASCAL_ISO

76
tests/gplus.gperf Normal file
View File

@@ -0,0 +1,76 @@
%{
/* Command-line: gperf -p -j1 -g -o -t -N is_reserved_word -k1,4,$ gplus.gperf */
%}
struct resword { char *name; short token; enum rid rid;};
%%
__alignof, ALIGNOF, NORID
__alignof__, ALIGNOF, NORID
__asm, ASM, NORID
__asm__, ASM, NORID
__attribute, ATTRIBUTE, NORID
__attribute__, ATTRIBUTE, NORID
__const, TYPE_QUAL, RID_CONST
__const__, TYPE_QUAL, RID_CONST
__inline, SCSPEC, RID_INLINE
__inline__, SCSPEC, RID_INLINE
__signed, TYPESPEC, RID_SIGNED
__signed__, TYPESPEC, RID_SIGNED
__typeof, TYPEOF, NORID
__typeof__, TYPEOF, NORID
__volatile, TYPE_QUAL, RID_VOLATILE
__volatile__, TYPE_QUAL, RID_VOLATILE
all, ALL, NORID /* Extension */,
except, EXCEPT, NORID /* Extension */,
exception, AGGR, RID_EXCEPTION /* Extension */,
raise, RAISE, NORID /* Extension */,
raises, RAISES, NORID /* Extension */,
reraise, RERAISE, NORID /* Extension */,
try, TRY, NORID /* Extension */,
asm, ASM, NORID,
auto, SCSPEC, RID_AUTO,
break, BREAK, NORID,
case, CASE, NORID,
catch, CATCH, NORID,
char, TYPESPEC, RID_CHAR,
class, AGGR, RID_CLASS,
const, TYPE_QUAL, RID_CONST,
continue, CONTINUE, NORID,
default, DEFAULT, NORID,
delete, DELETE, NORID,
do, DO, NORID,
double, TYPESPEC, RID_DOUBLE,
dynamic, DYNAMIC, NORID,
else, ELSE, NORID,
enum, ENUM, NORID,
extern, SCSPEC, RID_EXTERN,
float, TYPESPEC, RID_FLOAT,
for, FOR, NORID,
friend, SCSPEC, RID_FRIEND,
goto, GOTO, NORID,
if, IF, NORID,
inline, SCSPEC, RID_INLINE,
int, TYPESPEC, RID_INT,
long, TYPESPEC, RID_LONG,
new, NEW, NORID,
operator, OPERATOR, NORID,
overload, OVERLOAD, NORID,
private, PRIVATE, NORID,
protected, PROTECTED, NORID,
public, PUBLIC, NORID,
register, SCSPEC, RID_REGISTER,
return, RETURN, NORID,
short, TYPESPEC, RID_SHORT,
signed, TYPESPEC, RID_SIGNED,
sizeof, SIZEOF, NORID,
static, SCSPEC, RID_STATIC,
struct, AGGR, RID_RECORD,
switch, SWITCH, NORID,
this, THIS, NORID,
typedef, SCSPEC, RID_TYPEDEF,
typeof, TYPEOF, NORID,
union, AGGR, RID_UNION,
unsigned, TYPESPEC, RID_UNSIGNED,
virtual, SCSPEC, RID_VIRTUAL,
void, TYPESPEC, RID_VOID,
volatile, TYPE_QUAL, RID_VOLATILE,
while, WHILE, NORID,

63
tests/irc.gperf Normal file
View File

@@ -0,0 +1,63 @@
%{
extern int m_text(), m_private(), m_who(), m_whois(), m_user(), m_list();
extern int m_topic(), m_invite(), m_channel(), m_version(), m_quit();
extern int m_server(), m_kill(), m_info(), m_links(), m_summon(), m_stats();
extern int m_users(), m_nick(), m_error(), m_help(), m_whoreply();
extern int m_squit(), m_restart(), m_away(), m_die(), m_connect();
extern int m_ping(), m_pong(), m_oper(), m_pass(), m_wall(), m_trace();
extern int m_time(), m_rehash(), m_names(), m_namreply(), m_admin();
extern int m_linreply(), m_notice(), m_lusers(), m_voice(), m_grph();
extern int m_xtra(), m_motd();
%}
struct Message {
char *cmd;
int (* func)();
int count;
int parameters;
};
%%
NICK, m_nick, 0, 1
MSG, m_text, 0, 1
PRIVMSG, m_private, 0, 2
WHO, m_who, 0, 1
WHOIS, m_whois, 0, 4
USER, m_user, 0, 4
SERVER, m_server, 0, 2
LIST, m_list, 0, 1
TOPIC, m_topic, 0, 1
INVITE, m_invite, 0, 2
CHANNEL, m_channel, 0, 1
VERSION, m_version, 0, 1
QUIT, m_quit, 0, 2
SQUIT, m_squit, 0, 2
KILL, m_kill, 0, 2
INFO, m_info, 0, 1
LINKS, m_links, 0, 1
SUMMON, m_summon, 0, 1
STATS, m_stats, 0, 1
USERS, m_users, 0, 1
RESTART, m_restart, 0, 1
WHOREPLY,m_whoreply, 0, 7
HELP, m_help, 0, 2
ERROR, m_error, 0, 1
AWAY, m_away, 0, 1
DIE, m_die, 0, 1
CONNECT, m_connect, 0, 3
PING, m_ping, 0, 2
PONG, m_pong, 0, 3
OPER, m_oper, 0, 3
PASS, m_pass, 0, 2
WALL, m_wall, 0, 1
TIME, m_time, 0, 1
REHASH, m_rehash, 0, 1
NAMES, m_names, 0, 1
NAMREPLY,m_namreply, 0, 3
ADMIN, m_admin, 0, 1
TRACE, m_trace, 0, 1
LINREPLY,m_linreply, 0, 2
NOTICE, m_notice, 0, 2
LUSERS, m_lusers, 0, 1
VOICE, m_voice, 0, 2
GRPH, m_grph, 0, 2
XTRA, m_xtra, 0, 2
MOTD, m_motd, 0, 2

73
tests/jscript.gperf Normal file
View File

@@ -0,0 +1,73 @@
%{
/* Command-line: gperf -k'1,2,$' -t -p -K 'name' -H 'js_kw_hash' -N 'js_kw_lookup' -a -g jscript.gperf */
%}
struct js_keyword {
char * name;
int token;
}
%%
# Javascript reserved words, see "keywords.html"
abstract, TK_ABSTRACT
boolean, TK_BOOLEAN
break, TK_BREAK
byte, TK_BYTE
case, TK_CASE
catch, TK_CATCH
char, TK_CHAR
class, TK_CLASS
const, TK_CONST
continue, TK_CONTINUE
default, TK_DEFAULT
do, TK_DO
double, TK_DOUBLE
else, TK_ELSE
extends, TK_EXTENDS
false, TK_FALSE
final, TK_FINAL
finally, TK_FINALLY
float, TK_FLOAT
for, TK_FOR
function, TK_FUNCTION
goto, TK_GOTO
if, TK_IF
implements, TK_IMPLEMENTS
import, TK_IMPORT
in, TK_IN
instanceof, TK_INSTANCEOF
int, TK_INT
interface, TK_INTERFACE
long, TK_LONG
native, TK_NATIVE
new, TK_NEW
null, TK_NULL
package, TK_PACKAGE
private, TK_PRIVATE
protected, TK_PROTECTED
public, TK_PUBLIC
return, TK_RETURN
short, TK_SHORT
static, TK_STATIC
super, TK_SUPER
switch, TK_SWITCH
synchronized, TK_SYNCHRONIZED
this, TK_THIS
throw, TK_THROW
throws, TK_THROWS
transient, TK_TRANSIENT
true, TK_TRUE
try, TK_TRY
var, TK_VAR
void, TK_VOID
while, TK_WHILE
with, TK_WITH
%%
int js_keyword_lookup (register const char *str, register int len)
{
struct js_keyword * keyword = js_kw_lookup(str,len);
if (keyword)
return keyword->token;
else
return TK_IDENT;
}

142
tests/jstest1.gperf Normal file
View File

@@ -0,0 +1,142 @@
abstract
boolean
break
byte
case
catch
char
class
const
continue
default
do
double
else
extends
false
final
finally
float
for
function
goto
if
implements
import
in
instanceof
int
interface
long
native
new
null
package
private
protected
public
return
short
static
super
switch
synchronized
this
throw
throws
transient
true
try
var
void
while
with
%%
#include <stdlib.h>
#include <string.h>
#if defined(__STDC__) || defined(__cplusplus)
#define CONST const
#else
#define CONST
#endif
static CONST char* testdata[] = {
"bogus",
"abstract",
"boolean",
"break",
"byte",
"case",
"catch",
"char",
"class",
"const",
"continue",
"default",
"do",
"double",
"else",
"extends",
"false",
"final",
"finally",
"float",
"for",
"function",
"goto",
"if",
"implements",
"import",
"in",
"instanceof",
"int",
"interface",
"long",
"native",
"new",
"null",
"package",
"private",
"protected",
"public",
"return",
"short",
"static",
"super",
"switch",
"synchronized",
"this",
"throw",
"throws",
"transient",
"true",
"try",
"var",
"void",
"while",
"with"
};
int main ()
{
int i;
for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++)
{
#ifdef CPLUSPLUS_TEST
CONST char * resword = Perfect_Hash::in_word_set(testdata[i],strlen(testdata[i]));
#else
CONST char * resword = in_word_set(testdata[i],strlen(testdata[i]));
#endif
if (i > 0)
{
if (!resword)
exit (1);
if (strcmp(testdata[i],resword))
exit (1);
}
else
{
if (resword)
exit (1);
}
}
return 0;
}

147
tests/jstest2.gperf Normal file
View File

@@ -0,0 +1,147 @@
struct js_keyword {
char * name;
int token;
}
%%
abstract, 1
boolean, 2
break, 3
byte, 4
case, 5
catch, 6
char, 7
class, 8
const, 9
continue, 10
default, 11
do, 12
double, 13
else, 14
extends, 15
false, 16
final, 17
finally, 18
float, 19
for, 20
function, 21
goto, 22
if, 23
implements, 24
import, 25
in, 26
instanceof, 27
int, 28
interface, 29
long, 30
native, 31
new, 32
null, 33
package, 34
private, 35
protected, 36
public, 37
return, 38
short, 39
static, 40
super, 41
switch, 42
synchronized, 43
this, 44
throw, 45
throws, 46
transient, 47
true, 48
try, 49
var, 50
void, 51
while, 52
with, 53
%%
#include <stdlib.h>
#include <string.h>
#if defined(__STDC__) || defined(__cplusplus)
#define CONST const
#else
#define CONST
#endif
static CONST char* testdata[] = {
"bogus",
"abstract",
"boolean",
"break",
"byte",
"case",
"catch",
"char",
"class",
"const",
"continue",
"default",
"do",
"double",
"else",
"extends",
"false",
"final",
"finally",
"float",
"for",
"function",
"goto",
"if",
"implements",
"import",
"in",
"instanceof",
"int",
"interface",
"long",
"native",
"new",
"null",
"package",
"private",
"protected",
"public",
"return",
"short",
"static",
"super",
"switch",
"synchronized",
"this",
"throw",
"throws",
"transient",
"true",
"try",
"var",
"void",
"while",
"with"
};
int main ()
{
int i;
for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++)
{
#ifdef CPLUSPLUS_TEST
CONST struct js_keyword * resword = Perfect_Hash::in_word_set(testdata[i],strlen(testdata[i]));
#else
CONST struct js_keyword * resword = in_word_set(testdata[i],strlen(testdata[i]));
#endif
if (i > 0)
{
if (!resword)
exit (1);
if (strcmp(testdata[i],resword->name))
exit (1);
}
else
{
if (resword)
exit (1);
}
}
return 0;
}

147
tests/jstest3.gperf Normal file
View File

@@ -0,0 +1,147 @@
struct js_keyword {
const char * name;
int token;
}
%%
abstract, 1
boolean, 2
break, 3
byte, 4
case, 5
catch, 6
char, 7
class, 8
const, 9
continue, 10
default, 11
do, 12
double, 13
else, 14
extends, 15
false, 16
final, 17
finally, 18
float, 19
for, 20
function, 21
goto, 22
if, 23
implements, 24
import, 25
in, 26
instanceof, 27
int, 28
interface, 29
long, 30
native, 31
new, 32
null, 33
package, 34
private, 35
protected, 36
public, 37
return, 38
short, 39
static, 40
super, 41
switch, 42
synchronized, 43
this, 44
throw, 45
throws, 46
transient, 47
true, 48
try, 49
var, 50
void, 51
while, 52
with, 53
%%
#include <stdlib.h>
#include <string.h>
#if defined(__STDC__) || defined(__cplusplus)
#define CONST const
#else
#define CONST
#endif
static CONST char* testdata[] = {
"bogus",
"abstract",
"boolean",
"break",
"byte",
"case",
"catch",
"char",
"class",
"const",
"continue",
"default",
"do",
"double",
"else",
"extends",
"false",
"final",
"finally",
"float",
"for",
"function",
"goto",
"if",
"implements",
"import",
"in",
"instanceof",
"int",
"interface",
"long",
"native",
"new",
"null",
"package",
"private",
"protected",
"public",
"return",
"short",
"static",
"super",
"switch",
"synchronized",
"this",
"throw",
"throws",
"transient",
"true",
"try",
"var",
"void",
"while",
"with"
};
int main ()
{
int i;
for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++)
{
#ifdef CPLUSPLUS_TEST
CONST struct js_keyword * resword = Perfect_Hash::in_word_set(testdata[i],strlen(testdata[i]));
#else
CONST struct js_keyword * resword = in_word_set(testdata[i],strlen(testdata[i]));
#endif
if (i > 0)
{
if (!resword)
exit (1);
if (strcmp(testdata[i],resword->name))
exit (1);
}
else
{
if (resword)
exit (1);
}
}
return 0;
}

116
tests/makeinfo.gperf Normal file
View File

@@ -0,0 +1,116 @@
COMMAND;
%%
!, cm_force_sentence_end, false
', insert_self, false
*, cm_asterisk, false
., cm_force_sentence_end, false
:, cm_force_abbreviated_whitespace, false
?, cm_force_sentence_end, false
@, insert_self, false
TeX, cm_TeX, true
`, insert_self, false
appendix, cm_appendix, false
appendixsec, cm_appendixsec, false
appendixsubsec, cm_appendixsubsec, false
asis, cm_asis, true
b, cm_bold, true
br, cm_br, false
bullet, cm_bullet, true
bye, cm_bye, false
c, cm_comment, false
center, cm_center, false
chapter, cm_chapter, false
cindex, cm_cindex, false
cite, cm_cite, true
code, cm_code, true
comment, cm_comment, false
contents, do_nothing, false
copyright, cm_copyright, true
ctrl, cm_ctrl, true
defcodeindex, cm_defindex, false
defindex, cm_defindex, false
dfn, cm_dfn, true
display, cm_display, false
dots, cm_dots, true
emph, cm_emph, true
end, cm_end, false
enumerate, cm_enumerate, false
equiv, cm_equiv, true
error, cm_error, true
example, cm_example, false
exdent, cm_exdent, false
expansion, cm_expansion, true
file, cm_file, true
findex, cm_findex, false
format, cm_format, false
group, cm_group, false
i, cm_italic, true
iappendix, cm_appendix, false
iappendixsec, cm_appendixsec, false
iappendixsubsec, cm_appendixsubsec, false
ichapter, cm_chapter, false
ifinfo, cm_ifinfo, false
iftex, cm_iftex, false
ignore, cm_ignore, false
include, cm_include, false
inforef, cm_inforef, true
input, cm_include, false
isection, cm_section, false
isubsection, cm_subsection, false
isubsubsection, cm_subsubsection, false
item, cm_item, false
itemize, cm_itemize, false
itemx, cm_itemx, false
iunnumbered, cm_unnumbered, false
iunnumberedsec, cm_unnumberedsec, false
iunnumberedsubsec, cm_unnumberedsubsec, false
kbd, cm_kbd, true
key, cm_key, true
kindex, cm_kindex, false
lisp, cm_lisp, false
menu, cm_menu
minus, cm_minus, true
need, cm_need, false
node, cm_node, false
noindent, cm_noindent, false
page, do_nothing, false
pindex, cm_pindex, false
point, cm_point, true
print, cm_print, true
printindex, cm_printindex, false
pxref, cm_pxref, true
quotation, cm_quotation, false
r, cm_roman, true
ref, cm_xref, true
refill, cm_refill, false
result, cm_result, true
samp, cm_samp, true
sc, cm_sc, true
section, cm_section, false
setchapternewpage, cm_setchapternewpage, false
setfilename, cm_setfilename, false
settitle, cm_settitle, false
smallexample, cm_smallexample, false
sp, cm_sp, false
strong, cm_strong, true
subsection, cm_subsection, false
subsubsection, cm_subsubsection, false
summarycontents, do_nothing, false
syncodeindex, cm_synindex, false
synindex, cm_synindex, false
t, cm_title, true
table, cm_table, false
tex, cm_tex, false
tindex, cm_tindex, false
titlepage, cm_titlepage, false
unnumbered, cm_unnumbered, false
unnumberedsec, cm_unnumberedsec, false
unnumberedsubsec, cm_unnumberedsubsec, false
var, cm_var, true
vindex, cm_vindex, false
w, cm_w, true
xref, cm_xref, true
{, insert_self, false
}, insert_self, false
infoinclude, cm_infoinclude, false
footnote, cm_footnote, false

106
tests/modula.exp Normal file
View File

@@ -0,0 +1,106 @@
in word set AND
in word set ARRAY
in word set BEGIN
in word set BITS
in word set BY
in word set CASE
in word set CONST
in word set DIV
in word set DO
in word set ELSE
in word set ELSIF
in word set END
in word set EVAL
in word set EXCEPT
in word set EXCEPTION
in word set EXIT
in word set EXPORTS
in word set FINALLY
in word set FOR
in word set FROM
in word set IF
in word set IMPORT
in word set INTERFACE
in word set IN
in word set INLINE
in word set LOCK
in word set METHODS
in word set MOD
in word set MODULE
in word set NOT
in word set OBJECT
in word set OF
in word set OR
in word set PROCEDURE
in word set RAISES
in word set READONLY
in word set RECORD
in word set REF
in word set REPEAT
in word set RETURN
in word set SET
in word set THEN
in word set TO
in word set TRY
in word set TYPE
in word set TYPECASE
in word set UNSAFE
in word set UNTIL
in word set UNTRACED
in word set VALUE
in word set VAR
in word set WHILE
in word set WITH
in word set and
in word set array
in word set begin
in word set bits
in word set by
in word set case
in word set const
in word set div
in word set do
in word set else
in word set elsif
in word set end
in word set eval
in word set except
in word set exception
in word set exit
in word set exports
in word set finally
in word set for
in word set from
in word set if
in word set import
in word set interface
in word set in
in word set inline
in word set lock
in word set methods
in word set mod
in word set module
in word set not
in word set object
in word set of
in word set or
in word set procedure
in word set raises
in word set readonly
in word set record
in word set ref
in word set repeat
in word set return
in word set set
in word set then
in word set to
in word set try
in word set type
in word set typecase
in word set unsafe
in word set until
in word set untraced
in word set value
in word set var
in word set while
in word set with

40
tests/modula2.gperf Normal file
View File

@@ -0,0 +1,40 @@
AND
ARRAY
BEGIN
BY
CASE
CONST
DEFINITION
DIV
DO
ELSE
ELSIF
END
EXIT
EXPORT
FOR
FROM
IF
IMPLEMENTATION
IMPORT
IN
LOOP
MOD
MODULE
NOT
OF
OR
POINTER
PROCEDURE
QUALIFIED
RECORD
REPEAT
RETURN
SET
THEN
TO
TYPE
UNTIL
VAR
WHILE
WITH

106
tests/modula3.gperf Normal file
View File

@@ -0,0 +1,106 @@
AND
ARRAY
BEGIN
BITS
BY
CASE
CONST
DIV
DO
ELSE
ELSIF
END
EVAL
EXCEPT
EXCEPTION
EXIT
EXPORTS
FINALLY
FOR
FROM
IF
IMPORT
INTERFACE
IN
INLINE
LOCK
METHODS
MOD
MODULE
NOT
OBJECT
OF
OR
PROCEDURE
RAISES
READONLY
RECORD
REF
REPEAT
RETURN
SET
THEN
TO
TRY
TYPE
TYPECASE
UNSAFE
UNTIL
UNTRACED
VALUE
VAR
WHILE
WITH
and
array
begin
bits
by
case
const
div
do
else
elsif
end
eval
except
exception
exit
exports
finally
for
from
if
import
interface
in
inline
lock
methods
mod
module
not
object
of
or
procedure
raises
readonly
record
ref
repeat
return
set
then
to
try
type
typecase
unsafe
until
untraced
value
var
while
with

36
tests/pascal.exp Normal file
View File

@@ -0,0 +1,36 @@
in word set with
in word set array
in word set and
in word set function
in word set case
in word set var
in word set const
in word set until
in word set then
in word set set
in word set record
in word set program
in word set procedure
in word set or
in word set packed
in word set not
in word set nil
in word set label
in word set in
in word set repeat
in word set of
in word set goto
in word set forward
in word set for
in word set while
in word set file
in word set else
in word set downto
in word set do
in word set div
in word set to
in word set type
in word set end
in word set mod
in word set begin
in word set if

36
tests/pascal.gperf Normal file
View File

@@ -0,0 +1,36 @@
with
array
and
function
case
var
const
until
then
set
record
program
procedure
or
packed
not
nil
label
in
repeat
of
goto
forward
for
while
file
else
downto
do
div
to
type
end
mod
begin
if

153
tests/test-1.exp Normal file
View File

@@ -0,0 +1,153 @@
/* C code produced by gperf version 2.7 */
/* Command-line: ../src/gperf -p -j1 -g -o -t -N is_reserved_word -k1,3,$ */
/* Command-line: gperf -p -j1 -i 1 -g -o -t -N is_reserved_word -k1,3,$ c-parse.gperf */
struct resword { char *name; short token; enum rid rid; };
#define TOTAL_KEYWORDS 51
#define MIN_WORD_LENGTH 2
#define MAX_WORD_LENGTH 13
#define MIN_HASH_VALUE 8
#define MAX_HASH_VALUE 82
/* maximum key range = 75, duplicates = 0 */
#ifdef __GNUC__
__inline
#endif
static unsigned int
hash (str, len)
register const char *str;
register unsigned int len;
{
static unsigned char asso_values[] =
{
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 0, 83, 1, 2, 34,
19, 6, 11, 29, 0, 17, 83, 0, 23, 28,
26, 30, 31, 83, 15, 1, 0, 28, 13, 4,
83, 83, 5, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83
};
register int hval = len;
switch (hval)
{
default:
case 3:
hval += asso_values[(unsigned char)str[2]];
case 2:
case 1:
hval += asso_values[(unsigned char)str[0]];
break;
}
return hval + asso_values[(unsigned char)str[len - 1]];
}
#ifdef __GNUC__
__inline
#endif
struct resword *
is_reserved_word (str, len)
register const char *str;
register unsigned int len;
{
static struct resword wordlist[] =
{
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
{"__asm__", ASM, NORID},
{""},
{"__typeof__", TYPEOF, NORID},
{"__signed__", TYPESPEC, RID_SIGNED},
{"__alignof__", ALIGNOF, NORID},
{"break", BREAK, NORID},
{"__attribute__", ATTRIBUTE, NORID},
{""}, {""},
{"else", ELSE, NORID},
{"__attribute", ATTRIBUTE, NORID},
{"__typeof", TYPEOF, NORID},
{"int", TYPESPEC, RID_INT},
{"__alignof", ALIGNOF, NORID},
{"struct", STRUCT, NORID},
{"sizeof", SIZEOF, NORID},
{"switch", SWITCH, NORID},
{"__volatile__", TYPE_QUAL, RID_VOLATILE},
{""},
{"__inline__", SCSPEC, RID_INLINE},
{"__signed", TYPESPEC, RID_SIGNED},
{"__volatile", TYPE_QUAL, RID_VOLATILE},
{"if", IF, NORID},
{"__inline", SCSPEC, RID_INLINE},
{"while", WHILE, NORID},
{""},
{"__asm", ASM, NORID},
{"auto", SCSPEC, RID_AUTO},
{"short", TYPESPEC, RID_SHORT},
{"default", DEFAULT, NORID},
{"extern", SCSPEC, RID_EXTERN},
{""}, {""},
{"__const", TYPE_QUAL, RID_CONST},
{"static", SCSPEC, RID_STATIC},
{"__const__", TYPE_QUAL, RID_CONST},
{"for", FOR, NORID},
{"case", CASE, NORID},
{"float", TYPESPEC, RID_FLOAT},
{"return", RETURN, NORID},
{"typeof", TYPEOF, NORID},
{"typedef", SCSPEC, RID_TYPEDEF},
{"volatile", TYPE_QUAL, RID_VOLATILE},
{"do", DO, NORID},
{"inline", SCSPEC, RID_INLINE},
{"void", TYPESPEC, RID_VOID},
{"char", TYPESPEC, RID_CHAR},
{"signed", TYPESPEC, RID_SIGNED},
{"unsigned", TYPESPEC, RID_UNSIGNED},
{""}, {""},
{"double", TYPESPEC, RID_DOUBLE},
{"asm", ASM, NORID},
{""}, {""},
{"goto", GOTO, NORID},
{""},
{"const", TYPE_QUAL, RID_CONST},
{"enum", ENUM, NORID},
{"register", SCSPEC, RID_REGISTER},
{""}, {""}, {""}, {""}, {""}, {""},
{"continue", CONTINUE, NORID},
{""},
{"union", UNION, NORID},
{""}, {""}, {""}, {""}, {""},
{"long", TYPESPEC, RID_LONG}
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
register int key = hash (str, len);
if (key <= MAX_HASH_VALUE && key >= 0)
{
register const char *s = wordlist[key].name;
if (*str == *s && !strcmp (str + 1, s + 1))
return &wordlist[key];
}
}
return 0;
}

202
tests/test-2.exp Normal file
View File

@@ -0,0 +1,202 @@
/* C code produced by gperf version 2.7 */
/* Command-line: ../src/gperf -n -k1-8 -l */
#define TOTAL_KEYWORDS 40
#define MIN_WORD_LENGTH 2
#define MAX_WORD_LENGTH 14
#define MIN_HASH_VALUE 1
#define MAX_HASH_VALUE 256
/* maximum key range = 256, duplicates = 0 */
#ifdef __GNUC__
__inline
#endif
static unsigned int
hash (str, len)
register const char *str;
register unsigned int len;
{
static unsigned short asso_values[] =
{
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 25, 30, 35, 21, 0,
30, 15, 30, 45, 257, 257, 0, 5, 45, 0,
10, 0, 1, 20, 25, 15, 30, 40, 15, 5,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257, 257, 257, 257, 257,
257, 257, 257, 257, 257, 257
};
register int hval = 0;
switch (len)
{
default:
case 8:
hval += asso_values[(unsigned char)str[7]];
case 7:
hval += asso_values[(unsigned char)str[6]];
case 6:
hval += asso_values[(unsigned char)str[5]];
case 5:
hval += asso_values[(unsigned char)str[4]];
case 4:
hval += asso_values[(unsigned char)str[3]];
case 3:
hval += asso_values[(unsigned char)str[2]];
case 2:
hval += asso_values[(unsigned char)str[1]];
case 1:
hval += asso_values[(unsigned char)str[0]];
break;
}
return hval;
}
#ifdef __GNUC__
__inline
#endif
const char *
in_word_set (str, len)
register const char *str;
register unsigned int len;
{
static unsigned char lengthtable[] =
{
0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0,
0, 0, 0, 0, 0, 0, 4, 2, 0, 0, 0, 2, 3, 0,
0, 0, 2, 3, 0, 0, 0, 2, 4, 0, 0, 0, 4, 6,
0, 0, 0, 3, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0,
3, 5, 6, 0, 0, 6, 0, 0, 0, 0, 3, 0, 0, 0,
3, 0, 0, 0, 0, 2, 0, 0, 0, 0, 4, 0, 0, 9,
0, 4, 6, 6, 0, 0, 2, 3, 0, 0, 0, 5, 3, 0,
0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0,
0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
7, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0,
4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 10
};
static const char * wordlist[] =
{
"",
"OR",
"", "", "", "", "", "", "", "",
"LOOP",
"", "", "", "", "", "", "", "", "",
"ELSE",
"DO",
"", "", "",
"TO",
"MOD",
"", "", "",
"OF",
"FOR",
"", "", "",
"BY",
"FROM",
"", "", "",
"TYPE",
"MODULE",
"", "", "",
"SET",
"", "", "", "", "",
"EXPORT",
"", "", "", "",
"VAR",
"ARRAY",
"RECORD",
"", "",
"REPEAT",
"", "", "", "",
"END",
"", "", "",
"NOT",
"", "", "", "",
"IF",
"", "", "", "",
"CASE",
"", "",
"PROCEDURE",
"",
"EXIT",
"IMPORT",
"RETURN",
"", "",
"IN",
"AND",
"", "", "",
"ELSIF",
"DIV",
"", "", "",
"THEN",
"", "", "", "", "", "", "", "", "",
"IMPLEMENTATION",
"", "", "", "",
"WHILE",
"", "", "", "", "", "", "", "", "",
"CONST",
"POINTER",
"", "", "",
"UNTIL",
"", "", "", "",
"BEGIN",
"", "", "", "",
"WITH",
"", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "",
"",
"QUALIFIED",
"", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "",
"", "", "", "", "",
"DEFINITION"
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
register int key = hash (str, len);
if (key <= MAX_HASH_VALUE && key >= 0)
if (len == lengthtable[key])
{
register const char *s = wordlist[key];
if (*str == *s && !strcmp (str + 1, s + 1))
return s;
}
}
return 0;
}

186
tests/test-3.exp Normal file
View File

@@ -0,0 +1,186 @@
/* C code produced by gperf version 2.7 */
/* Command-line: ../src/gperf -p -j 1 -o -a -C -g -t -k1,4,$ */
/* Command-line: gperf -p -j1 -g -o -t -N is_reserved_word -k1,4,$ gplus.gperf */
struct resword { char *name; short token; enum rid rid;};
#define TOTAL_KEYWORDS 71
#define MIN_WORD_LENGTH 2
#define MAX_WORD_LENGTH 13
#define MIN_HASH_VALUE 4
#define MAX_HASH_VALUE 147
/* maximum key range = 144, duplicates = 0 */
#ifdef __GNUC__
__inline
#endif
static unsigned int
hash (str, len)
register const char *str;
register unsigned int len;
{
static const unsigned char asso_values[] =
{
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 0, 148, 19, 6, 27,
37, 0, 12, 1, 15, 63, 148, 4, 0, 56,
20, 15, 42, 148, 31, 5, 26, 39, 32, 10,
148, 40, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148
};
register int hval = len;
switch (hval)
{
default:
case 4:
hval += asso_values[(unsigned char)str[3]];
case 3:
case 2:
case 1:
hval += asso_values[(unsigned char)str[0]];
break;
}
return hval + asso_values[(unsigned char)str[len - 1]];
}
#ifdef __GNUC__
__inline
#endif
const struct resword *
in_word_set (str, len)
register const char *str;
register unsigned int len;
{
static const struct resword wordlist[] =
{
{""}, {""}, {""}, {""},
{"else", ELSE, NORID,},
{""},
{"long", TYPESPEC, RID_LONG,},
{""}, {""}, {""}, {""},
{"__alignof__", ALIGNOF, NORID},
{"__asm__", ASM, NORID},
{""}, {""},
{"while", WHILE, NORID,},
{""}, {""}, {""}, {""}, {""},
{"__alignof", ALIGNOF, NORID},
{"all", ALL, NORID /* Extension */,},
{"sizeof", SIZEOF, NORID,},
{"__const__", TYPE_QUAL, RID_CONST},
{"__volatile", TYPE_QUAL, RID_VOLATILE},
{"extern", SCSPEC, RID_EXTERN,},
{"__volatile__", TYPE_QUAL, RID_VOLATILE},
{"__inline", SCSPEC, RID_INLINE},
{"exception", AGGR, RID_EXCEPTION /* Extension */,},
{"__inline__", SCSPEC, RID_INLINE},
{"case", CASE, NORID,},
{"except", EXCEPT, NORID /* Extension */,},
{"new", NEW, NORID,},
{"break", BREAK, NORID,},
{"goto", GOTO, NORID,},
{""},
{"__attribute", ATTRIBUTE, NORID},
{""},
{"__attribute__", ATTRIBUTE, NORID},
{"this", THIS, NORID,},
{"raise", RAISE, NORID /* Extension */,},
{"class", AGGR, RID_CLASS,},
{"delete", DELETE, NORID,},
{"typeof", TYPEOF, NORID,},
{"typedef", SCSPEC, RID_TYPEDEF,},
{"for", FOR, NORID,},
{"raises", RAISES, NORID /* Extension */,},
{"__const", TYPE_QUAL, RID_CONST},
{"double", TYPESPEC, RID_DOUBLE,},
{"__typeof__", TYPEOF, NORID},
{""},
{"switch", SWITCH, NORID,},
{"auto", SCSPEC, RID_AUTO,},
{"do", DO, NORID,},
{"friend", SCSPEC, RID_FRIEND,},
{""},
{"reraise", RERAISE, NORID /* Extension */,},
{""},
{"volatile", TYPE_QUAL, RID_VOLATILE,},
{"__typeof", TYPEOF, NORID},
{"continue", CONTINUE, NORID,},
{"float", TYPESPEC, RID_FLOAT,},
{"const", TYPE_QUAL, RID_CONST,},
{"static", SCSPEC, RID_STATIC,},
{"virtual", SCSPEC, RID_VIRTUAL,},
{"__asm", ASM, NORID},
{"short", TYPESPEC, RID_SHORT,},
{"signed", TYPESPEC, RID_SIGNED,},
{"try", TRY, NORID /* Extension */,},
{""}, {""}, {""},
{"__signed__", TYPESPEC, RID_SIGNED},
{"catch", CATCH, NORID,},
{"public", PUBLIC, NORID,},
{"struct", AGGR, RID_RECORD,},
{"if", IF, NORID,},
{"asm", ASM, NORID,},
{"union", AGGR, RID_UNION,},
{""},
{"private", PRIVATE, NORID,},
{""}, {""}, {""},
{"operator", OPERATOR, NORID,},
{""}, {""}, {""},
{"default", DEFAULT, NORID,},
{"dynamic", DYNAMIC, NORID,},
{"overload", OVERLOAD, NORID,},
{"int", TYPESPEC, RID_INT,},
{"char", TYPESPEC, RID_CHAR,},
{""}, {""},
{"return", RETURN, NORID,},
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
{""}, {""},
{"__signed", TYPESPEC, RID_SIGNED},
{""},
{"void", TYPESPEC, RID_VOID,},
{""}, {""}, {""},
{"protected", PROTECTED, NORID,},
{""},
{"enum", ENUM, NORID,},
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
{""}, {""}, {""}, {""}, {""}, {""},
{"inline", SCSPEC, RID_INLINE,},
{"register", SCSPEC, RID_REGISTER,},
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
{""}, {""}, {""}, {""},
{"unsigned", TYPESPEC, RID_UNSIGNED,}
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
register int key = hash (str, len);
if (key <= MAX_HASH_VALUE && key >= 0)
{
register const char *s = wordlist[key].name;
if (*str == *s && !strcmp (str + 1, s + 1))
return &wordlist[key];
}
}
return 0;
}

162
tests/test-4.exp Normal file
View File

@@ -0,0 +1,162 @@
/* C code produced by gperf version 2.7 */
/* Command-line: ../src/gperf -D -p -t */
/* Command-line: gperf -p -j1 -i 1 -g -o -t -N is_reserved_word -k1,3,$ c-parse.gperf */
struct resword { char *name; short token; enum rid rid; };
#define TOTAL_KEYWORDS 51
#define MIN_WORD_LENGTH 2
#define MAX_WORD_LENGTH 13
#define MIN_HASH_VALUE 4
#define MAX_HASH_VALUE 82
/* maximum key range = 79, duplicates = 2 */
#ifdef __GNUC__
__inline
#endif
static unsigned int
hash (str, len)
register const char *str;
register unsigned int len;
{
static unsigned char asso_values[] =
{
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 0, 83, 40, 20, 50,
25, 10, 30, 0, 0, 50, 83, 0, 15, 0,
35, 0, 83, 83, 20, 0, 10, 40, 5, 15,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
83, 83, 83, 83, 83, 83
};
return len + asso_values[(unsigned char)str[len - 1]] + asso_values[(unsigned char)str[0]];
}
#ifdef __GNUC__
__inline
#endif
struct resword *
in_word_set (str, len)
register const char *str;
register unsigned int len;
{
static struct resword wordlist[] =
{
{"goto", GOTO, NORID},
{"__asm", ASM, NORID},
{"switch", SWITCH, NORID},
{"__asm__", ASM, NORID},
{"__const__", TYPE_QUAL, RID_CONST},
{"__inline__", SCSPEC, RID_INLINE},
{"__typeof__", TYPEOF, NORID},
{"__signed__", TYPESPEC, RID_SIGNED},
{"__alignof__", ALIGNOF, NORID},
{"__volatile__", TYPE_QUAL, RID_VOLATILE},
{"__attribute__", ATTRIBUTE, NORID},
{"enum", ENUM, NORID},
{"short", TYPESPEC, RID_SHORT},
{"struct", STRUCT, NORID},
{"__const", TYPE_QUAL, RID_CONST},
{"__inline", SCSPEC, RID_INLINE},
{"long", TYPESPEC, RID_LONG},
{"__volatile", TYPE_QUAL, RID_VOLATILE},
{"__attribute", ATTRIBUTE, NORID},
{"volatile", TYPE_QUAL, RID_VOLATILE},
{"else", ELSE, NORID},
{"break", BREAK, NORID},
{"do", DO, NORID},
{"while", WHILE, NORID},
{"signed", TYPESPEC, RID_SIGNED},
{"__signed", TYPESPEC, RID_SIGNED},
{"void", TYPESPEC, RID_VOID},
{"sizeof", SIZEOF, NORID},
{"__typeof", TYPEOF, NORID},
{"__alignof", ALIGNOF, NORID},
{"double", TYPESPEC, RID_DOUBLE},
{"default", DEFAULT, NORID},
{"asm", ASM, NORID},
{"auto", SCSPEC, RID_AUTO},
{"float", TYPESPEC, RID_FLOAT},
{"typeof", TYPEOF, NORID},
{"typedef", SCSPEC, RID_TYPEDEF},
{"register", SCSPEC, RID_REGISTER},
{"extern", SCSPEC, RID_EXTERN},
{"for", FOR, NORID},
{"static", SCSPEC, RID_STATIC},
{"return", RETURN, NORID},
{"int", TYPESPEC, RID_INT},
{"case", CASE, NORID},
{"const", TYPE_QUAL, RID_CONST},
{"inline", SCSPEC, RID_INLINE},
{"continue", CONTINUE, NORID},
{"unsigned", TYPESPEC, RID_UNSIGNED},
{"char", TYPESPEC, RID_CHAR},
{"union", UNION, NORID},
{"if", IF, NORID}
};
static short lookup[] =
{
-1, -1, -1, -1, 0, 1, 2, 3, -1, 4,
-80, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, -1, 19, 20, 21, -1, 22, -46, -3,
23, 24, -1, 25, 26, -1, 27, -1, 28, 29,
-1, 30, 31, 32, 33, 34, 35, 36, 37, -1,
-1, 38, -1, 39, -1, -1, 40, -1, -1, -1,
-1, 41, -1, 42, 43, 44, 45, -1, 46, -1,
-1, -1, -1, 47, 48, -1, -1, -1, -1, -1,
49, -1, 50
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
register int key = hash (str, len);
if (key <= MAX_HASH_VALUE && key >= 0)
{
register int index = lookup[key];
if (index >= 0)
{
register const char *s = wordlist[index].name;
if (*str == *s && !strcmp (str + 1, s + 1))
return &wordlist[index];
}
else if (index < -TOTAL_KEYWORDS)
{
register int offset = - 1 - TOTAL_KEYWORDS - index;
register struct resword *wordptr = &wordlist[TOTAL_KEYWORDS + lookup[offset]];
register struct resword *wordendptr = wordptr + -lookup[offset + 1];
while (wordptr < wordendptr)
{
register const char *s = wordptr->name;
if (*str == *s && !strcmp (str + 1, s + 1))
return wordptr;
wordptr++;
}
}
}
}
return 0;
}

124
tests/test-5.exp Normal file
View File

@@ -0,0 +1,124 @@
/* C code produced by gperf version 2.7 */
/* Command-line: ../src/gperf -g -o -j1 -t -p -N is_reserved_word */
/* ISO Pascal 7185 reserved words.
*
* For GNU Pascal compiler (GPC) by jtv@hut.fi
*
* run this through the Doug Schmidt's gperf program
* with command
* gperf -g -o -j1 -t -p -N is_reserved_word
*
*/
struct resword { char *name; short token; short iclass;};
#define TOTAL_KEYWORDS 35
#define MIN_WORD_LENGTH 2
#define MAX_WORD_LENGTH 9
#define MIN_HASH_VALUE 2
#define MAX_HASH_VALUE 43
/* maximum key range = 42, duplicates = 0 */
#ifdef __GNUC__
__inline
#endif
static unsigned int
hash (str, len)
register const char *str;
register unsigned int len;
{
static unsigned char asso_values[] =
{
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 18, 29, 14, 6, 7,
10, 20, 44, 28, 44, 44, 28, 19, 22, 15,
0, 44, 9, 23, 0, 23, 26, 2, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
0, 0, 13, 44, 30, 44, 44, 44, 0, 25,
1, 0, 44, 44, 0, 44, 1, 44, 25, 44,
44, 0, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 44
};
return len + asso_values[(unsigned char)str[len - 1]] + asso_values[(unsigned char)str[0]];
}
#ifdef __GNUC__
__inline
#endif
struct resword *
is_reserved_word (str, len)
register const char *str;
register unsigned int len;
{
static struct resword wordlist[] =
{
{""}, {""},
{"To", TO, PASCAL_ISO},
{""},
{"Type", TYPE, PASCAL_ISO},
{"Then", THEN, PASCAL_ISO},
{"Packed", PACKED, PASCAL_ISO},
{"While", WHILE, PASCAL_ISO},
{"Do", DO, PASCAL_ISO},
{"Procedure", PROCEDURE, PASCAL_ISO},
{"End", END, PASCAL_ISO},
{"Else", ELSE, PASCAL_ISO},
{"Downto", DOWNTO, PASCAL_ISO},
{"For", FOR, PASCAL_ISO},
{"File", FILE_, PASCAL_ISO},
{"Record", RECORD, PASCAL_ISO},
{"Repeat", REPEAT, PASCAL_ISO},
{"Or", OR, PASCAL_ISO},
{"Case", CASE, PASCAL_ISO},
{"Function", FUNCTION, PASCAL_ISO},
{"Const", CONST, PASCAL_ISO},
{"And", AND, PASCAL_ISO},
{"Mod", MOD, PASCAL_ISO},
{"Array", ARRAY, PASCAL_ISO},
{"Goto", GOTO, PASCAL_ISO},
{"Nil", NIL, PASCAL_ISO},
{"Not", NOT, PASCAL_ISO},
{"Set", SET, PASCAL_ISO},
{"Until", UNTIL, PASCAL_ISO},
{"Var", VAR, PASCAL_ISO},
{"Of", OF, PASCAL_ISO},
{"In", IN, PASCAL_ISO},
{"Program",PROGRAM,PASCAL_ISO},
{"Label", LABEL, PASCAL_ISO},
{"Div", DIV, PASCAL_ISO},
{"Begin", BEGIN_, PASCAL_ISO},
{"With", WITH, PASCAL_ISO},
{""}, {""}, {""}, {""}, {""}, {""},
{"If", IF, PASCAL_ISO}
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
register int key = hash (str, len);
if (key <= MAX_HASH_VALUE && key >= 0)
{
register const char *s = wordlist[key].name;
if (*str == *s && !strcmp (str + 1, s + 1))
return &wordlist[key];
}
}
return 0;
}

119
tests/test-6.exp Normal file
View File

@@ -0,0 +1,119 @@
GNU `gperf' generates perfect hash functions.
Usage: ../src/gperf [OPTION]... [INPUT-FILE]
If a long option shows an argument as mandatory, then it is mandatory
for the equivalent short option also.
Input file interpretation:
-e, --delimiters=DELIMITER-LIST
Allow user to provide a string containing delimiters
used to separate keywords from their attributes.
Default is ",\n".
-t, --struct-type Allows the user to include a structured type
declaration for generated code. Any text before %%
is considered part of the type declaration. Key
words and additional fields may follow this, one
group of fields per line.
Language for the output code:
-L, --language=LANGUAGE-NAME
Generates code in the specified language. Languages
handled are currently C++, ANSI-C, C, and KR-C. The
default is C.
Details in the output code:
-K, --slot-name=NAME Select name of the keyword component in the keyword
structure.
-H, --hash-fn-name=NAME
Specify name of generated hash function. Default is
`hash'.
-N, --lookup-fn-name=NAME
Specify name of generated lookup function. Default
name is `in_word_set'.
-Z, --class-name=NAME Specify name of generated C++ class. Default name is
`Perfect_Hash'.
-7, --seven-bit Assume 7-bit characters.
-c, --compare-strncmp Generate comparison code using strncmp rather than
strcmp.
-C, --readonly-tables Make the contents of generated lookup tables
constant, i.e., readonly.
-E, --enum Define constant values using an enum local to the
lookup function rather than with defines.
-I, --includes Include the necessary system include file <string.h>
at the beginning of the code.
-G, --global Generate the static table of keywords as a static
global variable, rather than hiding it inside of the
lookup function (which is the default behavior).
-W, --word-array-name=NAME
Specify name of word list array. Default name is
`wordlist'.
-S, --switch=COUNT Causes the generated C code to use a switch
statement scheme, rather than an array lookup table.
This can lead to a reduction in both time and space
requirements for some keyfiles. The COUNT argument
determines how many switch statements are generated.
A value of 1 generates 1 switch containing all the
elements, a value of 2 generates 2 tables with 1/2
the elements in each table, etc. If COUNT is very
large, say 1000000, the generated C code does a
binary search.
-T, --omit-struct-type
Prevents the transfer of the type declaration to the
output file. Use this option if the type is already
defined elsewhere.
Algorithm employed by gperf:
-k, --key-positions=KEYS
Select the key positions used in the hash function.
The allowable choices range between 1-126, inclusive.
The positions are separated by commas, ranges may be
used, and key positions may occur in any order.
Also, the meta-character '*' causes the generated
hash function to consider ALL key positions, and $
indicates the ``final character'' of a key, e.g.,
$,1,2,4,6-10.
-l, --compare-strlen Compare key lengths before trying a string
comparison. This helps cut down on the number of
string comparisons made during the lookup.
-D, --duplicates Handle keywords that hash to duplicate values. This
is useful for certain highly redundant keyword sets.
-f, --fast=ITERATIONS Generate the gen-perf.hash function ``fast''. This
decreases gperf's running time at the cost of
minimizing generated table size. The numeric
argument represents the number of times to iterate
when resolving a collision. `0' means ``iterate by
the number of keywords''.
-i, --initial-asso=N Provide an initial value for the associate values
array. Default is 0. Setting this value larger helps
inflate the size of the final table.
-j, --jump=JUMP-VALUE Affects the ``jump value'', i.e., how far to advance
the associated character value upon collisions. Must
be an odd number, default is 5.
-n, --no-strlen Do not include the length of the keyword when
computing the hash function.
-o, --occurrence-sort Reorders input keys by frequency of occurrence of
the key sets. This should decrease the search time
dramatically.
-r, --random Utilizes randomness to initialize the associated
values table.
-s, --size-multiple=N Affects the size of the generated hash table. The
numeric argument N indicates ``how many times larger
or smaller'' the associated value range should be,
in relationship to the number of keys, e.g. a value
of 3 means ``allow the maximum associated value to
be about 3 times larger than the number of input
keys.'' Conversely, a value of -3 means ``make the
maximum associated value about 3 times smaller than
the number of input keys. A larger table should
decrease the time required for an unsuccessful
search, at the expense of extra table space. Default
value is 1.
Informative output:
-h, --help Print this message.
-v, --version Print the gperf version number.
-d, --debug Enables the debugging option (produces verbose
output to the standard error).
Report bugs to <bug-gnu-utils@gnu.org>.

32
tests/test-7.exp Normal file
View File

@@ -0,0 +1,32 @@
in word set if
in word set do
NOT in word set int
in word set for
in word set case
NOT in word set char
NOT in word set auto
in word set goto
in word set else
NOT in word set long
NOT in word set void
NOT in word set enum
NOT in word set float
NOT in word set short
NOT in word set union
NOT in word set break
in word set while
NOT in word set const
NOT in word set double
NOT in word set static
NOT in word set extern
NOT in word set struct
in word set return
NOT in word set sizeof
NOT in word set switch
NOT in word set signed
NOT in word set typedef
NOT in word set default
NOT in word set unsigned
NOT in word set continue
NOT in word set register
NOT in word set volatile

26
tests/test.c Normal file
View File

@@ -0,0 +1,26 @@
/*
Tests the generated perfect hash function.
The -v option prints diagnostics as to whether a word is in
the set or not. Without -v the program is useful for timing.
*/
#include <stdio.h>
#define MAX_LEN 80
int
main (argc, argv)
int argc;
char *argv[];
{
int verbose = argc > 1 ? 1 : 0;
char buf[MAX_LEN];
while (gets (buf))
if (in_word_set (buf, strlen (buf)) && verbose)
printf ("in word set %s\n", buf);
else if (verbose)
printf ("NOT in word set %s\n", buf);
return 0;
}

54
tests/validate Executable file
View File

@@ -0,0 +1,54 @@
#! /bin/sh
# Validate gperf's operation on a given input file.
# Usage: validate languages input.gperf [more gperf options]
# Uses the environment variables GPERF, CC, CFLAGS, CXX, CXXFLAGS.
# Supposes gcc and g++.
# Exit on error
set -e
verbose () {
echo "$@"
"$@"
}
languages=$1
shift
for lang in `echo $languages | sed -e 's/,/ /g'`; do
case "$lang" in
KR-C )
echo "${GPERF} -I -L KR-C $@ > valitest.c"
${GPERF} -I -L KR-C "$@" > valitest.c
grep -n ' const ' valitest.c /dev/null && exit 1
verbose ${CC} ${CFLAGS} -traditional valitest.c -o valitest
./valitest
verbose ${CC} ${CFLAGS} -ansi -pedantic valitest.c -o valitest
./valitest
;;
C )
echo "${GPERF} -I -L C $@ > valitest.c"
${GPERF} -I -L C "$@" > valitest.c
verbose ${CC} ${CFLAGS} -traditional -Dconst= valitest.c -o valitest
./valitest
verbose ${CC} ${CFLAGS} -ansi -pedantic -pedantic-errors valitest.c -o valitest
./valitest
;;
ANSI-C )
echo "${GPERF} -I -L ANSI-C $@ > valitest.c"
${GPERF} -I -L ANSI-C "$@" > valitest.c
verbose ${CC} ${CFLAGS} -ansi -pedantic -pedantic-errors valitest.c -o valitest
./valitest
verbose ${CXX} ${CXXFLAGS} -ansi -pedantic -pedantic-errors valitest.c -o valitest
./valitest
;;
"C++" )
echo "${GPERF} -I -L C++ $@ > valitest.c"
${GPERF} -I -L C++ "$@" > valitest.c
verbose ${CXX} ${CXXFLAGS} -ansi -pedantic -pedantic-errors -DCPLUSPLUS_TEST valitest.c -o valitest
./valitest
;;
esac
done
exit 0