I need help in converting php grammar from Javacc to Freecc

4 views
Skip to first unread message

thesp0nge

unread,
Jan 23, 2009, 6:51:27 AM1/23/09
to FreeCC Development
Hi list.

I uploaded an hacked version from php.jj file you can find in javacc
site. I hacked the grammar so freecc can generate the files, compile
goes well but the parser doesn't work.

I mean trying to parse a very simple php script it fails with the
following error (it gave the same error for every PHP file). It sounds
so odd that I suspect that something went wrong with the grammar.

Can you help me?
Thanks
Paolo
--- The error ----

Call: AdditiveExpression
Call: MultiplicativeExpression
Call: CastExpression
Call: UnaryExpression
Call: PrefixIncDecExpression
Call: PostfixIncDecExpression
Call: InstanceOfExpression
Call: PostfixExpression
Call: PrimaryExpression
Return: PrimaryExpression
Return: PostfixExpression
Return: InstanceOfExpression
Return: PostfixIncDecExpression
Return: PrefixIncDecExpression
Return: UnaryExpression
Return: CastExpression
Return: MultiplicativeExpression
Return: AdditiveExpression
Exception in thread "main" ParseException: Encountered " "<" "< "" at
line 1, column 1 in .
Was expecting one of:
"clone" ...
"array" ...
"new" ...
<PREDEFINED_CONSTANT> ...
<INTEGER_LITERAL> ...
<FLOATING_POINT_LITERAL> ...
"\"" ...
"\'" ...
"<<<" ...
<IDENTIFIER> ...
"(" ...
"&" ...
"@" ...
"-" ...
"~" ...
"!" ...
"++" ...
"--" ...
"(" ...
"@" ...

at PhpParser.generateParseException(PhpParser.java:448)
at PhpParser.jj_consume_token(PhpParser.java:299)
at PhpParser.PrimaryExpression(PhpParser.java:4557)
at PhpParser.PostfixExpression(PhpParser.java:4381)
at PhpParser.InstanceOfExpression(PhpParser.java:4328)
at PhpParser.PostfixIncDecExpression(PhpParser.java:4255)
at PhpParser.PrefixIncDecExpression(PhpParser.java:4210)
at PhpParser.UnaryExpression(PhpParser.java:4137)
at PhpParser.CastExpression(PhpParser.java:4054)
at PhpParser.MultiplicativeExpression(PhpParser.java:3970)
at PhpParser.AdditiveExpression(PhpParser.java:3896)
at PhpModeler.main(PhpModeler.java:7)

Jonathan Revusky

unread,
Jan 23, 2009, 8:48:14 AM1/23/09
to freecc...@googlegroups.com
On Fri, Jan 23, 2009 at 12:51 PM, thesp0nge <thes...@gmail.com> wrote:
>
> Hi list.
>
> I uploaded an hacked version from php.jj file you can find in javacc
> site. I hacked the grammar so freecc can generate the files, compile
> goes well but the parser doesn't work.
>
> I mean trying to parse a very simple php script it fails with the
> following error (it gave the same error for every PHP file). It sounds
> so odd that I suspect that something went wrong with the grammar.

It looks to me like your grammar is starting in the wrong lexical
state. It probably needs to start in HTML_STATE, just from what I see.

So, if you have code that starts the parser, that looks something like:

PhpParser parser = new PhpParser(someReader);
etcetera...

you need that to be now:

PhpLexer lexer = new PhpLexer(someReader);
lexer.SwitchTo(PhpConstants.HTML_STATE);
PhpParser parser = new PhpParser(lexer);
etcetera...

I hope that's helpful,

JR
Reply all
Reply to author
Forward
0 new messages