Skip to content

Linguo is an experimental programming language designed to be as close to natural English as possible. It features a readable, English-like syntax while maintaining the power of a modern programming language.

Notifications You must be signed in to change notification settings

M-Husnain-Ali/Linguo-Compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Linguo Compiler 🚀

License: MIT C++: 17 LLVM: 19

Linguo is an experimental programming language designed to be as close to natural English as possible. It features a readable, English-like syntax while maintaining the power of a modern programming language.

remember greeting as "Hello, World!"
say greeting

🌟 Features

  • Natural English Syntax: Write code that reads like English sentences
  • Strong Type System: Implicit type inference with runtime type checking
  • Control Flow: Intuitive when/or/done conditionals and do this N times loops
  • Functions: Support for parameterized functions with return values
  • JIT Compilation: Uses LLVM for optimized Just-In-Time compilation
  • String Operations: Built-in string concatenation and manipulation
  • Arithmetic: Natural language arithmetic operations (increase, multiply by, etc.)

📋 Table of Contents

🔧 Installation

Prerequisites

  • LLVM 19 with development headers
  • Flex 2.6+
  • Bison 3.x
  • C++17 compiler

Ubuntu/Debian

sudo apt update
sudo apt install flex bison llvm-19 llvm-19-dev clang++

Windows

  1. Install LLVM 19
  2. Install MinGW or use WSL
  3. Add tools to your PATH

🚀 Quick Start

  1. Clone the repository

    git clone https://github.com/yourusername/linguo.git
    cd linguo
  2. Build the compiler

    mingw32-make  # on Windows
    # or
    make          # on Unix-like systems
  3. Run an example

    ./linguo examples/test.linguo

📖 Language Guide

Basic Syntax

// Variables
remember x as 42
remember greeting as "Hello!"

// Arithmetic
increase x by 5
multiply x by 2
divide x by 3

// Output
say x
say "Result: " + x

// Control Flow
when x is more than 10
    say "x is greater than 10"
done

// Loops
do this 3 times
    say "Loop iteration"
done

// Functions
create add a b
    remember result as a
    increase result by b
    give back result
end

🛠 Building from Source

  1. Generate lexer and parser

    flex linguo.l       # produces lex.yy.cpp
    bison -d linguo.y   # produces linguo.tab.cpp and linguo.tab.hpp
  2. Compile

    mingw32-make        # on Windows
    # or
    make                # on Unix-like systems
  3. Clean build files

    mingw32-make clean  # on Windows
    # or
    make clean          # on Unix-like systems

📝 Example Program

See our comprehensive example that demonstrates all language features:

// Basic variable declaration and output
remember greeting as "Welcome to Linguo!"
say greeting

// Arithmetic operations
remember x as 42
increase x by 8
multiply x by 2
say "Result: " + x

// Functions with parameters
create calculateAverage x y z
    remember sum as x
    increase sum by y
    increase sum by z
    remember average as sum
    divide average by 3
    give back average
end

// Function calls
remember avg as call calculateAverage with 15, 25, 35
say "Average is: " + avg

Find more examples in examples/test.linguo.

💻 Development

The compiler is structured into several components:

  • linguo.l: Flex lexical analyzer specification
  • linguo.y: Bison grammar and parser rules
  • ast.h: Abstract Syntax Tree definitions
  • codegen.cpp: LLVM IR generation and optimization
  • main.cpp: Compiler driver and CLI

🤝 Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

Please ensure your code follows our style guide and includes appropriate tests.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • LLVM Team for their excellent compiler infrastructure
  • The open-source community for inspiration and support

Made with ❤️ by Muhammad Husnain Ali

About

Linguo is an experimental programming language designed to be as close to natural English as possible. It features a readable, English-like syntax while maintaining the power of a modern programming language.

Topics

Resources

Stars

Watchers

Forks