From 2558d00d17c7b1000f08b4487efa18c8e59647f4 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 17 Jul 2022 18:15:09 +0200 Subject: [PATCH] Replace the terrible code generation shell script with a Lua script. --- util/ncgg/build.lua | 6 ++---- util/ncgg/cvtkeywords | 24 ------------------------ util/ncgg/make_enterkeyw_c.lua | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 28 deletions(-) delete mode 100755 util/ncgg/cvtkeywords create mode 100755 util/ncgg/make_enterkeyw_c.lua diff --git a/util/ncgg/build.lua b/util/ncgg/build.lua index bf459dafc..c514306b1 100644 --- a/util/ncgg/build.lua +++ b/util/ncgg/build.lua @@ -13,14 +13,12 @@ local cgglexer = flex { normalrule { name = "keywords", ins = { - "./cvtkeywords", - "util/cmisc+ed", + "./make_enterkeyw_c.lua", "./keywords", - matching(filenamesof(cggparser), "%.h$") }, outleaves = { "enterkeyw.c" }, commands = { - "%{ins[1]} %{ins[2]} %{ins[3]} %{ins[4]} %{outs[1]}" + "$LUA %{ins[1]} < %{ins[2]} > %{outs[1]}" } } diff --git a/util/ncgg/cvtkeywords b/util/ncgg/cvtkeywords deleted file mode 100755 index 46472ecbc..000000000 --- a/util/ncgg/cvtkeywords +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -: '$Id$' - -grep '^#' $3 >tokendefs -$1 -s $2 > $4 <<'!Funky!Stuff!' -g/^#/d -1,$s/\([^ ]*\)[ ][ ]*\(.*\)/ sy_p=lookup("\1",symkeyw,newsymbol);sy_p->sy_value.syv_keywno=\2;/ -1i -#include "lookup.h" -. -.r tokendefs -a - -void enterkeyw(void) { - register symbol *sy_p; - -. -$a -} -. -1,$p -!Funky!Stuff! -rm tokendefs - diff --git a/util/ncgg/make_enterkeyw_c.lua b/util/ncgg/make_enterkeyw_c.lua new file mode 100755 index 000000000..572cbb084 --- /dev/null +++ b/util/ncgg/make_enterkeyw_c.lua @@ -0,0 +1,26 @@ +print([[ +#include "param.h" +#include "lookup.h" +#include "varinfo.h" +#include "instruct.h" +#include "set.h" +#include "expr.h" +#include "iocc.h" +#include "y.tab.h" + +void enterkeyw(void) { +]]) + +for line in io.stdin:lines() do + if not line:find("^#") then + local _, _, w1, w2 = line:find("^(%g+)%s+(%g+)$") + print(string.format([[ + lookup("%s", symkeyw, newsymbol)->sy_value.syv_keywno = %s; + ]], w1, w2)) + end +end + +print([[ +} +]]) +