0

I know I should have try it first but I dont understand what is this asking about. My english is my very bad. Can you please telling in easy english. PLus this is very confusing. Please help me out

Write a BNF grammar for the for statement of C. Assume <expression> and <statement> and <block> are defined elsewhere nonterminals (you dont' define them). Statement is a single statement, including control statements but excluding block, and block is some code with {} around. Do not use the extended BNF notation.

For the above, write operational semantics.

Design a regular language where every sentence has to start with any number of strings 11, then repeats 100 any number of times, then repeat 00 at least once.

For the above, how many valid strings there are?

For the above, how many valid strings are there if we restrict the total length to a) at most 7 bits? b) exactly 7 bits?

Here is what I have tried

<for loop> ::= for ( <expression> ; <expression>; <expression> ) <statement>

4
Contributors
4
Replies
19
Views
2 Years
Discussion Span
Last Post by sepp2k
0

You need to do some studying. BNF stands for Backus-Naur Form which is an abstract representation of complex processes and languages. Here is the Wikipedia article about it: https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form

As an example, the United States Department of Defense (in conjunction with Bolt, Beranek, and Newman in Cambridge Massachusetts) developed TCP/IP and published a bunch of books that specified the protocols to be used, the DDNS (Department of Defense Networking Standards). They used BNF to describe all of these protocols in exquisite detail so that anyone could implement them correctly, in any language, and the resulting code could then be assumed to communicate properly with any other compliant system. I know, because in the early 1990's I did just that to develop from the DDNS handbooks (takes up at least a foot of shelf space) a complete TCP/IP stack from scratch for a real-time operating system that we were using for a US Navy project. We were not allowed to use existing code. The result was a TCP/IP stack that could communicate properly with SunOS, IBM, DEC, HP, Windows, and many other systems without error. I still have the handbooks on my shelf. :-)

In truth, BNF isn't hard to understand. Reading it helps to understand it.

0

You need to do some studying. BNF stands for Backus-Naur Form which is an abstract representation of complex processes and languages - basically a context-free grammar. Here is the Wikipedia article about it: https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form

As an example, the United States Department of Defense (in conjunction with Bolt, Beranek, and Newman in Cambridge Massachusetts) developed TCP/IP and published a bunch of books that specified the protocols to be used, the DDNS (Department of Defense Networking Standards). They used BNF to describe all of these protocols in exquisite detail so that anyone could implement them correctly, in any language, and the resulting code could then be assumed to communicate properly with any other compliant system. I know, because in the early 1990's I did just that to develop from the DDNS handbooks (takes up at least a foot of shelf space) a complete TCP/IP stack from scratch for a real-time operating system that we were using for a US Navy project. We were not allowed to use existing code. The result was a TCP/IP stack that could communicate properly with SunOS, IBM, DEC, HP, Windows, and many other systems without error. I still have the handbooks on my shelf. :-)

In truth, BNF isn't hard to understand. Reading it helps to understand it.

0
<for loop> ::= for ( <expression> ; <expression>; <expression> ) <statement>

All three expressions in a for-statement are optional and from C99 onwards the first one may be a variable definition instead. Also note that the assignment specifically says that <statement> does not include composite statements (for whatever reason), so you need to cover that as well.

Other than that this looks okay.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.