notc

command module
v0.0.0-...-83fa01f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 9 Imported by: 0

README

notc

A dynamic language that puts C to shame. (jk, I built this to understand how langauges are designed from the ground up)

Quick Start

To utilize the REPL, run ./notc, or provide it a file.

$ git clone https://github.com/EhsaanIqbal/notc
$ go build
$ ./notc examples/basic.notc

The Language

Explore: examples

Types

notc supports the following data types: null, bool, int, str, array, and fn. The int type signifies a signed 64-bit integer, while strings are immutable arrays of bytes, and arrays can dynamically grow.

Variable Bindings
>> let x = 10
Math
>> let x = 10
>> let y = x * 2
>> (x + y) / 2 - 3
12
Conditional Expressions

notc supports if and else:

>> let x = 10
>> let y = x * 2
>> if (x > y) { print("x is greater") } else { print("y is greater") }
x is greater
Functions and Closures

You can define named or anonymous functions, including functions within functions that reference outer variables (known as closures).

>> multiply := fn(x, y) { x * y }
>> multiply(50 / 2, 1 * 2)
50
>> fn(x) { x + 10 }(10)
20
>> newAdder := fn(x) { fn(y) { x + y } }
>> addTwo := newAdder(2)
>> addTwo(3)
5
>> sub := fn(a, b) { a - b }
>> applyFunc := fn(a, b, func) { func(a, b) }
>> applyFunc(10, 2, sub)
8
Strings
>> let x = "hello"
>> print(x + "mars")
hello mars
Arrays
>> myArray := ["x", "y", 1, fn(x) { x * x }]
>> myArray[0]
x
>> myArray[4 - 2]
1
Builtin Functions
  • len(iterable) Returns the length of the iterable (str, array).
  • print(value...) Outputs the value(s) to standard output followed by a newline.
  • push(array, value) Returns a new array with value added to the end of array.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Looks up the identifier in ident and returns the appropriate token type depending on whether the identifier is user-defined or a keyword
Looks up the identifier in ident and returns the appropriate token type depending on whether the identifier is user-defined or a keyword
Package evaluator implements a tree-walker interpreter that recursively walks the parsed AST and evaluates the nodes according to their semantic meaning
Package evaluator implements a tree-walker interpreter that recursively walks the parsed AST and evaluates the nodes according to their semantic meaning
Package lexer implements the lexical analysis that is used to transform the source code input into a stream of tokens for parsing by the parser.
Package lexer implements the lexical analysis that is used to transform the source code input into a stream of tokens for parsing by the parser.
Package object implements the object system of MaScript used to both represent values as the evaluator encounters and constructs them as well as how the user interacts with values.
Package object implements the object system of MaScript used to both represent values as the evaluator encounters and constructs them as well as how the user interacts with values.
Package token implements types and constants to support tokenizing the input source before passing the stream of tokens to the parser.
Package token implements types and constants to support tokenizing the input source before passing the stream of tokens to the parser.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL