2dd7da06273cfb11e2d11ddf745158385c588108
[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 int lex_double_p (void);
91 double lex_double (void);
92
93 /* Token matching functions. */
94 int lex_match (int);
95 int lex_match_id (const char *);
96 int lex_match_int (int);
97
98 /* Forcible matching functions. */
99 int lex_force_match (int);
100 int lex_force_match_id (const char *);
101 int lex_force_int (void);
102 int lex_force_num (void);
103 int lex_force_id (void);
104 int lex_force_string (void);
105
106 /* Comparing identifiers. */
107 int lex_id_match_len (const char *keyword_string, size_t keyword_len,
108                       const char *token_string, size_t token_len);
109 int lex_id_match (const char *keyword_string, const char *token_string);
110         
111 /* Weird token functions. */
112 int lex_look_ahead (void);
113 void lex_put_back (int);
114 void lex_put_back_id (const char *tokid);
115
116 /* Weird line processing functions. */
117 char *lex_entire_line (void);
118 char *lex_rest_of_line (int *had_dot);
119 void lex_discard_line (void);
120 void lex_set_prog (char *p);
121
122 /* Weird line reading functions. */
123 int lex_get_line (void);
124 void lex_preprocess_line (void);
125
126 /* Token names. */
127 const char *lex_token_name (int);
128 char *lex_token_representation (void);
129
130 /* Really weird functions. */
131 void lex_negative_to_dash (void);
132 void lex_reset_eof (void);
133 void lex_skip_comment (void);
134
135 #endif /* !lexer_h */