Compilers
What is done during syntax analysis (parsing) in a compiler?
- ARemoving whitespace and comments from the characters and splitting them into words
- BFinding frequently executed parts and converting them to machine code at run time
- CChecking the token sequence against the grammar and building the program structure as a tree
Show answer and explanation
Answer: C. Checking the token sequence against the grammar and building the program structure as a tree
Parsing checks whether the token sequence produced by lexical analysis follows the language grammar and builds structures, such as an if statement's condition and body or the operations inside an expression, into a tree (a syntax tree). Grammar errors such as a missing semicolon or mismatched parentheses are found here. Splitting into words while removing whitespace is lexical analysis, and converting to machine code at run time is JIT compilation.
- A. Splitting into words is lexical analysis.
- B. Run-time conversion is JIT compilation.
- C. Correct. It checks the grammar and builds the structure as a tree.