Exemple #1
0
def interpret(ast):
    # graphics.initialize()
    for node in ast:
        nodetype = node[0]
        if nodetype == "word-element":
            graphics.word(node[1])
        elif nodetype == "tag-element":
            tagname = node[1]
            tagargs = node[2]
            subast = node[3]
            closetagname = node[4]
            if tagname != closetagname:    # this error has detected at the parse step.
                graphics.warning("(mismatched" + tagname + " " + closetagname + ")")
            else:
                graphics.begintag(tagname, tagargs)
                interpret(subast)
                graphics.endtag()
        elif nodetype == "javascript-element":
            jstext = node[1]
            jslexer = lex.lex(module=jstokens)
            jsparser = yacc.yacc(module=jsgrammar,tabmodule="parsetabjs")
            jsast = jsparser.parse(jstext,lexer=jslexer)
            result = jsinterp.jsinterp(jsast)
            htmlast = htmlparser.parse(result,lexer=htmllexer)
            interpret(htmlast)
Exemple #2
0
def interpret(ast):
    # graphics.initialize()
    for node in ast:
        nodetype = node[0]
        if nodetype == "word-element":
            graphics.word(node[1])
        elif nodetype == "tag-element":
            tagname = node[1]
            tagargs = node[2]
            subast = node[3]
            closetagname = node[4]
            if tagname != closetagname:  # this error has detected at the parse step.
                graphics.warning("(mismatched" + tagname + " " + closetagname +
                                 ")")
            else:
                graphics.begintag(tagname, tagargs)
                interpret(subast)
                graphics.endtag()
        elif nodetype == "javascript-element":
            jstext = node[1]
            jslexer = lex.lex(module=jstokens)
            jsparser = yacc.yacc(module=jsgrammar, tabmodule="parsetabjs")
            jsast = jsparser.parse(jstext, lexer=jslexer)
            result = jsinterp.jsinterp(jsast)
            htmlast = htmlparser.parse(result, lexer=htmllexer)
            interpret(htmlast)
Exemple #3
0
import ply.lex as lex
import ply.yacc as yacc
import jstokens
import jsgrammars
import jsinterp

jslexer = lex.lex(module=jstokens)
jsparser = yacc.yacc(module=jsgrammars)

f = open("fib.js")
contents = f.read()
parse_tree = jsparser.parse(contents, lexer=jslexer)
print(parse_tree)

print(jsinterp.jsinterp(parse_tree))

## python dictionary test
# env = {"a" : 1}
# print(env)
# env["b"] = 2
# print(env)
#
# a = (1, "a", "b")
# print(a)
# print(a + tuple("c"))