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