[antlr-interest] Parallel source code parsing?

Ric Klaren klaren at cs.utwente.nl
Wed Aug 11 07:42:47 PDT 2004


On Wed, Aug 11, 2004 at 02:09:19PM -0000, Jörg Rech wrote:
>   I'm parsing sourcecode and need to extract the "normal" sourcecode
> as well as the AST from the code. Now I have the problem that while
> I can parse the code I additionally need to extract the code in raw
> ASCII without re-calculating the code from the AST.
>
> For example, the result should look like this:
> <Class name="c1" modifiers="a">
>   <Inline-Class name="ic1" modifiers="a, b">
>     ** SourceCode of Inline-Class with or without method code) **
>   </Inline-Class>
>   <Method name="meth1" modifiers="a, b">
>     ** SourceCode of Method meth1 **
>   </Method>
>   ** SourceCode of Class c1 (with or without code from meth1) **
> </Class>
>
> Is it possible to copy code from the document during parsing and
> feed it to two different (sub-)parsers (e.g., one for AST generation
> and one for source extraction)?
> Has anyone a idea or solution that could help me?

With some tinkering with the inputbuffers/lexer and token classes you might
get file offsets recorded in the tokens. Carrying the offsets over to the
AST should be trivial. Then when generating the 'xml' open the file another
time and read the chunks directly from the input file into place. At least
that's an idea when you don't need to parse the code again for some other
purpose.

Cheers,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893755  ----
-----+++++*****************************************************+++++++++-------
 "Don't call me stupid." "Oh, right. To call you stupid would be an insult
    to stupid people. I've known sheep that could outwit you! I've worn
              dresses with higher IQs!" --- A Fish Called Wanda



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list