Noxy
Linguagem de Programação Estaticamente Tipada

Uma linguagem poderosa estaticamente tipada com uma Virtual Machine baseada em pilha de alta performance escrita em Go e criada por Estêvão Fonseca. Suporte a tipos primitivos, structs, arrays dinâmicos, mapas e muito mais.

🦉 Mascote: Nossa coruja roxa simboliza a sabedoria e elegância no desenvolvimento de software.

Web Interpreter GitHub Ver Exemplos
hello.nx
print("Hello from Noxy!")

// Operações básicas
let x: int = 10
let y: int = 20
print("Sum: " + to_str(x + y))

// Exemplo de struct
struct Produto
    codigo: int,
    nome: string,
    preco: float
end

let produto: Produto = Produto(1, "Laptop", 2500.50)
print("Product: " + produto.nome)

Recursos da Linguagem

Sistema de Tipos Estático

Suporte completo para tipos int, float, string, bool e arrays com verificação de tipos em tempo de compilação.

VM Baseada em Pilha

Virtual Machine stack-based escrita em Go para alta performance e portabilidade.

Estruturas de Dados

Suporte nativo para structs, arrays, auto-referenciamento e estruturas de dados complexas.

Algoritmos Avançados

Implementação de busca binária, listas ligadas, árvores binárias e algoritmos de ordenação.

Auto-Referenciamento

Structs auto-referenciáveis usando o operador ref para criar estruturas de dados recursivas.

Conversões de Tipo

Função universal to_str e conversões numéricas para manipulação flexível de dados.

Sintaxe da Linguagem

Declaração de Variáveis

let x: int = 42
let y: float = 3.14
let texto: string = "Hello, World!"
let ativo: bool = true

Arrays

let numeros: int[5] = [1, 2, 3, 4, 5]
let matriz: float[3] = [1.1, 2.2, 3.3]
let tamanho: int = length(numeros)

Estruturas

struct Pessoa
    nome: string,
    idade: int,
    ativo: bool
end

let pessoa: Pessoa = Pessoa("João", 25, true)
pessoa.idade = 26

Funções

func add(a: int, b: int) -> int
    return a + b
end

func saudacao(nome: string)
    print("Olá, " + nome + "!")
end

Estruturas de Controle

if x > 10 then
    print("x é maior que 10")
else
    print("x é 10 ou menor")
end

while i < 10 do
    print(i)
    i = i + 1
end

Auto-Referenciamento

struct TreeNode
    valor: int,
    esquerda: ref TreeNode,
    direita: ref TreeNode
end

let raiz: TreeNode = TreeNode(50, null, null)
raiz.esquerda = ref TreeNode(25, null, null)

Exemplos Práticos

Hello World

Um exemplo básico mostrando a sintaxe fundamental da linguagem Noxy.

print("Hello from Noxy!")

// Operações básicas
let x: int = 10
let y: int = 30
print("Sum: ")
print(x + y)

// Exemplo de struct
struct Produto
    codigo: int,
    nome: string,
    preco: float
end

let produto: Produto = Produto(1, "Laptop", 2500.50)
print("Product: ")
print(produto.nome)

Árvore Binária

Implementação de uma árvore binária com travessia pre-order.

struct Node
  data: int,
  left: ref Node,
  right: ref Node
end

// Criar árvore binária
let root: Node = Node(1, null, null)
root.left = Node(2, null, null)
root.right = Node(3, null, null)
root.left.left = Node(4, null, null)
root.left.right = Node(5, null, null)

func pre_order(node: ref Node)
  if node != null then
    print(to_str(node.data))
    pre_order(node.left)
    pre_order(node.right)
  end
end

pre_order(root)

Lista Ligada

Implementação de uma lista ligada com operações de inserção e remoção.

struct Node
    valor: int,
    proximo: ref Node
end

func append(node: ref Node, valor: int)
    if node.proximo == null then
        node.proximo = ref Node(valor, null)
    else
        append(node.proximo, valor)
    end
end

func print_list(node: ref Node)
    while node != null do
        print(to_str(node.valor))
        node = node.proximo
    end
end

let lista: Node = Node(10, null)
append(lista, 20)
append(lista, 30)
print_list(lista)

HashMap

Implementação de um hashmap com chaves string usando função hash polinomial.

struct Node
    key: string,
    value: string,
    next: ref Node
end

let buckets: Node[16] = [null, null, null, null, ...]

func hash(chave: string, tamanho: int) -> int
    let hash_value: int = 0
    let i: int = 0
    while i < strlen(chave) do
        hash_value = (hash_value * 31 + ord(chave[i])) % tamanho
        i = i + 1
    end
    return hash_value
end

func push(key: string, value: string)
    let index: int = hash(key, 16)
    if buckets[index] == null then
        buckets[index] = Node(key, value, null)
    else
        // Adicionar à lista ligada
        let node: Node = buckets[index]
        while node.next != null do
            node = node.next
        end
        node.next = ref Node(key, value, null)
    end
end

Divisão Segura

Padrão Result para tratamento seguro de erros em operações que podem falhar.

struct Result
    is_ok: bool,
    value: int,
    error: string
end

func Ok(value: int) -> Result
    return Result(true, value, "")
end

func Err(error_name: string) -> Result
    return Result(false, 0, error_name)
end

func safe_divide(a: int, b: int) -> Result
    if b == 0 then
        return Err("DIVISION_BY_ZERO")
    end
    return Ok(a / b)
end

let result: Result = safe_divide(10, 0)
if result.is_ok then
    print("Resultado: " + to_str(result.value))
else
    print("Erro: " + result.error)
end

Instalação e Uso

Pré-requisitos

  • Go 1.21 ou superior
  • Git

Instalação

# Clone o repositório
git clone https://github.com/estevaofon/noxy-vm.git
cd noxy-vm

# Compile o projeto
go build -o noxy ./cmd/noxy

Compilando Programas

# Execute o programa
./noxy programa.nx

# Ou via Go run
go run ./cmd/noxy/main.go programa.nx