Wednesday, March 4, 2015

Context Free Grammar Assignment 2

Production rules:
1)      Expression -> Symbol
2)      Symbol -> { Star } | [ Star ] | ( Star )
3)      Star -> “void”
4)      Star -> *
5)      Star -> * Star
6)      Star -> Symbol Star

Terminals: * [] {} () “void”
NonTerminals: Expression Symbol Star
Start Symbol: Expression
Test 1:
{[**][](***)}
Expression=>1 Symbol
                =>2 { Star }
                =>6 { Symbol Star}
                =>2 { [ Star ] Star}
                =>5 { [ * Star] Star}
                =>4 { [ * *] Star}
                =>6 { [ * *] Symbol Star}
                =>2 { [ * *] [Star] Star}
                =>3 { [ * *] [] Star}
                =>6 { [ * *] [] Symbol Star}
                =>2 { [ * *][] (Star) Star}
                =>5 {{**}[] (* Star) Star}
                =>5 {{**}[] (* * Star) Star}
                =>5 {{**}[] (* * * Star) Star}
                =>4 {{**}[] (* * * *) Star}

                =>3{{**}[] (* * * *) }
Test 2:
{}
Expression =>1 Symbol
                  =>2 { Star }
                  =>3 {}
Test 3:
[ (*) *]
Expression =>1 Symbol
                   =>2 [ Star]
                   =>6 [ Symbol Star ]
                   =>2 [ ( Star) Star]
                   =>4 [(*)Star]
                   =>4 [(*)*]


PDF