[antlr-interest] Binary Expression Problem! --- Logical Operator IMPLIES Problem

Muhammad Masoom Alam doublemalam at yahoo.co.uk
Tue Jun 20 23:08:14 PDT 2006


Dear All,

IMPLIES is a logical operator whose perority is less
than any other logical operator like AND and OR. Some
body proposed a solution for the perority problem as: 

PredicateExp:PredicateAndExp (OR PredicateAndExp)*;
PredicateAndExp: Predicate (AND Predicate)*;
Predicate: ID | “(“ PredicateExp ”)”;

Now i want to add IMPLIES into the list of above
rules.
if i write a rule for IMPLIES as follows:

Predicate1: PredicateImplies IMPLIES PredicateImplies
((AND|OR) PredicateImplies IMPLIES PredicateImplies)*;
PredicateImplies: PredicateAndExp (OR
PredicateAndExp)*;
PredicateAndExp: Predicate (AND Predicate)*;
Predicate: ID | “(“ PredicateExp ”)”;

The problem is that the perorities of expressions are
not consistent in the first rule (Predicate1). For
example it contains Logical Operator AND|OR where as
following that rule PredicateImplies also contains a
logical operator (OR). That is, the logical operators
comes in two places in the Predicate1 and then in the
PredicateImplies and in the PredicateAndExp. How the
perority of IMPLIES can be preserved while putting the
IMPLIES logial operator into its correct place.?

Thanking You in advance.
MA









--- Sebastian Kaliszewski
<Sebastian.Kaliszewski at softax.com.pl> wrote:

> Sebastian Kaliszewski wrote:
> >>> The Grammar below is structured in a way that it
> >>> should observes the perority of relational
> operators.
> >>> But in this Grammar one problem persists i.e. a
> Binary
> >>> Expression should be comprised of two operands
> where
> >>> as from the Grammar it is obvivous that it may
> come up
> >>> with a single operand too. Could any body help
> me in
> >>> this regard to overcome the single operand issue
> >>> without loosing the operator's perority.
> >>> e.g. the Grammar permits: "Hello" where as the
> >>> required expression is "Hello" = "Hello" without
> >>> loosing the operator's perority.
> >>>
> >>> BinaryExp: EqualityExp;
> >>>
> >>> EqualityExp: RelationalExp ((Not_Equal|Equal)
> >>> RelationalExp)*;
> >>>
> >>> RelationalExp: additiveExp ((GT|GTE|LT|LTE)
> >>> additiveExp)*;
> >>>
> >>> additiveExp: MultipicativeExp
> >>> ((PLUS|MINUS)MultipicativeExp)*;
> >>>
> >>> MultipicativeExp: SimpleExp ((MUL|DIV|MOD)
> >>> SimpleExp)*;
> >>>
> >>> SimpleExp: STRING|CONSTANTVALUE;
> >>>
> >  >
> > 
> >> Try:
> >>
> >> EqualityExp: RelationalExp ((Not_Equal|Equal)
> RelationalExp)+
> >>
> >> I forget if antlr supports + though, i usually
> only use ? * :)
> > 
> > 
> > I'm affraid it's not what Muhammad wanted. I.e.
> this will only accept 
> > "hello" = "hello" but will not accept things like
> 10+40.
> > 
> > Something like this might be the sollution
> (although I find that 
> > restriction somewhat strange)
> > 
> > Binary: Relational ((EQ|NEQ) Relational)+ |
> BiRelational;
> > 
> > BiRelational: Additive ((GT|GTE|LT|LTE) Additive)+
> | BiAdditive;
> > 
> > Relational: Additive ((GT|GTE|LT|LTE) Additive)*;
> > 
> > BiAdditive: Multiplicative ((PLUS|MINUS)
> Multiplicative)+|BiMultiplicative;
> > 
> > Additive: Multiplicative ((PLUS|MINUS)
> Multiplicative)*;
> > 
> > BiMultiplicative: Simple ((MUL|DIV|MOD) Simple)+;
> > 
> > Multiplicative: Simple ((MUL|DIV|MOD) Simple)*;
> > 
> > Simple: STRING|CONSTANTVALUE;
> 
> Replying to myself
> 
> One probbaly needs to set predicates, like:
> 
> BiRelational: (Additive (GT|GTE|LT|LTE))=> Additive
> ((GT|GTE|LT|LTE) 
> Additive)+ | BiAdditive;
> 
> To resolve ambiguities. But that's probably the way
> it could be acheivied.
> 
> rgds
> -- 
> Sebastian Kaliszewski
> 



	
	
		
___________________________________________________________ 
All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease of use." - PC Magazine 
http://uk.docs.yahoo.com/nowyoucan.html


More information about the antlr-interest mailing list