Skip to content

Latest commit

 

History

History
191 lines (146 loc) · 3.63 KB

SYNTAX.md

File metadata and controls

191 lines (146 loc) · 3.63 KB

Neit Programming Language Guide

Neit Requirements

Neit requires clang to be installed on your system for building code. However, clang is not required to run the code using the interpreter.


Neit Command Line Arguments

Neit provides a set of easy-to-use command-line arguments for efficient development.

Main Commands

  • run

    • Lexes, parses, (future) optimizes, and runs Neit code in the interpreter.
    • Example:
      neit run joy.nsc
  • build

    • Lexes, parses, generates C code, and builds it with clang.
    • Example:
      neit build joy.nsc

Options

  • -h or --help

    • Displays help details about commands and options.
    • Example:
      neit -h
  • -grammar=<file>

    • Specifies a grammar file for parsing. File extension does not matter.
    • Example:
      neit run joy.nsc -grammar=grammar.txt
  • -opt=<level>

    • Specifies the optimization level for code generation.
      • 1 – Least optimizations for minor speed improvements.
      • 2 – Moderate optimizations for a balance of speed and size.
      • 3 – Full optimizations for faster and smaller output.
      • 4 – Aggressive optimizations with longer compile times.
    • Example:
      neit build joy.nsc -opt=2
  • -static

    • Generates a statically linked binary.
    • Example:
      neit build joy.nsc -static
  • -o=<name>

    • Specifies the output file name (default: output).
    • Example:
      neit build joy.nsc -o=mybinary
  • -cls

    • Clears the screen before running code (applies to the run command).
    • Example:
      neit run joy.nsc -cls
  • -retain-c

    • Retains the generated C file after building.
    • Example:
      neit build joy.nsc -retain-c

Neit Syntax

Variable Declaration

  • Declare a string variable:

    may name = "joy"
    
  • Declare an integer variable:

    may age = 16
    
  • Declare a float variable:

    may height = 16.2
    
  • Refrence a variable to another variable:

    may name2 = name
    

Print Statements

  • Print normal text:

    print Hello world
    
  • Print the value of a variable:

    print {name}
    

Comments

  • Single-line comments use the # symbol:

    # This is a single-line comment
    print Hello
    
  • Multi-line comments use ## to begin and end:

    ## Multi-line comment example:
    This spans multiple lines ##
    

Input

  • Take input from the user:
    may name = takein()
    print {name}
    

Clear Screen

  • Clear the screen using the cls command:
    cls
    

Functions (Commands)

  • Define a command (function):

    cmd hi {
      (name:str) # Define parameters (currently ignored but required)
      println hi
    }
    

    please note that the arguments are optinal and they can be empty , just put ()

  • Call a command:

    call hi {"joy"}
    
  • If no arguments are required:

    call hi
    

Semigen Grammar

You can specify custom grammar rules to change commands. The format is:

<original_command> ~ <replacement>

Example:

print ~ say

This replaces print with say. You can now use say instead of print to output text, while still being able to use print.

Note: Only commands can be changed, not other syntax elements.