QSP Syntax analyzer

Chimrod be88ac9588 Added the 'local' keyword 4 ay önce
bin baa258ac91 New test for duplicates evalutations in the code 8 ay önce
documentation 6c7c12803b Documentation update 10 ay önce
lib be88ac9588 Added the 'local' keyword 3 ay önce
test be88ac9588 Added the 'local' keyword 3 ay önce
tools e8b746742f Update the compilation rule for git hash inclusion 1 yıl önce
.gitignore 97ab5c9a21 Moved qparser and syntax in the library folder 1 yıl önce
dune-project 9bb8792a68 Update the project dependencies 9 ay önce
readme.md 14504f36b6 Update the readme as well 8 ay önce

readme.md

QSP Syntax Parser

This tool is a syntax analyzer for the QSP Language. It contains a syntaxic parser able to read the QSP language, and allow some analysis over it.

The application does not use regexes, but translates the source qsp file using a grammar to represent each instruction.

Command line

qsp_parser.exe input_file
  --version     Display the version of the application and exit
  --list-tests  Print all the available tests then exit
  --level       Filter with this message level [debug, warn, error]
  --global      Each line is refered from the begining of the file and not the location
  -<test>       Disable this test
  +<test>       Enable this test
  -help         Display this list of options
  --help        Display this list of options     Display this list of options

You can run the application by giving in argument the file to analyze: the results will be printed in the standard output:

 qsp_parser.exe test.qsrc 
 Location test                         
 [{ level = Warn; loc = Line 3 19:27;
    message = "The type Integer is expected but got String" };
   { level = Debug; loc = Line 4 26:30;
     message = "The type Integer is expected but got String" };
   { level = Debug; loc = Line 5 8:45;
     message = "Possible dead end (no else fallback)" };
   { level = Warn; loc = Lines 13-15;
     message = "Possible dead end (unmatched path)" }
   ]
Found 0 error(s), 2 warning(s)

Return code

The application will return the code 0 when all the tests are passed without errors, warnings or debug report and 1 otherwise.

Checks provided

I will take this small code as example. The output of the analysis is given just above:

# test
                                                ! Warning here, $ARGS expect a string
if $ARGS[1] = 0 or $ARGS[1] = 1:
        act 'action':  value = '123'            &! value is a numeric variable
        if value = 2: act 'other': gt 'other'   &! Dead end here if value ≠ 2
else
        act 'Action2': gt 'arg', 'arg1'
end

act 'Go':
    if 0:
        act 'Leave': gt 'begin'
    else
        act 'Label': 'Action'                   &! Dead end here
    end
end

--- test ---------------------------------

Type checking

The QSP language uses explicit variable name for string or numeric values and you can easily spot when a string value is used instead of a numeric.

Dead end

By analysing the branchs, the application can spot the block where no gt instructions are given, which can lead to dead end in the code.

Escaped string

The application will report text strings containing only one expression with a debug message.

For example "<<$variable>>" can be written directly: $variable>. This test will not report this usage when an integer converted into a string this way.

Duplicated test

In a single if branch, check if the same is repeated more than one once. In this case, only the first case is executed and the other test is ignored.

A warining will be raised here:

if $value = '1': 
    ! Do something
elseif $value = '1':
    ! Do something else
end