compiler construction - Three-address code and symbol tables -
i working on hobby retargetable c compiler in ocaml , i'm building bottom up. far have annotated ast type, abridged:
type 'e expr = | int of 'e * int | var of 'e * var | neg of 'e * 'e expr | add of 'e * 'e expr * 'e expr | sub of 'e * 'e expr * 'e expr and three-address code type (again abridged):
type node = copy of location * location | unary of location * unary_op * location | binary of location * location * binary_op * location , location = temp of int | int of int | var of string , unary_op = neg , binary_op = add | sub i have functions written transform ast list of tac nodes ignoring annotations. regarding have 2 questions:
what do differently when transforming type-annotated ast list of tac nodes? should add annotations tac nodes too? allow me later transform high level
int/chartypes lower-level onesi16/i8.how handle scoping? if have 2
vars have same name in different scopes?
how pass annotations tac open question, i'd agree want so.
one approach scoping name erasure; resolve scopes, replace each unique identifier unique "name" (or directly reference symbol table entry.) (this called gensymming, after traditional lisp gensym function.) more formally, α-reduction, term taken λ calculus. work languages, c, in names not available runtime.
languages in runtime introspection has access names (python, javascript) make process more complicated, can still associate each use of name specific scope. in languages scopes can dynamic (perl, lisp), have introduce name resolution operation tac.
Comments
Post a Comment