SharpScript is a custom programming language interpreter built in C, designed to provide a simple yet powerful scripting environment with modern language features. This project includes a complete interpreter implementation along with development tools and examples.
- Overview
- Features
- Architecture
- Installation
- Usage
- Language Syntax
- Examples
- Development Tools
- Testing
- Contributing
- License
- Documentation
SharpScript is an interpreted programming language that combines the simplicity of scripting languages with structured programming concepts. The interpreter is written in C and provides a complete development environment including lexical analysis, parsing, interpretation, and memory management.
The language supports variables, functions, control structures, namespaces, and built-in system functions for input/output operations. The project also includes additional tools like a web-based calculator and syntax highlighter.
- Variables: Declaration and assignment with type inference
- Functions: User-defined functions with parameters and return values
- Control Structures: If-else statements, loops, and conditional logic
- Namespaces: Organize code into logical modules
- Comments: Single-line comments using
#syntax - Error Handling: Built-in error and warning system functions
- Interactive REPL: Read-Eval-Print Loop for interactive development
- File Execution: Run SharpScript files with
.spsextension - Memory Management: Automatic memory allocation and cleanup
- Error Reporting: Detailed error messages with line information
- Cross-Platform: Designed for Windows 10/11 with MinGW32
- Web Calculator: Browser-based calculator with SharpScript integration
- Syntax Highlighter: Code highlighting for SharpScript syntax
- Built-in Functions: Mathematical operations, I/O operations, and utility functions
The SharpScript interpreter follows a traditional compiler architecture with the following components:
- Tokenizes source code into meaningful symbols
- Handles keywords, identifiers, operators, and literals
- Provides error handling for invalid tokens
- Builds Abstract Syntax Trees (AST) from tokens
- Implements recursive descent parsing
- Validates syntax and semantic rules
- Defines the structure of parsed code
- Represents program elements as tree nodes
- Enables semantic analysis and interpretation
- Executes the AST nodes
- Manages variable scopes and function calls
- Handles control flow and built-in operations
- Implements dynamic memory allocation
- Provides garbage collection mechanisms
- Manages string and object lifecycle
The interpreter includes several built-in system functions:
system.output(expression); # Print output to console
system.error(message); # Display error message
system.warning(message); # Display warning message
- Windows 10/11 operating system
- MinGW32 compiler toolchain
- Make utility (mingw32-make)
-
Clone the repository:
git clone https://github.com/yourusername/sharpscript.git cd sharpscript -
Build the interpreter:
mingw32-make
-
Verify installation:
./obj/bin/sharpscript.exe --help
The project uses a Makefile-based build system optimized for Windows:
- Compiler: GCC with MinGW32
- Flags: Wall, Wextra, C99 standard
- Output: Executable in
obj/bin/sharpscript.exe
Start the interactive interpreter:
sharpscriptIn REPL mode, you can:
- Type SharpScript expressions directly
- Test language features interactively
- Get immediate feedback on syntax and execution
Run a SharpScript file:
sharpscript script.sharpDisplay help information:
sharpscript --helpSharpScript uses explicit variable declaration with the &insert keyword:
&insert x = 10;
&insert name = "Hello World";
&insert pi = 3.14159;
Define functions using the function keyword:
function greet(void) {
system.output("Hello from SharpScript!");
}
function add(a, b) {
&insert result = a + b;
return result;
}
&insert x = 5;
if (x > 3) {
system.output("x is large");
} else {
system.error("x too small");
}
Single-line comments use the # character:
# This is a comment
&insert x = 10; # This is also a comment
Built-in system functions for I/O operations:
system.output("Hello World"); # Print to console
system.error("Error message"); # Display error
system.warning("Warning message"); # Display warning
# Simple SharpScript program
&insert x = 5;
function main(void) {
system.output(x);
if (x > 3) {
system.warning("x is large");
} else {
system.error("x too small");
}
}
&insert radius = 5;
&insert area = 3.14159 * radius * radius;
system.output("Area of circle: ");
system.output(area);
function calculate_area(radius) {
&insert pi = 3.14159;
&insert area = pi * radius * radius;
return area;
}
&insert result = calculate_area(10);
system.output("Area: ");
system.output(result);
The project includes a web-based calculator with SharpScript integration:
- Location:
tools/calculator/ - Features: Basic arithmetic, scientific functions, unit conversion
- Natural Language: Support for natural language input
- Multi-language: UI available in multiple languages
Usage:
- Open
tools/calculator/index.htmlin a web browser - Type expressions or natural language commands
- Use keyboard shortcuts for common operations
A web-based syntax highlighter for SharpScript code:
- Location:
tools/highlighter/ - Features: Syntax highlighting for SharpScript syntax
- Integration: Can be embedded in web applications
The project includes comprehensive test cases in the tests/ directory:
- Syntax Tests: Validation of language syntax
- Function Tests: Testing built-in and user functions
- Memory Tests: Memory management and garbage collection
- Error Handling: Error and warning system tests
- Namespace Tests: Namespace and scope testing
Execute test files using the interpreter:
sharpscript tests/help.sharp
sharpscript tests/math_functions.sharp
sharpscript tests/memory_functions.sharphelp.sharp: Tests help system functionalitymath_functions.sharp: Mathematical operations testingmemory_functions.sharp: Memory management testsnamespace_function_call.sharp: Namespace functionalityunit_convert.sharp: Unit conversion features
sharpscript/
├── src/ # Source code
│ ├── include/ # Header files
│ ├── builtins/ # Built-in functions
│ ├── lib/ # Library files
│ ├── main.c # Main entry point
│ ├── lexer.c # Lexical analyzer
│ ├── parser.c # Syntax parser
│ ├── interpreter.c # Code interpreter
│ ├── ast.c # Abstract syntax tree
│ └── memory.c # Memory management
├── examples/ # Example SharpScript files
├── tests/ # Test files
├── docs/ # Documentation
├── tools/ # Development tools
│ ├── calculator/ # Web calculator
│ └── highlighter/ # Syntax highlighter
├── obj/ # Build output
└── .vscode/ # VS Code configuration
We welcome contributions to the SharpScript project! Please see CONTRIBUTING.md for guidelines on:
- Code style and conventions
- Submitting issues and pull requests
- Development workflow
- Testing requirements
For security concerns and vulnerability reporting, please see SECURITY.md for our security policy and reporting procedures.
This project is licensed under the MIT License. See the LICENSE file for details.
For version history and changes, see CHANGELOG.md.
Additional documentation is available in the docs/ directory:
- Developer Guide: Technical implementation details
- User Guide: User-focused documentation
For questions, issues, or contributions:
- Create an issue in the GitHub repository
- Check existing documentation in the
docs/directory - Review test files in the
tests/directory for usage examples
SharpScript - A modern scripting language with simplicity and power combined.