[antlr-interest] Re: special c/c++ parsing

Terence Parr parrt at jguru.com
Wed May 14 11:50:30 PDT 2003


On Wednesday, May 14, 2003, at 11:41  AM, lgcraymer wrote:

> I'll echo Monty's comment.  Function calls can appear in enough places
> (including complex expressions and argument lists to functions) that
> it would be difficult to identify a subset grammar.  It is much easier
> to prune, even when you are dealing with a language as cumbersome as
> C++.

I've often wondered if something like the following (insanely slow) 
approach would work:

1. You provide a set of possible top-level match rules you are 
interested in matching like expr and method.

2. You provide a lexer that knows how to ignore comments and how to 
identify all tokens that could be seen (not just ones you are 
interested in).

3. Start walking the input token-by-token, attempting to match one of 
the top-level rules starting at token i.  If an attempt fails, try 
another top-level rule.  Failing that, move to next token and try again.

This mirrors the naive string search algorithm done by freshman CS 
students, but might actually work.  If you didn't care about speed, 
just ease of building the translator, I wonder if this would work.  It 
sounds actually like a very simple TokenStream object :)

Anybody wanna comment on the cases where this would fail?

Ter
--
Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org
Co-founder, http://www.peerscope.com link sharing, pure-n-simple
Lecturer in Comp. Sci., University of San Francisco


 

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




More information about the antlr-interest mailing list