Advertisement

Scripting Language Syntax Proposal

Started by April 13, 2004 10:38 AM
118 comments, last by irbrian 20 years, 9 months ago
I'm also writting a scripting language..
Written in visual basic... and i'm still writting it

< code >
dim [xy]
dim [input]
dim [out]
goto main
< io >



< /io >
SUB main
[out] = [input]* 2
if ([input] = ) ! (1 = 1)
goto main
end if
< miasm >
nop
jmp 0
< /miasm >
exit
< /code >

I was wondering if we could work together to finish a language which is as easy to write as your pythonish script, and is as simple as my basic c html ish script (by the way, the tags , ect. change how the interpreter(sp?) interpretes(sp?) the code afterwood, adding extra stuff for those who ask (the miasm is nifty too, its build on my VT (found at Planetsourcecode.com to allow the faster asm code to bu run rather then the slow script).

Hopefully you could use some of these ideas (and or merge the languages together)
EG.
< script>
< Efunct>
< code>

5 var strHello = "Hello!"
6 var nTest = IO.Input()
7 print ("Enter a number: ")
8 var lenHello = strHello.Length()
9
10 if (lenHello / 2 == nTest)
11 for (var nI = 0, i < lenHello, i++)

12 out = (strHello[nI] + "\n")

13 end if
14 else
15 [out] = Wrong answer.
16 end if
< /code >
< /Efunc >
< /script >
??

[edited by - Nice coder on April 14, 2004 6:00:38 AM]
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
quote:
Original post by Tommy Carlier
Suggestion: drop the var-keyword. It's not necessary. If you say
var x = y 
or you say
x = y  
it's basically the same thing. You can only assign something to a variable. Just check to see if the variable already exists: if it doesn't, just create it. Defining a function?
function fn(var x, var y)  
can be replaced by
function fn(x, y) 

I understand how the var keyword must seem extraneous. However there's still a reason for it, which I haven't really gotten to yet (because I didn't want to throw too many features into the mix just yet). I'll get to that in a little while, and you guys can certainly point out any suggestions for improving it.

[edited by - irbrian on April 14, 2004 10:57:12 AM]
---------------------------Brian Lacy"I create. Therefore I am."
Advertisement
quote:
Original post by I_Animated
irbrian, i wouldn''t mind helping you out... I do have a few suggestions, but I will save that for an email, or another post. I am off.
I''d be interesting in hearing your ideas, I_Animated. Shoot off an email at me when you''ve got a spare minute.



****************************************

Brian Lacy
ForeverDream Studios

Comments? Questions? Curious?


"I create. Therefore I am."
---------------------------Brian Lacy"I create. Therefore I am."
I personally like the ability to define a variable without assigning it a variable, even just as a way to indicate to the programmer that this is a new variable and isn''t going to be changed by anything outside this scope.
I absolutely dislike the idea of skipping a definition keyword. if you have x = y; create a new variable, that might seem quite handy, but there is one very huge drawback (just thinking of actionscript in flash). if you spell a variable only slightly wrong, that would lead to a very hard to debug code, since a new variable would be created without any warning / error.

myfancyvariable = 3;

myfnacyvariable = 5; // spelled wrong --> new variable

print(myfancyvariable);

the above code would output the value 3, although i would have wanted it to be 5 by this time. that was only a small sample pointing out my main idea.



Indeterminatus

--si tacuisses, philosophus mansisses--
Indeterminatus--si tacuisses, philosophus mansisses--
These issues are the primary reasons I chose to require variable declaration. The issues of scope clarity, preventing variable mix-ups, etc, are things I really don''t like about many soft-typed languages.

I also wanted to allow scripters to declare a variable with a specific type, so that even initial attempts to assign it a value of another type would be rejected. Sometimes it may be helpful to actually declare a variable as a certain type, or to declare it as a constant. Consider the following lines:
var w                // Declares a variable of unknown type ''w''var x = 3            // Declares int ''x'' with value 3var int y            // Declares int ''y'' with value 0 (null int)var const int z = 3  // Declares constant int ''z'' with value 3 
I haven''t decided for sure on allowing the following optional notation, but it seems natural. Basically, if and only if a type or const is specified, the ''var'' keyword is optional, as follows:
int aconst int b = 3const c = 8 
Even in the latter cases, the ''var'' unknown type is at work here, forming the foundation of the variable. Also, as a matter of elegance, to me it would seem disruptive to not use variable declaration except when declaring a typed or constant variable.
---------------------------Brian Lacy"I create. Therefore I am."
Advertisement
quote:
var w // Declares a variable of unknown type ''w''
w = None

quote:
var const int z = 3 // Declares constant int ''z'' with value 3
I fail to see the use of a constant value in a scripting language, which is inherently about mutability.

@Indeterminatus:
That''s a relatively minor problem. Maybe it''s just me, though, but I prefer 90% solutions. var doesn''t have enough benefits IMO, especially when typed declarations still exist (exactly how redundant is var const int z = 3?)

@irbrian:
Your Landrover/Escalade analogy doesn''t wash. Just because two pairs of objects are internally comparable does not make them cross-comparable.
quote:
Original post by Oluseyi
w = None
I fail to see how that is any more elegant a solution. Personally, I find it downright ugly.
quote:
I fail to see the use of a constant value in a scripting language, which is inherently about mutability.
You may have a point. C++ offers this option, but maybe its not necessary for the scripting language. Still, my main concern is offering scripters options without making things confusing. If its confusing to others maybe I'll throw it out. Thanks for the input.
quote:
@Indeterminatus:
That's a relatively minor problem. Maybe it's just me, though, but I prefer 90% solutions. var doesn't have enough benefits IMO, especially when typed declarations still exist (exactly how redundant is var const int z = 3?)
Confusing code is never a minor problem. And personally, I don't like incomplete solutions. Oh, and the redundancy issue is the primary supporting argument for allowing the alias, const int z = 3.

Three of the primary design goals with this language are Elegance/Readability, C-familiarity, and Accessibility. The var keyword plays heavily into the first two, and I don't feel it negatively impact the third.
quote:
@irbrian:
Your Landrover/Escalade analogy doesn't wash. Just because two pairs of objects are internally comparable does not make them cross-comparable.
I think my analogy was clear and highly relevant. The purpose of an analogy is to make a point. If you didn't understand my point, then I feel you could have said "I didn't understand your analogy." Simply stating that my analogy "doesn't wash" is unclear, and in my opinion, is not very polite or professional either.



[edited by - irbrian on April 14, 2004 2:43:19 PM]
---------------------------Brian Lacy"I create. Therefore I am."
I too am looking into creating a simple scripting language, but at the moment I've just been working on syntax for a configuration file (which I'm treating as a subset of the scripting language). Personally I like the use of braces and the semicolon as it keeps things "in the C family" so-to-speak and it's just something I'm used to.

Plus using if-endif is too BASIC-like...uh, I mean "wordy" for me

You can think of my configuration file format as a script that is limited to variable creation and assignment only. Later, I will expand it into a full-featured language as needed.

We start with five types of properties/variables: bool, int, real, string and composite. In the interest of getting some feedback in the same vein as irbrian, here is an example:

// Both C++ /* and C-style comments    are allowed*/Title = "title1.jpg"; // stringAutoSaveOn = ShowTitleScreen = true; // multiple assignment okPlayer { // this is a composite property/variable named "Player"  MaxHealth = 40; // int  XPosition = 0.0; // real  YPosition = 0.0;  ZPosition = 0.0;  Name = "Jeff";  Backpack { // composite within composite allowed    Color = "Brown";    MaxItems = 10;  }}  


I have done away with using a "DIM" or "var" keyword as I, too, feel it is superfluous. I have also made each property/variable a sort-of variant type that can be re-assigned a different type (i.e. if you later did AutoSaveOn = "false", it would be turned into a string property).

I have already written the BNF for the above format (the hardest part was getting the string description correct for escape codes). I have already coded up a parser using boost::spirit (very cool, btw!). Now I'm just working on the wrapping class that takes the parsed symbols and creates the above structure in code...

I'm wondering if I need an array type? I like how PHP allows objects/composites to be viewed as arrays and vice-versa so I may do something similar down the line.

Regards,
Jeff

Edit: Fixed some typos


[ CodeDread ]

[edited by - rypyr on April 14, 2004 3:37:05 PM]
quote:
Original post by rypyr
I too am looking into creating a simple scripting language, but at the moment I''ve just been working on syntax for a configuration file (which I''m treating as a subset of the scripting language). Personally I like the use of braces and the semicolon as it keeps things "in the C family" so-to-speak and it''s just something I''m used to.

Plus using if-endif is too BASIC-like...uh, I mean "wordy" for me

You can think of my configuration file format as a script that is limited to variable creation and assignment only. Later, I will expand it into a full-featured language as needed.

We start with five types of properties/variables: bool, int, real, string and composite. In the interest of getting some feedback in the same vein as irbrian, here is an example:


If you''re only having one integer type, I hope it will do something cool like type migration?

This topic is closed to new replies.

Advertisement