Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Is this context sensitive?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Michael Burrows  
View profile  
 More options Sep 25 2002, 6:23 pm
Newsgroups: comp.compilers.tools.javacc
From: michael.burr...@lineone.net (Michael Burrows)
Date: 25 Sep 2002 15:23:24 -0700
Local: Wed, Sep 25 2002 6:23 pm
Subject: Is this context sensitive?
Hi
I'm writing a Javascript grammar.  It has to distinguish between
arithmetical statements such as -
        a = b/c/d;
and regular expressions such as -
        a = /c/;

I have tried to resolve the confusion between regular expression
tokenization and arithmetic tokenization by specifying a start state
for the regular expression ie.

<ExpectingRegExp>
TOKEN:
{
        < RegularExpressionPattern:  ~["/", "*"]("\\/" | ~["/"])*  > :
DEFAULT

}

void Literal() :
{}
{
        <NullLiteral>
|       <BooleanLiteral>
|       <DecimalLiteral>
|       <OctalLiteral>
|       <HexLiteral>
|       <FloatLiteral>
|       <StringLiteral>
|       "/" {token_source.SwitchTo(ParserConstants.ExpectingRegExp); }
<RegularExpressionPattern>
{token_source.SwitchTo(ParserConstants.DEFAULT); }"/"

}

This doesn't seem to work. I guess it's defeated by lookahead.

Any ideas?

Thanks
Mike


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Nickell  
View profile  
 More options Sep 26 2002, 1:00 pm
Newsgroups: comp.compilers.tools.javacc
From: Eric Nickell <no-nickell-s...@parc.xerox.com>
Date: Thu, 26 Sep 2002 09:59:22 -0700
Local: Thurs, Sep 26 2002 12:59 pm
Subject: Re: Is this context sensitive?

On Wed, 25 Sep 2002 15:23:24 -0700, Michael Burrows wrote:
> This doesn't seem to work. I guess it's defeated by lookahead.

> Any ideas?

I have tried to avoid changing lexer states from the parser code, since
the lexer may be several tokens ahead of the parser.

Given your situation, here are some initial thoughts:

(1) Create a single token for a regular expression, including the initial
and final "/". This removes the confusion between "/" as an arithmetic
operator and a regular expression delimiter. You will have to deal with
the fact that your token includes the delimiters.

(2) Alternatively, see if you can determine which of your tokens may be
followed by a regular expression, and which cannot. (This is a more
difficult task, and more error prone.  And some grammars may not be
amenable to this.) So rather than 2 states (DEFAULT and
EXPECTING_REG_EXP), you would have at least 3: DEFAULT (where the *lexer*
knows that a regular expression is illegal),
SLASH_MEANS_REGULAR_EXPRESSION, and EXPECTING_REG_EXP. You must think
through each token in your grammar and decide whether you should be in
DEFAULT or SLASH_MEANS_REGULAR_EXPRESSION afterward.  (1) is easier.

hth
Eric


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Burrows  
View profile  
 More options Sep 27 2002, 2:03 pm
Newsgroups: comp.compilers.tools.javacc
From: michael.burr...@lineone.net (Michael Burrows)
Date: 27 Sep 2002 11:03:44 -0700
Local: Fri, Sep 27 2002 2:03 pm
Subject: Re: Is this context sensitive?

Eric Nickell <no-nickell-s...@parc.xerox.com> wrote in message <news:amveda$ndp$1@news.parc.xerox.com>...
> On Wed, 25 Sep 2002 15:23:24 -0700, Michael Burrows wrote:
> > This doesn't seem to work. I guess it's defeated by lookahead.

> > Any ideas?

> Given your situation, here are some initial thoughts:

> (1) Create a single token for a regular expression, including the initial
> and final "/". This removes the confusion between "/" as an arithmetic
> operator and a regular expression delimiter. You will have to deal with
> the fact that your token includes the delimiters.

I think (1) means that there are lots of cases that are supposed to be
arithmetic, but are interpreted as regexps.

> (2) Alternatively, see if you can determine which of your tokens may be
> followed by a regular expression, and which cannot. (This is a more
> difficult task, and more error prone.  And some grammars may not be
> amenable to this.) So rather than 2 states (DEFAULT and
> EXPECTING_REG_EXP), you would have at least 3: DEFAULT (where the *lexer*
> knows that a regular expression is illegal),
> SLASH_MEANS_REGULAR_EXPRESSION, and EXPECTING_REG_EXP. You must think
> through each token in your grammar and decide whether you should be in
> DEFAULT or SLASH_MEANS_REGULAR_EXPRESSION afterward.  (1) is easier.

(2) seems to solve the problem!

Many thanks,
Mike


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »