Also make sure you run it inside an event or function. The compiler should also give you the line number for the fail. I think it says line 3, 5 or something like that. If the statement isn't inside an event or function and the rest of the script is correct, the script will fail instantly and give back EOF error.
Everything that does something inside a script, with only the exception of declaring variables, has to be inside either an event or a function. Events are code blocks that listen for particular things that the game does and are the entry point for manipulating it with scripts. The OnMagicEffectStart in the code snippet of this post is an example of an event. It will fire whenever the magic effect starts being applied to the target.
Functions are code blocks that can be reused without needing to re-write all the pieces of it. For example, RemoveItem() is an event.
If your objective is to use a player's gold to cast something instead of, or in addition to, their magicka, there may be a better approach. I need to do some testing.