diff options
| author | sanine <sanine.not@pm.me> | 2025-01-03 12:27:10 -0600 | 
|---|---|---|
| committer | sanine <sanine.not@pm.me> | 2025-01-03 12:27:10 -0600 | 
| commit | 8f4210371554f318493f875491159acdb3fedcff (patch) | |
| tree | afa529a7817bcd8d83db56be66f9613199edb4b5 /grammar.lua | |
| parent | 88a6f54ef3e199f6dfef67f7a6d037f29dd47245 (diff) | |
implement ddfsmain
Diffstat (limited to 'grammar.lua')
| -rw-r--r-- | grammar.lua | 12 | 
1 files changed, 7 insertions, 5 deletions
| diff --git a/grammar.lua b/grammar.lua index d4adf32..bdc7347 100644 --- a/grammar.lua +++ b/grammar.lua @@ -36,9 +36,10 @@ function Grammar.expandSymbol(self, sequence, index, expansion)  end -function Grammar.expandSequence(self, sequence, n) +function Grammar.expandSequence(self, sequence, n, debug)    local i = 1    while i <= #sequence do +    if debug then print(sequence[i]) end      local choices = self.nonterminals[sequence[i]] or self.context[sequence[i]]      if choices then        local trigger = self.triggers[sequence[i]] @@ -59,8 +60,8 @@ function Grammar.expandSequence(self, sequence, n)  end -function Grammar.expand(self, genome, geneIndex, maxLoops) -  geneIndex = 0 +function Grammar.expand(self, genome, geneIndex, maxLoops, debug) +  geneIndex = geneIndex or 0    maxLoops = maxLoops or 2    local sequence = { '<start>' }    local count = 0 @@ -73,7 +74,8 @@ function Grammar.expand(self, genome, geneIndex, maxLoops)        gene = genome[1 + (geneIndex % #genome)]      end      local increment -    continue, increment = self:expandSequence(sequence, gene) +    if debug then print(geneIndex, gene) end +    continue, increment = self:expandSequence(sequence, gene, debug)      if not continue then break end      geneIndex = geneIndex+increment      count = count + 1 @@ -82,7 +84,7 @@ function Grammar.expand(self, genome, geneIndex, maxLoops)    for _, s in ipairs(sequence) do      result = result .. s    end -  return result +  return result, geneIndex  end | 
