|
Post by basica on Dec 5, 2014 17:55:36 GMT 1
alexfish,
I was wondering what m4basic was about and finally got around to reading Peter's link.
While this thread is discussing m4ide, a question came to mind.
Is m4basic an experimental try to convert Bacon code to using m4 as the translator from basic to c? And, so far, has been limited? What would the advantage be of using m4 over the existing programming?
Regards, basica (Sorry, if I've missed the obvious.....)
|
|
|
Post by alexfish on Dec 5, 2014 18:37:44 GMT 1
Hi Peter
This is I think a final beta testing of for loop
can now use name vars
BR Alex
define(FOR,`_FC pushdef(`_FC',`) popdef(`_FC') ') _FA(') define(_FA,` for(substr($@,0,eval(index(`$@',`TO')-2)) ; substr($@,0,index($@,=)) ifelse(eval(regexp(substr($@,eval(index($@,STEP)+4), eval(len($@)eval(- eval( 4+ index($@,STEP))))), `[-]')>0),1,>=,<=) substr($@,eval(2+index($@,TO)),eval(eval(index($@,STEP) eval(-eval(2+index($@,TO)))))) ; substr($@,0,index($@,=))+=substr($@,eval( 4+ index($@,STEP)),eval(len($@)eval(- eval( 4+ index($@,STEP))))) ) {')
bit of test code
FOR t = 1 TO 1000 STEP -p
NEXT
END result
Yes ;; U have to reverse the 1 and 1000 for it to work //
|
|
|
Post by vovchik on Dec 5, 2014 18:52:39 GMT 1
Dear Alex, It looks like a real mind-bender in M4, but the result is nice/perfect. With kind regards, vovchik
|
|
|
Post by alexfish on Dec 5, 2014 19:03:23 GMT 1
Hi Vovchik on M4 first thoughts where . what the crips is this ,. at same time thought Lex an easy option over it. final thoughts , once the bits began to click into place , M4 to me is lex yac + bison wrapped up in a suite the main stumbling block was to find the stream , the docs kept babbling on about (blagh,blag) well u got to punch the stream into gear and use the $@ , watch out "compulsive addiction" takes hold , but think U could handle if very well. BR Alex FROM M4
|
|
|
Post by Pjot on Dec 5, 2014 20:10:22 GMT 1
Hi basica, Well, it's experimental for sure ...actually, the m4basic project should be seen separate from BaCon. It is just my attempt to see how far we can get when using a macro processor. It turns out that the idea behind M4 is very old, its first release dates from 1977 and was invented by the same people who created the programming language C (Brian Kernighan and Dennis Ritchie). When using the concept of macros, the whole approach of text parsing is keyword based, contrary to BaCon for example, which is line based. If I had discovered M4 earlier, I most likely would have used it for the BaCon project altogether. The main advantage would be its automatic file reading and tokenization capabilities, which I had to program from scratch in the BaCon project. Using M4 would shorten the amount of code tremendously. BR Peter
|
|
|
Post by Pjot on Dec 5, 2014 20:15:35 GMT 1
Hi alex, Thanks for your efforts, but your proposition for the FOR/NEXT statement breaks the "hello" program (see below)? BR Peter
|
|
|
Post by alexfish on Dec 5, 2014 21:14:38 GMT 1
Hi Peter rather expected that one, on adapted version re on my sys the compilers ok on basics , will test against the hello program . re what i be saying the for loop is clean , I think says he I could be wrong but there have been instance of same when have programed the original source one can try declaring in main the will get err's if no subs or functions are called. if code is short then sometimes adding the end cures the problem I know what to look for , usually in declare the ; gets pushed to wrong position IE int t int ; main () and in U'r case with the for loop for (x = 1; x <=; x += 1 TO 5) out of interest can U post U'r version of the c code -n -p . are U still 64bit UPDATE have tested the original hello against the modded m4basic this is what I get temps.c: In function ‘main’: temps.c:35:13: error: ‘ab’ undeclared (first use in this function) =0; ab, bc, some in the original m4 the for is above strings in my code the for is below the strings , this rest of code unmodded did another version of lib to allow working out of main as far as I know the strings work , so now going back to test the hello + the for. BR Alex forgot to mention , will also look in for code + the lib , in defines , I am curious when editing why the highlighting is out of sync. as if there be a single " or ` Attachments:
|
|
|
Post by basica on Dec 5, 2014 21:47:56 GMT 1
peter, Thanks for your very good explanation for m4basic. After I've had some time trying to digest m4basic, I'll open a new thread. Sorry, alexfish, for breaking in when you're on a roll... Regards, basica
|
|
|
Post by alexfish on Dec 5, 2014 22:12:12 GMT 1
No problem
it be on topic .
BR Alex
|
|
|
Post by alexfish on Dec 6, 2014 9:21:47 GMT 1
Hi Peter
Found the problem
looks like the TO and STEP are still in the buffer , although they do not show in the output,? now looking.
here have changed the placement of a ; and the TO will show in the output this is re : hello demo
hopeful can do fix.
<= ; x += 1 TO 5 )
BR Alex
|
|
|
Post by alexfish on Dec 6, 2014 12:31:06 GMT 1
Peter this version needs the STEP if proves successful then will look to test for standard FOR t = 1 TO 50 @ NO step RE my Examples :: also to note that this version is for test if a VAR expression is used , since EVAL can not detect VARS; BR Alex Update M4 warps the brain matter , TO is not a problem , now need to sort the STEP mm! head going into the tunnel again , Peter U must have some Extraordinary constitution to tackle M4 oh dear me what I saying hope to be back soon with a solution:: till then .
|
|
|
Post by Pjot on Dec 6, 2014 19:18:47 GMT 1
Well, a slight form of mind masochism maybe Again, the FOR/NEXT gave me the biggest headache, so I'm not surprised you run into problems. It wasn't the first statement I implemented, actually, it was one of the last, after struggling with all the other stuff first. The learning curve for M4 is quite steep and examples are scarce. It's too bad, because M4 is very elegant because of its simplicity. I like it a lot, and already have used it in one of the projects occurring in my job. Anyway, now I have learned some of its concepts, I might have done some things in a different way, but it is always like that. Note that I recently added the 'changequote' line to m4basic, which avoids M4 translating tokens occurring in a plain string definition. BR Peter
|
|
|
Post by alexfish on Dec 7, 2014 12:06:55 GMT 1
+1
That's life ,
Yet , I like the way it is , it as all the necessary to get the job done + very easy to attach user defined macros for other libs BR Alex
|
|
|
Post by alexfish on Dec 7, 2014 13:31:42 GMT 1
Hi Peter have been going through the hello example found something but not sure , can U remember had reported a problem with the FILE IE a second called produced a bug here I am using the IDE with the include so can keep some things out the way IE the DECLARES etc The for loop works above the FILE code but not below it, here trimming back to where the buff fails. what I get in the for code is this */ /* Testing 'random' */ for(x = 1 ; x <= 10 ; x += 1 ) { } p
=fopen( "file.txt" , "w+" ); fprintf( p
,"%s", "This is a file test\n" ); /* Testing 'random' */ for( ; x <= = 1 10 ; x += 1 ) { } exit( +0); return(0);}
not sure what this means as of yet , possible this highlights the bug I mentioned , will continue testing the for in present form for now IE will see if can complete the hello example without the FILE WRITE etc Updated the only other fail is the terminal directives REM Testing 'color' COLOR FOREGROUND TO BLUE COLOR RESET For loop completes the demo by removing File and Terminal code , now going to test bring back the declares etc back into main. Update 2 : declares and subs back into main , initial test look ok have attached the hello file. BR Alex added to recap the original post Attachments:hello2.m4.tar.bz2 (1.36 KB)
|
|
|
Post by alexfish on Dec 7, 2014 15:55:53 GMT 1
Hi Peter
Now I see it
define(WRITELN,`_FC undefine(`TO') define(TO,`divert(1)') fprintf( divert(4)); divert(3),"%s",') define(COLOR,`_FC undefine(`TO') define(TO,`divert(2)),(int)(') define(RESET,`divert(2)`0),(int)(0'') divert(3)));fflush(stdout); divert(1)fprintf(stdout,"\033[%d%dm",(int)(')
now looking further
will look into 'IFDEF'
BR Alex
|
|