Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 18 Apr 2014, 09:14
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
BaCon - Bash-based Basic-to-C converter/compiler
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 36 [526 Posts]   Goto page: 1, 2, 3, ..., 34, 35, 36 Next
Author Message
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Fri 13 Nov 2009, 18:04    Post subject:  BaCon - Bash-based Basic-to-C converter/compiler
Subject description: supports GTK gui creation
 

Dear Puppians,

I know this should probably be in "Cutting Edge", but it is too late. Peter van Eerten, author of gtk-server, has written an amazing lexical parser/converter/compiler from basic to C in bash! He describes the program thus:

Quote:
BaCon is a free BASIC to C converter for Unix-based systems. The following design goals were followed:
Must run on each Unix/Linux/BSD platform, including MacOSX
Converted sourcecode must be compilable with GCC
Must resemble genuine BASIC with implicit variable delarations
Spoken language constructs are preferred
To use Bacon your system must have Korn Shell or Bourne Again Shell (BASH) available. If both Korn Shell nor Bash are available on your platform, download and install the free Public Domain Korn Shell which can execute BaCon also. Furthermore BaCon works with the traditional Korn Shell KSH88, but also with a newer Kornshell implementation like the MirBSD Korn Shell.


It supports gtk gui creation via glade and via calls to gtk libs. I have packaged the "compiled" compiler (yes, BaCon compiles itself!), the bash version and examples in the attached archive. The GTK apps I tried were about 20-30k in size after stripping.

BaCon presupposes a compiling environment, so if you don't have gcc, gtk headers etc. installed, you won't be able to do anything except to examine the source. I have also cleaned up a few examples. Documentation is included in the /doc dir.

Now, if we could only write a little lib (in Bacon - it supports includes) to understand gtkdialog syntax, we would have a nice little tool and very and small speedy apps - and the problems that Zigbert retularly experiences with widgets misbehaving or not recognizing one another's states would be solved.

With kind regards,
vovchik

BTW. BaCon - via functions and subroutines - is a "structured" variety of the language, which means no spaghetti. You can use it like Pascal and also make direct C calls. The sources are available at: http://www.basic-converter.org.
bacon.jpg
 Description   
 Filesize   28.28 KB
 Viewed   7457 Time(s)

bacon.jpg

bacon.tar.gz
Description 
gz

 Download 
Filename  bacon.tar.gz 
Filesize  166.06 KB 
Downloaded  1480 Time(s) 
Back to top
View user's profile Send private message 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Fri 13 Nov 2009, 18:30    Post subject:  

Vovchik,

Extraordinary.
I look forward to trying this.
Hey BASIC Puppy programmers - must be a few . . .
Wot ya gonna work on?

Very exciting Smile

Quote:
The GTK apps I tried were about 20-30k in size after stripping.


How big were they before stripping?
How long did the stripping take?
Did you require a high degree of C knowledge to do this?

Hope to see this in future devx
Smile

_________________
Puppy WIKI
Back to top
View user's profile Send private message Visit poster's website 
BarryK
Puppy Master


Joined: 09 May 2005
Posts: 7047
Location: Perth, Western Australia

PostPosted: Fri 13 Nov 2009, 20:36    Post subject:  

I continue to be amazed at the new projects that come out.

We should ask Peter to write a Bash-to-C converter!

Ahem, before anyone responds that there is one, no there isn't. There is a public domain tool that embeds Bash source inside a binary executable. That offers no advantages except hides the Bash source.

There is actually a shell to C converter, a commercial product, but it is not for Bash, one of the other shells.

Anyway, back onto BaCon -- yes, fascinating!

_________________
http://bkhome.org/news/
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Fri 13 Nov 2009, 20:50    Post subject:  

bash scripts usually make heavy use of pipes.
A pipe is like a "send the result to"

Code:
found=`ls | grep "test"`
echo "$found"


show the content of the current folder - send the result to the search-tool "grep", and search for "test"

In Basic, or C, you usually use inbuilt functions for this, so no subshell is opened.

Code:
result = dir()
found = search (result , "test")
print found

function search (thearray , thesearchword)
  REM here would follow some lines of search code
  return theresult
end function


So the design of Basic/C and Bash programs use very different concepts.
Basic/C: inbuilt code
Bash: external utilities, the typical GNU idea to put utilities in a chain.

I think the modular approach of Bash, is also the potential drawback, that might make it much slower than the other languages.
Each utility is run in a subshell, and even worse: invoking another interpreter, if the utility is a script.


------------------------
Bacon looks interesting. Small executables, and by importing functions from shared libraries, the function calls are very close to the C syntax.
Like this existing C documentation can be used as programming reference.

Like http://www.gtk.org/documentation.html.

Mark

_________________
my recommended links

Last edited by MU on Fri 13 Nov 2009, 21:13; edited 4 times in total
Back to top
View user's profile Send private message Visit poster's website 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Fri 13 Nov 2009, 20:54    Post subject:  

Dear Lobster,

I think we gain about 25% reduction by stripping (see the make-all script). It is instantaneous with such small binaries. The C stuff I changed in, for instance, gtkabout1.bac was pretty trivial - and I annotated my changes just to show how to create a button. Of course, we could write BaCon functions to wrap the gtk lib calls and make everything pretty and transparent - and more Basic-like.

I just got a nice email from Peter, the author, and he promises a working setenv, in addition to getenv, and a better system call (returning stdout and stderr) soon. I would also like to see CASE implemented, and he is considering it. We should send him bug reports or post them here, so that he gets feedback and continues to improve what I think is a very small, useful and CLEVER development tool.

If we have interesting libs or progs, we should also let him know so that he can post them on his site, too.

With kind regards,
vovchik

PS. I will look into the monkeymenu business. I think I first copied the Mr. Tech dir from FF into the appropriate Seamonkey dir, added a bit to the rdf (copied from a legitimate Seamonkey2 extension) and, after restarting Seamonkey2 and having fixed the rdf for monkeymenu in the same way, used Mr. Tech's local install feature to bring it in. It really works, although I haven't been able to adjust the size of the search box but did not try very hard. Since I was experimenting and not really counting on success, I didn't do a good job of recording my steps.
Back to top
View user's profile Send private message 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Fri 13 Nov 2009, 21:06    Post subject:  

Quote:
I just got a nice email from Peter


. . . Sizzle . . .

_________________
Puppy WIKI
Back to top
View user's profile Send private message Visit poster's website 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Sat 14 Nov 2009, 09:24    Post subject:  

Dear Puppians,

No great BaCon progs yet, but here is a little BaCon template generator I bashed out this morning to ensure that henceforth we all program "cleanly". I AM making a joke. Smile

With kind regards,
vovchik

PS. I should have written it in BaCon, I think.
mkbac.tar.gz
Description 
gz

 Download 
Filename  mkbac.tar.gz 
Filesize  859 Bytes 
Downloaded  1301 Time(s) 
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Sat 14 Nov 2009, 20:36    Post subject:  

Dear Puppians,

Although no great shakes here, I managed, as a test, to translate my bash mkbac into BaCon. My coding is exceptionally primitive, but I simply wanted to see how much time it would take to understand the syntax for basic procedures such as string handling, simple file i/o and parameter passing. The size of the BaCon binary is, obviously, much larger than the bash file, but that was to be expected, since the bash version doesn't really do that much and makes its own external calls (e.g date). I have attached the source and a binary.

I imagine MU and a few others on the forum could write a number of useful function libraries to simplify file, string handling, gtk calls and file i/o. What is amazing is that it works!

With kind regards,
vovchik
bac-mkbak.tar.gz
Description 
gz

 Download 
Filename  bac-mkbak.tar.gz 
Filesize  10.69 KB 
Downloaded  1305 Time(s) 
Back to top
View user's profile Send private message 
gerry

Joined: 26 Jul 2007
Posts: 946
Location: England

PostPosted: Sun 15 Nov 2009, 04:09    Post subject:  

@Vovchik- I may be thoroughly confused here. Are you using Bacon language? If yes, then visit 99-bottles-of-beer.org, and be the first to do the exercise in Bacon.

Gerry
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Sun 15 Nov 2009, 05:57    Post subject:  

Dear Puppians,

Peter is fabulous. He has done a new beta (attached) that includes everything I suggested: a select/case statement, a setenv and, most importantly, exec, which allows us to do things like this:

Code:
result$ = EXEC$("ls -l")


Hats off! Now to test all of this....

With kind regards,
vovchik

PS. Gerry, I will have a look at 99 bottles. Yes, the previous post contains my BaCon port of a bash script.
bacon-vb2.tar.gz
Description 
gz

 Download 
Filename  bacon-vb2.tar.gz 
Filesize  120.24 KB 
Downloaded  1267 Time(s) 
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Sun 15 Nov 2009, 09:25    Post subject:  

Dear Gerry,

Thanks for the suggestion. I posted this at 99-bottles-of-beer.net. The team will have to examine the code first, but here it is, in all its inelegant glory. It does, however, demonstrate the new SELECT/CASE statement, which I wanted to try out. There are 1000 ways of doing this, at the very minimum. My approach was guided by the esteemed and widely accepted principle of "minimum thought".

Code:
' *****************************************************
' PROGRAM:   beer.bac
' PURPOSE:   http://99-bottles-of-beer.net   
' AUTHOR:      vovchik (Puppy Linux forum)   
' DEPENDS:   gcc, bacon, bash
' PLATFORM:   Puppy Linux (actually, any *nix)
' DATE:      15-11-2009
' COMMENTS:   Not elegant - but works
' *****************************************************

' *********************
' INIT VARS
' *********************
beer_bottles = 100
stock$ = "bottles"
what$ = "of beer"
where$ = "on the wall"
action$ = "Take one down and pass it around, "
' *********************
' END INIT VARS
' *********************

' *********************
' MAIN
' *********************
REPEAT
   beer_bottles = beer_bottles - 1
   SELECT beer_bottles
      CASE 0
         stock$ = "No more bottles"
         action$ = "Go to the store and buy some more, "
         stock_depleted$ = CONCAT$(STR$(beer_bottles + 99)," ","bottles")
      CASE 1
         stock$ = CONCAT$(STR$(beer_bottles)," ","bottle")
         stock_depleted$ = "no more bottles"
      CASE 2
         stock$ = CONCAT$(STR$(beer_bottles)," ","bottle")
         stock_depleted$ = CONCAT$(STR$(beer_bottles-1)," ","bottle")
         ' stock_depleted$ = "no more bottles"
      DEFAULT
         stock$ = CONCAT$(STR$(beer_bottles)," ","bottles")
         stock_depleted$ = CONCAT$(STR$(beer_bottles-1)," ","bottles")
   END SELECT
   PRINT
   PRINT stock$," ", what$," ", where$, ", ", LCASE$(stock$), " ", what$, "."
   PRINT action$, stock_depleted$, " ", what$," ", where$,"."
   PRINT
UNTIL beer_bottles EQ 0
END
' *********************
' END MAIN
' *********************


With kind regards,
vovchik
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Sun 15 Nov 2009, 09:41    Post subject:  

Dear Puppians,

When I tried the following:
Code:
 result$ = EXEC$("ls -l")
PRINT result$


I got this:

Code:
root$ [/mnt/hdb6/install/bacon-vb2/tests]-> bacon exectest.bac
Starting conversion... done.
Applying indentation... done.
Starting compilation... done.
Program 'exectest' ready.
root$ [/mnt/hdb6/install/bacon-vb2/tests]-> ./exectest
total 72
-rwxr-xr-x 1 root root 22160 2009-11-15 14:59 beer
-rw-r--r-- 1 root root  1518 2009-11-15 15:04 beer.bac
-rw-r--r-- 1 root root 12172 2009-11-15 12:28 beer.txt
-rwxr-xr-x 1 root root 27051 2009-11-15 15:30 exectest
-rw-r--r-- 1 root root  1229 2009-11-15 15:30 exectest.bac

root$ [/mnt/hdb6/install/bacon-vb2/tests]-> ERROR: signal for
SEGMENTATION FAULT received - memory invalid or array out of bounds?
Try to compile the program with TRAP LOCAL to find the cause.


The exec routine executes correctly, as the screen output indicates, but something happens on returning from the function.

I have already mentioned this to Peter, so expect a bugfix soon.

Please post your but reports here, if you have any, so that he can attend to them.

With kind regards,
vovchik
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Sun 15 Nov 2009, 11:28    Post subject:  

Dear Puppians,

Mea culpa! Turns out I was an idiot. Peter showed me the correct syntax for GETENVIRON and SETENVIRON:

Code:
x$="MYGUI"
y$="<This is a test.>"
SETENVIRON x$, y$
z$ = GETENVIRON$(x$)
PRINT z$


The commands work as advertised.

Importantly, Peter has fixed the EXEC$ function. The new BaCon files are attached.

With kind regards,
vovchik
bacon-vb2a.tar.gz
Description 
gz

 Download 
Filename  bacon-vb2a.tar.gz 
Filesize  116.72 KB 
Downloaded  1242 Time(s) 
Back to top
View user's profile Send private message 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Sun 15 Nov 2009, 13:31    Post subject:  

Hey vovchik


A nice find thank you


I have to blow the dust off some old floppies
I have few programs I want to test


I didn't see the OUT command
that would allow port control for robotics/cnc Very Happy

is that a possible ?

*when I was a student all the formulas to help solve math for electronics I wrote in
basic


Joe

_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Sun 15 Nov 2009, 13:51    Post subject:  

Dear Joe (Big Bass),

We could always ask Peter whether he might consider implementing an OUT command directly. He is very forthcoming. But, you could also write your own function that would call a C routine and adjust your source accordingly. That is the nice thing about BaCon - it is "best friends" with C, so that if a routine is available in a C lib, you can generally call it - first having figured out the calling syntax and required var types. I am certain you could integrate your existing formulas pretty easily in an include lib. That lib might also interest some others (like the gmp include lib) in the first post.

With kind regards,
vovchik
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 36 [526 Posts]   Goto page: 1, 2, 3, ..., 34, 35, 36 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0990s ][ Queries: 13 (0.0089s) ][ GZIP on ]