Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
Working it seems maybe possibly up till now at least
Browse files Browse the repository at this point in the history
  • Loading branch information
Arghnews committed Feb 13, 2017
1 parent 1f2a64c commit 28f6ed1
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 25 deletions.
Binary file removed .actual_grammar.swp
Binary file not shown.
Binary file removed .baba.py.swp
Binary file not shown.
Binary file removed .example.lua.swp
Binary file not shown.
2 changes: 1 addition & 1 deletion actual_grammar
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ args_back ::= args | `:´ Name args

args ::= `(´ [ explist ] `)´ | tableconstructor | String

explist ::= { exp `,´ } exp
explist ::= exp { `,´ exp }

tableconstructor ::= `{´ [ fieldlist ] `}´

Expand Down
39 changes: 32 additions & 7 deletions baba.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import copy
import sys
import traceback

Token = collections.namedtuple('Token', ['type', 'value', 'line', 'column'])

Expand Down Expand Up @@ -175,6 +176,7 @@ def exp_p(i, tokens):
def stat_for(i, tokens):
if contains(i, tokens, [("Name",MATCH_TYPE)]) and contains(i+1, tokens, [("=",MATCH_VALUE)]):
i, tokens = matchTypeNow(i, tokens, "Name")
print("Equals in stat_for, Name",i)
i, tokens = matchValueNow(i, tokens, "=")
i, tokens = exp(i, tokens)
i, tokens = matchValueNow(i, tokens, ",")
Expand Down Expand Up @@ -205,11 +207,20 @@ def stat_local(i, tokens):
return i, tokens

def stat(i, tokens):
if contains(i, tokens, firstSets["varlist"]):
print("We're in stat",i)
a = contains(i, tokens, firstSets["varlist"])
b = contains(i+1, tokens, [("=",MATCH_VALUE)])
print("First and second conds",a,b)
print(tokens[i],tokens[i+1])
if contains(i, tokens, firstSets["varlist"]) and contains(i+1, tokens, [("=",MATCH_VALUE), ("[",MATCH_VALUE)]):
print("In stat, going to do varlist",tokens[i],i)
i, tokens = varlist(i, tokens)
print("In stat, going to match =",tokens[i],i)
i, tokens = matchValueNow(i, tokens, "=")
print("In stat, going to match explist",tokens[i],i)
i, tokens = explist(i, tokens)
elif contains(i, tokens, firstSets["functioncall"]):
print("In stat, done",tokens[i],i)
elif contains(i, tokens, firstSets["functioncall"]) and contains(i+1, tokens, firstSets["exp_args_back"]+firstSets["args_back"]):
i, tokens = functioncall(i, tokens)
elif contains(i, tokens, [("do",MATCH_VALUE)]):
i, tokens = matchValueNow(i, tokens, "do")
Expand Down Expand Up @@ -339,9 +350,14 @@ def exp_front(i, tokens):

def exp_back(i, tokens):
if contains(i, tokens, [("[",MATCH_VALUE)]):
print("\n")
print("In exp back start",tokens[i],i)
i, tokens = matchValueNow(i, tokens, "[")
print("In exp back matched [",tokens[i],i)
i, tokens = exp(i, tokens)
print("In exp back exp",tokens[i],i)
i, tokens = matchValueNow(i, tokens, "]")
print("In exp_back leaving",tokens[i],i)
elif contains(i, tokens, [(".",MATCH_VALUE)]):
i, tokens = matchValueNow(i, tokens, ".")
i, tokens = matchTypeNow(i, tokens, "Name")
Expand Down Expand Up @@ -369,9 +385,9 @@ def args(i, tokens):

def explist(i, tokens):
error("Starting explist",i)
i, tokens = star(i, tokens, [(exp,MATCH_FUNCTION),(",",MATCH_VALUE)], 2)
error("In explist, done with star(exp, ,)",i)
i, tokens = exp(i, tokens)
error("In explist, done with first exp",i)
i, tokens = star(i, tokens, [(",",MATCH_VALUE),(exp,MATCH_FUNCTION)], 2)
error("Leaving explist",i)
return i, tokens

Expand All @@ -394,10 +410,12 @@ def field(i, tokens):
i, tokens = matchValueNow(i, tokens, "[")
i, tokens = exp(i, tokens)
i, tokens = matchValueNow(i, tokens, "]")
print("Equals in field, in [",i)
i, tokens = matchValueNow(i, tokens, "=")
i, tokens = exp(i, tokens)
elif contains(i, tokens, [("Name",MATCH_TYPE)]):
i, tokens = matchTypeNow(i, tokens, "Name")
print("Equals in field, in Name",i)
i, tokens = matchValueNow(i, tokens, "=")
i, tokens = exp(i, tokens)
elif contains(i, tokens, firstSets["exp"]):
Expand Down Expand Up @@ -441,6 +459,7 @@ def exp(i, tokens):
i, tokens = exp(i, tokens)
i, tokens = exp_p(i, tokens)
error("Returning from exp",i)
#traceback.print_exc()
return i, tokens

def funcname(i, tokens):
Expand Down Expand Up @@ -491,10 +510,16 @@ def matchTerminalInList(i, tokens, list):
return i, tokens

def matchTypeNow(i, tokens, type):
return matchType(type)(i,tokens)
b = matchType(type)(i,tokens)
if b:
print("Matched",i," to ",type)
return b

def matchValueNow(i, tokens, value):
return matchValue(value)(i,tokens)
b = matchValue(value)(i,tokens)
if b:
print("Matched",i," to ",value)
return b

def matchType(type):
def f(i, tokens):
Expand Down Expand Up @@ -537,7 +562,7 @@ def lookahead(i, tokens, func_tuples, lookahead_n):
b = match_t(tokens, i+j, func_tuples[j][0])
elif func_tuples[j][1] == MATCH_FUNCTION:
firstSet = firstSets[func_tuples[j][0].__name__]
b = contains(i, tokens, firstSet)
b = contains(i+j, tokens, firstSet)
#b = i_changed(i+j, tokens, func_tuples[j][0])
if not b:
errors_switch -= 1
Expand Down
7 changes: 7 additions & 0 deletions crap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
chunk
stat

varlist
var
exp_front exp_back
exp_args_back
18 changes: 1 addition & 17 deletions example.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1 @@
function lmap(f, l)
return delay(function()
return cons(f(lcar(l)), lmap(f, lcdr(l)));
end);
end;

function lmerge(a, b)
return delay(function()
local x, y = lcar(a), lcar(b);
if x <= y then
return cons(x, lmerge(lcdr(a), b));
else
return cons(y, lmerge(a, lcdr(b)));
end;
end);
end;

a[0][0] = b

0 comments on commit 28f6ed1

Please sign in to comment.