Version

Syntax Errors (Syntax Parsing Engine)

Topic Overview

Purpose

This topic explains the syntax errors found by the Syntax Parsing Engine.

Required background

The following topics are prerequisites to understanding this topic:

Topic Purpose

This topic provides an overview of the Syntax Parsing Engine.

This topic provides an overview of the Syntax Parsing Engine’s Grammar.

The topics in this group explain the lexical analysis performed by the Syntax Parsing Engine.

This topic explains the syntax analysis performed by the Syntax Parsing Engine.

In this topic

This topic contains the following sections:

Syntax Errors

Overview

Syntax errors occur when the text in a document being analyzed does not conform to the required structure defined by the grammar. Syntax error detection is more complicated than lexical error detection because the analyzer not only needs to make the best guess about what the problem might be, but it also needs to make the best guess about what the solution might be so it can provide meaningful error messages.

Example

Example productions for a non-terminal symbol named VariableDeclarationStatement:

VariableDeclarationStatement → Type IdentifierToken SemicolonToken

VariableDeclarationStatement → Type IdentifierToken EqualsToken Expression SemicolonToken

VariableDeclarationStatement → VarKeyword IdentifierToken EqualsToken Expression SemicolonToken

Document content to be parsed: "int x = ;"

During lexical analysis the following significant tokens will be produced:

  • <IdentifierToken, "int">;

  • <IdentifierToken, "x">;

  • <EqualsToken, "=">;

  • <SemicolonToken, ";">;

The Syntax Parsing Engine will start syntax analyzing the significant tokens and when it gets to the "SemicolonToken" it will assume an error is found because none of the above production bodies match the processed tokens. The Syntax Parsing Engine will try to figure out what is either missing from the text or not supposed to be there. To do this the parser determines all possible productions that can be built in the current state and tries to match all of them with the tokens parsed.

Note
Note

At this point the first "IdentifierToken" has been reduced to a Type non-terminal symbol, because of the context in which it is used.

It is clear that the first production is not the one that should be created, because that production has a semicolon immediately after the identifier (and not an equal sign as in the example text). Also it is clear that the third production is not the one to be created, because that production starts with a "var" keyword. In this case the only possible production is the second and based on its definition it is clear that the error in this case is a missing expression.

Related Content

Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic explains the lexical errors found by the Syntax Parsing Engine.

The topics in this group explain the strategies used during the syntax analyzing of the document to identify syntax errors.

This topic explains semantic errors, which are not handled by the Syntax Parsing Engine.