95553f10c868280e3ae60919ad18353d12b30c02
[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 #include <ctype.h>
24 #include "bool.h"
25
26 /* Returns nonzero if character CH may be the first character in an
27    identifier. */
28 #define CHAR_IS_ID1(CH)                         \
29         (isalpha ((unsigned char) (CH))         \
30          || (CH) == '@'                         \
31          || (CH) == '#'                         \
32          || (CH) == '$')
33
34 /* Returns nonzero if character CH may be a character in an
35    identifier other than the first. */
36 #define CHAR_IS_IDN(CH)                         \
37         (CHAR_IS_ID1 (CH)                       \
38          || isdigit ((unsigned char) (CH))      \
39          || (CH) == '.'                         \
40          || (CH) == '_')
41
42 /* Token types. */
43 /* The order of the enumerals below is important.  Do not change it. */
44 enum
45   {
46     T_ID = 256, /* Identifier. */
47     T_POS_NUM,  /* Positive number. */
48     T_NEG_NUM,  /* Negative number. */
49     T_STRING,   /* Quoted string. */
50     T_STOP,     /* End of input. */
51
52     T_AND,      /* AND */
53     T_OR,       /* OR */
54     T_NOT,      /* NOT */
55
56     T_EQ,       /* EQ */
57     T_GE,       /* GE or >= */
58     T_GT,       /* GT or > */
59     T_LE,       /* LE or <= */
60     T_LT,       /* LT or < */
61     T_NE,       /* NE or ~= */
62
63     T_ALL,      /* ALL */
64     T_BY,       /* BY */
65     T_TO,       /* TO */
66     T_WITH,     /* WITH */
67
68     T_EXP,      /* ** */
69
70     T_FIRST_KEYWORD = T_AND,
71     T_LAST_KEYWORD = T_WITH,
72     T_N_KEYWORDS = T_LAST_KEYWORD - T_FIRST_KEYWORD + 1
73   };
74
75
76 extern int token;
77 extern double tokval;
78 extern char tokid[9];
79 extern struct string tokstr;
80
81 #include <stddef.h>
82
83 /* Initialization. */
84 void lex_init (void);
85 void lex_done (void);
86
87 /* Common functions. */
88 void lex_get (void);
89 void lex_error (const char *, ...);
90 int lex_end_of_command (void);
91
92 /* Token testing functions. */
93 bool lex_is_number (void);
94 double lex_number (void);
95 bool lex_is_integer (void);
96 long lex_integer (void);
97
98 /* Token matching functions. */
99 int lex_match (int);
100 int lex_match_id (const char *);
101 int lex_match_int (int);
102
103 /* Forcible matching functions. */
104 int lex_force_match (int);
105 int lex_force_match_id (const char *);
106 int lex_force_int (void);
107 int lex_force_num (void);
108 int lex_force_id (void);
109 int lex_force_string (void);
110
111 /* Comparing identifiers. */
112 int lex_id_match_len (const char *keyword_string, size_t keyword_len,
113                       const char *token_string, size_t token_len);
114 int lex_id_match (const char *keyword_string, const char *token_string);
115 int lex_id_to_token (const char *id, size_t len);
116         
117 /* Weird token functions. */
118 int lex_look_ahead (void);
119 void lex_put_back (int);
120 void lex_put_back_id (const char *tokid);
121
122 /* Weird line processing functions. */
123 const char *lex_entire_line (void);
124 const char *lex_rest_of_line (int *end_dot);
125 void lex_discard_line (void);
126 void lex_set_prog (char *p);
127
128 /* Weird line reading functions. */
129 int lex_get_line (void);
130 void lex_preprocess_line (void);
131
132 /* Token names. */
133 const char *lex_token_name (int);
134 char *lex_token_representation (void);
135
136 /* Really weird functions. */
137 void lex_negative_to_dash (void);
138 void lex_reset_eof (void);
139 void lex_skip_comment (void);
140
141 #endif /* !lexer_h */