Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compiler Tools JavaCC > Conditional par...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 486 of 548
Post > Topic >>

Conditional parsing

by studentshack@[EMAIL PROTECTED] Nov 11, 2007 at 12:21 PM

Hi,

Please bear with this possibly complicated problem.

I can perfectly form an LL1 grammar for javacc to parse logical
expressions, e.g  4+a>-3.  This grammar does  logical expressions
without precedence (to be brief):

Logical  -> UnaryLogical ( (AND | OR) UnaryLogical ) *

UnaryLogical -> "(" Logical ")"    |    NOT UnaryLogical  | ArithmExpr
LOGOP ArithmExpr

ArithmExpr    -> UnaryArithExpr ( (+|-|*|/) UnaryArithExpr  )*

UnaryArithExpr -> "(" ArithmExpr ")"  |   (+| -) UnaryArithExpr   |
IDENTIFIER | NUMBER

LOGOP ->  ">" | "<" | "==" | "<=" | ">="


The problem is, I am not sure how to recognise the possibility of a
function declaration instead of an expression, e.g:  f (SomeArith)
without breaking LL1 compatibility, and hence resorting to  lookaheads
and what not. These functions cannot be nested (i.e AND'es or OR'ed).

Consider for example, these statements that should all be recorgnised
by the new grammar:

4+5 > 6
(4+5) > 5
a(3)
a
(a)
(a(3))
!(a(3))

The third example is a function name without an argument, and should
be recognised. The functions return boolean and hence can replace the
logical expressions. I just can't come up with an LL1 parser for this.

Any help is greatly appreciated.

John
 




 2 Posts in Topic:
Conditional parsing
studentshack@[EMAIL PROTE  2007-11-11 12:21:19 
Re: Conditional parsing
"studentshack@[EMAIL  2007-11-11 14:52:58 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 23 23:38:26 CDT 2008.