An attempt to build a scripting language from scratch in C
  • C 97.6%
  • Makefile 2.2%
  • Fancy 0.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-02-28 22:34:52 +02:00
docs modify headers 2026-02-28 22:34:52 +02:00
examples remove uber 2026-02-28 21:06:49 +02:00
src modify headers 2026-02-28 22:34:52 +02:00
CLAUDE.md Add coding style section to CLAUDE.md documenting project conventions 2026-02-19 00:29:37 +02:00
fype modify headers 2026-02-28 22:34:52 +02:00
INSTALL added v0.1 branch 2008-08-26 08:17:55 +00:00
LICENSE Rename COPYING to LICENSE file for convention 2026-02-28 22:28:32 +02:00
Makefile Implement function named arguments, ret, and multiple return values 2026-02-19 10:13:51 +02:00
NEW len and ind implemented 2008-11-09 11:28:26 +00:00
README.md Add README.md and array slicing support 2026-02-20 21:53:23 +02:00
README.txt Rename func keyword to fun 2026-02-19 10:20:11 +02:00
tags Clean up scanner_run() and interpret_run(): narrow signatures, fix SoC [SoC/DIP] 2026-02-28 16:15:57 +02:00
test.fy 2009-01-11 16:47:36 +00:00
test.out Update test.out to reflect token type and scanner fixes 2026-02-28 19:57:50 +02:00
TODO new todo 2008-11-09 13:14:17 +00:00

Fype

For Your Program Execution — a lightweight scripting language.

Synopsis

fype script.fy           # Run a .fy file
fype -e "say 1 + 2;"     # Run inline code
fype -h                  # Show help
fype -v                  # Show version

About

Fype is a single-pass, simultaneous-parse-and-interpret scripting language. There is no AST; the scanner produces a flat token list which the interpreter consumes directly.

Fype is developed under the BSD license.

Building

make           # Build the fype binary
make install   # Install to /usr/local/bin
make clean     # Remove build artifacts

Data Types

Fype uses automatic type conversion between these types:

  • integer — whole numbers
  • double — floating-point numbers
  • string — text strings

Explicit conversion: integer, double, string.

Syntax

Comments

# Single-line comment

#* Block comment *#

#* Multi-line
   block comment *#

say 1 #* inline *# + 1;

Variables

my foo = 1 + 2;       # declare and assign
my bar = 4, baz = 5;  # multiple declarations
my bay;               # defaults to 0

Arithmetic

say 10 + 3;   # 13
say 10 - 3;   # 7
say 10 * 3;   # 30
say 10 / 3;   # 3 (integer division)
say neg 5;    # -5
incr x;       # x = x + 1
decr x;       # x = x - 1

Comparison

5 == 5   # equal
5 != 4   # not equal
5 < 10   # less than
5 <= 5   # less or equal
5 > 3    # greater than
5 >= 5   # greater or equal
not 0    # logical not (returns 1)

Bitwise

5 and 3   # bitwise AND
5 or 2    # bitwise OR
5 xor 3   # bitwise XOR
2 :< 2    # left shift (2 << 2 = 8)
8 :> 2    # right shift (8 >> 2 = 2)

Conditionals

if 1 { say "true"; }
ifnot 0 { say "false"; }

Loops

while x < 10 { incr x; }
until x == 10 { incr x; }
loop {
    if x == 5 { break; }
    incr x;
}
do { incr x; } while x < 10;
do { incr x; } until x == 10;

break exits the loop; next skips to the next iteration.

Procedures

Procedures share the caller's scope:

proc greet {
    say "Hello";
    my local_var = 42;  # visible to caller
}
greet;

Functions

Functions have local scope and support parameters and return values:

# Zero-arg function
fun answer() { ret 42; }
say answer();

# With parameters
fun add(a, b) { ret a + b; }
say add(3, 5);

# Multiple return values
fun minmax(a, b) {
    if a < b { ret a, b; }
    ret b, a;
}
say minmax(3, 7);  # prints 3 then 7

Arrays

my nums = [10, 20, 30, 40, 50];
say len nums;      # 5
say nums[0];       # 10
say nums[1 + 1];   # 30 (expression index)
nums[2] = 99;      # element assignment

# Slices (half-open ranges)
my sub = nums[1:4];   # [20, 30, 40]
my head = nums[:2];   # [10, 20]
my tail = nums[3:];   # [40, 50]
my copy = nums[:];    # full shallow copy

Scoping

my outer = 1;
{
    my inner = 2;
    say defined inner;  # 1
}
say defined inner;      # 0

Synonyms (Aliases)

my foo = 42;
my bar = \foo;      # bar is an alias for foo
foo = 99;
say bar;            # 99 (reflects change)
say syms foo;       # 2 (two symbols point to same value)
undef foo;
say defined bar;    # 1 (alias keeps value alive)

Built-in Functions

Function Description
put x Print without newline
say x Print with newline
ln Print newline
len arr Array length
defined id 1 if defined, else 0
undef id Undefine a symbol
syms id Count synonyms
assert cond Assert condition is true
exit n Exit with code n
fork Fork a subprocess
gc Run garbage collector
scope Print visible symbols

Examples

See the examples/ directory for complete demonstrations:

  • variables.fy — variable declarations
  • expressions.fy — arithmetic expressions
  • conditionals.fy — if/ifnot
  • control.fy — while/until loops
  • loop_do.fy — loop, break, next, do-while, do-until
  • functions.fy — functions and nesting
  • func_args_ret.fy — function arguments and return values
  • procedures.fy — procedures
  • slices.fy — array slicing
  • synonyms.fy — aliases
  • scopeing.fy — lexical scoping
  • bitwise.fy — bitwise operators
  • types.fy — type conversion
  • io.fy — I/O operations
  • fork.fy — process forking
  • comments.fy — comment syntax
  • break_next.fy — loop control
  • uber.fy — comprehensive example exercising all features

Author

Paul C. Buetow (https://buetow.org)

Website

https://codeberg.org/snonux/fype