Skip to content

Intro To YodaScript

Dustin Van Tate Testa edited this page May 16, 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.

Values

YodaScript operates via a small set of datatypes.

Types

  • EMT: Empty: No value
  • DEC: Float: double precision floating point number
  • STR: String: text
  • REF: Reference: points to another value or null
  • IMR: Weak Reference: reference which prevents the value it points to from changing. Attempting to change the destination value will mutate the weak reference instead. (weak keyword)
  • MAC: Macro: Block of code (internally same as string)
  • INT: Integer: GMP arbitrary-precision integer type
  • ARR: List: An array of references to values
  • OBJ: Object: An object is functionally equivalent to a dictionary which supports lambdas having a sense of self. In addition, special members can overload functionality.
  • LAM: Lambda: anonymous function
  • DEF: Defined Value: gets evaluated immediately by interpreter (how define works)
  • NSP: Namespace: A scope for defined values preventing global namespace pollution
Clone this wiki locally