1

I have a Vb.net program which is a financial application. It is a charting program that means it loads stock market data and shows charts. I need to create a small interpreter so that users can write code and execute.

For e.g. if user wants to apply a technical tool such as moving average then he can type, Dim M as Integer. M= MovingAvg("Simple",10)

Stuff like that, it should support statements like variable decl, arrays, for next, do loop, calculation like addition, subtraction, multiplication & division. Plus other statements that are specific to my software. There is no need for going lower level or thinking on exe terms as I am not building a standalone windows application.

Before I begin I would like to take advice from you guys. How should I go about it and what important things I should keep in mind ?

I did consider language like LUA, that I could embed but it was too much of a task plus Lua's style of programming would be complex for non-programmers. Thats why I want to stick to BASIC language style.

Any comments or recommendations or pdf (ebook) to refer to will be appreciated.

Thanks,

Greatchap

Greatchap
  • 382
  • 8
  • 21

2 Answers2

0

This is a common requirement in financial domain. You will have to use a "Expression Evaluation" library.

Some of these are:

http://flee.codeplex.com/

http://www.codeproject.com/KB/recipes/eval3.aspx

Shamit Verma
  • 3,839
  • 23
  • 22
  • Thanks for your help. Should I write code for interpreter from scratch or use an existing tool. Though I want to use a language type which is easy to understand/code, I was wondering if something like microsoft script control or so could be useful. But script control has support till XP only so I don't think its wise to use it. Anything similar or any tool to aid in syntax highlighting/intellisense. The language syntax should be basic type and I will have to add my own syntax for few functions. – Greatchap Mar 16 '11 at 08:58
  • This is called "Domain Specific Language" E.g. http://lambda-the-ultimate.org/node/2201 regarding IDE, would be best to have it work according to scenario (E.g. Risk modeling). That might be less work then building a general purpose IDE (Or writing plugins for exiting IDEs) – Shamit Verma Mar 16 '11 at 09:12
  • @Shamit: Well Easy Language as mentioned in the post above, is a proprietory of a software (TradeStation) and cannot be used by me. I think I might have to write an IDE from scratch. – Greatchap Mar 16 '11 at 10:55
  • This might be of interest : http://martinfowler.com/dsl.html and http://stackoverflow.com/questions/23448/dsl-in-finance – Shamit Verma Mar 16 '11 at 11:00
  • @Shamit, thanks for the info. I think i might develope my own from scratch. By the way how should I deal with syntax highlighting and intellisense. Did see two commercial products but they are tough to customise. – Greatchap Mar 16 '11 at 19:02
  • In that case you can start with Notepad++, It has syntax highlighting + Autocomplete (intellisense). You can add a new language to it with a plugin. It is open source. – Shamit Verma Mar 17 '11 at 03:36
  • I want my own editor. So I want a program (e.g. a dll) which I can include in my project and can do the task for me in my own application. – Greatchap Mar 17 '11 at 08:18
0

It is easy to embed IronPython. If you really want to stick with a vb-alike language, then you can use VB.NET itself for scripting - Mono provides a managed vb.net compiler implementation.

SK-logic
  • 9,605
  • 1
  • 23
  • 35
  • I think I will write my language from scratch. All I am wondering is how to deal with syntax highlighting and intellisense. I did come across 2 popular commercial products but customizing them is tough plus one of them is too expensive. – Greatchap Mar 16 '11 at 19:01
  • Then you can take a look at the examples for visual studio: http://msdn.microsoft.com/en-us/library/bb166570%28v=vs.80%29.aspx – SK-logic Mar 17 '11 at 10:13
  • @Greatchap, also, I'd recommend to consider implementing a compiler instead of an interpreter - surprisingly, in .NET it is easier. – SK-logic Mar 17 '11 at 10:15
  • @SK-logic: I do not need a compiler as I am building a windows application. This language would be domain specific. Plus whatever little research I did on the web, I figured that building a compiler in most cases is way tougher compared to an interpreter. – Greatchap Mar 17 '11 at 10:54
  • @Greatchap, what's the problem with a compiler for a "windows application" (whatever it means)? Building a small [e]DSL compiler on top of .NET in fact is easier than building an interpreter - because you can rely on a lower level language compiler (C# itself, or IronPython, or F#, or whatever else) for your code generation. See this tutorial: http://meta-alternative.net/calc.pdf - you can use the same code generation techniques with C# or VB.NET easily. – SK-logic Mar 17 '11 at 11:01
  • @SK-logic. I appreciate your help. In my previous message i forgot to include Not. I mean I am not building a application that would run in windows. This app has to interact with another program that I have made. For e.g. If you write code in my language like Show Chart(); then my interpeter should show chart and so on. The meta-alternative pdf seems a little complex. – Greatchap Mar 18 '11 at 09:10
  • @Greatchap, ok, I see, you want a REPL. That's not a problem at all, as .NET provides http://msdn.microsoft.com/en-us/library/system.reflection.emit.dynamicmethod.aspx - that's how all the modern .NET scripting languages compilers work. Also, take a look at http://www.linqpad.net/ - it does something quite similar to what you're trying to achieve. – SK-logic Mar 18 '11 at 09:50
  • @Sk-logic, Linqpad is not for me, its for database developers. I am checking out the msdn link which might be useful but I am not sure. If that works out great else I might have to design my own from scratch. I am trying out syntax highlight & intellisense editor but commercial products are not easy to customize. As my syntax will be qbasic type. – Greatchap Mar 18 '11 at 12:08
  • @Greatchap, Linqpad is a general expressions evaluator. You can mimic its design for whatever your DSL needs are. The other msdn link I gave in my comment above is an example of a MSVS syntax highlighting using a trivial yacc-alike parser. For your qbasic-type syntax it should be sufficient (actually, anything will be ok, as long as syntax is trivial). – SK-logic Mar 18 '11 at 13:16
  • @Sk-logic: how can I choose a editor for syntax highlighting & intellisense. (easy to customise at least). – Greatchap Mar 18 '11 at 17:31
  • @Greatchap, it is a Visual Studio add-in. Highlighting is turned on for files with a selected extension. And your users won't have to install Visual Studio - instead, you can embed it into your application, see http://msdn.microsoft.com/en-us/library/bb685612.aspx – SK-logic Mar 18 '11 at 17:39
  • @Sk-logic: It's nice that VS do provide, but just incase if I decide to write my own interpreter which supports basic lang + my own set of functions & keywords, then I would need an Ide supporting syntax highlight,formatting & intellisense. In such a case which one should I try? Some of the commercial ones are difficult to edit.(As I want my lang to be more on the simple side, I think VS & using it as an ending may be overwhelming.) – Greatchap Mar 19 '11 at 07:00
  • @Greatchap, the example I gave you is exactly about defining your own syntax highlighting for your own language. You can cut VS down to a bare text editor, with no other menus. And if you really want something compact, I'd recommend trying ICSharpCode.TextEditor, it is free, open source and very easy to customise. I used it in a number of projects for editing my own languages, as well as the Visual Studio Shell. – SK-logic Mar 19 '11 at 09:44
  • @Sk-logic: I am thankful to you for helping me out. Unfortunately the VS editor front & ICSharpCode.TextEditor both are not really working out for me. I mean inthe first case I dont know how to start, and incase of ICSharpCode, I dunno how to modify or so. The demo app does nothing. Can you help me a bit here, please? – Greatchap Mar 19 '11 at 16:33
  • @Greatchap, the VS demo adds a syntax highlighting for a tiny C-like language `MyC`, try opening one of the demo files supplied. You can take its syntax (defined in a yacc-like language) and modify as you like. ICSharpCode highlighting is defined with a set of regular expressions, see the resource files embedded into the .dll. – SK-logic Mar 19 '11 at 18:09
  • @SK-logic: I can't find any files you have attached. Where do I look? – Greatchap Mar 19 '11 at 19:24