Re: My scripting language - any suggestions?

=?ISO-8859-1?Q?Christoffer_Lern=F6?= <lerno@dragonascendant.com>
Wed, 27 Aug 2008 08:52:34 -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)
Re: My scripting language - any suggestions? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-08-31)
Re: My scripting language - any suggestions? licaner@gmail.com (lican) (2008-08-31)
[10 later articles]
| List of all articles for this month |

From: =?ISO-8859-1?Q?Christoffer_Lern=F6?= <lerno@dragonascendant.com>
Newsgroups: comp.compilers
Date: Wed, 27 Aug 2008 08:52:34 -0700 (PDT)
Organization: Compilers Central
References: 08-08-069
Keywords: interpreter
Posted-Date: 28 Aug 2008 10:07:16 EDT

On 26 Aug, 01:41, lican <lica...@gmail.com> wrote:
> 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:


This is a bit similar to what I am playing around with, let me give
you my own very subjective opinions.




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


If you want a more pure OO, it would make more sense with v.is_array()
than the functional is_array(v).


Also consider "Child.new()" instead of "new Child()", since the former
allows you to easily create class clusters (http://developer.apple.com/
documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/
chapter_3_section_9.html)




> etc. Upgraded PHP? Something like that... Anyway I'm having some
> difficulties. One small decision, should variables should be declared:
>
> 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


All of these have advantages and drawbacks.
Using something like "var" signals to the reader that the variable is
actually created at this point and it allows you to catch errors like:


var someVal = 5
if (someThing) someVar = 7 // Incorrect spelling of "someVal"
immediately detected by compiler.


On the other hand "a = 5" is very convenient and reduces the amount of
text you both have to read and write. So it is a trade-off.


> And the second problem. What kind of scope to implement. In PHP you
> have either global or local (function) scope. So writing:
>
> if( variable )
> {
> a = 5;
> }
> print(a);


This would be more clear-cut if you had variable-declarations
explicit. In that case, the scope would be expected to be in the block
where it is declared.
Without a declaration then function scope is more reasonable, the
reason is this:


// If enforcing block scope, we need to make a peudo-declaration here:
a = 616; // dummy value to move "a" outside of the if-blocks.
if (variable)
{
    a = 5;
}
else
{
    a = 6;
}


> 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? :)


This paper argues that register based VMs are better:
http://www.usenix.org/events/vee05/full_papers/p153-yunhe.pdf




/Christoffer


Post a followup to this message

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