Smalc

From Esolang
Jump to navigation Jump to search

Smalc is a joke calculator (created to be better than Desmos) implemented as a project to learn Elixir. Created by User:Joe

Spec

Literals

There are no number literals in the calculator, only identifiers. If an identifier can't be found in the context, it's then treated as a base 16 number. The language was implemented this way so you could redefine the values of numbers.

Operators

What the math operators correspond to in Smalc: All operators are right-associative as well.

Operator Type Symbol Precedence
+ prefix min 60
- infix max 70
* postfix + 50
/ infix - 40
pow mixfix (a S b c) extrema 30
mod prefix @ 80
sqrt postfix sin NONE

Preprocessor

Before the program is interpreted, every [ in the text is replaced with ((( and every ] is replaced with )).

Brackets

Expressions can be bracketed with mismatching (, ), [, ], {, }. But because of the way they're implemented in the parser, you can't nest bracketed expressions lol.

Variables

Variables are defined as such:

: expr ident : expr

Identifiers are any sequence of alphanumeric characters.

When accessing a variables, you reverse the name. A variable defined as PI would be accessed as IP.

Examples

(((1400 * 1000000) / 1) - 16) + 4000000

is equivalent to

min {578 F4240 + - 1) max 10 3D0900

in Smalc.

Implementation

Interpreter in Elixir with repl