Skip to content

Commit

Permalink
Merge pull request #3 from Denis-Olejnik/dev
Browse files Browse the repository at this point in the history
Updated README
  • Loading branch information
DenisOlejnik authored Jan 5, 2023
2 parents 5da8a10 + 9e40bed commit da4d02d
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 61 deletions.
34 changes: 19 additions & 15 deletions MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 23 additions & 24 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,37 @@ namespace LexicalAnalyzer
{
public partial class MainForm : Form
{
private const bool DEV_MODE = true;
private const bool DEV_MODE = false;
private bool syntaxTreeIsExpanded = false;

private ArrayList list = new ArrayList();

public MainForm()
{
InitializeComponent();

if (DEV_MODE)
{
textBox_FilePath.Text = "X:\\Dev\\Projects\\GUMRF\\LexicalAnalyzer\\Tests\\Normal code Simple.txt";
if (File.Exists(textBox_FilePath.Text))
try
{
using (StreamReader reader = new StreamReader(textBox_FilePath.Text))
textBox_FilePath.Text = "X:\\Dev\\Projects\\GUMRF\\LexicalAnalyzer\\Samples\\Sample 3.txt";
if (File.Exists(textBox_FilePath.Text))
{
string fileContent = reader.ReadToEnd();
textBox_FileViewer.Text = fileContent;
}
using (StreamReader reader = new StreamReader(textBox_FilePath.Text))
{
string fileContent = reader.ReadToEnd();
textBox_FileViewer.Text = fileContent;
}

fillTabsContent();
fillTabsContent();
}
else throw new FileNotFoundException($"The following file was not found: \n{textBox_FilePath.Text}!");
}
catch (FileNotFoundException fileNotFound)
{
MessageBox.Show(fileNotFound.Message, "File not found!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, this.GetType().Name, MessageBoxButtons.OK);
}
}
}
Expand Down Expand Up @@ -63,7 +73,6 @@ private void button_openFile_Click(object sender, EventArgs e)
catch (FileNotFoundException fileNotFound)
{
MessageBox.Show(fileNotFound.Message, "File not found!", MessageBoxButtons.OK);
throw;
}
catch (Exception exception)
{
Expand Down Expand Up @@ -95,24 +104,14 @@ private void button_ShowDeepestTreeView_Click(object sender, EventArgs e)
{
try
{
GetDeeperLevel(SyntaxTreeView?.Nodes[0]);
list.Sort();
throw new NotImplementedException();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, this.GetType().Name, MessageBoxButtons.OK);
}
}

private void GetDeeperLevel(TreeNode node)
{
for (int i = 0; i < node.Nodes.Count; i++)
{
GetDeeperLevel(node.Nodes[i]);
list.Add(node.Nodes[i].Level);
}
}

private void textBox_FilePath_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (Int32)(Keys.Enter))
Expand Down Expand Up @@ -153,6 +152,7 @@ private void fillTabsContent()

// Build a syntax tree
parser.GenerateAbstractSyntaxTree(SyntaxTreeView, lexicList);
syntaxTreeIsExpanded = false;
}

private void button_RegenerateTreeView_Click(object sender, EventArgs e)
Expand All @@ -166,8 +166,7 @@ private void button_RegenerateTreeView_Click(object sender, EventArgs e)
}

fillTabsContent();
SyntaxTreeView?.ExpandAll();
syntaxTreeIsExpanded = true;
button_ToggleTreeViewVisib_Click(sender, e);
}

}
Expand Down
43 changes: 33 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
# Lexical analyzer

The program performs lexical analysis of a program written in the Pascal programming language.
The program implements lexical and syntactic parsers. The program is written for code that is very similar to Pascal (PascalABC).

![OnStartupPic](/readme/LexicalAnalyzer_OnStartup.png?raw=true)
### Implemented features
- Lexical analyzer
- Syntax analyzer
- Basic error search (Unknown type/value)

![ReadsFilePic](/readme/LexicalAnalyzer_ReadsFile.png?raw=true)

![LexicalTablePic](/readme/LexicalAnalyzer_LexicalTable.png?raw=true)

![ErrorExamplePic](/readme/LexicalAnalyzer_ErrorExample.png?raw=true)
### Implemented lexems
- Variable ("true" and "true1" are different)
- States (true, false)
- Separators (';' does not equal ':')

## Not implemented:
- Search for errors in the logic or spelling of lexemes
- Floating point number detection
- Arrays[]
- ...
- A lot of other things.
- Arrays []
- Loops (for, while, etc)
- A lot of other things.

## Screenshots
![Program startup](/readme/0_Startup.png)

![Source file example](/readme/1_SourceFileExample.png)

![Lexical table example](/readme/2_LexicalTableExample.png)

![Syntax tree example](/readme/3_SyntaxTreeExample.png)

![Error example](/readme/4_ErrorExample.png)

This abstract syntax tree is based on the file ```\Samples\Sample 2.txt```
![Abstract syntax tree for Sample code #1](/readme/_AbstractSyntaxTree.png)


## License

[MIT](https://choosealicense.com/licenses/mit/)

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file removed Tests/AST.png
Binary file not shown.
12 changes: 0 additions & 12 deletions Tests/Normal code - Binary.txt

This file was deleted.

Binary file removed Tests/PriorityTable.drawio.png
Binary file not shown.
Binary file added readme/0_Startup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added readme/1_SourceFileExample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added readme/2_LexicalTableExample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added readme/3_SyntaxTreeExample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added readme/4_ErrorExample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed readme/LexicalAnalyzer_ErrorExample.png
Binary file not shown.
Binary file removed readme/LexicalAnalyzer_LexicalTable.png
Binary file not shown.
Binary file removed readme/LexicalAnalyzer_OnStartup.png
Binary file not shown.
Binary file removed readme/LexicalAnalyzer_ReadsFile.png
Binary file not shown.
File renamed without changes

0 comments on commit da4d02d

Please sign in to comment.