Make your own free website on Tripod.com







[an error occurred while processing this directive]



3. The grammar

Unluckily to create an agent, which is able to understand a language, we need to write down the language's grammatical rules and make them part of the agent's knowledge. I say unluckily, because I think the study of grammars is an argument as boring as important in the world of computer science and artificial intelligence (I hope my university professor of " Theoretical Computer science "will never read this...). The reason for which the study of the grammars in computer science is fundamental is obvious: it's enough to look at programming languages. Basic, Pascal, Prolog, C, Java, or what else you prefer, there is always a grammar to respect. But... which is difference between a programming language grammar and the one we use everyday in order to communicate (I mean human speech grammar)? Well the basic difference is that in the first case we talk of formal grammars, while in the second one of informal grammars. I do not know if you are familiar with these concepts and if you understood which is the problem, however is not my intention to talk much more about grammars. First of all we can introduce the problem considering that writing a formal grammar is relatively simple, while writing a grammar for an informal language is very, very difficult. Well, which is the solution? Expert people are sill talking about it. Someone suggest to use formal grammars in the place of informal ones in intelligent agents developing. This means loosing in language's expressiveness, but it simplifies the work. The question now is: "how does it works in practical a formal grammar?". Therefore, through the rules (or productions) of a formal grammar it is possible to formulate/recognize all the phrases of the language for which the grammar has been written. To the aim to make this last concept easier to understand, let's write some of the productions that express the grammar of a language similar to the Pascal.




< Program > = Program < Identificator >; < Body >.
< Body > = [ < Declaration Variable > ] [ < Declaration Procedures > ] [ < Block > ]
< Block > = [ Begin ] < Instruction > { < Instruction > } [ End ]
< Instruction > = If < Condition > Then < Block > Else < block > |
While < Condition > I give < Instruction > |
Repeat < Instruction > Until < Condition > |
For (< Iterance >) I give < Block >
< Declaration Variable > = Var < Identificator > {, < Variable > }: < Type >; { < Declaration Variable > }
< Declaration Procedures > = Identificator < Procedures > ([ < Parameter > ] {, < Parameter > }) < Block >
...
=
...
...
=
...
< Parameter > = Type: < Identificator >;
< Condition > = < Identificator > < Identificator > < Comparison > |
< Condition > And < Condition > |
< Condition > Or < Condition > |
Not < Condition > |
...
< Comparison > = < | = | > | > = | <> | < =
< type > = INTEGER |
REAL |
CHAR |
BOOLEAN |
< Identificatire > = < Letter > { < Letter > | < Number > }
< Letter > = to | b | c |? | y | z | To | B | C |? | Y | Z
< Number > = 0 | 1 | 2 |? | 8 | 9



It is necessary to add some rule else which is not possible to express through the productions you saw, however it should not be a great problem. So, we have written the grammar of a programming language! Remember: a formal language! Come back to the problem of the natural language (expressed through an informal grammar) and think to the huge quantity of rules we had to write to express its grammar. Well, let's ask ourselves if it is possible to use a formal grammar and write the rules of natural languages through production (a little different from the one we saw). Sincerely I'm not able to answer to this question, but if want to use a grammar like the one we have just used, the answer is surely "no!". However other "formal grammars" exist. They are a little more complex to handle, but with advanced expressive potentialities. Are they enough? I really don't know! But what is so ugly (or beautiful, according to the point of view) in natural language to make the implementation of a grammar so much complicated? Omitting the problems connected to the greater complexity of the natural language compared to the one of a whichever formal language (I refer to verbs conjugation, inflexion, lexical amplitude) the difficulties come essentially from what is called the problem of ambiguity. Ambiguity could be easily solved at the lexical and perhaps grammatical level too, but it gets more and more difficult to solve semantic ambiguity. We are going to talk about it in next chapter.




Italia HyperBanner Network