My scripting language - any suggestions?

lican <licaner@gmail.com>
Mon, 25 Aug 2008 16:41:28 -0700 (PDT)

          From comp.compilers

Related articles
My scripting language - any suggestions? licaner@gmail.com (lican) (2008-08-25)
Re: My scripting language - any suggestions? jaluber@gmail.com (Johannes) (2008-08-27)
Re: My scripting language - any suggestions? lerno@dragonascendant.com (=?ISO-8859-1?Q?Christoffer_Lern=F6?=) (2008-08-27)
Re: My scripting language - any suggestions? licaner@gmail.com (lican) (2008-08-29)
Re: My scripting language - any suggestions? jaluber@gmail.com (Johannes) (2008-08-30)
Re: My scripting language - any suggestions? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-08-31)
Re: My scripting language - any suggestions? ademakov@gmail.com (Aleksey Demakov) (2008-08-31)
[12 later articles]
| List of all articles for this month |

From: lican <licaner@gmail.com>
Newsgroups: comp.compilers
Date: Mon, 25 Aug 2008 16:41:28 -0700 (PDT)
Organization: Compilers Central
Keywords: interpreter, question
Posted-Date: 26 Aug 2008 23:31:25 EDT

Hi!


I've been writing my own scripting language for 6 months (with some
small breaks). I wrote the lexer, parser (similar to recursive
descent, but extended; LL grammar) and now I'm writing the
interpreter. The syntax is similar to C/C++ and the language is mostly
influenced by PHP and Lua. Sample code:


[code]
// a comment


class Child extends Parent
{
        public x;
        protected y;
        private z;


        static public function Run()
        {
                /*
                        other stuff
                */
                super.Run();
        }
}


t = [ 1, 2, 3 ]; // array, like array() in PHP
a =
[
        x = t,
        'y' = 15,
        'z' = 'to jest co6',
];


foreach( a as k,v ): petla
{
        if( is_array(v) )
                foreach( v as v2 )
                        print(v2);
        else
                print(v);
}


for( i = 0; i < 5; ++i )
        print(i);


k = new Child a;
[/code]


Yeah. It's just like PHP, but without the '$'. One significant
difference will be that you can do


[code]
t.DoSth();
[/code]


instead of


[code]
array_DoSth(t);
[/code]


etc. Upgraded PHP? Something like that... Anyway I'm having some
difficulties. One small decision, should variables should be declared:


[code]
var a = 5; // or
local a = 5; // like in lua or unreal script, or
global a = 5; // declaration of a global variable in given scope, not
like referencing global variables in PHP, or
a = 5;
[/code]


And the second problem. What kind of scope to implement. In PHP you
have either global or local (function) scope. So writing:


[code]
if( variable )
{
        a = 5;
}


print(a);
[/code]


gives the result '5'. Something like this would mean a compiler error
in C++. But I'm willing to implement it as per block (like in C/C++)
scope. Anyone seeing any prons/cons? The interpreter is a simple AST
walking class, but when some problems are fixed I will replace it with
a bytecode VM (like in Lua). And as for the VM itself... stack or
register based? :)


That's all of my questions (doubts) so far. Thanks for your help. But
if you're just gonna write 'use (f)lex/yacc/whatever' or 'why another
language, python/ruby/php/whatever is great' please don't :P I'm not
even going to read it. Everyone else is invited to this discussion.
Help me build my first scripting language! :)


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.