Compilers

What is done during syntax analysis (parsing) in a compiler?

  1. ARemoving whitespace and comments from the characters and splitting them into words
  2. BFinding frequently executed parts and converting them to machine code at run time
  3. 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.
Practice this topic Back to topic

More Compilers questions

  1. Which is the best example of an error found during semantic analysis?
  2. Which describes an abstract syntax tree (AST)?
  3. What is the main advantage of using an intermediate representation (IR), independent of both source language and CPU, inside a compiler?
  4. Which describes a basic block?
  5. In a control-flow graph, what do the nodes and edges represent?