How to Fix Parsing Errors and Unexpected Symbol Errors

Fix Parsing Errors and Unexpected Symbol Errors

Particularly if you’re new to programming, you’ll probably see a lot of parsing errors and unexpected symbol errors. Fortunately, while irritating to see, they are among some of the easiest programming errors to solve. Here is how to fix parsing errors and unexpected symbol errors in Unity, C#, and pretty much all other forms of programming.

What are Parsing and Unexpected Symbol Errors?

In layman’s terms, parsing errors and unexpected symbol errors mean you have either added or omitted extra syntax. Usually, it can be traced to one of three things:

  1.  You have added or removed an extra semicolon – ;
  2. You have added or removed an extra parenthesis – ()
  3. You have added or removed an extra squiggly parenthesis {}

There are other reasons why this particular error may occur, such as incorrectly using operations like greater than, less than, or adding or subtracting variable values. However, it’s more likely the source of your error can be traced to one of the above reasons.

Having just one too many or few of any of these can throw your entire script out of whack. Like Goldilocks and the Three Bears, it has to be juuuuuuuuuuuuust right.

So how can you quickly catch and detect these errors?

error message

A console error message in Unity

How Can You Fix Them?

The easiest way to fix a parsing error or unexpected symbol error is simply to double-click on the error message as it appears in the console. This will take you directly to the portion of the code giving you a problem.

For instance, if I were to double-click on the error message from the above screenshot, it would take me to line 27 in Monodevelop, which has “DontDestroyOnLoad” highlighted with a red squiggly line.

Missing Semicolon

The error in Monodevelop

There is nothing wrong with this line of code, however, if you look directly above, you will see there is no semicolon after instance = this. Once a semicolon is added, the problem is solved!

Alternatively…

Another very simple way of detecting and fixing a parsing error or unexpected symbol error is to press CTRL+F while in Monodevelop, and search for missing syntax. This can be particularly helpful if you have multiple errors or are dealing with a larger script.

Take a look at the sample code I’ve pasted below. As a challenge, use CTRL+F to see if you can detect the errors within. As a hint, I’ve created two errors. In one instance, I’ve added something extra, and in another, I’ve omitted something. See if you can figure out what’s wrong.

Did you figure it out?

If not – here’s the answer. On line 23 there is an extra ) bracket after if (instance != null));

The second error is a bit trickier to spot, but there is no closing squiggly bracket } for the if statement on line 40.

Using CTRL+F and checking individually to see if there are an equal number of brackets, these errors would not be too difficult to catch.

Hopefully, this information gives you a better idea of how to catch and fix parsing errors and unexpected symbol errors on your own. If you still need help, check out our sample video below, which will guide you through all of this in detail.

By | 2017-06-26T01:54:38+00:00 June 22nd, 2017|Tutorials|Comments Off on How to Fix Parsing Errors and Unexpected Symbol Errors

About the Author:

Jonathan is the Executive Producer at Wild Cockatiel Games. He's an avid gamer and currently loves playing Overwatch. He's also an author seeking publication for his YA fantasy novel, Elementalists: The Fires of Canicus.