Syntax analysis
As a programmer, you are probably already familiar with syntax error messages and the general idea of syntax, which is to understand what kinds of words or lexemes must appear, in what order, for a given communication to be well formed, which is to say grammatically correct, in a language. Most human languages are picky about this, while a few are very flexible about word order. Most programming languages are far simpler and more restrictive than natural human languages about what constitutes a legal input.
The input for syntax analysis consists of the output of the previous chapter on lexical analysis. Communication, such as a message or a program, is broken down into a sequence of component words and punctuation. This could be an array or list of token objects, although for parsing, all the algorithm requires is the sequence of integer codes returned from calls to yylex()
, one after another. It is the job of syntax analysis to determine whether the communication...