How to check syntax without evaluating the script?



is there method to check the syntax grammar without actually evaluating the script?
thank you in advance.


Extended and early detection of errors in scripts

I recently added this function (on develop branch currently) that allows you to parse and eval a script independently.

This is an example of doing it from within ChaiScript:


I tried this (the parse part) but an error in the script file does not seem to produce an exception. For example, I have a script that contains (among other stuff) a function like like this

def func1(int i)
puts (i + i);

where the ‘xxx’ is clearly bogus but running parse (and even evaluating it) against this script does not produce any exceptions. I don’t see a problem until I actually try to eval ‘func1’ itself.


That’s actually not “clearly bogus”

  • semicolons are not required in chaiscript
  • so xxx is seen as a statement in itself
  • ChaiScript does not require pre-declaration of identifiers
  • xxx might be a not-yet-defined global value or def'd function

The only way to know that func1 will fail in this case is to actually try to call it and see if xxx has been defined as something

If you did something that was actually a syntax error you’d see what you expect:

def func1(int i)
  puts (i+i);

(I added a colon, which has not place there).


Got it — unfortunately evaluating the function in advance is generally not feasible because it can actually “do” something that you don’t want to have happen until you’re ready.


I’ve been toying with the idea of a ‘compile’ function that would go and solidify the identifiers in a script, but I haven’t had the time yet to play with it.