HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

A JASS2 Parser

03-29-2009, 08:22 PM#1
Zoxc
Here is my JASS parser which is designed to be used as a background syntax checker and parser. I though I should put it up here for some gentle testing

Command line options

JassParserCLI <options> <documents>
  • --implicit-reals and -ir: Reports implicit conversion from integer constants to reals.
  • --pjass: Emulate PJASS CLI.
  • --report-leaks: Reports memory leaks at shutdown.
  • --return-bug and -rb: This will emulate the return bug.
  • --help: Shows version and command line options.

Known bugs
  • Globals and types can be declared anywhere (intensional)
  • Variable shadowing does not work correctly with 1.24.

Version history

Hidden information:

Version 0.1.12
  • Classifies error messages and reports the error location more accurately.
  • Fixed: A bug where a operation involving a integer and a real would result in a integer.

Version 0.1.11
  • Better handling of undefined identifiers
  • Fixed: A string comparison bug

Version 0.1.10
  • Strong typechecking on return statements.

Version 0.1.9
  • Added a option to emulate the return bug. Return bug emulation is now off by default.

Version 0.1.8
  • Added checking for UTF-8 BOM
  • Fixed: Couldn't convert null to boolean
  • Fixed: \" wasn't valid in strings

Version 0.1.7
  • Added a help command line options
  • Fixed: Reals needed numbers behind the separator if it didn't start with 0

Version 0.1.6
  • Added detection for implicit conversion from integer constant to reals
  • Fixed: Numbers couldn't be followed by an identifier
  • Fixed: Non-constant natives couldn't be used in constant expressions

Version 0.1.5
  • Better parsing of unknown functions
  • Fixed: Uninitialized variables could be used in their first assignment
  • Fixed: Global code arrays were allowed
  • Fixed: Code function with parameters didn't report an error
  • Fixed: Unknown characters on a new line had the wrong line number

Version 0.1.4
  • Fixed: Symbols from another file could be redeclared

Version 0.1.3
  • Emulated the return bug
  • Fixed: Parameters couldn't be used in constant funcitons

Version 0.1.2
  • Checks for uninitialized variables
  • Checks if functions used as code has parameters
  • Checks for constant locals
  • Checks for returns instead of return
  • Removed vJASS keywords
  • Fixed: A stack overflow with !
  • Fixed: Strings made the column index in errors wrong
  • Fixed: Checks for variable assignments in constant functions
  • Fixed: Local variables can't have the same name as function or global array
  • Fixed: Constants couldn't be in derived base-types
  • Fixed: Variables could be used in their initializers
  • Fixed: Arrays could have initializers
  • Fixed: No errors if variables had an array index or not
  • Fixed: Functions can't be in global variable initializers
  • Fixed: Non-constant functions can't be in constant functions
  • Fixed: Functions can't be in it's own local variable initializers
  • Fixed: No return was needed function with a return type

Version 0.1.1
  • Typechecking added
  • Fixed: Local variables could be declared anywhere
  • Fixed: Recursive function weren't allowed

Version 0.1
  • Parses blizzard.j without errors


You can find the latest source here: http://github.com/Zoxc/JassParser
Attached Files
File type: 7zJassParser_0.1.5.7z (813.6 KB)
File type: 7zJassParserCLI_0.1.12.7z (43.6 KB)
03-29-2009, 09:49 PM#2
peq
The error messages seam to be better understandable than Pjass.

However I found one error when parsing my map script.

Collapse JASS:
if this==null then
this line is generated by jasshelper and "this" is an integer. Pjass allows this but your tool throws an error.

Maybe you could also add a check for uninitialized variables, so something like this should throw an error:
Collapse JASS:
function stupid takes nothing returns nothing
  local integer i 
  call doSomethingWith(i) // i used without initialisation
endfunction
03-30-2009, 05:15 PM#3
Barade
Source code?
03-30-2009, 06:15 PM#4
C2H3NaO2
Is it portable?
Can we use it without gui in scripts?
Should there be syntax errors in the demo?

edit: You haven't written the parse part by hand?
Collapse JASS:
function t takes nothing returns nothing
    if 1==0then
    endif
endfunction
does not work, but it is correct jass code. (afaik only adolf used it ^^)
03-30-2009, 06:28 PM#5
Zoxc
Quote:
Originally Posted by C2H3NaO2
Is it portable?
Yes, with a simple port to freepascal

Quote:
Originally Posted by C2H3NaO2
Can we use it without gui in scripts?
Not yet.

Quote:
Originally Posted by C2H3NaO2
Should there be syntax errors in the demo?
Plenty of 'em.

Quote:
Originally Posted by C2H3NaO2
You haven't written the parse part by hand?
I have :)

Quote:
Originally Posted by C2H3NaO2
Collapse JASS:
function t takes nothing returns nothing
    if 1==0then
    endif
endfunction
does not work, but it is correct jass code. (afaik only adolf used it ^^)
Fuck blizzard :)

I updated the parser with most of the complaints I found in the PJASS thread.
03-31-2009, 04:45 PM#6
Zoxc
Here is version 0.1.3. Now it handles the return bug and has a pjass compatible command line interface. Simply replace the pjass.exe you were using with JassParserCLI.exe.
04-04-2009, 02:29 AM#7
Vexorian
Line numbers sometimes get off-by-one errors like in this blizzard.j:
Attached Files
File type: zipBlizzard.j.zip (58.0 KB)
04-04-2009, 09:09 AM#8
Skater
Bugreport:

Collapse JASS:
globals
    code array cc //this gives no error
endglobals

function bla takes nothing returns nothing
endfunction

function test takes nothing returns nothing
    call TriggerAddCondition(CreateTrigger(), Condition(function bla)) //this gives no error
endfunction
04-04-2009, 11:13 AM#9
Deaod
the second bug is no bug.
04-04-2009, 11:28 AM#10
peq
it is a bug, bla has to return a boolean.
---
It is really nice you added the Checks for uninitialized variables but it could still be better. This two functions give no error:

Collapse JASS:
function foo takes nothing returns nothing
    local integer i
    set i = i + 1
endfunction

function bar takes nothing returns integer
    local integer i
    if false then
        set i = 5
    endif
    return i
endfunction
04-04-2009, 11:36 AM#11
Deaod
It should, but it doesnt have to. Returning no boolean is fine, as long as noone with a Mac plays your map.
04-04-2009, 12:12 PM#12
akolyt0r
Quote:
Originally Posted by peq
...

Collapse JASS:
function bar takes nothing returns integer
    local integer i
    if false then
        set i = 5
    endif
    return i
endfunction

that example would be really hard to implement .as you wont have a simple "false", but some real condition there normally ..and parser cant check usually if that condition will come true.
But still it should display a warning that some code paths can return non-initialized-shit
04-04-2009, 01:15 PM#13
Vexorian
Quote:
Originally Posted by akolyt0r
that example would be really hard to implement .as you wont have a simple "false", but some real condition there normally ..and parser cant check usually if that condition will come true.
But still it should display a warning that some code paths can return non-initialized-shit
It shouldn't matter whether the condition is false or not, normally uninitialized var parsers react to code like that giving an error.
04-04-2009, 02:08 PM#14
akolyt0r
Ah true ...
Well pretty much true ...Visual Studio C# throws an error for this aswell ...
but Visual Studio C++ doesnt ...but Oh'well ..Visual Studio C++ sucks anyways..
04-04-2009, 04:20 PM#15
Zoxc
Fixed some stuff. The uninitialized variable thing is really just a simple flag designed to catch the most primitive errors. The Condition/Filter thing is more or less a WC3 bug and would require special handling, maybe I'll add it later.