How to Fix Syntax Errors

By Dan Stone

Fixing syntax errors is essential in computer programming: the program will not work until the errors are corrected. Syntax errors mean the program can't understand commands based on the programming language's rules. In programming, syntax refers to proper command arrangement (like rules of grammar) and spelling. Programmers can resolve syntax errors with the help of Interactive Development Environment debug tools and manual code-checking best practices.

Misplaced and Missing Punctuation

Punctuation symbols tell the system where commands end, how code is grouped together and how to call different parts of the code. IDE debugging efficiently catches misplaced and missing punctuation errors. While different programming languages have a wide-range of different punctuation uses, there are general rules to guide you. For example, ending a line of code with a colon instead of a semicolon in the C++ programming language is an incorrect character and causes a syntax error.

Containing Commands with Punctuation

Languages like Java and JavaScript use parentheses and brackets to explain how code fits together. The program will not be able to understand the command if all parentheses and brackets don't feature matching opening and closing characters. Quotation marks can also cause problems when incorrectly used or missing. For example, if you're using a quotation mark within a text string designated by quotation marks, you need to use an escape sequence on the internal quotation mark or else the program will end the string at an incorrect point. While the IDE may identify what line of code has the syntax error, the programmer can use single-step tracing to look at where each enclosure begins and ends to locate the error.

Out-of-Date Code

Programming languages can be updated to new standards -- which includes removing existing commands. If you're running older code against a program using an updated code interpretation standard you may encounter syntax errors for antiquated commands. For example, prior to Internet Explorer 10 the browser could use JavaScript display effect commands called "DX Filters." If you run code that uses DX Filters on IE 9 the code will work, whereas if you run it on IE 10 it won't work. Use updated, supported programming techniques to replace out-of-date code.

Improperly Used Commands

The IDE debugging system easily identifies incorrectly used commands. For example, the program will have a syntax error if you have a number that's stored as a string like "22" and try to add another number to it. The program treats strings, even if they are numbers, as text. While the IDE will identify where the number and string are added together, the programmer needs to trace the code backwards to determine where the string became a string.

Invalid Variable and Function Names

Programming languages that are structured around variables (assigned values) and functions (called code groups) will encounter syntax errors when either data type is used incorrectly. The variable could be set as a string when it should be an integer or a function could be named after a language-reserved command name. Additionally, each language has unique naming rules for what variables and functions can be named such as acceptable character types, case sensitivity, and initial character limitations. For example, the PHP language will not allow variable names to begin with a number.