[antlr-interest] Parsing OpenEdge (4GL database language) without preprocessor phase

Jim Idle jimi at temporal-wave.com
Fri Jan 28 09:15:40 PST 2011


Follow the example of the C pre-processor and stamp the pre-processor
output with file and line,offset:

assign customer.name = { ## "myinc.i" 1 0 ## 7 * 14 ## "origin.oe" 23 0 ##
}

Then collect this info in the lexer. If you override nextToken and derive
a new token type from CommonToken, it can track that. You could also do
this without overrides with more state programming in the lexer.

jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Pieter van Ginkel
> Sent: Friday, January 28, 2011 4:56 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Parsing OpenEdge (4GL database language)
> without preprocessor phase
>
> I need to write a parser for OpenEdge (a 4GL database language), but I
> need to preserve facts of the source files that would otherwise be lost
> through the preprocessor.
>
> E.g., the following contrived example:
>
> assign customer.name = {myinc.i}.
>
> And an include myinc.i with the contents:
>
> 7 * 14
>
> I need to have an AST that contains the fact that customer.name was
> assigned with {myinc.i} and not 7 * 14. The includes are normally
> processed using a preprocessor, so theoretically it's possible that the
> includes are accessed anywhere within a file (not in a neat location
> like after the assign in the above example). However, the code base is
> quite clean and this shouldn't pose much of a problem.
>
> The reason I need this is that I am writing an application for source
> analysis for which I need to know every detail of the source file.
>
> Can this be done with ANTLR? Any tips?
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list