Re: Query on YAPP Usage

Martin Klang <[email protected]> Sat, 25 Aug 2007 14:16:34 +0100
Newsgroups gmane.text.xml.o-xml
Message-ID <[email protected]>
You're welcome!

Recursive descent parsers are notoriously bad at error reporting. =20
Generally, if no valid production can be found, the parser returns an =20=

empty result - it can't tell you where or why it failed.
One thing you can try is to extend your grammar with error branches, =20
e.g.
Operator ::=3D PlusOperator | MinusOperator | InvalidOperatorError ;
- though be careful that you don't end up with false matches higher =20
up. I think it only works if Operator is the last match in any other =20
production. It's quite tricky to define productions of the errors =20
that don't interfere with normal parsing.

I had a look at the problem you were experiencing, with 'abc' wrongly =20=

accepted as a number. It's a bug or issue in the YAPP lexer that, in =20
order to find the best match efficiently, it uses an exclusion =20
string: for each terminal, all other terminal characters are removed =20
from the token and what's left is considered a match. The 'other' =20
string, the exclusion, is hence only made up of characters contained =20
in other terminals, and since no other terminal in your grammar =20
contains the letters, it wrongly matches them as a number.
You can change/fix this behaviour by editing tokenizer.xsl, and =20
changing the variable t:allChars to a static list of 'matchable' =20
characters, eg:
   <xsl:variable name=3D"t:allChars">
     <![CDATA=20
[ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_=3D=20
+`~,<.>/?;:'"\|[{]}=A7=B1!@=A3$%^&*()]]>
   </xsl:variable>

Better still, if you use XSLT 2.0 you can rewrite the tokenizer to =20
use XSLT 2.0 regular expressions, and support Extended BNF.

hope this helps,

/m

On 23 Aug 2007, at 12:34, <[email protected]> =20
<[email protected]> wrote:

>
>
> Hi,
> Thanks a zillion for letting all of us know on how to use YAPP. Now =20=

> I am
> able to generate the parser xsl file & call it from my own style sheet
> using the same as illustrated by you. But I have an observation over
> here. I was trying to see what this resulting YAPP parser will do if I
> pass an invalid  data (as my project requirement is to validate the =20=

> data
> with BNF rule). Hence I passed the in param in the call template as =20=

> '123
> + abc', and I see this output as:
>
> <term name=3D"AdditiveExpression">
> <term name=3D"number">123</term>
> <term name=3D"AdditiveExpression-rest">
> <term name=3D"plus">+</term>
> <term name=3D"number">abc</term>
> <term name=3D"AdditiveExpression-rest"/>
>
> Where as my BNF rule is as below
>
> minus ::=3D '-' ;
> plus ::=3D '+' ;
> number ::=3D '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' =
;
> Expression ::=3D AdditiveExpression end ;
> AdditiveExpression ::=3D number | AdditiveExpression minus number |
> AdditiveExpression plus number ;
>
>
> After going through the mailing archive, I have sensed that YAPP does
> not support "error detection & reporting". I want to re confirm if =20
> this
> is true and also willing to know whether YAPP, in future is going to
> have such enhancements done. If no, can you pls give us some =20
> guidelines
> on how can we make YAPP as an error detecting + reporting tool?
>
>
>
>
> Thanks & Regards,
> Pnvd Sudhir
>