Top Banner

of 26

Formal Grammars Real

Mar 07, 2016

Download

Documents

romeofatima

Formal Grammars Real
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • REYNALD JAY F. HIDALGO, MS Computer ScienceProfessor

  • A set of atomic/non-divissible symbols

    Eg. A = {a,b,c,d,e,f,g,h,I,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}A = {a,b,c}A = {0, 1}A = {+,-,*,/}

  • A sequence of symbol/s from a given alphabet

    Eg.A = {a,b,c}w = aw = bw = cw = aaw = abcw = ccc

  • Denotes the empty string

    w=

  • Denotes the length of a given string (an integer value)

    w = abcd/w/ = 4w = 0/w/ = 1w = 12/w/ = 2w = /w/ = 0

  • Fundamental operation on strings

    Let be the first string and be the 2nd stringThe concatenation of and is denoted by = .

  • = .

    Where is the prefix of and is a proper prefix if while is the suffix of and is a proper suffix if

  • Any string concatenated with will result to the same string

  • denotes k copies of w

    Given w = abcw3 = 3 copies 0f w = abcabcabc

  • Is a subset of the powerset W

  • S L EL V :=E if B then A else EE AB A < AB A = AA T + AA TT VT 0T 1T (E)V xV yV w

    1. Generate the Algol statement w:= if x < y then 0 else x + y + 1

    Prove that the following Algol statement is valid

    x:= ( 1 + ( 0 + x ) )

    Generate the Algol Statement

    y := if ( x + y ) = 1 then 0 else ( if x < 0 then x else 0 )

  • NTP

  • It is a four-tupleG = (N, T, P, )Where N is a finite set of nonterminal symbolsT is a finite set of terminal symbolsN and T are disjoint: N T = P is a finite set of productions is the sentence symbol; (NT)

  • Each production P is an ordered pair of strings (,) = = In which ,, are possible empty strings in (NT)* and A is or a nonterminal letter. We usually write production () as

  • Let G1 have N = {A,B,C}, T =(a,b) and the set of productions A A aABC A abC CB BC bB bb bC bIdentify the Language L generated by G1

  • Let G2 have N = {A,B,C}, T (a,b,c) and the set of productions AA aABCA abCCB BCbB bbbC bccC ccIdentify the Language L generated by G2

  • Let G3 have N = {S}, T= (a,b) and the set of productions SS aSbS abdentify the Language L generated by G3

  • The Language L(G) generated by a formal grammar G is the set of terminal strings derivable from

  • Given a G an L can be derived

  • 1. Let G4 have N = {A,B}, T= (1,0) and the set of productions 1B 1 A 1B B 0A A 1 Identify the Language L generated by G4

    2. Let G5 have N = {A,B}, T= (1,0) and the set of productions B1 1 A B1 B A0 A 1 Identify the Language L generated by G5

  • Occurs when 2 or more derivation trees can be drawn from a single w

  • StructuralLabeling

  • Let G6 have N = {A}, T (0,1) and the set of productions AA A0AA 1Draw a derivation tree for the string 10101

  • Let G7 have N = {A,B}, T (1,0) and the set of productions A A B0 A A0 B B0 A 1 B 1Draw a derivation tree for the string 100

  • S S ScS S c 2. A B A A a A b A c B + B * Prove that the following Grammars are ambiguous. How? ConceptsN = {A,B,S}

  • AN {}, , and (N T)*, B N, a T

    TYPEFORMAT OF PRODUCTIONSREMARKS0AUnrestricted Substitution RulesContracting1A, Context SensitiveNon-Contracting2A , Context FreeNon-Contracting

    3A aBA aA BaA aRegular, Right Linear

    Regular, Left LinearNon-Contracting