(This is the older material - click here - for current specification content)

4. Syntactic Analysis (Parsing)

Once the input character stream (the source code) has been broken up into separate tokens by lexical analysis, another stage begins.

This stage is called syntactic analysis or 'parsing'.

Stage 1: Syntax Analysis

This phase analyses the syntax of the statements to ensure they conform to the rules of grammar for the computer language in question.

For example, many languages want to see an end-of-line marker of some kind, such as a semi-colon. If it is missing then syntax anlaysis adds an error comment to the compiler error report.

print file

should be

print file;

Another very common mistake is to miss the closing part of a loop statement like this

 For x = 1 to 10
   print file    

where the compiler is expecting to encounter a 'next x' statement at some point to mark the end of the loop code.

The proper format may be

    For x = 1 to 10
     print file;
Next x    

Stage 2: Semantic Analysis

Now that the syntax has been analysed, it is time to make sense of the relationships between tokens. This is called semantic analysis.

Syntactic analysis prepares the way to the final stage of a compiler namely code generation.

 

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: Syntactic Analysis

 

 

Copyright © www.teach-ict.com