Re: An interesting Parser problem
- From: torbenm@xxxxxxxxxxxxx (Torben Ægidius Mogensen)
- Date: Fri, 30 Nov 2007 09:35:05 +0100
"sachin.goyal.new@xxxxxxxxx" <sachin.goyal.new@xxxxxxxxx> writes:
So we need to construct a parse tree of the input. But after editing,
we want to conserve the comments and white space as much as possible
so that the user does not see drastic changes to original code.
One approach is to store to file name and offset information of each
token in the parse tree. During decompiling, text between two offsets
is copied as such from original file if its not edited. If edited,
then the new text is used.
An alternative is to store leading whitespace and comments as an extra
attribute to every lexical token. When you build the abstract syntax
tree, you can combine the whitespace attributes of the tokens and the
text of the keywords etc. that appear in a production into a single
format string, e.g., " if (%s) %s\n else %s", so printing the syntax
tree is done by first creating strings for subtrees and then using the
format string to combine them into a single string.
Torben
.
- Prev by Date: Re: An interesting Parser problem
- Next by Date: Re: Incrementally implementing a simple ML compiler using LLVM
- Previous by thread: Re: An interesting Parser problem
- Next by thread: Re: An interesting Parser problem
- Index(es):
Relevant Pages
|
|