Dec-20-2019, 06:59 PM
(This post was last modified: Dec-20-2019, 07:23 PM by Gribouillis.)
kingsman Wrote:(a) I am ten years oldHere is a basic algorithmic scheme that you could follow for such a work
I love eating apple
I am a boy
(b) Apple is my favourite fruit
I am a male
I have birthed 10 years
Output:Description of the input language: it has 3 statements
age_stm:
syntax: "I am <number> years old"
parameters:
number: a number written in english
eating_stm:
syntax: "I love eating <food>"
parameters:
food: the name of some food
gender_stm:
syntax: "I am a <gender>"
parameters:
gender: boy or girl
First step: PARSING OF THE INPUT FILE
The aim of this step is to recognize the statements contained
in the input file and their parameters. In the example, the result is
a sequence of python objects
age_stm(number = ten)
eating_stm(food = apple)
gender_stm(gender = boy)
Second step: CODE GENERATION
each parsed statement is translated in a statement of the second
language according to a specific rule
rule for an age_stm:
convert the number in english to a number in digits
emit the statement "I have birthed <digits> years"
rule for a eating_stm:
identify the type of the food (eg apple is a fruit)
emit the statement "<food> is my favorite <food type>"
rule for a gender_stm:
convert the gender to the appropriate transcription (boy -> male)
emit the statement "I am a <converted gender>"
There may be many more rules, for example there may be rules to change the
order of the emited statements, also a single input statement may induce
more than one output statement, etc.