Jump to content
LordGolias

SQF parser and static analyser

Recommended Posts

I am presenting to the world a parser, static analyzer, and interpreter of SQF, along with a front-end for using it in Atom. Here is an example of what you get on your screen.

 

In a nutshell, the backend parses SQF code in Atom and spits errors back to the interface. It currently supports most of the basic functionality like

 

* assignment, private, params, global variables, and scopes

* math, comparison and logic operators

* control operators (if, switch, for, while, etc.)

 

The code is available here:

 

This is WIP but I believe that it can already help people identifying issues in the code, avoiding the frustration of finding small errors by restarting the mission in the Editor, etc. In the long term, this has the potential of becoming the de-facto static analyzer of SQF.

It was tested in Atom installed both in MacOS and Windows 10 (with powerShell).

 

For the experts: this is not an ad-hoc solution to the problem; it uses a proper parser that builds a lexical tree of SQF statements. The backend is extremely powerful and very well maintained (99% of test-covered), and allows for very complex stuff like running SQF code in an emulated environment:

from sqf.interpreter import interpret
interpreter, outcome = interpret('_x = [1, 2]; _y = _x; reverse _y;')
# outcome equals to "Nothing"
# interpreter['_x'] equals to Array([Number(2), Number(1)])
# interpreter['_y'] equals to Array([Number(2), Number(1)])

The static analyzer does not use the interpreter and thus cannot detect syntactic errors that can only be resolved at run-time, but it does a pretty decent amount of syntax checking (including missing privates).

 

Help on this endeavor is obviously highly appreciated!

  • Like 6

Share this post


Link to post
Share on other sites

I was looking through your code and noticed that there is no grammar file. Did you write your parser by hand? Kudos on this by the way.

Share this post


Link to post
Share on other sites
44 minutes ago, K-Town said:

I was looking through your code and noticed that there is no grammar file. Did you write your parser by hand? Kudos on this by the way.

 

yes, I wrote the parser myself. Thanks!

Share this post


Link to post
Share on other sites
Just now, LordGolias said:

 

yes, I wrote the parser myself. Thanks!

You are a brave soul. ;)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×