June 10, 2016
On Friday, 10 June 2016 at 11:11:49 UTC, Chris wrote:
> Nice. Anyone interested in turning this into "DScript"? Having a scripting language powered by D would also boost D's prestige. And it would be easy to write modules in pure D.

So I use my toy thing from time to time and it is pretty cool. My favorite part (and the reason I made it) is the easy interop with D itself: you basically just assign your D functions and values to a global object and get them out via the same var type - in D!

var globals = var.emptyObject;
globals.write = &(writeln!string);
var result = interpret(your_script_string, globals);
writeln(result);


where the script string looks like:

write("Hi!");
10 + 3 * 4;


and it will work:

$ dmd test.d arsd/script.d arsd/jsvar.d
$ ./test
Hi!
22



So really easy to use in all three ways: D interop is easy, the script lang itself is easy, and compiling it is easy, it is just the two modules.


I've even did a bit of GUI and DOM wrapping with it and my simpledisplay.d and dom.d in toys... a surprisingly big chunk of things just work.



The downside though is that it is something I basically slapped together in a weekend to support var.eval on a lark... it has a few weird bugs and the code is no longer beautiful as it has grown organically, and it isn't very fast, it is a simple AST interpreter that makes liberal use of new objects in D (even like a null object is allocated on the D side), but it is REALLY easy to use and coupled with native D functions for real work, it might just be interesting enough to play with.

tho idk if I'd recommend it for serious work. Just use D for that!
June 10, 2016
On Friday, 10 June 2016 at 14:25:37 UTC, Adam D. Ruppe wrote:
>
> To make an interpreter, you can just add a method to the AST objects that interprets and gives a result.... boom, it works!

Given my limited knowledge of compilers/interpreters, this part kind of seems like magic.

Let's say you have something simple like 1+2, you would build an AST that looks something like
   +
  / \
 1   2
What would be the next step?
June 10, 2016
On Friday, 10 June 2016 at 15:03:30 UTC, jmh530 wrote:
> On Friday, 10 June 2016 at 14:25:37 UTC, Adam D. Ruppe wrote:
>>
>> To make an interpreter, you can just add a method to the AST objects that interprets and gives a result.... boom, it works!
>
> Given my limited knowledge of compilers/interpreters, this part kind of seems like magic.
>
> Let's say you have something simple like 1+2, you would build an AST that looks something like
>    +
>   / \
>  1   2
> What would be the next step?

1. this is heavily OT. ;-)
2. you may take a look at my gml engine. it has clearly separated language parser and AST builder (gaem.parser), and AST->VM compiler (gaem.runner/compiler.d).
June 10, 2016
On Friday, 10 June 2016 at 15:03:30 UTC, jmh530 wrote:
> On Friday, 10 June 2016 at 14:25:37 UTC, Adam D. Ruppe wrote:
>>
>> To make an interpreter, you can just add a method to the AST objects that interprets and gives a result.... boom, it works!
>
> Given my limited knowledge of compilers/interpreters, this part kind of seems like magic.
>
> Let's say you have something simple like 1+2, you would build an AST that looks something like
>    +
>   / \
>  1   2
> What would be the next step?

https://en.wikipedia.org/wiki/Tree_traversal#Post-order
June 10, 2016
On Friday, June 10, 2016 07:45:03 Ola Fosheim Grøstad via Digitalmars-d wrote:
> On Friday, 10 June 2016 at 05:37:37 UTC, Jonathan M Davis wrote:
> > I assume that you're not from the US?
>
> Right, I am in Oslo (Norway).
>
> > In the US at least, professional programmers are almost always referred to officially as software engineers (though they use the term programmers informally all the time), whereas the terms computer science and computer scientist are generally reserved for academics
>
> Well, I don't know what is "official". Some norwegian companies seem to use convoluted "international business" terminology for everything, which is just weird and "snobbish". I think "system developer" ("systemutvikler") is the broad general term here.

Well, I meant official as in what someone's job title would be. Most developers have titles like "Software Engineer" or "Senior Softweer Engineer." They'e frequently called programmers and/or software developers when not talking about titles.

> So you can be an "informatiker" (broad term for your education) with an education in the fields of "computer science" and "software engineering", and work in the role of a "system developer".
>
> If you have a bachelor that fulfills the requirements for starting on a comp.sci. master then you are a computer scientist, but if you have a bachelor that doesn't and focus more on practical computing then you are a software engineer?
>
> You can have an education that is all about discrete math and still be a computer scientist. You couldn't then say you have a bachelor in software engineering, as it would be wrong. Likewise, you can have a bachelor in software engineering and barely know anything about complexity theory.

Yeah. Most universities in the US have a Computer Science degree, but some have Software Engineering as a separate degree. My college had Computer Science, Software Engineer, and Computer Engineering, which is atypical. All of them took practical courses, but the SE guys didn't have to take some of the more theoretical stuff and instead took additional classes focused on working on projects in teams and whatnot. And CPE was basically a hybrid between Computer Science and Electrical Engineering with an aim towards embedded systems. But all of them had more of a practical focus than is the case at many schools, because the school's motto is "learn by doing," and they focus a lot on the practical side of things, whereas many Computer Science programs suffer from not enough practical skills being taught. The college in the city where I lived for my last job is notoriously bad at teaching their Computer Science students much in the way of practical skills.

I think that it's by far the most typical though that someone gets a degree in Computer Science (with varying degrees of practical skils involved) and then takes a job as a Software Engineer. And if you got a good focus on pratical skills in school in addition to the theory, then you went to a good school, whereas some schools do a very poor job on the practical side of things.

> > And while the term informatics (or very similar terms) are used in several other languages/countries, I've never heard the term used in the US except to mention that some other languages/countries use the term informatics for computer science, and I'm willing to bet that relatively few programmers in the US have ever even heard the term informatics.
>
> Yes, but it makes sense to distinguish between "computer science"
> (the timeless math and concepts behind computing) and "software
> engineering" (contemporary development methodology and practice).
> Although I think an education should cover both. "Informatics"
> just covers it all (as an educational field).

Agreed. A good education covers both the theoritical stuff and the practical stuff, and some schools do distinguish based on what the focus of their program is, but in the US at least, it's very common to have a Computer Science program and less common to have a Software Engineering program (though I think that Software Engineering degrees are becoming more common).

- Jonathan M Davis


June 10, 2016
On Friday, 10 June 2016 at 14:25:37 UTC, Adam D. Ruppe wrote:
> On Friday, 10 June 2016 at 13:55:28 UTC, Chris wrote:
>> I have neither time nor the required expertise to write a scripting language from scratch ;) You on the other hand ... :-)
>
> Oh, it isn't that hard, at least to do a quick basic thing. You might want to start with the various math parsers. A postfix one is relatively easy:
>
> 2 3 +
>
> break it up into tokens, read them in, build a syntax tree (well, for the postfix thing, it is probably a stack!).
>
> That approach will even work for a Lisp-like language!
>
> Then try an infix one. You'd use the same tokenizer, but the parser is different... and this kind of parser gets you started for a typical script language.
>
> 2 + 3
>
> The way this works is you read the token, peek ahead, create an object and build a tree. You'd use different functions for different contexts. So it might start with readExpression which readFactor. Then readFactor might call readAddend...
>
> If you look at the D grammar: http://dlang.org/spec/grammar.html you'll find the various terms are defined as WhateverExpressions and often recursively...
>
> you can write the parser to follow that basically the same way! You end up with one of these: https://en.wikipedia.org/wiki/Recursive_descent_parser
>
> Once you get addition and multiplication working with correct order of operations, you just kinda start adding stuff! Make a function call and an if/loop statement and boom, you have a simple programming language.
>
> After that, it is basically just adding more token recognition and AST classes.
>
>
>
> To make an interpreter, you can just add a method to the AST objects that interprets and gives a result.... boom, it works! Compiling is basically the same idea, just spitting out something other than the result of the expression - spitting out code that gives you the result. That gets harder to get into all the fancy techniques, but it builds on the same foundation.
>
>
>
> It is a good thing to know how to do, at least the basic parts!

I agree. It's good to know how to do it. But don't get me started, else I'll have a new obsession ... ;)

But seriously, would you like to work on something like DScript. Your scripting language already fulfills things that were on my wishlist (easy D interop).
June 10, 2016
On Friday, 10 June 2016 at 14:34:53 UTC, Adam D. Ruppe wrote:
> var globals = var.emptyObject;
> globals.write = &(writeln!string);

Woah, I never thought of using it like that!

> The downside though is that it is something I basically slapped together in a weekend to support var.eval on a lark... it has a few weird bugs

And yet it somehow seems to _work_ better than std.variant. :/

> tho idk if I'd recommend it for serious work. Just use D for that!

I use it in my toml parser and it's very pleasant.  I figured it probably isn't very fast, but it works and that's important.

-Wyatt
June 10, 2016
On Friday, 10 June 2016 at 15:14:02 UTC, ketmar wrote:
>
> 1. this is heavily OT. ;-)

I didn't forget to mark it! :-)

> 2. you may take a look at my gml engine. it has clearly separated language parser and AST builder (gaem.parser), and AST->VM compiler (gaem.runner/compiler.d).

I couldn't for the life of me find a link to this.
June 10, 2016
On Friday, 10 June 2016 at 15:35:32 UTC, jmh530 wrote:
> On Friday, 10 June 2016 at 15:14:02 UTC, ketmar wrote:
>>
>> 2. you may take a look at my gml engine. it has clearly separated language parser and AST builder (gaem.parser), and AST->VM compiler (gaem.runner/compiler.d).
>
> I couldn't for the life of me find a link to this.

He linked it earlier:
http://repo.or.cz/gaemu.git/tree/HEAD:/gaem/parser

-Wyatt
June 10, 2016
On Friday, 10 June 2016 at 15:40:45 UTC, Wyatt wrote:
>
> He linked it earlier:
> http://repo.or.cz/gaemu.git/tree/HEAD:/gaem/parser
>
> -Wyatt

Cheers.