Docsity

Principle-Programming Language - Quiz 1 with Answers | CS 310, Quizzes of Computer Science

Toggle sidebar
bg1
Principles of Programming Languages - Quiz I
K. Subramani
LDCSEE,
West Virginia University,
Morgantown, WV
1 Instructions
1. The quiz is to be turned in by 11 : 50 am.
2. Each question is worth 3points.
3. Attempt as many problems as you can. You will be given partial credit, as per the policy discussed in class.
2 Problems
1. Categorize the errors that can occur in a program, with an example of each category.
2. Let Σ = {0,1}denote an alphabet. Let L⊆Σ∗denote the language which consists of all strings that start with 0and
end with 1. Write a regular expression and a CFG corresponding to L.
3. Consider the CFG G=hV, T , P, Si, with V={S},T={0,1}and Pgiven by:
S→0S1|1S0|
Argue that every string in L(G)has an equal number of 0s and 1s.
4. Consider the CFG G=hV, T , P, Si, with V={S},T={a}and Pgiven by:
S→S·S|a
Write the set equation corresponding to this grammar and give a solution to this equation.
5. Consider the following block of Ccode:
#include <stdio.h>
int a, b;
int p(void)
{
int a, p;
a =0; b=1; p=2;
return p;
}
1
pf2

Partial preview of the text

Download Principle-Programming Language - Quiz 1 with Answers | CS 310 and more Quizzes Computer Science in PDF only on Docsity!

Principles of Programming Languages - Quiz I

K. Subramani

LDCSEE,

West Virginia University,

Morgantown, WV

{[email protected]}

1 Instructions

  1. The quiz is to be turned in by 11 : 50 am.
  2. Each question is worth 3 points.
  3. Attempt as many problems as you can. You will be given partial credit, as per the policy discussed in class.

2 Problems

  1. Categorize the errors that can occur in a program, with an example of each category.
  2. Let Σ = { 0 , 1 } denote an alphabet. Let L ⊆ Σ∗^ denote the language which consists of all strings that start with 0 and end with 1. Write a regular expression and a CFG corresponding to L.
  3. Consider the CFG G = 〈V, T, P, S〉, with V = {S}, T = { 0 , 1 } and P given by:

S → 0 S 1 | 1 S 0 | 

Argue that every string in L(G) has an equal number of 0 s and 1 s.

  1. Consider the CFG G = 〈V, T, P, S〉, with V = {S}, T = {a} and P given by:

S → S · S | a

Write the set equation corresponding to this grammar and give a solution to this equation.

  1. Consider the following block of C code:

#include <stdio.h>

int a, b;

int p(void) { int a, p; a =0; b=1; p=2; return p; }

void print( void) { printf(‘‘%d\n%d\n’’,a,b); }

void q(void) { int b;

a= 3; b=4; print(); }

main() { a=p(); q(); }

What values will be printed, when the program is parsed using (a) Lexical scope, and (b) Dynamic scope?