jep parsing and variable

39 views
Skip to first unread message

Asharaf

unread,
Sep 14, 2009, 3:30:24 PM9/14/09
to Jep Java Users
Hi

I am evaluating the following expression

1.COUNT==2.COUNT && 2.AMOUNT>100

but it always gives me error saying that value not set

but if use the expression like this(i.e. by moving the number to the
other end of the token) ..

COUNT.1==COUNT.2 && AMOUNT.2>100

its giving me the correct result.

Note: i am setting values by using the method jep.addVariable
(nextToken, 100);

where
nextToken is COUNT.1, COUNT.2 etc

looks like JEP is trying to parse expression token(1.COUNT) thinking
that it is a number.

unfortunately i dont have control over the expression string as its
coming from a database

any help, pointers highly appreciated.

thanks
~a

Richard Morris

unread,
Sep 15, 2009, 3:35:12 PM9/15/09
to jep-...@googlegroups.com
Hi Asharaf,

The problem is that the parser is interpreting
1.COUNT
as
1.0 times COUNT
and you have no COUNT variable.

You can modify the parsing rules using the configurable parser
http://www.singularsys.com/jep/doc/html/confparser.html
which you will need to use instead of the standard parser.

You will need to make a new IdentifierTokenMatcher which matches the
regular expression for your variables
new IdentifierTokenMatcher("[\\w\\.]*[a-zA-Z_][\\w\\.]*+")
would match any string of letters, numbers, _ and . which contains at
least one letter or underscore.

You would also need to modify the order of the matchers, so that
your new IdentifierTokenMatcher comes before the NumberTokenMatcher.
This will mean force it to try and recognise the input as a identifier
rather than number.

If you need some more help let me know.

Rich
--
Richard Morris
Web: www.singsurf.org www.pfaf.org
Email: ri...@singsurf.org
Tel: (+44) 01208 872963
Post: 1 Lerryn View, Lerryn, Lostwithiel, Cornwall, PL22 0QJ
Reply all
Reply to author
Forward
0 new messages