AQA A Level · Computer Science 7517

上下文無關語言:練習題

5 條多項選擇題即時批改,另有 5 條文字題附完整解題步驟,全部圍繞「上下文無關語言」。

10 條題目30 免費,無需登記
第 1 題
1

Which of the following is the most accurate reason why Backus-Naur Form (BNF) is used to represent context-free languages instead of regular expressions?

第 2 題
1

Consider the following BNF production rules:
\(\langle expr \rangle ::= \langle digit \rangle \ | \ \langle digit \rangle \langle expr \rangle\)
\(\langle digit \rangle ::= 0 \ | \ 1 \ | \ 2 \ | \ 3 \ | \ 4 \ | \ 5 \ | \ 6 \ | \ 7 \ | \ 8 \ | \ 9 \)
Which of the following strings is NOT valid according to these rules?

第 3 題
1

A language \(L\) is defined by the following BNF grammar:
\(\langle S \rangle ::= a \langle S \rangle b \ | \ ab \)
Which of the following sets represents the language \(L\)?

第 4 題
1

Which of the following statements regarding context-free languages and their representation is correct?

第 5 題
1

A context-free language is being defined using Backus-Naur Form (BNF). Consider the following rules:

\( \langle S \rangle ::= \langle A \rangle | \langle A \rangle \langle S \rangle \)
\( \langle A \rangle ::= "(" \langle S \rangle ")" | "()" \)

Which of the following describes the set of strings generated by this grammar?

第 6 題
3

Explain why Backus-Naur Form (BNF) is required to describe some languages that cannot be defined using regular expressions.

先自己寫一次答案,再對照解題步驟。

第 7 題
5

A programmer is developing a compiler for a new programming language. Explain why Backus-Naur Form (BNF) must be used to define the syntax of the language instead of a regular expression if the language allows for nested parentheses to any depth.

先自己寫一次答案,再對照解題步驟。

第 8 題
5

A student needs to define a syntax for nested mathematical expressions where brackets must always be balanced. Explain why a syntax diagram or BNF is a better choice for this than a regular expression.

先自己寫一次答案,再對照解題步驟。

第 9 題
5

A language is described using Backus-Naur Form (BNF). Consider the following production rules for a simplified arithmetic expression:
<expression> ::= <term> | <term> "+" <expression>
<term> ::= <digit> | <digit> "*" <term>
<digit> ::= "2" | "3"

(a) Explain why this language is considered context-free rather than regular.
(b) Provide a derivation or draw a syntax diagram to show that the string "2*3+2" is valid according to these rules.

先自己寫一次答案,再對照解題步驟。

第 10 題
7

Backus-Naur Form (BNF) is used to define the syntax of context-free languages.

(a) Explain why a regular expression cannot be used to define a language that requires matching balanced parentheses of any depth, while BNF can.

(b) Given the following BNF rules:
\( \langle expr \rangle ::= \langle term \rangle | \langle term \rangle "+" \langle expr \rangle \)
\( \langle term \rangle ::= "x" | "(" \langle expr \rangle ")" \)
Show the derivation for the string "x+(x)".

(c) Identify the recursive element in the rules above and explain its significance.

先自己寫一次答案,再對照解題步驟。

* thinka提供的內容由AI生成,可能並非總是準確或最新。請將其用作輔助資源,並與官方材料進行核實。

你已看過標準答案,接下來輪到批改你的答案。

這一頁可以告訴你好答案的樣子,卻無法指出你的答案欠缺什麼。thinka 按真實評分準則批改你的文字答案,約 15 秒完成。

想多做幾條同類題目?立即開始練習呢個課題,即做即批改。

立即練習