'Expansion within (..)* can be matched by empty string' problem

View: New views
5 Messages — Rating Filter:   Alert me  

'Expansion within (..)* can be matched by empty string' problem

by happYboi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey guys,

I am working on a parser for a mini version of Java. Anyways, I get this error rather often :
"Expansion within (..)* can be matched by empty string ". I would like to know why. Does Javacc not accept

For the below code, it generates the error at (stm=Stm())*. I can't see what's wrong with this.

String StmList():
{
String output = "";
String stm = "";
}
{
        output = "{" (stm = Stm())* "}"
                { output +=  stm ; }
        { return output; }
}
       

String Stm():
{
String output="";
}
{
        (
                        LOOKAHEAD ( "while" "(" Exp() ")" PriStm()  )
                        output = WhileStm()
                |
                        LOOKAHEAD ("if" "(" Exp() ")" PriStm() "else" PriStm() )
                        output = IfElseStm()
                |
                        output = PriStm()
        )
        { return output; }
}

Thanks for the help!


Re: 'Expansion within (..)* can be matched by empty string' problem

by J.Chris Findlay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The fact that the effective RegExp looks like (a*)* such that an input of 'b' would match blank an infinite number of times is what it's complaining about I think.

On Fri, Aug 14, 2009 at 10:43 PM, happYboi <ber_lim25@...> wrote:

Hey guys,

I am working on a parser for a mini version of Java. Anyways, I get this
error rather often :
"Expansion within (..)* can be matched by empty string ". I would like to
know why. Does Javacc not accept

For the below code, it generates the error at (stm=Stm())*. I can't see
what's wrong with this.

String StmList():
{
String output = "";
String stm = "";
}
{
       output = "{" (stm = Stm())* "}"
               { output +=  stm ; }
       { return output; }
}


String Stm():
{
String output="";
}
{
       (
                       LOOKAHEAD ( "while" "(" Exp() ")" PriStm()  )
                       output = WhileStm()
               |
                       LOOKAHEAD ("if" "(" Exp() ")" PriStm() "else" PriStm() )
                       output = IfElseStm()
               |
                       output = PriStm()
       )
       { return output; }
}

Thanks for the help! :drunk:


--
View this message in context: http://www.nabble.com/%27Expansion-within-%28..%29*-can-be-matched-by-empty-string%27-problem-tp24969704p24969704.html
Sent from the java.net - javacc users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...




--
- J.Chris Findlay
  (c:

Re: 'Expansion within (..)* can be matched by empty string' problem

by happYboi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the reply,

Maybe you could show what you mean through a simple example? As I do not really get what you were trying to say.

Thanks


J.Chris Findlay wrote:
The fact that the effective RegExp looks like (a*)* such that an input of
'b' would match blank an infinite number of times is what it's complaining
about I think.

On Fri, Aug 14, 2009 at 10:43 PM, happYboi <ber_lim25@hotmail.com> wrote:

>
> Hey guys,
>
> I am working on a parser for a mini version of Java. Anyways, I get this
> error rather often :
> "Expansion within (..)* can be matched by empty string ". I would like to
> know why. Does Javacc not accept
>
> For the below code, it generates the error at (stm=Stm())*. I can't see
> what's wrong with this.
>
> String StmList():
> {
> String output = "";
> String stm = "";
> }
> {
>        output = "{" (stm = Stm())* "}"
>                { output +=  stm ; }
>        { return output; }
> }
>
>
> String Stm():
> {
> String output="";
> }
> {
>        (
>                        LOOKAHEAD ( "while" "(" Exp() ")" PriStm()  )
>                        output = WhileStm()
>                |
>                        LOOKAHEAD ("if" "(" Exp() ")" PriStm() "else"
> PriStm() )
>                        output = IfElseStm()
>                |
>                        output = PriStm()
>        )
>        { return output; }
> }
>
> Thanks for the help! :drunk:
>
>
> --
> View this message in context:
> http://www.nabble.com/%27Expansion-within-%28..%29*-can-be-matched-by-empty-string%27-problem-tp24969704p24969704.html
> Sent from the java.net - javacc users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@javacc.dev.java.net
> For additional commands, e-mail: users-help@javacc.dev.java.net
>
>


--
- J.Chris Findlay
  (c:

Re: 'Expansion within (..)* can be matched by empty string' problem

by J.Chris Findlay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The error is that the ()* expansion, meaning zero or more of its contents, contains something that can be matched by the blank string, which means zero or more potentially zero length strings, which is impossible to resolve as there are an infinite number of ways to make it match, and searching for the longest match would result in an infinite loop.
Examine the expression inside the ()* and make sure it can't be matched by blank.

On Sun, Aug 16, 2009 at 8:18 PM, happYboi <ber_lim25@...> wrote:

Thanks for the reply,

Maybe you could show what you mean through a simple example? As I do not
really get what you were trying to say.

Thanks



J.Chris Findlay wrote:
>
> The fact that the effective RegExp looks like (a*)* such that an input of
> 'b' would match blank an infinite number of times is what it's complaining
> about I think.
>
> On Fri, Aug 14, 2009 at 10:43 PM, happYboi <ber_lim25@...> wrote:
>
>>
>> Hey guys,
>>
>> I am working on a parser for a mini version of Java. Anyways, I get this
>> error rather often :
>> "Expansion within (..)* can be matched by empty string ". I would like to
>> know why. Does Javacc not accept
>>
>> For the below code, it generates the error at (stm=Stm())*. I can't see
>> what's wrong with this.
>>
>> String StmList():
>> {
>> String output = "";
>> String stm = "";
>> }
>> {
>>        output = "{" (stm = Stm())* "}"
>>                { output +=  stm ; }
>>        { return output; }
>> }
>>
>>
>> String Stm():
>> {
>> String output="";
>> }
>> {
>>        (
>>                        LOOKAHEAD ( "while" "(" Exp() ")" PriStm()  )
>>                        output = WhileStm()
>>                |
>>                        LOOKAHEAD ("if" "(" Exp() ")" PriStm() "else"
>> PriStm() )
>>                        output = IfElseStm()
>>                |
>>                        output = PriStm()
>>        )
>>        { return output; }
>> }
>>
>> Thanks for the help! :drunk:
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/%27Expansion-within-%28..%29*-can-be-matched-by-empty-string%27-problem-tp24969704p24969704.html
>> Sent from the java.net - javacc users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@...
>> For additional commands, e-mail: users-help@...
>>
>>
>
>
> --
> - J.Chris Findlay
>   (c:
>
>

--
View this message in context: http://www.nabble.com/%27Expansion-within-%28..%29*-can-be-matched-by-empty-string%27-problem-tp24969704p24991384.html
Sent from the java.net - javacc users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...




--
- J.Chris Findlay
  (c:

Re: 'Expansion within (..)* can be matched by empty string' problem

by happYboi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks a lot for the explanation. Everything is working now.


J.Chris Findlay wrote:
The error is that the ()* expansion, meaning zero or more of its contents,
contains something that can be matched by the blank string, which means zero
or more potentially zero length strings, which is impossible to resolve as
there are an infinite number of ways to make it match, and searching for the
longest match would result in an infinite loop.
Examine the expression inside the ()* and make sure it can't be matched by
blank.

On Sun, Aug 16, 2009 at 8:18 PM, happYboi <ber_lim25@hotmail.com> wrote:

>
> Thanks for the reply,
>
> Maybe you could show what you mean through a simple example? As I do not
> really get what you were trying to say.
>
> Thanks
>
>
>
> J.Chris Findlay wrote:
> >
> > The fact that the effective RegExp looks like (a*)* such that an input of
> > 'b' would match blank an infinite number of times is what it's
> complaining
> > about I think.
> >
> > On Fri, Aug 14, 2009 at 10:43 PM, happYboi <ber_lim25@hotmail.com>
> wrote:
> >
> >>
> >> Hey guys,
> >>
> >> I am working on a parser for a mini version of Java. Anyways, I get this
> >> error rather often :
> >> "Expansion within (..)* can be matched by empty string ". I would like
> to
> >> know why. Does Javacc not accept
> >>
> >> For the below code, it generates the error at (stm=Stm())*. I can't see
> >> what's wrong with this.
> >>
> >> String StmList():
> >> {
> >> String output = "";
> >> String stm = "";
> >> }
> >> {
> >>        output = "{" (stm = Stm())* "}"
> >>                { output +=  stm ; }
> >>        { return output; }
> >> }
> >>
> >>
> >> String Stm():
> >> {
> >> String output="";
> >> }
> >> {
> >>        (
> >>                        LOOKAHEAD ( "while" "(" Exp() ")" PriStm()  )
> >>                        output = WhileStm()
> >>                |
> >>                        LOOKAHEAD ("if" "(" Exp() ")" PriStm() "else"
> >> PriStm() )
> >>                        output = IfElseStm()
> >>                |
> >>                        output = PriStm()
> >>        )
> >>        { return output; }
> >> }
> >>
> >> Thanks for the help! :drunk:
> >>
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/%27Expansion-within-%28..%29*-can-be-matched-by-empty-string%27-problem-tp24969704p24969704.html
> >> Sent from the java.net - javacc users mailing list archive at
> Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@javacc.dev.java.net
> >> For additional commands, e-mail: users-help@javacc.dev.java.net
> >>
> >>
> >
> >
> > --
> > - J.Chris Findlay
> >   (c:
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/%27Expansion-within-%28..%29*-can-be-matched-by-empty-string%27-problem-tp24969704p24991384.html
> Sent from the java.net - javacc users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@javacc.dev.java.net
> For additional commands, e-mail: users-help@javacc.dev.java.net
>
>


--
- J.Chris Findlay
  (c: