summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2025-01-02 18:40:21 -0600
committersanine <sanine.not@pm.me>2025-01-02 18:40:21 -0600
commit88a6f54ef3e199f6dfef67f7a6d037f29dd47245 (patch)
tree771f22ebaacb8bf5342e55491404d4d7b9e2dcbd
parent81c38745be62a90de537c50cfbd777a9d582dadf (diff)
begin implementing metagrammar for ddf
-rw-r--r--.gitignore2
-rw-r--r--example.lua21
-rw-r--r--grammar.lua4
3 files changed, 20 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3819313
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.swp
+*.swo
diff --git a/example.lua b/example.lua
index 2bd87fa..9f4a852 100644
--- a/example.lua
+++ b/example.lua
@@ -17,10 +17,15 @@ for line in csvFile:lines() do
end
end
-print(#data)
-for i, v in ipairs(data[1]) do
- print(i, v)
-end
+
+local metaproduction = {}
+metaproduction["<start>"] = {{'<functions>'}}
+metaproduction["<functions>"] = { {}, {'<function>', '<functions>'} }
+metaproduction["<function>"] = {{ 'defun(', '<arity>', ')\n' }}
+metaproduction["<arity>"] = { {'0'}, {'1+', '<arity>'} }
+
+local metagrammar = Grammar.createGrammar(metaproduction, {})
+
local production = {}
production["<start>"]={{'<expr>'}}
@@ -41,7 +46,8 @@ production["<number>"]={ {'0.','<digit>','<digit>','<digit>'} }
local grammar = Grammar.createGrammar(production, {})
-math.randomseed(0)
+--math.randomseed(0)
+math.randomseed(os.time())
function randomGenome()
@@ -54,6 +60,11 @@ function randomGenome()
end
+local g = randomGenome()
+print(#g, metagrammar:expand(randomGenome()))
+os.exit(0)
+
+
function randomPop()
local pop = {}
for n=1,1000 do
diff --git a/grammar.lua b/grammar.lua
index 286723d..d4adf32 100644
--- a/grammar.lua
+++ b/grammar.lua
@@ -59,10 +59,10 @@ function Grammar.expandSequence(self, sequence, n)
end
-function Grammar.expand(self, genome, maxLength)
+function Grammar.expand(self, genome, geneIndex, maxLoops)
+ geneIndex = 0
maxLoops = maxLoops or 2
local sequence = { '<start>' }
- local geneIndex = 0
local count = 0
local continue = true
while continue do