Assign 1
Assign 1
b) Formal language is a quadruple (N, T, P, S), where: N is a finite set of nonterminal symbols T is a finite set of terminal symbols that is disjoint from N P is a finite set of production rules where a rule is of the form X Y X, Y in (T union N)* where '*' is closure operations S is a symbol in N that is called the start symbol. Alphabet is a finite set of symbols which are used to form words in a language e.g. = {a, b} where is an alphabet String over an alphabet is a finite-length sequence of elements of an alphabet e.g. If = {a, b} then strings over can be a, ab, bbaa, abab, aaaabbaab etc.
What is a natural language grammar? A Grammar, G, is a tuple: G= (VT,VN,S,P), such that: VT is the finite set of Terminal Symbols. VN is the finite set of Non-Terminal Symbols. S is the Scope of the Language, and S VN. P is the finite set of Productions. Based on the definition of a grammar above, generate a language over the alphabet (0,1,2,3,4,5,6,7,8,8,.). This language must be able to accept integer numbers and floating point numbers as valid strings in it. Illustrate with relevant example.
(c) Type 0 Grammar Languages dened by Type-0 grammars have no restrictions on their grammar rules, except that there must be at least one non-terminal on the left-hand side. They are accepted by Turing machines and the rule is of the form:
, where and are arbitrary strings over a vocabulary V i.e. terminal and non-terminal respectively and (terminal symbol is not an empty string) Examples of unrestricted languages are almost all natural languages.
Type 1 Grammar (Context sensitive) Context-Sensitive grammars may have more than one symbol on the left-hand-side of their grammar rules, provided that at least one of them is a non-terminal and the number of symbols on the left-hand-side does not exceed the number of symbols on the right-hand-side. Their rules have the form: A where A is a single non-terminal symbol, and are any combination of terminals and non-terminals. The automaton which recognizes a context-sensitive language is called a linear-bounded automaton: Examples of context-sensitive languages are most programming languages Type 2 Grammar (Context free) A Context-Free Grammar (CFG) is one whose production rules are of the form: A where A is any single non-terminal, and is any combination of terminal and non-terminals. Examples of CFLs are some simple programming languages . Type 3 Grammar (Regular) A regular language is one which can be represented by a regular grammar, described using a regular expression, or accepted using an FSA. Regular grammar is of two kinds Right-linear (right-regular), with rules of the form: A B or A . Where A and B are single non-terminal symbols, is terminal symbol parse tree with these grammars are right-branching. Left-linear (left-regular), with rules of the form A B or A Parse trees with these grammars are left-branching. Examples of regular languages are pattern matching languages (regular expressions).