Parsing own scripting language

J

Jesper, Denmark

Hi,

I've come to the conclusion that a scripting language will make a fine
solution for a feature that I want to program for an app.

I do not expect any problems parsing the script the old fashion way by
manually searching the string. However, if there are good tools - tutorials -
on the matter I would like to know about it. I've come across the Regex
functionality, I guess it could be used - but to what extent.

The language will contain some few keywords and will also contain nested
structures like loops within loops.

Can Regex help me parse such structures or do you know of any other tools?

Regards
Jesper.
 
P

Pavel Minaev

Jesper said:
I've come to the conclusion that a scripting language will make a fine
solution for a feature that I want to program for an app.
[...]
The language will contain some few keywords and will also contain nested
structures like loops within loops.
Can Regex help me parse such structures or do you know of any other tools?

Regex is insufficient for structures with nesting, and I would suggest itis
the wrong approach to this problem anyway.

I wholeheartedly agree. Regex-parsing any even moderately complicated
language typically results in extremely messy, brittle, non-extensible
parsing code.
You probably want a parser generator. I found a few in Google, e.g.http://grammatica.percederberg.net/

Personally, I would recommend ANTLR v3 (http://antlr.org). It supports
LL(*) grammars, which are very obvious and easy to write (even if not
quite as efficient as an LALR parser can be).
 
P

Pavel Minaev

I've come to the conclusion that a scripting language will make a fine
solution for a feature that I want to program for an app.

If so, consider not reinventing the wheel, and using one of the
existing .NET languages. Note that you can even use C# or VB.NET as a
"scripting" language - see System.CodeDom namespace, and specifically
class CodeDomProvider, which allows to compile C# and VB.NET source
code to in-memory assemblies at run-time; those assemblies can then be
accessed via reflection. Alternatively, you can use JScript.NET, which
is a "true scripting" language that comes with .NET framework out of
the box, and is easily embeddable. Then, there's also IronPython -
http://www.codeplex.com/IronPython.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top