SA
i ask if any one can help me in this grammar problem :

Expression ::= Expression ( "&&" | "<" | "+" | "-" | "*" ) Expression
| Expression "[" Expression "]"
| Expression "." "length"
| Expression "." Identifier "(" ( Expression ( "," Expression )* )? ")"
| <INTEGER_LITERAL>
| "true"
| "false"
| Identifier
| "this"
| "new" "int" "[" Expression "]"
| "new" Identifier "(" ")"
| "!" Expression
| "(" Expression ")" Identifier ::= <IDENTIFIER>

this grammar contain left recursion and left factoring , i resolved left factoring

void Expression():
{
}
{
Expression()
( ( "&&" | "<" | "+" | "-" | "*" ) Expression()
| "[" Expression() "]"
| "." "length"
| "." Identifier() "(" ( Expression() ( "," Expression() )* )? ")" )
| (<NUMBER>)+
| "true"
| "false"
| Identifier()
| "this"
| <NEW> ("int" "[" Expression() "]"| Identifier() "(" ")")
| "!" Expression()
| "(" Expression() ")"
}
but left recursion no : i think it is now look like
A->A(B|C|E|D)
A->(B|C|E|D)expr2
expr2->(B|C|E|D)expr2*
but I'm not sure can any one confirm .

Thanks in advance Guys .

reply asap .

i think i solved it now :
void Expression():
{
}
{
Expression3() R()
}
void Expression2():
{}
{
(<NUMBER>)+
| "true"
| "false"
| Identifier()
| "this"
| <NEW> ("int" "[" Expression() "]"| Identifier() "(" ")")
| "!" Expression()
| "(" Expression() ")"
}
void Expression3():
{}
{
( "&&" | "<" | "+" | "-" | "*" ) Expression()
| "[" Expression() "]"
| "." "length"
| "." Identifier() "(" ( Expression() ( "," Expression() )* )? ")"
}

void R():{}
{
(Expression2()R())
}

The last time I saw anything that looked like what you posted, I think we called it BNF.
As a grad student in the early 70s.

This article has been dead for over six months. Start a new discussion instead.