Skip to content

Intro To YodaScript

Dustin Van Tate Testa edited this page Mar 13, 2019 · 4 revisions

YodaScript was designed as an advanced, stack-based scripting language.

Syntax

> 1 2 + print
3

Postfix notation

In order to focus on code and not on style, the language doesn't have much in the way of style, following a relatively simple postfix syntax for most things. Although there are downsides (ie - no clear indentation style), it has a number of benefits. Although I've come to like the benefits that postfix notation brings, the main reason I've kept it is because I don't feel like implementing something like an abstract syntax tree, and postfix notation is easy to parse

> $a 100 =
> $a 50 + print
150

Lines

YodaScript doesn't really have statements. Programs can be thought of as one large expression that gets parsed with side-effects. Nonetheless, I still recommend separating code into lines in order to improve clarity.

Constructs

Most languages have literals, operators and structures, however for YodaScript, there are only two things the user can type, operators and literals. Literals include obvious things like strings and numbers, but also things like variable names, things enclosed in curly braces (macros), and more. Operators include obvious things like print and +, but also things like namespace member requests, and user defineed values and operators.

Implementation [missing: links to code]

To the interpreter there are only two things: space delimited operators (ie- +, print, while, etc.) which get processed in O(1) time, and everything else would be categorized as tokens (ie - "hello world", { "hi" print } (1 token), $obj.mem (2 tokens), etc.), which get evaluated in O(N) time (with N being the number of tokens in the language). This concept makes it easy to evaluate code from start to finish by checking for operators (see: CodeFeed.hpp: CodeFeed.setTok()) and looking for tokens if none are found. I like this system as it allows me to provide syntax that does what's needed to add features without causing overwhelming complexity or performance hurdles.

... more coming soon :D

Values

References

Clone this wiki locally