1. Pseudocode translator

Just out of curiosity, would anybody be interested in program that could =
take pseudocode and translate it into an optimized(sp?) Euphoria .ex =
.exw file?
Maybe fodder for a group project?

I like fooling around with AI/Natural Language/etc., but it's not the =
kind of thing that could ever be completed.  This just seems like a =
viable first step, IMHO.

BTW: I've just jumped on the Linux bandwagon, and would be very =
interested in a Euphoria port.  Imagine a natural language interface for =
UNIX ;0)

Mike Sabal
http://home.att.ne.jp/gold/mjs/index.html

new topic     » topic index » view message » categorize

2. Re: Pseudocode translator

Mike Sabal wrote:
> Just out of curiosity, would anybody be interested in program that could take
> pseudocode and translate it into an optimized(sp?)
> Euphoria .ex .exw file?

heh...define "pseudocode"....*big* definition...*multiple* sources
for debate...the way I see it, as soon as you 'define' pseudocode,
and thus limiting the choices of verbiage available to a programmer
or even the curious novice, you have...in effect...just created a
"High-Level" programming language instead of a true "Natural
Language" environment...*shrug* just the way I see it...
it's a catch-22:if you define it, it ain't what you want, and if you
don't define it, it ain't what you want either...
*ducks a few flames that whizz by*
now, before I'm misinterpreted here, I do -not- believe that a
natural language IDE/whatever you wanna call that environment is
impossible...
steps needed?
1> import the entire dictionary ala webster's
2> import the entire set of grammer constructs
3> filter through a "Grammatic" clone (trademark used without any
        permission--suffer :) )
4> filter through an as yet undeveloped and unheard of complete
        inference/mood/context system
5> heh...well if the phrase made it this far, oh just "simply"
        convert it now into code...

> Maybe fodder for a group project?
*big* *huge* *monsterous* size group perhaps????
this is a chore + ( chore * 0.5 )

> I like fooling around with AI/Natural Language/etc., but it's not the kind of
thing
> that could ever be completed.
actually, I disagree here a tad bit, as mentioned above...it could
sorta mebbe kinda be done :)

--snip--

> Imagine a natural language interface for UNIX ;0)
yeah...i kinda think that only a mainframe could actually crunch this
kinda system...even 300MHZ Pentiums prolly can't even touch this
level of processing...dunno....

and finally....yeah I *want* macros...I find myself using 1-3 line
code segments over and over and over and just hate to put them in
seperate procedures because these code fragments are often found
inside rather large loops and I can't spare the overhead (trucolor
sure is pretty, but I sure move a *lot* of data)
now, granted, I do cut/paste...still...readability would be so very
much improved for me....not to mention development time savings and
debug time savings....I'm not advocating this as a necessary
inclusion to Euphoria base code either...

'nuff rambling...l8tr all...Mike






--------------------------------------
If it wasn't for typos,
I'd never get any coding done at all.
;)

new topic     » goto parent     » topic index » view message » categorize

3. Re: Pseudocode translator

At 05:05 AM 3/22/98 +0000,mdeland wrote:
>Mike Sabal wrote:
>> Just out of curiosity, would anybody be interested in program that could take
>> pseudocode and translate it into an optimized(sp?)
>> Euphoria .ex .exw file?
>
.the way I see it, as soon as you 'define' pseudocode,
>and thus limiting the choices of verbiage available to a programmer
>or even the curious novice, you have...in effect...just created a
>"High-Level" programming language instead of a true "Natural
>Language" environment...*shrug* just the way I see it...
>it's a catch-22:if you define it, it ain't what you want, and if you
>don't define it, it ain't what you want either...
>*ducks a few flames that whizz by*

No flames here, you're right. However, I notice that I
write a *lot* of pseudocode when programming Euphoria:
The first pass at a function might look like:

 function Lookup (object target, object list)
            -- for each item on the list
            -- check for list[INDEX] = target[INDEX]
            -- and list[NAME] = target[NAME]
            -- if found, then
  return list[item]
            -- otherwise
  return -1
  end function

To add the actual code is pretty simple, and I've already
written both pseudocode and documentation. Isn't the
worst habit to get into...
------------------------------------------------------
Visit my Euphoria programming web site:
http://www.mindspring.com/~mountains
------------------------------------------------------

new topic     » goto parent     » topic index » view message » categorize

4. Re: Pseudocode translator

------ =_NextPart_000_01BD5656.D9EE6F20
Content-Transfer-Encoding: quoted-printable

I apologize for this being a bit longish, but since I've actually worked =
out the details of the PPG, I figured I'd let people know what I was =
offering before I asked if there was interest. smile

---=20

After a number of discussions with Ralf, I had come up with a =
pre-processor generator (PPG). The initial design recursively broke up =
expressions into smaller patterns, until some atomic level was reached. =
However, there were some serious problems that I was unable to resolve, =
so I set it aside.

I came back to it later, and converted it to a high-level pattern =
matcher. If a line of code matched a pattern, it would then apply the =
replacement rules that followed. Comments would be automatically =
stripped off before code was handed to the pattern matcher.

The focus of the program is on the "high level" grammar. It doesn't =
actually know anything about Euphoria; it's just a pattern matcher. It =
could just as easily generate Fortran code. One of the reasons I had =
written it was as the "next generation" of PP - one that would be much =
easier to maintain.

Here's a simple example of a portion of a grammar, to show you the =
syntax:

| ^1 +=3D ^2 |
   -- C-like +=3D
   >>^1 =3D ^1 + ^2

The pipes {|} delimit a pattern. The caret (^} preceeds a matched =
pattern. Code that follows is directly translated into Euphoria, with =
the exception of the {>>}, which converts into a puts() to the output =
file.

The code generated would create code along the lines of:

   elsif match( "^1", "+=3D", "^2" ) then
      out( outFile, "--C-like +=3D" )
      out( p[1] & " =3D " & + " & p[2] )

You could then run this PP program against an input file such as:

   a =3D +=3D 23

and get:

   a =3D a + 23

Here's another trivial example:

| { ^1, ^2 } =3D ^3 |
-- Python-like assignment
-- tmp is a global variable already created
>>tmp =3D ^3
>>^1 =3D tmp[1]
>>^2 =3D tmp[2]

This would convert:

   { x, y } =3D get_position()

into:

   tmp =3D get_position()
   x =3D tmp[1]
   y =3D tmp[2]


If you wanted, you could write a more general pattern like:

| { ^1 } =3D ^2 |
   -- python-like assignment
-- first arg can be comma delimited

   -- assign to local variable
   >>tmp =3D ^2

   -- convert sub-list into elements
   s =3D comma_delimited( ^1 )

   -- assign each element of the list
   for i =3D 1 to length( s ) do
      -- the reciever of the value
      ^3 =3D s[i]
      -- the value
      ^4 =3D sprintf( "tmp[%d]", i )
      -- assignment
      >>^3 =3D ^4
   end for

Here, comma_delimited() is a user-defined function that converts a comma =
delimited sequence such as {"a,b,c"} into separate elements, { "a", "b", =
"c" }. The code is a bit clunky, but it can handle more general =
expressions, such as:

   { x, y, cx, cy } =3D getWindowSize( myWin )

Notice that {>>} sends everything out literally, except for ^ variables.

PPG's ability to handle nested expressions is also fairly limited. There =
is an ability to define "aliases", which are automatically replaced with =
lookup values.=20

Aliases are associated with keys, so that if you set up alias with a =
structure (like a loop, or a case statement), you can destroy all the =
aliases at the end of the structure.

Here's an example that uses aliases:

| with each ^1 in ^2 do |

   -- define a "with" loop with only one variable
=20
   -- increment the loop variable count
   indexCount =3D indexCount + 1

  -- create a loop variable
   ^3 =3D "index" & indexCount

-- tell the system to create an alias for ^1 bound to a key
-- the first arg is the key
   -- the second arg is the pattern to search for
   -- the third arg is the pattern to replace it with
   var =3D alias( indexCount, ^1, ^2 & "[index" & ^3 & "]" )

   -- create a line of code
   >>for ^3 =3D 1 to length( ^2 ) do

| end with |

   -- release the alias bound to the loop key
   unaliases( indexCount )

-- decrement the loop index count
   indexCount =3D indexCount - 1

-- generate an end loop code
>>end for

This would convert the code:

with each name in list do
      puts( 1, name )
   end with

into:

   for index1 =3D 1 to length( list ) do
      puts( 1, list[index1] )
   end for


PPG is not quite complete, but much of it is written and working. =
However, I was not convinced that there would be that much interest/need =
for such a tool, and so I shelved it.=20

PPG really doesn't know about Euphoria, and has only general =
pattern-matching abilities. Within a limited realm, it's pretty snazzy =
at what it can do - most of the features of PP (except for the [1..end]) =
can be coded in it fairly easily.

Is this interesting to people? Should I finish it? The majority of the =
work left to be done is on the alias routines, which are fairly =
straightforward.

Being buried under Win32Lib, I can't promise to get PPG done in a timely =
manner, even if there is interest - but I'd take a shot at it, if there =
is sufficent interest.

-- David Cuny

------ =_NextPart_000_01BD5656.D9EE6F20

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu