• Post Reply Bookmark Topic Watch Topic
  • New Topic

Implementing operator overloading and inline functions  RSS feed

 
Yotam Ohayon
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there... i am building a small scale interpreter. so far i have the capability to calculate mathematical expressions including
variables and several functions (such as MOD, MAX etc...). i need to add two capabilities:

Online Operator Overloading
Operator overloading is a term which refers to the creation of new operators which have the functionality of one
of your existing functions

so for example after typing overload *# POW, 3 *# 2 will result 9.

Inline Function Creation
In addition to operator overloading, you will also need to support inline function creation4. In other words, you
will support the creation of new functions, using the following syntax:
inline _FUNC{@arg1, @arg2, ...} <function code>

So, i have no idea where to start. If anyone can link me somewhere i can read about known techniques or existing java tools
that might help me, that would be very helpfull. I don't even know what to look for. thanks!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to do this, depends a lot on how you designed your interpreter as it is now.

Somewhere in your interpreter there must be some code that recognises an operator and executes the function that the operator has. To give an operator a different meaning, as you want to do for "operator overloading", you'll have to make that part so flexible that you can replace the standard function of the operator with some other function.

Implementing inline functions is probably going to be a little bit harder. First, make sure that you can parse the syntax for inline functions. Then you'd have to store the function code in some way, so that you can execute it later when someone wants to call the function.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!