How to distinguish grammar types in formal languages in the principle of compiling

Source: Internet
Author: User

the judgment of four kinds of grammar is very simple, say, four kinds of grammar is to stipulate the left and right character of the formation of the composition of the rules are different, the other can not understand not to think about, you just know when the judgment is the production of the left and right to match the rules to judge. Here's how to judge based on the characteristics of the left and right sides of the resulting type.

first, it should be clear that four kinds of grammars, fromModel 0 To Type 3, its rules and conventions more and more, the restrictions are more and more, so we can judge from the most complex Type 3, and then judge, if not in accordance with the 3 type, then look is not 2 type, not 2 type, then see is not 1 type, of course, for the problem of cooked friends, not so complicated , can be seen directly at a glance.

What is the norm for Type 3 grammar?
1th: The left must have only one character, and must be non-terminator;
2nd: The right side can have a maximum of two characters, and when there are two characters, one must be terminator and the other non-terminator. This character must be a terminator when there is only one character to the right.
3rd: ForType 3 Grammar of all the production, the right side of the two-character production, the right side of the two characters Terminator and non-terminator relative position must be fixed, that is, if a production of the right side of the two-character arrangement is: Terminator + non-terminator, then all the production of the right side as long as two characters, Must be preceded by a terminator and followed by a non-terminating character. And vice versa, either, it's all: non-terminator + terminator.

Judging by the above rules, the three grammars you give are clearly not part of theType 3 grammar.

Look againHow to judge the Type 2 grammar:
1th: WithThe 1th of the 3-type grammar is the same: the left must have only one non-terminator.
2nd:Type 2 grammar the right side of all the production types can contain several terminator and non-Terminator (as long as there is a limited number of lines, no limit).

according toThe rule of 2 grammar, your three grammar is 2 type grammar, namely: context-independent grammar.

Look againHow to judge the Type 1 grammar:
1th:Type 1 grammar the left side of all production can contain one, two, or more than two characters, but must have at least one non-terminator.
2nd: WithType 2 grammar 2nd the same.

according to1 Grammar judging rules, obviously, your grammar also belongs to the 1 type.

Finally,Type 0 grammar, this will not be seen, as long as you can describe it, all belong to this type, that is, type 0.

How to distinguish grammar types in formal languages in the principle of compiling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.