checkin of 0.3.0
[pspp-builds.git] / src / lexer.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18    02111-1307, USA. */
19
20 #if !lexer_h
21 #define lexer_h 1
22
23 /* Returns nonzero if character CH may be the first character in an
24    identifier. */
25 #define CHAR_IS_ID1(CH)                         \
26         (isalpha ((unsigned char) (CH))         \
27          || (CH) == '@'                         \
28          || (CH) == '#'                         \
29          || (CH) == '$')
30
31 /* Returns nonzero if character CH may be a character in an
32    identifier other than the first. */
33 #define CHAR_IS_IDN(CH)                         \
34         (CHAR_IS_ID1 (CH)                       \
35          || isdigit ((unsigned char) (CH))      \
36          || (CH) == '.'                         \
37          || (CH) == '_')
38
39 /* Token types. */
40 /* The order of the enumerals below is important.  Do not change it. */
41 enum
42   {
43     T_ID = 256, /* Identifier. */
44     T_NUM,      /* Number. */
45     T_STRING,   /* Quoted string. */
46     T_STOP,     /* End of input. */
47
48     T_AND,      /* AND */
49     T_OR,       /* OR */
50     T_NOT,      /* NOT */
51
52     T_EQ,       /* EQ */
53     T_GE,       /* GE or >= */
54     T_GT,       /* GT or > */
55     T_LE,       /* LE or <= */
56     T_LT,       /* LT or < */
57     T_NE,       /* NE or ~= */
58
59     T_ALL,      /* ALL */
60     T_BY,       /* BY */
61     T_TO,       /* TO */
62     T_WITH,     /* WITH */
63
64     T_EXP,      /* ** */
65
66     T_FIRST_KEYWORD = T_AND,
67     T_LAST_KEYWORD = T_WITH,
68     T_N_KEYWORDS = T_LAST_KEYWORD - T_FIRST_KEYWORD + 1,
69   };
70
71
72 extern int token;
73 extern double tokval;
74 extern char tokid[9];
75 extern struct string tokstr;
76
77 #include <stddef.h>
78
79 /* Initialization. */
80 void lex_init (void);
81
82 /* Common functions. */
83 void lex_get (void);
84 void lex_error (const char *, ...);
85 int lex_end_of_command (void);
86
87 /* Token testing functions. */
88 int lex_integer_p (void);
89 long lex_integer (void);
90
91 /* Token matching functions. */
92 int lex_match (int);
93 int lex_match_id (const char *);
94 int lex_match_int (int);
95
96 /* Forcible matching functions. */
97 int lex_force_match (int);
98 int lex_force_match_id (const char *);
99 int lex_force_int (void);
100 int lex_force_num (void);
101 int lex_force_id (void);
102 int lex_force_string (void);
103
104 /* Comparing identifiers. */
105 int lex_id_match_len (const char *keyword_string, size_t keyword_len,
106                       const char *token_string, size_t token_len);
107 int lex_id_match (const char *keyword_string, const char *token_string);
108         
109 /* Weird token functions. */
110 int lex_look_ahead (void);
111 void lex_put_back (int);
112 void lex_put_forward (int);
113
114 /* Weird line processing functions. */
115 char *lex_entire_line (void);
116 char *lex_rest_of_line (int *had_dot);
117 void lex_discard_line (void);
118 void lex_set_prog (char *p);
119
120 /* Weird line reading functions. */
121 int lex_get_line (void);
122 void lex_preprocess_line (void);
123
124 /* Token names. */
125 const char *lex_token_name (int);
126 char *lex_token_representation (void);
127
128 /* Really weird functions. */
129 void lex_negative_to_dash (void);
130 void lex_reset_eof (void);
131 void lex_skip_comment (void);
132
133 #endif /* !lexer_h */