more code completion fun!

Heiko Leberer Heiko_Leberer at non.agilent.com
Wed Mar 14 18:33:51 GMT 2001


christopher j bottaro wrote:
> 
> > Assuming, that (list)* means, possible multiple instances of one of the
> > rules in list:
> >
> > you should redefine (unary_op|INCR|DECR) postfix_expr
> >
> > Those ()? and ()* are great to save some place in writing, but
> > apparently they do not lead to carefully designed rules.
> >
> > How should the parser generator differ between
> >
> > "++ident" as result from "unary_op unary_op postfix_expr"
> > "++ident" as result from "INC postfix_expr"
> 
> the lexer will choose to send to the parser INCR as opposed to '+' '+'
> 
> > Additionally this grammar allows  constructs like "++ ++ ++ 123" from
> > "INC INC INC postfix_expr).
> 
> i thought this was legal in c++ although behavior of such an expression is
> "undefined".

It's probaly syntactically legal, since it's an unary expression (I
don't have the grammar at hand), but it's definitely semantically
illegal.

The INC operator requires a lvalue, meaning a place, where you can store
the result of the operation.
A variable "a" is a lvalue, an "INC a" is not.
Since you're not generating code, you don't need to cover this, but if
you had to and you could cover this in the syntax, you should do it, it
won't compile any way.

... 
> the c++ grammer (written for yacc) is given in
> the back of Stroustrup's book, and it has quite a few ambiguities.  also, it
> allows for stuff like 2[2], which correct me if i'm wrong, has no meaning in
> c++.

s.a.

> 
> also, the reason to use antlr isn't really to make the grammer easier to
> write.  its because of the code it generates.  you can write rules that take
> arguments and return values.  also, error recovery is supposedly a lot more
> advanced than yacc (i've only used it very basically though).
> 
> the following antlr rule will match a code block starting with '{' and ending
> with '}' and in matching it,
....
 
> it would be such a pain to do this with yacc.  sorry for the antlr plug, but
> i think its really really cool.  and hopefully, as i learn more about
> grammers and parsing, i can get this code completion stuff down.
> 

On the first glance, the snippet you provided looked like an enhanced
yacc, but your second example (which I snipped), gives a better idea of
the capabilities.
ANTLR seems to be really interesting. If I only had more time.


Best regards,
Heiko

-
to unsubscribe from this list send an email to kdevelop-request at kdevelop.org with the following body:
unsubscribe »your-email-address«



More information about the KDevelop mailing list