hello my luft ballons
[(“word-element”, “hello”),
(“word-element”,”my”),
(“javascript-element”), “document.write(99);”)
(“word-elment”, “luftballons”),
]
def interpret(trees): for tree in trees: treetype = tree[0] if treetype == "word-element": graphics.word(node[1]) elif treetype == "javascript-element": jstext = tree[1] jslexer = lex.lex(module=jstokens) jsparser = yacc.yacc(module=jsgrammar) jstree = jsparser.parse(jstext,lexer=jslexer) result = jsinterp.interpret( jstree ) graphics.word( result )
def env_lookup(vname, env): if vname in env[1]: return (env[1])[vname] elif env[0] == None: return None else: return env_lookup(vname, env[0])
var a = 1;
function mistletue(baldr){
baldr = baldr + 1;
a = a + 2;
baldr = baldr + a;
return baldr;
}
write (mistletue(5));
def optimize(tree):
etype = tree[0]
if etype == "binop":
a = tree[1]
op = tree[2]
b = tree[3]
if op == "*" and b == ("number","1"):
return a
return tree
def remove_html_markup(s):
tag = False
out = ""
for c in s:
if c == '<':
tag = True
elif c == '>':
tag = False
elif not tag:
out = out + c
return out
print remove_html_markup("<b>foo</b>")