C&C on a language design

Started by
14 comments, last by Joakim_ar 17 years, 8 months ago
It'd work, but it isn't quite a solution to the problem I had in mind, since it doesn't represent the functionality of else if, which is there to avoid having to nest all the alternatives inside each other, ie. (BASIC style)
if x = a then    print "a"else    if x = b then        print "b"    else         if x = c then            print "c"        end if    end ifend if vs.if x = a then    print "a"else if x = b then    print "b"else if x = c then    print "c"end if

But I appriciate the feedback :)
In case you were wondering what to put in your next christian game; don't ask me, because I'm an atheist, an infidel, and all in all an antitheist. If that doesn't bother you, visit my site that has all kinds of small utilities and widgets.
Advertisement
You could do something similar to Smalltalk's method:
booleanObject ifTrue: [ ... ] ifFalse: [ ... ]." ... "booleanObject ifTrue: [ ... ].


The first line would call the ifTrue:ifFalse: method of the boolean object, and the second would call the ifTrue: method of the boolean object. Blocks in Smalltalk are in square brackets.
Thank you for your input!

I have a shallow knowlegde of smalltalk, and the ifTrue, ifFalse methods of Boolean sure is clever. In fact, I earlier posted a reply to this post asking if a smalltalkISH version would look better, ie.
(x = 23).if({...do this if true}, {...do this if false})

I decided it wasn't prettier, didn't reslove the elsif problem and deleted it. The alternatives-closure is a solution I can easily live with.
In case you were wondering what to put in your next christian game; don't ask me, because I'm an atheist, an infidel, and all in all an antitheist. If that doesn't bother you, visit my site that has all kinds of small utilities and widgets.
Looks like some of the more advanced stuff from ECMAScript.

Hmmm... I'm actually kind of morbidly interested in language design and implementation. Do you have a BNF/EBNF spec for your grammar yet?

PS: The closure syntax you "borrowed" is from Ruby.
daerid@gmail.com
Not yet; I'm going to use the ANTLR tool for the lexing/parsing/traversing the syntax tree, so there's going to be one. Right now I'm focusing on the vm side of things though.

I've decided to leave objects out of the first prototype, and I think the remaining syntax is quite standard from a parsing perspective (maybe with the exception of not having a line delimiter, but lua does that too).

I'll post the ANTLR without too much semantic code when I've done it if you're interested :)

Oh yeah, that's right. I haven't been doing a lot of ruby myself, so thats why it didn't cross my mind to mention it. I have been reading about it though. I like that particular syntax :)

[Edited by - Joakim_ar on August 25, 2006 4:13:30 AM]
In case you were wondering what to put in your next christian game; don't ask me, because I'm an atheist, an infidel, and all in all an antitheist. If that doesn't bother you, visit my site that has all kinds of small utilities and widgets.
Here's the LL(2) grammar presented in ANTLR syntax. I have not tested this yet and there are no guarantees that it's 100% correct. I have removed the syntax for building parser trees and replaced most tokens with string literals for convenience.

start    : (statement)* EOF    ;statement    : bindStatement    | rebindStatement    | expression    ;bindStatement    : ID ":=" expression    ;rebindStatement    : ID "=" expression    ;apply    : atom "(" (argument ("," argument)*)? ")"    ;argument    : ID ":" expression    | "*" expression    | expression    ;parameter    : ID ":" expression    | "*" ID    | ID    ;closure    : "{" (statement)* "}"    | "{" "|" parameter ("," parameter)* "|" (statement)* "}"    ;expression    : notExpression    ;notExpression    : ("!")? andExpression    ;andExpression    : relExpression (("&&"|"||") relExpression)*    ;relExpression    : addExpression (("=="|"!="|">"|">="|"<"|"<=") addExpression)*    ;addExpression    : multExpression (("+"|"-") multExpression)*    ;multExpression    : powExpression (("*"|"&#47;") powExpression)*    ;powExpression    : negExpression (("^") negExpression)*    ;negExpression    : "-" atom    | atom    ;atom    : NUMBER    | ID    | "(" expression ")"    | closure    | apply    ;

The dot-syntax for object isn't there yet as explained in my previous post.

[Edited by - Joakim_ar on August 27, 2006 5:39:43 PM]
In case you were wondering what to put in your next christian game; don't ask me, because I'm an atheist, an infidel, and all in all an antitheist. If that doesn't bother you, visit my site that has all kinds of small utilities and widgets.

This topic is closed to new replies.

Advertisement