Re: An interesting Parser problem

torbenm@app-4.diku.dk (Torben =?iso-8859-1?Q?=C6gidius?= Mogensen)
Fri, 30 Nov 2007 09:35:05 +0100

          From comp.compilers

Related articles
An interesting Parser problem sachin.goyal.new@gmail.com (sachin.goyal.new@gmail.com) (2007-11-29)
Re: An interesting Parser problem torbenm@app-4.diku.dk (2007-11-30)
Re: An interesting Parser problem DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-11-30)
Re: An interesting Parser problem holgersiegel74@yahoo.de (Holger Siegel) (2007-11-30)
Re: An interesting Parser problem cfc@shell01.TheWorld.com (Chris F Clark) (2007-11-30)
Re: An interesting Parser problem gene.ressler@gmail.com (Gene) (2007-12-02)
Re: An interesting Parser problem rlwatkins@gmail.com (RLW) (2007-12-08)
| List of all articles for this month |
From: torbenm@app-4.diku.dk (Torben =?iso-8859-1?Q?=C6gidius?= Mogensen)
Newsgroups: comp.compilers
Date: Fri, 30 Nov 2007 09:35:05 +0100
Organization: Department of Computer Science, University of Copenhagen
References: 07-11-081
Keywords: parse, editor
Posted-Date: 30 Nov 2007 20:33:29 EST

"sachin.goyal.new@gmail.com" <sachin.goyal.new@gmail.com> 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



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.