tailieunhanh - learn prolog now phần 7

Hãy chắc chắn rằng bạn hiểu lý do tại sao Prolog không nhận được vào vòng lặp vô hạn với ngữ pháp này vì nó đã làm với các phiên bản trước. Đạo đức là: DCGs không phải ảo thuật. Họ là một ký hiệu tốt đẹp, nhưng bạn có thể không phải lúc nào cũng chỉ để "viết ngữ pháp như một DCG 'và nó làm việc. | 104 Chapter 7. Definite Clause Grammars s -- simple_s. s -- simple_s conj s. simple_s -- np vp. np -- det n. vp -- v np. vp -- v. det -- the . det -- a . n -- woman . n -- man . v -- shoots . conj -- and . conj -- or . conj -- but . Make sure that you understand why Prolog doesn t get into infinite loops with this grammar as it did with the previous version. The moral is DCGs aren t magic. They are a nice notation but you can t always expect just to write down the grammar as a DCG and have it work. DCG rules are really ordinary Prolog rules in disguise and this means that you must pay attention to what your Prolog interpreter does with them. A DCG for a simple formal language As our last example we shall define a DCG for the formal language db . What is this language And what is a formal language anyway A formal language is simply a set of strings. The term formal language is intended to contrast with the term natural language whereas natural languages are languages that human beings actually use fomal languages are mathematical objects that computer scientists logicians and mathematicians define and study for various purpose. A simple example of a formal language is d b . There are only two words in this language the symbol a and the symbol b. The language afb consist of all strings made up from these two symbols that have the following form the string must consist of an unbroken block of as of length followed by an unbroken block of bs of length and nothing else. So the strings ab aabb aaabbb and aaaabbbb all belong to db . Note that the empty string belongs to db too after all the empty string consists of a block of as of length zero followed by a block of bs of length zero. On the other hand aaabb and aaabbba do not belong to dbn. Now it is easy to write a context free grammar that generates this language s - s - l s r l - a r - b The first rule says that an s can be realized as nothing at all. The second rule says that an s can be made up of an l for .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.