Skip to content

The Minsk Compiler is a simple C# compiler designed for basic arithmetic expressions. It features lexical analysis, parsing, syntax tree generation, and interactive expression evaluation with parse tree visualization. Users can clone the repository, open it in Visual Studio, build and run the project to start evaluating expressions.

Notifications You must be signed in to change notification settings

MITTALBHAVYA/MINSK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minsk Compiler This project is a simple compiler written in C#. It includes a lexer, parser, syntax tree, and an evaluator for basic arithmetic expressions.

Features Lexical analysis Parsing Syntax tree generation Expression evaluation Parse tree visualization Supported Expressions The compiler currently supports basic arithmetic expressions involving:

Addition (+) Subtraction (-) Multiplication (*) Division (/) Parentheses for grouping (()) Usage Running the Compiler Clone the repository. Open the solution in Visual Studio or any other C# IDE. Build and run the project. Interactive Mode The compiler runs in an interactive mode. After running the program, you can type in arithmetic expressions to be evaluated.

Commands #showTree: Toggle the display of the parse tree. #cls: Clear the console. Example markdown Copy code

1 + 2 * 3 7

#showTree Showing parse trees.

1 + 2 * 3 └── BinaryExpression ├── NumberToken 1 ├── PlusToken + └── BinaryExpression ├── NumberToken 2 ├── StarToken * └── NumberToken 3 7 Code Overview Main Program The Main method in Program.cs handles reading user input, toggling the display of the parse tree, and evaluating expressions.

PrettyPrint The PrettyPrint method recursively prints the syntax tree for visualization.

Lexer The Lexer class is responsible for breaking the input text into a sequence of tokens.

Parser The Parser class processes the tokens produced by the lexer and constructs a syntax tree.

Syntax Tree The syntax tree is represented by various classes inheriting from SyntaxNode, including:

SyntaxToken ExpressionSyntax NumberExpressionSyntax BinaryExpressionSyntax ParenthesizedExpressionSyntax Evaluator The Evaluator class walks the syntax tree and computes the value of the expression.

Future Improvements Support for more complex expressions and additional operators. Improved error handling and diagnostics. Optimization passes on the syntax tree. Additional features such as variable assignments and functions. Contributing Contributions are welcome! Please fork the repository and submit pull requests. showcase License This project is licensed under the MIT License. See the LICENSE file for more details.

Acknowledgments Inspired by the Minsk series by @terrajobst.

About

The Minsk Compiler is a simple C# compiler designed for basic arithmetic expressions. It features lexical analysis, parsing, syntax tree generation, and interactive expression evaluation with parse tree visualization. Users can clone the repository, open it in Visual Studio, build and run the project to start evaluating expressions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages