Quiz 9 Flashcards

(10 cards)

1
Q

Which of the following is not typically the responsibility of lexical analysis in a compiler?
Identifying keywords, identifiers, and literals; Detecting syntax errors in the code; Removing whitespace and comments; Tokenizing input code into lexemes

A

Detecting syntax errors in the code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The parsing phase, also known as syntax analysis, is the process of breaking down source code into basic units called tokens, T/F?

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which of the following statements about parse trees and ASTs is false?
Both parse trees and ASTs are used in semantic analysis in compilers; ASTs provide a simplified, abstracted view of the source code structure, focusing on the essential syntax elements; Parse trees are generally deeper than ASTs because they include all grammar rule applications; Parse trees contain all tokens from the source code, whereas ASTs may omit certain tokens like punctuation

A

Both parse trees and ASTs are used in semantic analysis in compilers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Reserved words are identifiers that have special meaning in a programming language and cannot be used for variable names, T/F?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which of the following is an example of the longest match principle?
Source: ==
Tokens: = and == are both valid tokens

The lexer throws an error due to ambiguity; The lexer matches a single == token; the lexer matches two == tokens; the lexer ignores both tokens

A

The lexer matches a single == token

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which of the following best describes the role of syntactic analysis in a compiler?
Optimizing the code for better performance; Breaking down the code into tokens for easier processing; Translating high-level code to machine code; Checking that the program conforms to the language’s grammatical structure

A

Checking that the program conforms to the language’s grammatical structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which of the following context-free grammar G:
S -> aSb | e
Which of the following is not a valid sentence in G?
abab; aabb; aaabbb; ab

A

abab

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In Backus-Naur Form (BNF), which of the following symbols is typically used to denote a non-terminal?

::=
<…>
|

A

<…>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which of the following is typically represented as a leaf node in both a parse tree and an AST?
Grammar rules like <expression> or <term>; Identifiers and literals; Keywords like if and else; Operators like + and *</term></expression>

A

Identifiers and literals

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which of the following strings does not match with the regular expression (a|b)?[0-9]+c*
b52; a3cc; ac; 123

A

ac

How well did you know this?
1
Not at all
2
3
4
5
Perfectly