Pattern matching lists in the tree parser
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   k_s
Posted On:   Friday, September 16, 2005 12:57 AM

Based on limited exposure to this tool, I have a couple of queries that I'm hoping would be answered. 1. How do you deal with lists in the pattern matcher (or the "tree parser"). Assuming that your tree is constructed as (root ch1 ch2 ch3 ch4 ch5....chn somethingelse), perhaps coming out of a rule such as r : ch* somethingelse How do I get the equivalent of "cons" or "nil" kind of pattern matching that I would normally get in, say, Haskell that would allow me to access each element of the list? As a possible "fix", perhaps I could have generated my s-exp as (root (CONS ch1 (CONS ch2 ..... (CONS chn NULL))))    More>>

Based on limited exposure to this tool, I have a couple of
queries that I'm hoping would be answered.


1. How do you deal with lists in the pattern matcher
(or the "tree parser"). Assuming that your tree is constructed as (root ch1 ch2 ch3 ch4 ch5....chn somethingelse), perhaps coming out of a rule
such as


r : ch* somethingelse


How do I get the equivalent of "cons" or "nil" kind of
pattern matching that I would normally get in, say, Haskell
that would allow me to access each element of the list?


As a possible "fix", perhaps I could have generated my s-exp
as (root (CONS ch1 (CONS ch2 ..... (CONS chn NULL)))) somethingelse) that would then be easily pattern-matched. The problem here is that I don't see an easy way of constructing such a s-exp when I have the production as
expressed above. I necessary have to resort to a
mangle of the production to use something else such as


chlist : | ch chlist;

r : root chlist somethingelse;


which basically voids ANTLR's claim of allowing the programmer to write "natural" looking productions.


..... Or perhaps I miss it entirely......


2. Can I give an argument to each rule in the tree pattern matcher? Currently, it can return a value for every node.
Let's assume I wish to write an interpreter for a language
so that each subexpression has to be interpreted in a particular context (basically its "scope"). How do I pass it in systematically without using globals or some random hack.


3. ANTLR does not seem to generate syntactically valid code. ANTLR does not flag an error in my .g file, it is only caught later by javac. Is there any flag to have early error flagging in ANTLR and forcing it to only generate syntactically valid code? Note that the errors do not arise from errors in any embedded java fragments, but from ANTLR specifications themselves.

Thanks.


Regards,

-K

   <<Less
About | Sitemap | Contact