[antlr-interest] Re: multiple slashes
William Lam
xeenman at yahoo.com
Wed Feb 18 19:10:37 PST 2004
whoops didn't specify the grammar correctly
expression
: ( alpha ( DOT alpha )? | delimited_identifier DOT alpha )
(DIVIDE (alpha ( DOT alpha )? | delimited_identifier
DOT alpha))*
;
in my lexer I have a rule
identifier
: alpha
| delimited_identifier
;
divide
: '/' ( {_ttype=delimited_identifier } alpha ( '/' alpha )* )?
;
alpha options { testLiterals=true; }
: 'a' .. 'z' ( 'a' .. 'z' | '0' .. '9' | '_' | '$' | '#' )*
;
these rules can match
/a/b//c <---- /a/b divided by /c
but cannot match simple examples such as a/b
any ideas?
wil
--- In antlr-interest at yahoogroups.com, "William Lam" <xeenman at y...>
wrote:
> Hi all,
>
> I need to parse a language that treats forward slash '/' as both a
> delimiter and as the divide character.
>
> identifiers can be standalone or have the forward slash joining
them
> together
>
> foo
>
> or
>
> /foo/bar/car
>
> so we can have instances of
>
> /foo/bar/car.zoo/a <---- z/foo/bar/car.oo is being divided by a
>
> or
>
> foo/bar <---------- foo divided by bar
>
> or
>
> a//foo/bar/car.zoo <------- a divided by /foo/bar/car.zoo
>
> in my grammar i have a rule
>
> expression
> : identifier ( DIVIDE identifier)
> ;
>
> in my lexer I have a rule
>
> identifier
> : alpha
> | delimited_identifier
> ;
>
> divide
> : '/' ( {_ttype=delimited_identifier } alpha ( '/' alpha )
* )?
> ;
>
> alpha options { testLiterals=true; }
> : 'a' .. 'z' ( 'a' .. 'z' | '0' .. '9' | '_' | '$' | '#' )*
> ;
> these rules can match
>
> /a/b//c <---- /a/b divided by /c
>
> but cannot match simple examples such as a/b
>
> any ideas?
>
> wil
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list