What you want to do "is hard" as a generic solution and you will find lots 
and lots of literature on program translation.

That being said, you should break this up into a two step process, step one 
is to parse the "generic language" (which looks an *awful* lot like perl... 
:-) into a data structure which encapsulates a generic view of the 
constructs.  A second step takes that data structure and produces the 
appropriate output.

For example, "$var = 10"

assignment:

lhs "=" expression

lhs:

scalar | array | hash

scalar:

/\$[\w]+/

expression:

{whole expression tree}

...

atom

...

atom:

constant
...

constant:

string_constant | integer

integer:

/[-+]?\d+/

Once you have the data structure, you can look at it and to produce scheme, 
the program will see that you are doing an assign of a variable to a constant 
and emit the "Define var1 = 10" string etc.

This really is two problems and each one should be though out separately.
On Monday, Oct 25, 2004 "Prentice, Phillip R" said:

> Hello,
> 
> =20
> 
> I was wondering if anyone could help me begin to write some grammer for
> a conversion project.  I basically have a generic language where
> variables, arrays, and hash's are defined.  I want these variables to be
> translated to a tool specific datastructure, i.e TCL, scheme, etc.  I am
> assuming I would have to create a different set of grammar(s) for each
> language I want the variables translated to.  However, I am having
> trouble defining the grammar for parsing the genericLanguange.  Could
> you help me get started by showing me how I would go about parsing the
> below 3 structures in the GenericLangauge section below.  I would
> appreciate any insight or suggestions.
> 
> =20
> 
> Thanks in advance,
> 
> -Phillip
> 
> =20
> 
> e.g. for example
> 
> =20
> 
> __GenericLanguage__
> 
> =20
> 
> $var =3D 10
> 
> $var1 =3D "variable1"
> 
> @var2 =3D [1,2,3]
> 
> %var3 =3D {'key1'=3D>'value1', 'key2'=3D>'value2}
> 
> =20
> 
> __Translate-to-SchemeLanguage__
> 
> =20
> 
> Define var1 =3D variable1
> 
> Define var2 =3D '(1 2 3)
> 
> ...
> 
> =20
> 
> __Translate-to-TCLLanguage__
> 
> =20
> 
> Set var1 variable
> 
> =20
> 
> 
> ------_=_NextPart_001_01C4BAE7.C2C3FB0C--

--
 Intel, Corp.
 5000 W. Chandler Blvd.
 Chandler, AZ 85226

-- 
 Intel, Corp.
 5000 W. Chandler Blvd.
 Chandler, AZ  85226


Reply via email to