Python Forum
Python for syntax conversion
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python for syntax conversion
#4
kingsman Wrote:(a) I am ten years old
I love eating apple
I am a boy

(b) Apple is my favourite fruit
I am a male
I have birthed 10 years
Here is a basic algorithmic scheme that you could follow for such a work
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.
Reply


Messages In This Thread
Python for syntax conversion - by kingsman - Dec-20-2019, 02:52 PM
RE: Python for syntax conversion - by ichabod801 - Dec-20-2019, 03:58 PM
RE: Python for syntax conversion - by kingsman - Dec-20-2019, 05:33 PM
RE: Python for syntax conversion - by Gribouillis - Dec-20-2019, 06:59 PM
RE: Python for syntax conversion - by kingsman - Dec-21-2019, 04:49 PM
RE: Python for syntax conversion - by Gribouillis - Dec-21-2019, 05:16 PM
RE: Python for syntax conversion - by kingsman - Dec-22-2019, 10:02 AM
RE: Python for syntax conversion - by buran - Dec-21-2019, 05:47 PM
RE: Python for syntax conversion - by Gribouillis - Dec-22-2019, 10:58 AM
RE: Python for syntax conversion - by kingsman - Dec-23-2019, 04:44 PM
RE: Python for syntax conversion - by Gribouillis - Dec-23-2019, 05:13 PM
RE: Python for syntax conversion - by kingsman - Dec-24-2019, 11:55 AM
RE: Python for syntax conversion - by Gribouillis - Dec-24-2019, 01:03 PM
RE: Python for syntax conversion - by kingsman - Dec-26-2019, 12:48 PM
RE: Python for syntax conversion - by Gribouillis - Dec-26-2019, 05:50 PM
RE: Python for syntax conversion - by kingsman - Dec-27-2019, 01:07 PM
RE: Python for syntax conversion - by Gribouillis - Dec-27-2019, 01:47 PM
RE: Python for syntax conversion - by kingsman - Dec-27-2019, 02:05 PM
RE: Python for syntax conversion - by Gribouillis - Dec-27-2019, 02:15 PM
RE: Python for syntax conversion - by kingsman - Dec-27-2019, 03:49 PM
RE: Python for syntax conversion - by kingsman - Apr-27-2020, 09:26 AM
RE: Python for syntax conversion - by Gribouillis - Dec-27-2019, 04:18 PM
RE: Python for syntax conversion - by kingsman - Dec-27-2019, 04:26 PM
RE: Python for syntax conversion - by kingsman - Apr-27-2020, 03:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python format conversion bluefrog 2 2,790 Jul-22-2018, 03:49 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020