From: nishi Date: Mon, 3 Jun 2024 12:50:54 +0000 (+0000) Subject: add grammar X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=dfb89bd45c19b629b1978916a4dda0cfdcf5d418;p=dataworks.git add grammar git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@137 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- diff --git a/Client/main.c b/Client/main.c index b330acd..17f5967 100644 --- a/Client/main.c +++ b/Client/main.c @@ -124,6 +124,7 @@ int main(int argc, char** argv) { } if(banner) { printf("DataWorks version %s %s %s\n", dataworks_get_version(), dataworks_get_compile_date(), dataworks_get_platform()); + printf("Using Yacc: %s\n", dataworks_get_yacc_version()); if(dataworks_get_endian() == 'L') { printf("This system is little-endian.\n"); } else { diff --git a/Grammar/Makefile b/Grammar/Makefile new file mode 100644 index 0000000..99a26b5 --- /dev/null +++ b/Grammar/Makefile @@ -0,0 +1,18 @@ +# $Id$ + +.SUFFIXES: .c .o +.PHONY: all clean + +all: dw.tab.o dw.yy.o + +.c.o: + $(CC) $(CFLAGS) -fPIC -c -o $@ $< + +dw.tab.c: dw.y + $(YACC) $(YFLAGS) -o $@ dw.y + +dw.yy.c: dw.l + $(LEX) $(LFLAGS) -o $@ dw.l + +clean: + rm -f *.o dw.tab.c dw.tab.h dw.yy.c diff --git a/Grammar/dw.l b/Grammar/dw.l new file mode 100644 index 0000000..8f369e2 --- /dev/null +++ b/Grammar/dw.l @@ -0,0 +1,57 @@ +/* $Id$ */ +/* --- START LICENSE --- */ +/* -------------------------------------------------------------------------- */ +/* Copyright (c) 2024 Crabware. */ +/* 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 "dw.tab.h" +#include "grammersym.h" +#include +extern YYSTYPE yylval; +%} + +%% + +["][^"]*["] { + yylval.string = strdup(yytext + 1); + yylval.string[strlen(yylval.string) - 1] = 0; + return (STRING); +} +['][^']*['] { + yylval.string = strdup(yytext + 1); + yylval.string[strlen(yylval.string) - 1] = 0; + return (STRING); +} +[a-zA-Z0-9_\-]+ { + yylval.ident = strdup(yytext); + return (IDENTIFIER); +} +[\(\),] { + return (yytext[0]); +} +[ \t\v]* { + return (SPACE); +} diff --git a/Grammar/dw.y b/Grammar/dw.y new file mode 100644 index 0000000..6bf4052 --- /dev/null +++ b/Grammar/dw.y @@ -0,0 +1,79 @@ +/* $Id$ */ +/* --- START LICENSE --- */ +/* -------------------------------------------------------------------------- */ +/* Copyright (c) 2024 Crabware. */ +/* 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 "grammersym.h" +#include +%} + +%token IDENTIFIER STRING SPACE +%start command + +%union { + char* string; + char* ident; +} + +%% + +argument + : STRING { + printf("%s\n", $1); + } + ; + +single_argument + : SPACE argument SPACE + | SPACE argument + | argument SPACE + | argument + ; + +arguments + : single_argument + | arguments ',' single_argument + ; + +command + : IDENTIFIER SPACE '(' arguments ')' { + printf("%s\n", $1); + } + | IDENTIFIER '(' arguments ')' { + printf("%s\n", $1); + } + ; + +%% + +#if defined(YYBISON) +const char* yaccver = "GNU Bison " YYBISON_VERSION; +#elif defined(YYBYACC) +#define XSTR(x) #x +#define STR(x) XSTR(x) +const char* yaccver = "Berkeley Yacc " STR(YYMAJOR) "." STR(YYMINOR); +#endif diff --git a/Grammar/grammersym.h b/Grammar/grammersym.h new file mode 100644 index 0000000..4f93ba9 --- /dev/null +++ b/Grammar/grammersym.h @@ -0,0 +1,3 @@ +int yyparse(void); +int yylex(void); +int yyerror(const char* msg); diff --git a/Library/Makefile b/Library/Makefile index 6f24ebd..c0b4bd0 100644 --- a/Library/Makefile +++ b/Library/Makefile @@ -3,7 +3,7 @@ .PHONY: all clean .SUFFIXES: .c .o -OBJS = parser.o database.o util.o dataworks.o database_table.o database_db.o database_record.o exec.o +OBJS = parser.o database.o util.o dataworks.o database_table.o database_db.o database_record.o exec.o ../Grammar/dw.tab.o ../Grammar/dw.yy.o all: $(LIB_PREFIX)dataworks$(LIB_SUFFIX) $(STATICLIB_PREFIX)dataworks$(STATICLIB_SUFFIX) diff --git a/Library/dataworks.c b/Library/dataworks.c index def7b61..ef2afed 100644 --- a/Library/dataworks.c +++ b/Library/dataworks.c @@ -53,7 +53,10 @@ const char* dataworks_platform = "Unknown/" #endif PLATFORM_M " (" PLATFORM_P ")"; +extern const char* yaccver; + const char* dataworks_get_version(void) { return dataworks_version; } +const char* dataworks_get_yacc_version(void) { return yaccver; } const char* dataworks_get_compile_date(void) { return dataworks_compile_date; } const char* dataworks_get_platform(void) { return dataworks_platform; } char dataworks_get_endian(void) { @@ -62,6 +65,11 @@ char dataworks_get_endian(void) { } const char* dataworks_get_copyright(void) { return dataworks_copyright; } + +int yywrap() { return 1; } + +int yyerror(const char* err) { return 0; } + bool dataworks_get_if_supported(void) { #ifdef SUPPORTED return true; diff --git a/Library/dataworks.h b/Library/dataworks.h index 8d6da92..f76073e 100644 --- a/Library/dataworks.h +++ b/Library/dataworks.h @@ -50,6 +50,14 @@ extern "C" { */ const char* dataworks_get_version(void); +/** + * @~english + * @brief Get the version of Yacc used by DataWorks + * @return Yacc version of DataWorks + * + */ +const char* dataworks_get_yacc_version(void); + /** * @~english * @brief Get the compilation date of DataWorks diff --git a/common-decl.mk b/common-decl.mk index 64d97d8..173847b 100644 --- a/common-decl.mk +++ b/common-decl.mk @@ -3,11 +3,15 @@ CC = cc SHCC = cc AR = ar +YACC = yacc +LEX = lex AR_ARGS = rcs \$$@ RANLIB = ranlib WINDRES = windres CFLAGS = -g -std=c99 -D_DEFAULT_SOURCE LDFLAGS = -L`pwd`/Library +YFLAGS = -d +LFLAGS = LIBS = LIB_PREFIX = lib LIB_SUFFIX = .so @@ -17,3 +21,5 @@ EXEC_SUFFIX = PLATFORM_M = `uname -m` PLATFORM_P = `uname -p | sed -E "s/[ \\(\\)]/-/g"` LINK_LIB = ../Library/$(STATICLIB_PREFIX)dataworks$(STATICLIB_SUFFIX) + +COMPILE_FLAGS = CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="$(LIBS)" LIB_PREFIX="$(LIB_PREFIX)" LIB_SUFFIX="$(LIB_SUFFIX)" EXEC_SUFFIX="$(EXEC_SUFFIX)" PLATFORM_M="$(PLATFORM_M)" PLATFORM_P="$(PLATFORM_P)" STATICLIB_PREFIX="$(STATICLIB_PREFIX)" STATICLIB_SUFFIX="$(STATICLIB_SUFFIX)" AR="$(AR)" RANLIB="$(RANLIB)" SHCC="$(SHCC)" LINK_LIB="$(LINK_LIB)" AR_ARGS="$(AR_ARGS)" WINDRES="$(WINDRES)" YACC="$(YACC)" LEX="$(LEX)" LFLAGS="$(LFLAGS)" YFLAGS="$(YFLAGS)" diff --git a/common.mk b/common.mk index 36a7652..2c27310 100644 --- a/common.mk +++ b/common.mk @@ -1,14 +1,15 @@ # $Id$ -COMPILE_FLAGS = CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="$(LIBS)" LIB_PREFIX="$(LIB_PREFIX)" LIB_SUFFIX="$(LIB_SUFFIX)" EXEC_SUFFIX="$(EXEC_SUFFIX)" PLATFORM_M="$(PLATFORM_M)" PLATFORM_P="$(PLATFORM_P)" STATICLIB_PREFIX="$(STATICLIB_PREFIX)" STATICLIB_SUFFIX="$(STATICLIB_SUFFIX)" AR="$(AR)" RANLIB="$(RANLIB)" SHCC="$(SHCC)" LINK_LIB="$(LINK_LIB)" AR_ARGS="$(AR_ARGS)" WINDRES="$(WINDRES)" +.PHONY: all no-doc replace format clean ./Library ./Client ./Document ./Grammar archive archive-prepare archive-cleanup archive-targz archive-zip dosbox prepare-dosbox dosbox-x cleanup-dosbox -.PHONY: all no-doc replace format clean ./Library ./Client ./Document archive archive-prepare archive-cleanup archive-targz archive-zip dosbox prepare-dosbox dosbox-x cleanup-dosbox +all: ./Grammar ./Library ./Client ./Document -all: ./Library ./Client ./Document +no-doc: ./Grammar ./Library ./Client -no-doc: ./Library ./Client +./Grammar:: + $(MAKE) -C $@ $(COMPILE_FLAGS) -./Library:: +./Library:: ./Grammar $(MAKE) -C $@ $(COMPILE_FLAGS) ./Client:: ./Library @@ -20,7 +21,7 @@ no-doc: ./Library ./Client FILES = `find . -name "*.c" -or -name "*.h"` replace: - for i in $(FILES); do \ + for i in $(FILES) ./Grammar/dw.y ./Grammar/dw.l; do \ echo -n "$$i ... "; \ perl replace.pl < $$i > $$i.new; \ mv $$i.new $$i; \ @@ -32,6 +33,7 @@ format: clean: rm -f *.zip *.tar.gz + $(MAKE) -C ./Grammar clean $(COMPILE_FLAGS) $(MAKE) -C ./Library clean $(COMPILE_FLAGS) $(MAKE) -C ./Client clean $(COMPILE_FLAGS) $(MAKE) -C ./Document clean $(COMPILE_FLAGS)