--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussion+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I did implement a push pop mechanism directly in the C runtime, but it was only in the C runtime. I am sure that it could be added to the v4 Cpp target - it is useful. But I can't speak to what other priorities are there for the Cpp target.
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussion+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
It might seem so at first, but in practice very little additional work is required.
Consider the simplest case where the included files are specified by the same grammar (as is the case for C/C++ style includes). The added work is limited to the include context handling - to fire a new instance of the parser against the included file on a first walker pass and, for subsequent passes, fire up new instances of the walker.
Notably, the lexer/parser and walker/listener code is the same for the base and include files.
If a symbol/state table is used, it is passed to each new walker instance on start and recovered at the walk's end. The continuity of the table is maintained - there is no need to be aware of whether the table is being evaluated in connection with the base file or an include. Well, except for reporting error locations. Since the base and include parse-trees are not actually merged, all of their line/col location information is accurate relative to it's tree. Just need to track the name of the "current" parse-tree's file being walked - easily done using the table itself.
Defines are just scoped additions to the table. Each ifdef context is evaluated in the walk against the table, and either the block's subtree is walked or not.
There is one case (at least) that is not easily handled by a stream switching approach: where the name of an included file is a computed value. For example:@Include "config.nom" // specifies the value of __JIM
@Define base = "someDir/"
@Ifdef __JIM
@Define file = "jim.nom"
@Else
@Define file = "gerald.nom"
@Endif
@Include $base + $file
For stream switching, you would need a custom pre-processor parser to figure out the name of the include file.
The functional tree merging approach handles this with no additional coding required.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussion+unsubscribe@googlegroups.com.
Consider the simplest case where the included files are specified by the same grammar (as is the case for C/C++ style includes). The added work is limited to the include context handling - to fire a new instance of the parser against the included file on a first walker pass and, for subsequent passes, fire up new instances of the walker.
I would expect that the parser rule for your standard `while` statement would evaluate `
MACRO(val)` as a standard method statement. So your parse tree would be something like
....
statement WHILE (
statement MACRO (
val)
)
On Thursday, December 29, 2016 at 9:06:25 PM UTC-8, Stan Sokorac wrote:
#define MACRO(c) c ? dec() : inc();...if I have some code that uses the macro:while (MACRO(val)) { print_value(val); }
...it seems that I need to either preprocess the file to swap MACRO(val) with 'val ? dec() : inc()' and then run the parser again, or switch token streams at MACRO and serve up the macro value, no? You don't fire up a new parser to parse the macro code, do you? It's not a given that the macro code is parseable outside of current parse context, as it could contain just a code fragment.
Stan
On Wednesday, August 31, 2016 at 11:45:08 PM UTC-5, Gerald Rosenberg wrote:
Hi Jim,
It might seem so at first, but in practice very little additional work is required.
Consider the simplest case where the included files are specified by the same grammar (as is the case for C/C++ style includes). The added work is limited to the include context handling - to fire a new instance of the parser against the included file on a first walker pass and, for subsequent passes, fire up new instances of the walker.
Notably, the lexer/parser and walker/listener code is the same for the base and include files.
If a symbol/state table is used, it is passed to each new walker instance on start and recovered at the walk's end. The continuity of the table is maintained - there is no need to be aware of whether the table is being evaluated in connection with the base file or an include. Well, except for reporting error locations. Since the base and include parse-trees are not actually merged, all of their line/col location information is accurate relative to it's tree. Just need to track the name of the "current" parse-tree's file being walked - easily done using the table itself.
Defines are just scoped additions to the table. Each ifdef context is evaluated in the walk against the table, and either the block's subtree is walked or not.
There is one case (at least) that is not easily handled by a stream switching approach: where the name of an included file is a computed value. For example:@Include "config.nom" // specifies the value of __JIM
@Define base = "someDir/"
@Ifdef __JIM
@Define file = "jim.nom"
@Else
@Define file = "gerald.nom"
@Endif
@Include $base + $file
For stream switching, you would need a custom pre-processor parser to figure out the name of the include file.
The functional tree merging approach handles this with no additional coding required.
Best,
Gerald
On Wednesday, August 31, 2016 at 7:00:11 PM UTC-7, Jim Idle wrote:
I was thinking about this and I think your tree based solution won't work for the majority of languages that allow includes without an awful lot of later processing while walking the that is a lot easier to do in a pre-processing or direct include stage. Things like
jim1.h
#define MACRO(c) c ? dec() : inc();
--
You received this message because you are subscribed to a topic in the Google Groups "antlr-discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/antlr-discussion/FUQbEtonUlw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to antlr-discussion+unsubscribe@googlegroups.com.
The code above will not parse unless you perform macro substitution.Unless you put some limits on what can be in a macro, it seems like there's no way to avoid preprocessing... at which point, you might as well deal with includes in the preprocessor, too :(.
To unsubscribe from this group and all its topics, send an email to antlr-discussi...@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to antlr-discussion+unsubscribe@googlegroups.com.