This project is a simple lexical and syntactical analyzer for a custom programming language. It performs lexical analysis to identify keywords, identifiers, constants, operators, and syntax analysis to validate the structure of the program.
- Lexical Analysis: Identifies keywords, identifiers, constants, and various operators.
- Syntax Analysis: Validates the structure of the program.
- Visual Feedback: Displays the analysis results in list boxes with color-coded highlighting.
- Error Detection: Highlights syntax errors with line and character position details.
- Interactive UI: Simple Windows Forms interface for input and output.
-
Clone the repository:
git clone https://github.com/tanvir-ahamed04/csharp-compiler.git
-
Open the solution in Visual Studio.
-
Restore the NuGet packages if any.
-
Build the solution to resolve dependencies.
-
Run the application in Visual Studio.
-
Input your program code in the provided text box.
-
Click the buttons to perform lexical and syntax analysis:
- Lexical Analysis: Click the
Analyze Lexically
button. - Syntax Analysis: Click the
Analyze Syntax
button.
- Lexical Analysis: Click the
-
The results will be displayed in the list boxes:
- The first list box will show the lexical analysis results.
- The second list box will show any syntax errors and the syntax analysis results.
-
Form1.cs: Main form containing the logic for lexical and syntax analysis.
-
Properties:
input_program
: Stores the input program code.input_pointer
,num
,text
,line_number
,char_position
: Various pointers and counters for analysis.identable
,constable
: Instances ofIdentable
andConstable
classes to store identifiers and constants.presentInput
: Stores the current input token.
-
Methods:
button1_Click
: Handles lexical analysis when the button is clicked.button2_Click
: Handles syntax analysis when the button is clicked.print
,output
: Helper methods to print messages in the list boxes.nextInput
: Retrieves the next token from the input program.match
,ParseProgram
,parseIdentifierList
, etc.: Methods for syntax analysis.
-
-
Identable.cs: Class to handle identifiers.
clear
,addidentifier
,dump
: Methods to manage identifiers.
-
Constable.cs: Class to handle constants.
clear
,add
,dump
: Methods to manage constants.
Contributions are welcome! Please fork this repository and submit pull requests with your improvements.
This project is licensed under the MIT License. See the LICENSE file for details.
This README file provides an overview of the project, its features, setup instructions, usage, code structure, and contribution guidelines.