6d91645ce3b075e5ab9f761bcef710a0cbb0ac12
[pspp-builds.git] / src / language / lexer / 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., 51 Franklin Street, Fifth Floor, Boston, MA
18    02110-1301, USA. */
19
20 #if !lexer_h
21 #define lexer_h 1
22
23 #include <ctype.h>
24 #include <stdbool.h>
25 #include <stddef.h>
26 #include <data/identifier.h>
27 #include <data/variable.h>
28 #include <libpspp/getl.h>
29
30 struct lexer;
31
32 /* Initialization. */
33 struct lexer * lex_create (struct source_stream *);
34 void lex_destroy (struct lexer *);
35
36 struct source_stream * lex_get_source_stream (const struct lexer *);
37
38
39 /* Common functions. */
40 void lex_get (struct lexer *);
41 void lex_error (struct lexer *, const char *, ...);
42 void lex_sbc_only_once (const char *);
43 void lex_sbc_missing (struct lexer *, const char *);
44 int lex_end_of_command (struct lexer *);
45
46 /* Token testing functions. */
47 bool lex_is_number (struct lexer *);
48 double lex_number (struct lexer *);
49 bool lex_is_integer (struct lexer *);
50 long lex_integer (struct lexer *);
51
52 /* Token matching functions. */
53 bool lex_match (struct lexer *, int);
54 bool lex_match_id (struct lexer *, const char *);
55 bool lex_match_int (struct lexer *, int);
56
57 /* Forcible matching functions. */
58 bool lex_force_match (struct lexer *, int);
59 bool lex_force_match_id (struct lexer *, const char *);
60 bool lex_force_int (struct lexer *);
61 bool lex_force_num (struct lexer *);
62 bool lex_force_id (struct lexer *);
63 bool lex_force_string (struct lexer *);
64         
65 /* Weird token functions. */
66 int lex_look_ahead (struct lexer *);
67 void lex_put_back (struct lexer *, int);
68 void lex_put_back_id (struct lexer *, const char *tokid);
69
70 /* Weird line processing functions. */
71 const char *lex_entire_line (struct lexer *);
72 const struct string *lex_entire_line_ds (struct lexer *);
73 const char *lex_rest_of_line (struct lexer *, int *end_dot);
74 void lex_preprocess_line (struct string *, enum getl_syntax,
75                           bool *line_starts_command,
76                           bool *line_ends_command);
77 void lex_discard_line (struct lexer *);
78 void lex_discard_rest_of_command (struct lexer *);
79
80 /* Weird line reading functions. */
81 bool lex_get_line (struct lexer *);
82 bool lex_get_line_raw (struct lexer *, enum getl_syntax *);
83
84 /* Token names. */
85 const char *lex_token_name (int);
86 char *lex_token_representation (struct lexer *);
87
88 /* Token accessors */
89 int lex_token (const struct lexer *);
90 double lex_tokval (const struct lexer *);
91 const char *lex_tokid (const struct lexer *);
92 const struct string *lex_tokstr (const struct lexer *);
93
94 /* Really weird functions. */
95 void lex_negative_to_dash (struct lexer *);
96 void lex_skip_comment (struct lexer *);
97
98 #endif /* !lexer_h */