This repository contains a basic interpreter written in Dart. It includes a lexer, parser, and interpreter capable of handling simple arithmetic expressions, variable declarations, and print statements.
- Tokenizes input using a lexer.
- Parses expressions, including:
- Arithmetic operations:
+
,-
,*
,/
- String literals
- Variable declarations (
var
keyword) - Print statements (
print
keyword)
- Arithmetic operations:
- Supports basic syntax validation.
The interpreter expects a .dse
file as input. You can run the interpreter using the following command:
dart run bin/interpreter_app.dart
Place your .dse
file in the appropriate path (as defined in Paths.appPath
) and ensure the file has valid syntax. The interpreter will read the file, tokenize the content, parse the tokens, and execute the resulting commands.
var x = 10;
var y = 20;
print x + y;
print "Hello, World!";
Running interpreter for file: app.dse
30
Hello, World!
finished in 0.004s
- core/lexer.dart: Contains the
Lexer
class responsible for tokenizing the source code. - core/parser.dart: Contains the
Parser
class, which handles the parsing and interpreting of tokens. - lib/main.dart: Main entry point for running the interpreter.
- constants/path.dart: Provides file path constants.
Token | Description |
---|---|
number |
Integer literals |
plus |
+ operator |
minus |
- operator |
star |
* operator |
slash |
/ operator |
print |
Print statement |
identifier |
Variable names |
eof |
End of file |
qmark |
Question mark (not used) |
string |
String literals |
variable |
var keyword |
equals |
= assignment operator |
semicolon |
; statement terminator |
comment |
Comments (// style) |
The interpreter supports simple function definitions and invocations.
func testFunc = (a, b) {
print a;
print b;
};
testFunc(5, 3);
In this example, the function testFunc
takes two arguments, a
and b
, and print their one by one.
- Function definition using the
func
keyword. - Parameterized function calls.
- Dart SDK
Install the Dart SDK by following the instructions at https://dart.dev/get-dart.
Feel free to fork this repository and submit pull requests. Contributions, such as improvements to the interpreter, additional features, or bug fixes, are welcome.
There are currently no automated tests, but you can test the interpreter by writing .dse
files and running them with the interpreter.
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
The repository is hosted on GitHub. Clone it or explore the code here.