Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hash3liZer/Syntax-Checker
A Simple Syntax Checker to check for basic errors in a file. Written in C++
https://github.com/hash3liZer/Syntax-Checker
Last synced: about 2 months ago
JSON representation
A Simple Syntax Checker to check for basic errors in a file. Written in C++
- Host: GitHub
- URL: https://github.com/hash3liZer/Syntax-Checker
- Owner: hash3liZer
- License: lgpl-2.1
- Created: 2020-12-17T17:33:33.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2020-12-23T12:27:34.000Z (over 3 years ago)
- Last Synced: 2024-07-08T16:40:11.372Z (2 months ago)
- Language: C++
- Size: 35.2 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Syntax-Checker
A versatile syntax checker written in C++. Checks for issues with keywords and brackets.
## Developers
## Syntax Check
Its a Semester Project built to correctly parse the `code` file and seperate keywords and brackets and checks for any mistake in the Syntax. Its highly versatile as it also would correctly parse each word or bracket separatly even if all the code is written in a single line. If any of the below condition would be True, the compilter would throw an error:
- If Imbalanced Brackets detected .e.g
[ [ {] } ]
- Code doesn't start with the keyword
begin
- Code doesn't end with the keyword
end
-
end
occurs without abegin
-
endif
occurs without anif
-
endfor
occurs without anfor
-
endwhile
occurs without anwhile
-
elseif
occurs without anif
-
else
occurs without anif
-
else
occurs two times - If brackets are not opened correctly like
begin{ {if int a; }endif }end
## File Parsing
One the main algorithms built in this project is correctly parsing all the lines given in the file. The code is given below. The following code will accept a string meaning, a line and the line number and separate each word found and the brackets and pass it to another function named `validate`. All this code is available in the syntax.cpp file.
```c++
void looper(string line, int line_counter) {
string converter = "";
for (int i = 0; i < line.length(); i++) {
if (!isalpha(line[i]) || i + 1 == line.length()) {
if (i + 1 == line.length()) {
if (isalpha(line[i])) {
converter += line[i];
validate(converter, line_counter);
}
else {
validate(converter, line_counter);
converter = line[i];
validate(converter, line_counter);
}
}
else {
validate(converter, line_counter);
converter = line[i];
validate(converter, line_counter);
}
converter = "";
}
else {
converter += line[i];
}
}
}
```
## Compilation
The code was compiled and tested on **Visual Studio Community Version 2019**. However, it would perfectly compile on previous versions as well. Tested upto version `2012`. After compilation you can supply direct file as an argument. If you don't, the program will interactively ask to provide the file:
## Contribution
All code contribution are welcomed.