hash3liZer / Syntax-Checker

A Simple Syntax Checker to check for basic errors in a file. Written in C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Syntax-Checker

A versatile syntax checker written in C++. Checks for issues with keywords and brackets.

Syntax Checker Image Loading...

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 a begin
  • endif occurs without an if
  • endfor occurs without an for
  • endwhile occurs without an while
  • elseif occurs without an if
  • else occurs without an if
  • 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.

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:

Compiled File

Contribution

All code contribution are welcomed.

About

A Simple Syntax Checker to check for basic errors in a file. Written in C++

License:GNU Lesser General Public License v2.1


Languages

Language:C++ 100.0%