Skip to content

ewanc26/sigi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sigi

A pure symbolic stack language that compiles to C.

Character set: !@#$%^&*()-+=[]{}|;:'",.<>/?\~ plus digits 0-9

All syntax is symbolic. No alphanumeric keywords.


Installation

pip install -e .

This installs the sigic compiler.


Usage

# Compile to C
sigic hello.si -o hello.c

# Compile and run immediately
sigic hello.si --run

# Debug: show tokens
sigic hello.si --emit-tokens

# Debug: show AST
sigic hello.si --emit-ast

Symbol reference

Symbol Name Effect
!N PUSH Push number N (int or float)
@ DUP Duplicate top of stack
# SWAP Swap top two elements
$ DROP Discard top of stack
+ ADD Pop b, pop a → push a + b
- SUB Pop b, pop a → push a - b
* MUL Pop b, pop a → push a * b
/ DIV Pop b, pop a → push a / b
% MOD Pop b, pop a → push fmod(a, b)
= EQ Pop b, pop a → push 1 if equal, else 0
< LT Pop b, pop a → push 1 if a < b
> GT Pop b, pop a → push 1 if a > b
~ NOT Pop a → push 1 if zero, else 0
` ` PRINT
^ PRINTC Pop and print as character
? INPUT Read number from stdin
: STORE Pop address, pop value → store to var
<n> LOAD Push value of variable n (digits 0-99)
[ body ] WHILE Loop while stack top is nonzero
{ then ; else } IF-ELSE Pop condition, execute then or else
{N body } FUNC Define function N (0-99)
(N) CALL Call function N
"text" STRING Print characters
'x CHAR Push character code
\\ COMMENT Line comment

Examples

Hello World

"Hello, World!\n"

Arithmetic

!3 !4 + |     \ prints 7
!10 !3 - |    \ prints 7
!4 !5 * |     \ prints 20

Stack operations

!5 @ + |      \ 10 (DUP + ADD)
!1 !2 # | |   \ 2 1 (SWAP)

Variables

!42 !0 :       \ store 42 in var 0
0 |            \ print 42

Functions

{0 "Hi\n"}     \ define fn 0
{1 !42 |}      \ define fn 1
(0)            \ call fn 0
(1)            \ call fn 1

Control flow

!1 { "yes" ; "no" }    \ prints "yes"
!0 { "yes" ; "no" }    \ prints "no"

While loops

!5 [ @ | !1 - ] $      \ prints 5 4 3 2 1

Design

Sigi is deliberately minimal. Every operation is a single character. There are no reserved words—only punctuation.

The language is stack-based with postfix notation, making parsing trivial.

Inspired by Forth, Joy, and other concatenative languages.

About

No description, website, or topics provided.

Resources

Contributing

Security policy

Stars

Watchers

Forks

Languages