Confused about example of creating a formal grammar -


i'm reading dick grune's parsing techniques - practical guide , i'm stuck on example of formal grammar (starting page 22). starts this:

0. name may replaced “tom”    name may replaced “dick”    name may replaced “harry” 1. sentence may replaced name 2. sentence may replaced sentence, name 3. “, name” @ end of sentence must replaced “and name”    before name replaced of replacements 4. sentence finished when no longer contains non-terminals 5. start our replacement procedure sentence 

then re-writes more formally follows:

0. name -> tom    name -> dick    name -> harry 1. sentence -> name    sentence -> list end 2. list -> name    list -> list , name 3. , name end -> , name 4. start symbol sentence 

the re-write above (figure 2.2 in book) introduces "list". assume list non-terminal, can't figure out comes or means.

also, unless mis-read text, figure 2.2 supposed same first figure, don't match. example, rule #2 first figure ("sentence may replaced sentence, name") in fig. 2.2?

you didn't copy table properly. 2 must be:

list -> name

list -> list , name

list can either single name or list, comma , name.

e.g. "dick , tom , harry" valid sentence because construct following way:

sentence (replace sentence)

list end (list replaced "list , name")

list , name end (replace list "list , name" again)

list , name , name end (now replace list name)

name , name , name end (replace ", name end" "and name")

name , name , name (replace names)

dick , tom , harry

i hope answer second question well.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -