more code completion fun!

Oliver Strutynski olistrut at gmx.de
Wed Mar 14 09:35:55 GMT 2001


> it only gets complicated with a function call that takes doesn't take an
> identifier as an argument:
> easy:  func1(foo, bar)->
> hard:  func2(3==(3+1), 7+bar)->

For the development of a Java Parser it helped to treat all operators as 
functions and to add them to your symbol table as well (don't forget operator 
overloading!). I am not sure about the details of the C++ grammar, but in 
Java you had something the following grammar for expressions:

[...]
AdditiveExpression: MultiplicativeExpression() ( ( "+" | "-" ) 
MultiplicativeExpression() )*

MultiplicativeExpression() UnaryExpression() ( ( "*" | "/" | "%" ) 
UnaryExpression() )*

and a UnaryExpression finally resolves to a PrimaryExpression which can be 
for instance a Name or a Literal.

So an expression like (7+bar) would expand to an additive expression with two 
grandchildren (Literal and Name) for the symbols 7 and bar. Then you can 
recursively determine the type of the operands (int and typeof bar) and 
search for a matching function with signature func(int,typeof bar). This will 
give you the return type needed for evaluating the rest of the expression 
(not sure whether it is possible to overlad the -> operator as well).


Oliver

-- 
_____________________________________________________________________
 Oliver Strutynski                                olistrut at iname.com

-
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