From 37210199dd4cde2f67990e1682487efd045336fa Mon Sep 17 00:00:00 2001 From: nishi Date: Tue, 23 Apr 2024 03:09:16 +0000 Subject: [PATCH] parser git-svn-id: file:///raid/svn-main/nishi-serenade/trunk@10 0f02c867-ac3d-714e-8a88-971ba1f6efcf --- Serenade/Makefile | 2 +- Serenade/main.c | 11 ++++++++++ Serenade/parser.c | 31 +++++++++++++++++++++++++++ Serenade/parser.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++ Tool/configgen.c | 21 ++++++++++++++----- 5 files changed, 112 insertions(+), 6 deletions(-) create mode 100644 Serenade/parser.c create mode 100644 Serenade/parser.h diff --git a/Serenade/Makefile b/Serenade/Makefile index 345995b..a2412fc 100644 --- a/Serenade/Makefile +++ b/Serenade/Makefile @@ -1,6 +1,6 @@ # $Id$ -SERENADE_OBJS = main.o +SERENADE_OBJS = main.o parser.o .PHONY: all clean .SUFFIXES: .o .c diff --git a/Serenade/main.c b/Serenade/main.c index 8f96d61..e79e2be 100644 --- a/Serenade/main.c +++ b/Serenade/main.c @@ -29,6 +29,7 @@ /* --- END LICENSE --- */ #include "serenade.h" +#include "../config.h" #include #include @@ -41,6 +42,7 @@ int main(int argc, char** argv){ 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]); @@ -51,7 +53,16 @@ int main(int argc, char** argv){ 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 } diff --git a/Serenade/parser.c b/Serenade/parser.c new file mode 100644 index 0000000..f96c9ec --- /dev/null +++ b/Serenade/parser.c @@ -0,0 +1,31 @@ +/* $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" diff --git a/Serenade/parser.h b/Serenade/parser.h new file mode 100644 index 0000000..eb14ffb --- /dev/null +++ b/Serenade/parser.h @@ -0,0 +1,53 @@ +/* $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 diff --git a/Tool/configgen.c b/Tool/configgen.c index acf8546..2a6f6c6 100644 --- a/Tool/configgen.c +++ b/Tool/configgen.c @@ -32,11 +32,15 @@ #include #include -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?", @@ -45,7 +49,7 @@ const char* asks[] = { }; 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); } @@ -71,18 +75,25 @@ int main(int argc, char** argv){ 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); } -- 2.43.0