print(level self namecomposites class assignnode(treenode)def __init__(selfvarval)self varself val varval def validate(selfdict)self val validate(dictdon' validate var def apply(selfdict)self var assignself val apply(dict)dict def trace(selflevel)print(level 'set 'self var trace(level self val trace(level ################################################################################the parser (syntax analysertree builder################################################################################class parserdef __init__(selftext='')self lex scanner(textself vars {'pi': self traceme tracedefault def parse(self*text)if textself lex newtext(text[ ]tree self analyse(if treeif self tracemeprint()tree trace( if self errorcheck(tree)self interpret(treemake scanner add constants external interface reuse with new text parse string dump parse-treecheck names evaluate tree def analyse(self)tryself lex scan(get first token return self goal(build parse-tree except syntaxerrorprint('syntax error at column:'self lex startself lex showerror(except lexicalerrorprint('lexical error at column:'self lex startself lex showerror(def errorcheck(selftree)trytree validate(self varserror checker return 'okexcept undefinederror as instanceargs is tuple varinfo instance args print("'%sis undefined at column%dvarinfocustom language parsers