Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Implementing operator overloading and inline functions

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!
Java Cowboy
Posts: 16084
Android Scala IntelliJ IDE Spring Java
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!