Pristine Ack-5.5
[Ack-5.5.git] / util / cmisc / tabgen.1
1 .TH TABGEN 1 "$Revision: 1.4 $"
2 .ad
3 .SH NAME
4 tabgen \- table generator for C-programs
5 .SH SYNOPSYS
6 .B tabgen
7 \fIarguments\fP
8 .SH DESCRIPTION
9 .I Tabgen
10 is a handy tool for generating tables for C-programs from a compact
11 description. The current version is only suitable for generating character
12 tables. The output is produced on standard output.
13 It works by maintaining an internal table of values, printing this table
14 when this is requested.
15 .PP
16 Each argument given to
17 .I tabgen
18 is either a command or a description. Descriptions are discussed first.
19 .PP
20 A description consists of a value (a string), directly followed by a semicolon,
21 directly followed by a list of indices for which the table to be generated
22 has this value. This list of indices must be in a certain \fBinputformat\fP,
23 characterized by a charactet.
24 Currently, there is only one inputformat, "c". In this format, the indices
25 are characters. There are two special characters: '\e' and '-'. The '\e'
26 behaves like in a C-string, and the '-' describes a range, unless
27 it starts the list of indices.
28 .PP
29 Some examples of descriptions:
30 .nf
31         STIDF:a-zA-Z_
32         STSKIP:\er \et\e013\ef
33 .fi
34 .PP
35 These descriptions have the effect that the internal table values for
36 'a' through 'z', 'A' through 'Z', and '_' are set to STIDF, and that the
37 internal table values for carriage-return, space, tab, vertical-tab, and
38 form-feed are set to STSKIP.
39 .PP
40 A command is introduced by a special character. On the command line,
41 a command is introduced by a '-'. The following commands are
42 recognized:
43 .IP I\fIchar\fP
44 switch to a different input format. This command is only there for future
45 extensions.
46 .IP f\fIfile\fP
47 read input from the file \fIfile\fP. In a file, each line is an argument
48 to \fItabgen\fP. Each line is either a command or a description. In a file,
49 commands are introduced by a '%'.
50 .IP F\fIformat\fP
51 Values are printed in a printf format. The default value for this format
52 is \fB"%s,\en"\fP. This can be changed with this command.
53 .IP T\fItext\fP
54 Print \fItext\fP literally at this point.
55 .IP p
56 Print the table as it is built at this point.
57 .IP C
58 Clear the table. This sets all internal table values to 0.
59 .IP i\fIstr\fP
60 Initialize all internal table values to \fIstr\fP. if \fIstr\fP is not
61 given, this command is equivalent to the C command.
62 .IP S\fInum\fP
63 Set the table size to \fInum\fP entries. The default size is 128.
64 .SH "AN EXAMPLE"
65 .PP
66 The next example is a part of the \fItabgen\fP description of the
67 character tables used by the lexical analyser of the ACK Modula-2 compiler.
68 This description resides in a file called char.tab.
69 .I
70 Tabgen
71 is called as follows:
72 .nf
73         tabgen -fchar.tab > char.c
74 .fi
75 .PP
76 The description as given here generates 2 tables: one indicating a class
77 according to which token a character can be a start of, and one indicating
78 whether a character may occur in an identifier.
79 .nf
80
81 %       Comments are introduced with space or tab after the %
82 %S129
83 %F      %s,
84 %       CHARACTER CLASSES
85 %iSTGARB
86 STSKIP: \et\e013\e014\e015
87 STNL:\e012
88 STSIMP:-#&()*+,/;=[]^{|}~
89 STCOMP:.:<>
90 STIDF:a-zA-Z
91 STSTR:"'
92 STNUM:0-9
93 STEOI:\e200
94 %T#include "class.h"
95 %       class.h contains #defines for STSKIP, STNL, ...
96 %Tchar tkclass[] = {
97 %p
98 %T};
99 %       INIDF
100 %C
101 1:a-zA-Z0-9
102 %Tchar inidf[] = {
103 %F      %s,
104 %p
105 %T};
106 .fi
107 .SH BUGS
108 .PP
109 .I Tabgen
110 assumes that characters are 8 bits wide.