Syntax-Checker

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

LGPL-2.1 License

Stars
6

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:

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:

Contribution

All code contribution are welcomed.