# $Id$
-SERENADE_OBJS = main.o
+SERENADE_OBJS = main.o parser.o
.PHONY: all clean
.SUFFIXES: .o .c
/* --- END LICENSE --- */
#include "serenade.h"
+#include "../config.h"
#include <string.h>
#include <stdbool.h>
if(argv[i][0] == '-'){
if(strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-V") == 0){
printf("Serenade LISP %s\n", SERENADE_VERSION);
+ printf("Support: %s\n", SUPPORT);
return 1;
}else{
fprintf(stderr, "%s: %s: invalid option\n", argv[0], argv[i]);
loaded = true;
}
}
+#ifdef HAS_REPL_SUPPORT
if(!loaded){
printf("Welcome to Serenade LISP %s\n", SERENADE_VERSION);
+ printf("Support: %s\n", SUPPORT);
}
+ return 0;
+#else
+ if(!loaded){
+ fprintf(stderr, "usage: %s [options] input\n", argv[0]);
+ return 1;
+ }
+#endif
}
--- /dev/null
+/* $Id$ */
+/* --- START LICENSE --- */
+/* -------------------------------------------------------------------------- */
+/* Serenade is a Lisp Dialect */
+/* -------------------------------------------------------------------------- */
+/* Copyright (c) 2024 Nishi. */
+/* Redistribution and use in source and binary forms, with or without modific */
+/* ation, are permitted provided that the following conditions are met: */
+/* 1. Redistributions of source code must retain the above copyright noti */
+/* ce, this list of conditions and the following disclaimer. */
+/* 2. Redistributions in binary form must reproduce the above copyright n */
+/* otice, this list of conditions and the following disclaimer in the documen */
+/* tation and/or other materials provided with the distribution. */
+/* 3. Neither the name of the copyright holder nor the names of its contr */
+/* ibutors may be used to endorse or promote products derived from this softw */
+/* are without specific prior written permission. */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS */
+/* " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, TH */
+/* E IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPO */
+/* SE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS */
+/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CON */
+/* SEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITU */
+/* TE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPT */
+/* ION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, S */
+/* TRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN AN */
+/* Y WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY */
+/* OF SUCH DAMAGE. */
+/* -------------------------------------------------------------------------- */
+/* --- END LICENSE --- */
+
+#include "parser.h"
--- /dev/null
+/* $Id$ */
+/* --- START LICENSE --- */
+/* -------------------------------------------------------------------------- */
+/* Serenade is a Lisp Dialect */
+/* -------------------------------------------------------------------------- */
+/* Copyright (c) 2024 Nishi. */
+/* Redistribution and use in source and binary forms, with or without modific */
+/* ation, are permitted provided that the following conditions are met: */
+/* 1. Redistributions of source code must retain the above copyright noti */
+/* ce, this list of conditions and the following disclaimer. */
+/* 2. Redistributions in binary form must reproduce the above copyright n */
+/* otice, this list of conditions and the following disclaimer in the documen */
+/* tation and/or other materials provided with the distribution. */
+/* 3. Neither the name of the copyright holder nor the names of its contr */
+/* ibutors may be used to endorse or promote products derived from this softw */
+/* are without specific prior written permission. */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS */
+/* " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, TH */
+/* E IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPO */
+/* SE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS */
+/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CON */
+/* SEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITU */
+/* TE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPT */
+/* ION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, S */
+/* TRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN AN */
+/* Y WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY */
+/* OF SUCH DAMAGE. */
+/* -------------------------------------------------------------------------- */
+/* --- END LICENSE --- */
+
+#ifndef __SERENADE_PARSER_H__
+#define __SERENADE_PARSER_H__
+
+enum types {
+ SN_TYPE_DOUBLE,
+ SN_TYPE_STRING,
+ SN_TYPE_TREE,
+ SN_TYPE_VOID
+};
+
+struct sn_generic {
+ int type;
+ double number;
+ char* string;
+ struct sn_tree* tree;
+};
+
+struct sn_tree {
+ struct sn_generic* type;
+ struct sn_generic** args;
+};
+
+#endif
#include <stdbool.h>
#include <ctype.h>
-const char* asks[] = {
+char choice[256];
+
+char* asks[] = {
+ "repl",
"y",
"HAS_REPL_SUPPORT",
"Do you want the REPL support?",
+ "ffi",
"n",
"HAS_FFI_SUPPORT",
"Do you want the FFI support?",
};
void show_dialog(int n){
- fprintf(stderr, "[default is %c] %s ", asks[n * 3][0], asks[n * 3 + 2]);
+ fprintf(stderr, "[default is %c] %s ", asks[n * 4 + 1][0], asks[n * 4 + 3]);
fflush(stderr);
}
oldc = c;
if(fread(&c, 1, 1, stdin) <= 0) break;
if(c == '\n'){
- char ch = asks[n * 3][0];
+ char ch = asks[n * 4 + 1][0];
if(nl){
ch = tolower(oldc);
}
- fprintf(out, "#%s %s\n", ch == 'y' ? "define" : "undef", asks[n * 3 + 1]);
+ choice[n] = ch;
+ fprintf(out, "#%s %s\n", ch == 'y' ? "define" : "undef", asks[n * 4 + 2]);
n++;
nl = false;
- if(asks[n * 3] == NULL) break;
+ if(asks[n * 4 + 1] == NULL) break;
show_dialog(n);
}else{
nl = true;
}
}
+ fprintf(out, "#define SUPPORT \"");
+ for(n = 0; asks[n * 4] != NULL; n++){
+ if(n > 0) fprintf(out, " ");
+ fprintf(out, "%c%s", choice[n] == 'y' ? '+' : '-', asks[n * 4]);
+ }
+ fprintf(out, "\"\n");
if(load) fclose(out);
}