Python 3, 80 bytes
def f(x,g={}):
for s in x:
k=s.pop(-1)
for n in s:g[n]=g.get(k,k)
return g
Takes input as a list of lists of terms, returns a dict of variable name to value.
Original answer, 54 bytes
def f(x):g={};exec(x,g);del g['__builtins__'];return g
Takes input as a newline separated list of statements (as in the initial example in the question), returns a dict of variable name to value.
Assumes that neither __builtins__ nor any python keyword will be the name of a variable, so invalid. Also fails for variables with no assignment as pointed out by @caird coinheringaahing.
Miriam
- 843
- 7
- 19