FAQ
Hello,



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.



Thanks in advance,

-Phillip



e.g. for example



__GenericLanguage__



$var = 10

$var1 = "variable1"

@var2 = [1,2,3]

%var3 = {'key1'=>'value1', 'key2'=>'value2}



__Translate-to-SchemeLanguage__



Define var1 = variable1

Define var2 = '(1 2 3)

...



__Translate-to-TCLLanguage__



Set var1 variable

Search Discussions

  • Ron D. Smith at Oct 26, 2004 at 6:30 pm
    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
  • Randal L. Schwartz at Oct 27, 2004 at 12:50 pm
    "Phillip" == Phillip R Prentice writes:
    Phillip> I was wondering if anyone could help me begin to write some
    Phillip> grammer for a conversion project.

    It's rude to post the same question to multiple forums without
    disclosing such. You've also asked this question on perlmonks, and
    gotten some seriously good answers there.

    Thanks for wasting Another Group's Time.

    --
    Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
    <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
    Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
    See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprecdescent @
categoriesperl
postedOct 25, '04 at 11:10p
activeOct 27, '04 at 12:50p
posts3
users3
websitemetacpan.org...

People

Translate

site design / logo © 2019 Grokbase