occs-compilers-2014-spring / discussion

A place for discussion
0 stars 0 forks source link

Grammars and Abstract Syntax Trees #6

Open ikehz opened 10 years ago

ikehz commented 10 years ago

Hey everyone,

Hope break's going well.

I'm working on refactoring my abstract syntax tree (AST) to be easier to deal with, and I'm curious if & what others are doing in the same vein.

I've pretty much settled on not refactoring anything above expressions, aside from taking a little liberty with how lists, (like declarations and params,) are represented.

However, once we get down to the level of expression, things seem to get pretty hairy. If we have a statement

x = y;

it'd be really nice to not have to traverse down all of the levels, expression.rhs.e.t.f.factor.id to get to y. So, I'm thinking I'll just push everything below expression into roughly the same level, so we have different kinds of expressions that have different kinds of children, (i.e. now we'd have expression.rhs, because the expression's rhs would just be an id). It gets confusing when building the tree, though, to make sure we still have all the right precedence rules, etc.

Are others experimenting with similar refactors?

ikehz commented 10 years ago

(Sections 7.5, 7.6, and 7.7 of the textbook are helpful for thinking about this stuff, by the way.)