• Home
  • Queen's University
  • Software Specifications
  • Context-Free Languages and Regular Expressions

Context-Free Languages and Regular Expressions

L= {al bk | 0 <= i <= k}: Language L is context free but not regular Classes consists exactly all CFL: languages accepted by non-deterministic Pushdown P {x = x*x+1;} x <= 0:false Q1{C}P1 Q2{C}P2 -> Generally valid Q1&&Q2{C}P1&&P2 A reduces to B, B is unsolvable: possible that A is solvable or unsolvable Following statements are true? a)Some DSD do not have equiv RegEx b)Some NDSD do not have equiv RegEx c)Some RegEx do not have equiv deterministic SD d) Above three statements are all false a*b(a+ba*b)* - > bbaab E L All strings that have prefix abbb: abbb(a+b)* All strings have substring abba: (a+b)*abba(a_b)* All strings over 2 that do not have suffix ab: (a+b)*(aa+bb+ba)+a+b+¿ All strings over 2 that do not have substring ab: (b*+a*)b*a* = b*a* All strings over 2 that do not have aa as substring: (ab+b)*+(ab+b)*a {am b" | m,n>= 0, m = n(mod2)}: (aa)*(bb)*+(aa)*a(bb)*b All strings that begin end end with 010: 010(0+1)*010+01010+010 All strings having an even # occurrences of 1: (0+10*1)* All strings over {b,c} have substring bcbc: (b+c)*bcbc(b+c)* All strings over {b,c} have odd length: (bb+bc+cb+cc)*(b+c) tan one way to parse an element and get the same string Exists(u= 0, u<x+ y + z) 2*(x+y+z)+u >= W+x All strings over {b,c} the have odd # occurrences of symbol b: c*b(c+bc*b)* P{z=x+y+z;} Exists(u=0; u < z) 2*z + u >= w+x (reg hoares) ForAll(a=0,a<y+z) Exists(b=0, b < u) y+z+b >= a*v All strings over {b,c} that have at least two occurrences of b's and at most one occurrence of c: b*(bb+cbb+bcb+bbc)b* Ambiguity: If some string has more than one parse tree // If there is more P{x=y+z;} ForAll(y=0; y < x) Exists(z=9; z<u) x+z > y*v (2 var sub) Have bbc as a substringb A and B are regular languages over alphabet 2, following is true -> A intersect B is always Regular 0 06 1 0 A and B are NON-regular languages, following is true -> A union B is always infinite *Some regular languages are finite and some infinite Which of the following properties does NOT always prevent using RDP constructed directly from given grammar productions: All strings over {b,c} that do not have cbc as a substring: b*(c*bbb*)*c*b* P{x=y+z;} Exists(y=0,y<50) x*z >= w+y (no substitution) first(A) & productions // Follow(S) n First(A) = null L C 6 1 > 0 C a) grammer is ambiguous b) grammar has two productions where strings w1 \= w2 begin with same terminal symbol c) grammer has left-recursive productions d) All of the above properties always prevent RDP What language generate from CFG: S -> aSbbb | Sb l & : {ai bk | 0 <= 3i <= k} Should X be in P&&B{C} X in order to make valid P{if(B)C}Q inference rule for "if(B)C" -> X should be: (P && !B) implies Q Correctness statement: true {C} false Correctness statement invalid for any terminating code C Let P and Q be any assertions, following holds always: (P && Q) is stronger