AQA A Level · Computer Science 7517

Context-free languages:練習問題

その場で採点される選択問題 5 問と、解説つきの記述問題 5 問。すべて「Context-free languages」からの出題です。

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 秒で採点します。

同じような問題をもっと解きたい?このトピックの新しい問題を、解きながら採点。

練習を始める