Skip to content

VoidbornGames/HumanScript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

HumanScript

An English-like programming language that compiles to native executables. HumanScript is designed for simplicity and readability, abstracting away complex syntax while providing core programming functionalities like variables, control flow, file operations, and system interaction.

๐Ÿš€ What's New in Version 3.0

Version 3.0 is a major evolutionary leap, transforming HumanScript into a truly powerful and modern scripting language while retaining its core philosophy of simplicity and readability.

1. Major Upgrade: Nim Backend

  • The most significant change is the complete shift from generating Assembly language to generating Nim. This is a massive architectural improvement.
  • Why Nim? It's a modern, high-performance, garbage-collected language with a Python-like syntax but C-like speed. It compiles to C, then to native code, giving us the best of all worlds: performance, safety, and portability.

2. Full-Featured Expressions

  • We can now support complex arithmetic expressions with proper operator precedence, just like Python, C#, or C++.
  • Example: set result to 10 plus 5 times 2; now correctly evaluates to 20 (multiplication happens before addition).

3. Nested Control Structures

  • A long-requested feature is finally here! You can now nest if, else, and repeat statements inside each other, and inside functions.
  • This allows for much more complex and powerful program logic, such as loops inside conditionals, or conditionals inside loops.
  • Example: A repeat loop that contains an if statement to break out of the loop under a certain condition.

4. File Reading

  • A new command read file "path.txt" and store it in variable has been added.
  • This allows your programs to read configuration files, process logs, or handle user-generated content from previous runs.

5. Robust Parser & Code Generation

  • The parser has been significantly refactored to handle nested structures and complex expressions gracefully.
  • The code generator now correctly translates all these new features into clean, efficient Nim code.

6. Modernized Syntax & Semantics

  • Blocks: All control structures (if, repeat, function) now use [ and ] for clear, C-style block delimiters instead of relying on indentation. This is more robust and familiar to programmers from other languages.
  • Semicolons: All statements now end with a semicolon ;, enforcing a clear and consistent statement structure.

7. Cross-Platform Foundation

  • By compiling to Nim and then to C, we are no longer limited to Windows-specific assembly tools. The same HumanScript compiler can now run on Linux and macOS and produce native executables for those platforms.

In short, version 3.0 transforms HumanScript from a simple toy language into a genuinely powerful and modern scripting language, while keeping its core goal of being human-readable.

  • Windows 10, 11, Server (2016+)

  • Linux (Ubuntu, Debian, CentOS, etc.)

  • macOS (10.12+)

Table of Contents

Features

๐ŸŒ English-like Syntax

Write code that reads like plain English, making it accessible to beginners and non-programmers.

  • Variables: define name as "John".

  • Printing: print "Hello, World!".

  • Comments: # This is a comment.

๐Ÿงฎ Variables & Operations

Work with numbers and strings using intuitive commands.

  • Arithmetic: add 5 to score. or set total to price plus tax.

  • String Concatenation: set full_name to first_name combined with last_name.

  • Type Conversion: turn age to text as age_text.

๐Ÿ”„ Control Flow

Implement logic with natural language conditions and loops.

  • Conditionals: if age is greater than 18:, else if:, else:

  • Loops: repeat 5 times ... ]

๐Ÿ–ฅ๏ธ System Interaction

Interact with the underlying operating system and other processes.

  • Run Processes: run process "notepad.exe".

  • File I/O: write "Log entry" to "C:\logs\app.log".

  • Pause Execution: wait for 3 seconds.

๐Ÿ”ง Functions

Organize your code into reusable blocks.

  • Define Function: define function named say_hello ... ]

  • Call Function: run function say_hello.

๐Ÿ“ Input/Output

Communicate with the user via the console.

  • Get Input: store console input in user_name.

  • Print Output: print "Welcome, ". print user_name.

Requirements

To compile HumanScript code, you need the following tools:

  • Windows/Linux/macOS (to run the compiler and the output)

  • .NET 8 SDK (to build the HumanScript compiler from source)

  • Nim Compiler (version 2.0+): For compiling the generated Nim code

  • GCC or MinGW (included with Nim installation): For C compilation backend

Note: The Nim compiler and GCC are automatically handled by the HumanScript compiler. No manual installation of assembly tools required!

Installation

  1. Clone the repository:

bash
Copy
Download
git clone https://github.com/your-username/HumanScript.git
cd HumanScript
  1. Install Nim (if not already installed):

    • Windows: Download from nim-lang.org

    • Linux: sudo apt install nim or use choosenim

    • macOS: brew install nim or use choosenim

  2. Compile the Compiler:

bash
Copy
Download
dotnet build

The compiled HumanScript.exe will be in the bin\Debug\net8.0 directory. You can copy it to the project root for convenience.

Getting Started

  1. Create a HumanScript file (e.g., hello.eng):

human
Copy
Download
# hello.eng
define message as "Hello from HumanScript!".
print message.
  1. Compile your script:

bash
Copy
Download
HumanScript.exe hello.eng
  1. Run the resulting executable:

bash
Copy
Download
hello.exe

Output:

text
Copy
Download
Hello from HumanScript!

Language Syntax

Here is a quick reference for the available commands in HumanScript.

Variables

human
Copy
Download
define my_number as 42.
define my_string as "This is a string".
define is_ready as true.

Arithmetic

human
Copy
Download
define counter as 0.
add 10 to counter.
subtract 5 from counter.
multiply counter by 2.
divide counter by 3.

Set variable to a result

set total to price plus tax. set result to base_value times multiplier.

Strings

human
Copy
Download
define first_name as "John".
define last_name as "Doe".
define full_name as "".

Concatenate strings

set full_name to first_name combined with last_name. print full_name. # Outputs: JohnDoe

Convert number to string

define age as 30. define age_text as "". turn age to text as age_text.

Control Flow

human
Copy
Download
define score as 85.

if score is greater than 90: print "Excellent!". else if score is greater than 70: print "Good job!". else: print "Keep trying".

repeat 3 times [ print "This will print 3 times". ]

Functions

human
Copy
Download
define function named greet
[
print "Hello there!".
]

Main program

print "Calling a function...". run function greet. print "Function finished.".

System & File Operations

human
Copy
Download
# Run an external program
run process "calc.exe".

Wait for 2 seconds

wait for 2 seconds.

Write a literal string to a file

write "Log entry at 10:00 AM" to "C:\temp\log.txt".

Write a variable to a file

define user_data as "User: Alice". write user_data to "C:\temp\users.txt".

How It Works

The HumanScript compiler translates your readable .eng file into a native executable through a streamlined process:

  1. Parsing: HumanScript.exe reads your .eng source file and validates the syntax.

  2. Code Generation: It generates clean Nim code, saving it as temp.nim.

  3. Compilation: It calls the Nim compiler to compile temp.nim into an optimized executable.

  4. Optimization: Nim compiles to C, which is then compiled to native machine code for maximum performance.

text
Copy
Download
Your Code (.eng) -> HumanScript Compiler -> Nim Code (.nim) -> Nim Compiler -> Executable (.exe)

Contributing

Contributions are welcome! If you have a feature request, bug report, or a pull request, please open an issue or submit a pull request.

  1. Fork the repository.

  2. Create a new branch (git checkout -b feature/amazing-feature).

  3. Commit your changes (git commit -m 'Add some amazing feature').

  4. Push to the branch (git push origin feature/amazing-feature).

  5. Open a Pull Request.

License

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

About

HumanScript is a simple, English-like programming language designed to be easily readable and writable by everyone.

Resources

License

Stars

Watchers

Forks