Re: An interesting Parser problem



"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

.



Relevant Pages

  • Re: efficient string tokenizer
    ... >> 1 Using getlineavoids reinventing the wheel. ... >> 2 This option makes a copy of the input string into the stringstream, ... >is only one token by the original code and it is two tokens in your code. ...
    (comp.lang.cpp)
  • Re: efficient string tokenizer
    ... >> I'm looking for a fast way to split a string into individual tokens. ... > 1 Using getlineavoids reinventing the wheel. ... It also has different behaviour from the original code. ...
    (comp.lang.cpp)
  • Re: reassigning value of a pointer
    ... >> declare that and assign a value and then print it ok. ... > memory with malloc/memset, ... > memory based on string size. ... Your original code had several problems. ...
    (comp.lang.c)
  • Re: sqlexec() with multiple SQL commands
    ... If you look close at the original code you'll see with that line break it ... would be a VFP line continuation character. ... >> string would be different. ... >> and I should not expect to see the difference but that SQL Server will? ...
    (microsoft.public.fox.vfp.queries-sql)
  • Re: Excel; Join records question?
    ... David's original code kept track of column A and built a string ... based on the data column. ... Dim wsSource As Worksheet ... Dim xArg As String, xStr As String, nRow As Long ...
    (microsoft.public.excel)