Hi,

I want to build a standard parse-tree for a regular expression, but
I'm having one or two difficulties.  For example, the expression:

    ABC|123

should yield a tree of:

          |
        /   \
      .       .
     / \     / \
    .  C   .  3
   / \     / \
  A B   1 2

Alternatives (|) work, but I can't make concatenation of sequential
symbols (.) work at all - they end up as flat lists, rather than
nested:

         |
       /   \
     .       .
     |       |
  ABC  123

A simple grammar that shows the concatenation issue is here:

grammar test;

options { output=AST; }

tokens { CONCAT; }

start   :       regex EOF;

regex   :       chars ( ALT^ chars )* ;

chars   :       CHAR+ -> ^(CONCAT CHAR+) ;

ALT     :       '|' ;

CHAR    :       (~ALT) ;

My real regular expression grammar is somewhat longer, and also
contains groups and quantifiers.  It parses regular expressions very
well - with a somewhat deep parse tree - but I'm having problems
transforming the parse-tree into an AST.  Should I even be trying to
produce an AST?  I can of course simply write code that transforms the
parse tree into the structures I need - but I imagined that the AST
mechanism would be innately capable of this.  Any ideas are welcome,

Regards,

Matt.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to