This machine mirrors various open-source projects.
20 Gbit/s uplink.
If there are any issues or you want another project mirrored, please contact
mirror-service -=AT=- netcologne DOT de !
00001 /* $Id: lispreader.hxx,v 1.1 2003/01/08 23:14:59 grumbel Exp $ */ 00002 /* 00003 * lispreader.h 00004 * 00005 * Copyright (C) 1998-2000 Mark Probst 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Library General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Library General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Library General Public 00018 * License along with this library; if not, write to the 00019 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00020 * Boston, MA 02111-1307, USA. 00021 */ 00022 00023 #ifndef __LISPREADER_H__ 00024 #define __LISPREADER_H__ 00025 00026 #include <stdio.h> 00027 00028 #define LISP_STREAM_FILE 1 00029 #define LISP_STREAM_STRING 2 00030 #define LISP_STREAM_ANY 3 00031 00032 #define LISP_TYPE_INTERNAL -3 00033 #define LISP_TYPE_PARSE_ERROR -2 00034 #define LISP_TYPE_EOF -1 00035 #define LISP_TYPE_NIL 0 00036 #define LISP_TYPE_SYMBOL 1 00037 #define LISP_TYPE_INTEGER 2 00038 #define LISP_TYPE_STRING 3 00039 #define LISP_TYPE_REAL 4 00040 #define LISP_TYPE_CONS 5 00041 #define LISP_TYPE_PATTERN_CONS 6 00042 #define LISP_TYPE_BOOLEAN 7 00043 #define LISP_TYPE_PATTERN_VAR 8 00044 00045 #define LISP_PATTERN_ANY 1 00046 #define LISP_PATTERN_SYMBOL 2 00047 #define LISP_PATTERN_STRING 3 00048 #define LISP_PATTERN_INTEGER 4 00049 #define LISP_PATTERN_REAL 5 00050 #define LISP_PATTERN_BOOLEAN 6 00051 #define LISP_PATTERN_LIST 7 00052 #define LISP_PATTERN_OR 8 00053 00054 typedef struct 00055 { 00056 int type; 00057 00058 union 00059 { 00060 FILE *file; 00061 struct 00062 { 00063 char *buf; 00064 int pos; 00065 } string; 00066 struct 00067 { 00068 void *data; 00069 int (*next_char) (void *data); 00070 void (*unget_char) (char c, void *data); 00071 } any; 00072 } v; 00073 } lisp_stream_t; 00074 00075 typedef struct _lisp_object_t lisp_object_t; 00076 struct _lisp_object_t 00077 { 00078 int type; 00079 00080 union 00081 { 00082 struct 00083 { 00084 struct _lisp_object_t *car; 00085 struct _lisp_object_t *cdr; 00086 } cons; 00087 00088 char *string; 00089 int integer; 00090 float real; 00091 00092 struct 00093 { 00094 int type; 00095 int index; 00096 struct _lisp_object_t *sub; 00097 } pattern; 00098 } v; 00099 }; 00100 00101 lisp_stream_t* lisp_stream_init_file (lisp_stream_t *stream, FILE *file); 00102 lisp_stream_t* lisp_stream_init_string (lisp_stream_t *stream, char *buf); 00103 lisp_stream_t* lisp_stream_init_any (lisp_stream_t *stream, void *data, 00104 int (*next_char) (void *data), 00105 void (*unget_char) (char c, void *data)); 00106 00107 lisp_object_t* lisp_read (lisp_stream_t *in); 00108 void lisp_free (lisp_object_t *obj); 00109 00110 lisp_object_t* lisp_read_from_string (const char *buf); 00111 00112 int lisp_compile_pattern (lisp_object_t **obj, int *num_subs); 00113 int lisp_match_pattern (lisp_object_t *pattern, lisp_object_t *obj, lisp_object_t **vars, int num_subs); 00114 int lisp_match_string (const char *pattern_string, lisp_object_t *obj, lisp_object_t **vars); 00115 00116 int lisp_type (lisp_object_t *obj); 00117 int lisp_integer (lisp_object_t *obj); 00118 float lisp_real (lisp_object_t *obj); 00119 char* lisp_symbol (lisp_object_t *obj); 00120 char* lisp_string (lisp_object_t *obj); 00121 int lisp_boolean (lisp_object_t *obj); 00122 lisp_object_t* lisp_car (lisp_object_t *obj); 00123 lisp_object_t* lisp_cdr (lisp_object_t *obj); 00124 00125 lisp_object_t* lisp_cxr (lisp_object_t *obj, const char *x); 00126 00127 lisp_object_t* lisp_make_integer (int value); 00128 lisp_object_t* lisp_make_real (float value); 00129 lisp_object_t* lisp_make_symbol (const char *value); 00130 lisp_object_t* lisp_make_string (const char *value); 00131 lisp_object_t* lisp_make_cons (lisp_object_t *car, lisp_object_t *cdr); 00132 lisp_object_t* lisp_make_boolean (int value); 00133 00134 int lisp_list_length (lisp_object_t *obj); 00135 lisp_object_t* lisp_list_nth_cdr (lisp_object_t *obj, int index); 00136 lisp_object_t* lisp_list_nth (lisp_object_t *obj, int index); 00137 00138 void lisp_dump (lisp_object_t *obj, FILE *out); 00139 00140 #define lisp_nil() ((lisp_object_t*)0) 00141 00142 #define lisp_nil_p(obj) (obj == 0) 00143 #define lisp_integer_p(obj) (lisp_type((obj)) == LISP_TYPE_INTEGER) 00144 #define lisp_real_p(obj) (lisp_type((obj)) == LISP_TYPE_REAL) 00145 #define lisp_symbol_p(obj) (lisp_type((obj)) == LISP_TYPE_SYMBOL) 00146 #define lisp_string_p(obj) (lisp_type((obj)) == LISP_TYPE_STRING) 00147 #define lisp_cons_p(obj) (lisp_type((obj)) == LISP_TYPE_CONS) 00148 #define lisp_boolean_p(obj) (lisp_type((obj)) == LISP_TYPE_BOOLEAN) 00149 00150 #endif