From 560f2c0e1f6c509047dd33d4f987837408fc32ff Mon Sep 17 00:00:00 2001 From: Simon Schmidt Date: Fri, 17 Mar 2017 22:26:50 +0100 Subject: [PATCH] erweitert --- Makefile | 2 +- Unbenanntes Dokument | 0 buildmacro.c | 69 ++++++++++++++++++++++++++++++++++++++++++++ buildmacro.h | 29 +++++++++++++++++++ luab.c | 38 ++++++++++++++++++++++-- luab.h | 5 +++- main.c | 20 +++++++++---- parser.c | 46 +++++++++++++++++++++++++++-- test.txt | 7 ++--- tokenizer.c | 1 + 10 files changed, 201 insertions(+), 16 deletions(-) delete mode 100644 Unbenanntes Dokument create mode 100644 buildmacro.c create mode 100644 buildmacro.h diff --git a/Makefile b/Makefile index 3402a0a..3605188 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ lib.a: $(CC) -c $< -o $@ xpp += main.o -xpp += patlist.o strtest.o output.o tokenizer.o luab.o parser.c +xpp += patlist.o strtest.o output.o tokenizer.o luab.o parser.o buildmacro.o xpp += lib.a lua.a xpp: $(xpp) diff --git a/Unbenanntes Dokument b/Unbenanntes Dokument deleted file mode 100644 index e69de29..0000000 diff --git a/buildmacro.c b/buildmacro.c new file mode 100644 index 0000000..0bdfc91 --- /dev/null +++ b/buildmacro.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2017 Simon Schmidt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include +#include "buildmacro.h" + +sds bdmcr_build_macro(sds* args,int n,sds body){ + int i; + sds dest = smust(sdsnew("local ")); + for(i=0;idata); + //printf("%s\n",(char*)dest->data); return 0; } diff --git a/parser.c b/parser.c index 03d11be..9a9a4af 100644 --- a/parser.c +++ b/parser.c @@ -61,6 +61,46 @@ static void parser_parse_args(struct tokenizer *t,lua_State* L){ OutputStream_detroy(dest); } +static void parser_parse_args_semicolon(struct tokenizer *t,lua_State* L){ + OutputStream dest = OutputStream_new(); + int c = 0; + sds s = 0; + for(;;){ + s = tokenize_get(t,(OutputStream)0); + if(!s) { + fprintf(stderr,"unexpected EOF\n"); + abort(); + } + switch(*s){ + case '(': + c++; + break; + case ')': + if(!c){ + sdsclear(s); + goto end; + } + c--; + break; + case ';': + if(!c){ + luab_pushsds(L,(sds)(dest->data) ); + sdssetlen((sds)(dest->data),0); + *((sds)(dest->data)) = 0; + sdsclear(s); + continue; + } + break; + } + OutputStream_write(dest,s,sdslen(s)); + OutputStream_write(dest," ",1); + sdsclear(s); + } +end: + luab_pushsds(L,(sds)(dest->data) ); + OutputStream_detroy(dest); +} + static void parser_parse_body(struct tokenizer *t,lua_State* L){ OutputStream dest = OutputStream_new(); int c = 0; @@ -95,7 +135,7 @@ static void parser_parse_body(struct tokenizer *t,lua_State* L){ void parser_parse(struct tokenizer *t,lua_State* L,OutputStream dest){ sds s; - int i; + int i,N; for(;;){ s = tokenize_get(t,dest); @@ -118,7 +158,8 @@ void parser_parse(struct tokenizer *t,lua_State* L,OutputStream dest){ abort(); } sdsclear(s); - parser_parse_args(t,L); + if(i&MT_SEMI) parser_parse_args_semicolon(t,L); + else parser_parse_args(t,L); } if(i&MT_BODY){ s = tokenize_get(t,dest); @@ -132,6 +173,7 @@ void parser_parse(struct tokenizer *t,lua_State* L,OutputStream dest){ } sdsclear(s); parser_parse_body(t,L); + lua_insert(L,2); } luab_call(L); diff --git a/test.txt b/test.txt index 9267077..27ae5bf 100644 --- a/test.txt +++ b/test.txt @@ -2,11 +2,10 @@ int main(int argc,const char** argv){ int i,j; /* for(i=0;ibuffer = smust(sdscat(t->buffer,data)); return 2; } +#define LINEP printf("\n%d\n",__LINE__); sds tokenize_get(struct tokenizer *t, OutputStream targ){ const char* eoc; size_t skp;