0

How to generate rules to translate 1 form of grammar into another??

for example:

GRAMMAR 1:

BLOCK: while ( id:=N) { BLOCK } | id:=N
N: 1 | 2 | 3 | 4 | 5

GRAMMAR 2:

BLOCK: while id:=N DO BLOCK END | id:=N
N: 1 | 2 | 3 | 4 | 5

I want 2 generate a translation such that I can translate a statement in Grammar 2 into the corresponding statement in Grammar 1...

2
  • Give us some more detail about the syntax tree and how you created it? Commented Oct 24, 2010 at 15:14
  • Fundamentally you want to build a full language translator. That's simply not an easy task, even if you have two grammars in your possession. If nothing else, you have to handle the semantic differences. Commented Jan 14, 2013 at 18:52

1 Answer 1

1

Umm, create a parser that converts a sentence from Grammar 1 into a syntax tree, and then convert the syntax tree back into a sentence in Grammar 2?

Sign up to request clarification or add additional context in comments.

4 Comments

created the syntax tree. But how to make it 'convert' into a sentence in grammar 2??
If the two grammars are equivalent, then you simply need to traverse the tree, and generate the string as you go.
Hmm thanx. :) But cant we write some translation rules?? It would be helpful if you write some sample rules for me..
What do you mean by "translation rules"? If the two grammars are similar enough, then perhaps you can get away with a simple string search-and-replace. If not, then you'll have to go via some intermediate representation (a syntax tree seems like the obvious choice).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.