[antlr-interest] Re: multiple slashes
mzukowski at yci.com
mzukowski at yci.com
Thu Feb 19 12:15:02 PST 2004
Boy that's weird. It might help if you spell the rules out in English, like
"if you start with a slash then you've started an identifier", etc. First
figure out how you would do it by hand. Once that is clear we can help you
express it in antlr.
Monty
www.codetransform.com
-----Original Message-----
From: William Lam [mailto:xeenman at yahoo.com]
Sent: Wednesday, February 18, 2004 7:11 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Re: multiple slashes
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
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