Sorry, this was originally posted in VB.Net newsgroup, but I meant for it to
be posted to the C# group initially, so I'm sorry for the multi-post, my
mistake.
-------------------------------------
I have a console app that accepts input from the user. This input can be a
command for the application, or a mathematical equation/formula. Currently,
I'm using a trick I found on the Internet that creates a dynamic JScript
assembly, loads it, which I then send any non-commands the user entered to a
method that simply passes this input to the val() function. This works, but
I'd like to go further and create my own (or somebody else's) val()
equivalent. I understand that it may be difficult and take awhile to do,
but every time I start on this trek, I just select all and delete because I
confuse myself too much...anyone have any pointers??
Thanks,
Mythran
Fred Mellender - 16 Jan 2008 23:15 GMT
Depending on exactly what you are trying to parse, your problem can be easy
or difficult. The easiest solution is a "recursive descent parser". Use
Google to find links. Search the usual places for implementations in C#.
E.G. http://en.wikipedia.org/wiki/Recursive_descent_parser
I wrote a more general purpose parser in C#, but it is probably overkill for
your problem. http://www.frontiernet.net/~fredm/parser/LinguistWebPage.htm
> Sorry, this was originally posted in VB.Net newsgroup, but I meant for it
> to be posted to the C# group initially, so I'm sorry for the multi-post,
[quoted text clipped - 18 lines]
> Thanks,
> Mythran
Brian Gideon - 17 Jan 2008 02:29 GMT
> Sorry, this was originally posted in VB.Net newsgroup, but I meant for it to
> be posted to the C# group initially, so I'm sorry for the multi-post, my
[quoted text clipped - 13 lines]
> Thanks,
> Mythran
Those dynamic code variants make for easy work arounds, but they have
a lot of disadvantages. The infix to postfix techniques are pretty
easy, but if the expressions are too complex you'll have to explore
the more advanced parsing techniques.
There are a few compiler compilers out there for C#. ANTLR is one
example. However, I think they have a big learning curve and it's
probably overkill for an expression evaluator.
I was *very* disappointed with the expression evaluators in C# I found
the internet. Even the commercial ones were deficient in some way or
another. I eventually wrote my own. Maybe I should release it to the
public sometime...
Mythran - 17 Jan 2008 16:45 GMT
>> Sorry, this was originally posted in VB.Net newsgroup, but I meant for it
>> to
[quoted text clipped - 33 lines]
> another. I eventually wrote my own. Maybe I should release it to the
> public sometime...
Basically, I'm writing a console calculator that allows you to store
variables, write function addons that can be called from the console app
(which also needs to be parsed), set application commands (change
background/foreground color in application), etc. I got the function call
parsing to work (I successfully parse out these *commands* and run their
associated code blocks, but I don't have the 'addon' portion working yet).
<shrug> Thanks for the reply :) I'll continue diggin and reviewing the
link(s) posted by Fred too...
Thanks again,
Mythran