In the syntax-analysis phase, a compiler verifies whether or not the tokens generated by the lexical analyzer are grouped according to the syntactic rules of the language. If the tokens in a string are grouped according to the language's rules of syntax, then the string of tokens generated by the lexical analyzer is accepted as a valid construct of the language; otherwise , an error handler is called. Hence, two issues are involved when designing the syntax-analysis phase of a compilation process:
All valid constructs of a programming language must be specified; and by using these specifications, a valid program is formed . That is, we form a specification of what tokens the lexical analyzer will return, and we specify in what manner these tokens are to be grouped so that the result of the grouping will be a valid construct of the language.
A suitable recognizer will be designed to recognize whether a string of tokens generated by the lexical analyzer is a valid construct or not.
Therefore, suitable notation must be used to specify the constructs of a language. The notation for the construct specifications should be compact, precise, and easy to understand. The syntax-structure specification for the programming language (i.e., the valid constructs of the language) uses context-free grammar (CFG), because for certain classes of grammar, we can automatically construct an efficient parser that determines if a source program is syntactically correct. Hence, CFG notation is required topic for study.