|
M4BASIC
Sept 26, 2014 17:48:02 GMT 1
Post by alexfish on Sept 26, 2014 17:48:02 GMT 1
Hi Peter
Have been doing some testing on M4BASIC
have noted that RETURN has +0 , this throws an err if trying to pass a widget pointer
on the file open , can not allocate more than one file , also can not re-open the file
BR Alex
|
|
|
M4BASIC
Sept 27, 2014 7:07:56 GMT 1
Post by Pjot on Sept 27, 2014 7:07:56 GMT 1
Thanks Alex,
I will take a look at it.
BR Peter
|
|
|
M4BASIC
Sept 27, 2014 17:49:15 GMT 1
Post by alexfish on Sept 27, 2014 17:49:15 GMT 1
Hi Peter
been playing around with CONCAT
looks like the m4 version does not like certain chars
in short did some bits in bacon
the first line a$ is from part of the exec script
the code will output some bits that can be tested with M4BASIC
also can adapt the first a $ for M4BASIC, then will give approximation of some limitations.
not sure what actual problems is since read and concat of file appears to be working see second code block
BR Alex
a$=CONCAT$("tail -n +${LINE%%:*} $0 | ${AWK} '{if ($0 != ",CHR$(34),"BASIC",CHR$(34),"){split($0, byte); for(i=1; i <= NF; i++) printf(",CHR$(34),"%c",CHR$(34)," byte[i]);} }' > ${TEMPDIR}/basic.m4.gz")
a$=CONCAT$("tail -n +${LINE%%:*} $0 | ${AWK} '{if ($0 != ",CHR$(34),"BASIC",CHR$(34),"){split($0, byte);") FOR t= 1 TO LEN(a$) new$=CONCAT$(new$,"CHR(",STR$(ASC(MID$(a$,t,1))),"),") NEXT PRINT new$ PRINT "\n--------------------------------------\n" a$=CONCAT$("for(i=1; i <=; i++) printf(",CHR$(34),"%c",CHR$(34)," byte[i]);} }' > ${TEMPDIR}/basic.m4.gz") FOR t= 1 TO LEN(a$) new$=CONCAT$(new$,"CHR(",STR$(ASC(MID$(a$,t,1))),"),") NEXT PRINT new$ PRINT "\n--------------------------------------\n" a$=CONCAT$("(i=1; i <=; i++) printf(",CHR$(34),"%c",CHR$(34)," byte[i]);} }' > ${TEMPDIR}/basic.m4.gz") FOR t= 1 TO LEN(a$) new$=CONCAT$(new$,"CHR$(",STR$(ASC(MID$(a$,t,1))),"),") NEXT PRINT new$ new$=CONCAT$(CHR$(105),CHR$(61),CHR$(49),CHR$(59),CHR$(32),CHR$(105),CHR$(32),CHR$(60),CHR$(61),CHR$(59),CHR$(32),CHR$(105),CHR$(43),CHR$(43),CHR$(41),CHR$(32),CHR$(112),CHR$(114),CHR$(105),CHR$(110),CHR$(116),CHR$(102),CHR$(40),CHR$(34),CHR$(37),CHR$(99),CHR$(34),CHR$(32),CHR$(98),CHR$(121),CHR$(116),CHR$(101),CHR$(91),CHR$(105),CHR$(93),CHR$(41),CHR$(59),CHR$(125),CHR$(32),CHR$(125),CHR$(39),CHR$(32),CHR$(62),CHR$(32),CHR$(36),CHR$(123),CHR$(84),CHR$(69),CHR$(77),CHR$(80),CHR$(68),CHR$(73),CHR$(82),CHR$(125),CHR$(47),CHR$(98),CHR$(97),CHR$(115),CHR$(105),CHR$(99),CHR$(46),CHR$(109),CHR$(52),CHR$(46),CHR$(103),CHR$(122)) PRINT new$
new$=CONCAT$(CHR$(105),CHR$(61),CHR$(49),CHR$(59),CHR$(32),CHR$(105),CHR$(32),CHR$(60),CHR$(61),CHR$(59),CHR$(32),CHR$(105),CHR$(43),CHR$(43),CHR$(41),CHR$(32),CHR$(112),CHR$(114),CHR$(105),CHR$(110),CHR$(116),CHR$(102),CHR$(40),CHR$(34),CHR$(37),CHR$(99),CHR$(34),CHR$(32),CHR$(98),CHR$(121),CHR$(116),CHR$(101),CHR$(91),CHR$(105),CHR$(93),CHR$(41),CHR$(59),CHR$(125),CHR$(32),CHR$(125),CHR$(39),CHR$(32),CHR$(62),CHR$(32),CHR$(36),CHR$(123),CHR$(84),CHR$(69),CHR$(77),CHR$(80),CHR$(68),CHR$(73),CHR$(82),CHR$(125),CHR$(47),CHR$(98),CHR$(97),CHR$(115),CHR$(105),CHR$(99),CHR$(46),CHR$(109),CHR$(52),CHR$(46),CHR$(103),CHR$(122)) PRINT new$
the read in of all the file
DECLARE name TYPE char* DECLARE concat_name TYPE char* DECLARE myfile TYPE FILEPTR DECLARE myfile2 TYPE FILEPTR DECLARE isp TYPE long DECLARE ln TYPE long
name = "Hello cruel world";
PRINT (LEN(name)) FORMAT "%ld\n" REM init the variable concat_name to "" else get garbage at start of concat LET concat_name=""
PRINT "\n File read result \n --------------- \n" IF FILEEXISTS("bm4.sh") THEN
OPEN "bm4.sh" FOR READING AS myfile
WHILE NOT(ENDFILE(myfile)) DO READLN name FROM myfile
LET isp = INSTR(name, "=") IF isp >0 THEN PRINT "= found\n" ENDIF
LET concat_name=CONCAT(concat_name,name) WEND
CLOSE myfile
PRINT concat_name NL
ENDIF
PRINT " *-----ppp---------*\n -- * DONE *--\n"
|
|
|
M4BASIC
Sept 27, 2014 22:20:39 GMT 1
Post by Pjot on Sept 27, 2014 22:20:39 GMT 1
Hi Alex,
For your last program, please note that M4 does not do any parsing. So it cannot see if a keyword is mentioned in a string between double quotes, or not.
For example, these lines will go wrong:
FOR t= 1 TO LEN(a$) new$=CONCAT$(new$,"CHR(",STR$(ASC(MID$(a$,t,1))),"),") NEXT
Here, CHR is mentioned within double quotes. However, M4 cannot see this, and will think it is a macro, expanding it right away, which gives unpredictable results.
BR Peter
|
|
|
M4BASIC
Sept 28, 2014 2:03:42 GMT 1
Post by alexfish on Sept 28, 2014 2:03:42 GMT 1
Hi Peter think post not easy to understand Run the code under bacon , all bits work use the bacon bacongui shell , you will notice the bits that can be copied into the M4BASIC CONCAT I am aware the $ is not required in M4BASIC adapt the first line of the concat code in the post and test in M4BASIC also test the the CHR bits from the output of bacon shell they once code is in M4BASIC of concating the chr(*) bits try to print it then possible will understand 1. yes i am aware of the parser limitations of m4 , also , hint hint lex yak and bison 2. think also there be a problem with concat method or the print. BR Alex
|
|
|
M4BASIC
Sept 28, 2014 7:41:35 GMT 1
Post by Pjot on Sept 28, 2014 7:41:35 GMT 1
Alex, For any assignment you must use LET. In case of strings the LET statement just assigns a pointer. So then it is an assignment 'by reference'. Therefore, if you want to assign a string to a variable 'by value', then you need to use SET instead. This is the default BASIC way of assigning strings to variables. So, all your CONCAT assignments must be preceded with SET first. Thanks for looking into the M4Basic project. It is an experiment to see how far we can get with plain M4. Interestingly, only a few lines of code are needed to already get a very powerful converter, be it not a portable one; it only works with GNU C and the Boehm Grabage collector. Of course I know Lex and Yacc (or Flex and Bison, their GNU counterparts). Especially an implementation based on Flex would be interesting! BR Peter
|
|
|
M4BASIC
Sept 28, 2014 13:39:01 GMT 1
Post by alexfish on Sept 28, 2014 13:39:01 GMT 1
Hi Peter
Found the limitation of M4BASIC CONCAT
Yes Understand limitation of certain chars , IE in Bacon = ", this we know , one uses CHR$
M4 BASIC has a few more , so one has to experiment to find those bits,
The main limitation on the concat iterator
Looks like the MAX ITER = 85
as a workaround one can concat up to 85 bit then can add to it
IE This works
SET my_concat = CONCAT(CHR(116),CHR(97),CHR(105),CHR(108),CHR(32),CHR(45),CHR(110),CHR(32),CHR(43),CHR(36),CHR(123),CHR(76),CHR(73),CHR(78),CHR(69),CHR(37),CHR(37),CHR(58),CHR(42),CHR(125),CHR(32),CHR(36),CHR(48),CHR(32),CHR(124),CHR(32),CHR(36),CHR(123),CHR(65),CHR(87),CHR(75),CHR(125),CHR(32),CHR(39),CHR(123),CHR(105),CHR(102),CHR(32),CHR(40),CHR(36),CHR(48),CHR(32),CHR(33),CHR(61),CHR(32),CHR(34),CHR(66),CHR(65),CHR(83),CHR(73),CHR(67),CHR(34),CHR(41),CHR(123),CHR(115),CHR(112),CHR(108),CHR(105),CHR(116),CHR(40),CHR(36),CHR(48),CHR(44),CHR(32),CHR(98),CHR(121),CHR(116),CHR(101),CHR(41),CHR(59),CHR(32),CHR(102),CHR(111),CHR(114),CHR(40),CHR(105),CHR(61),CHR(49),CHR(59),CHR(32),CHR(105),CHR(32),CHR(60),CHR(61),CHR(32))
SET my_concat = CONCAT(my_concat,CHR(78),CHR(70),CHR(59),CHR(32),CHR(105),CHR(43),CHR(43),CHR(41),CHR(32),CHR(112),CHR(114),CHR(105),CHR(110),CHR(116),CHR(102),CHR(40),CHR(34),CHR(37),CHR(99),CHR(34),CHR(32),CHR(98),CHR(121),CHR(116),CHR(101),CHR(91),CHR(105),CHR(93),CHR(41),CHR(59),CHR(125),CHR(32),CHR(125),CHR(39),CHR(32),CHR(62),CHR(32),CHR(36),CHR(123),CHR(84),CHR(69),CHR(77),CHR(80),CHR(68),CHR(73),CHR(82),CHR(125),CHR(47),CHR(98),CHR(97),CHR(115),CHR(105),CHR(99),CHR(46),CHR(109),CHR(52),CHR(46),CHR(103),CHR(122))
PRINT my_concat
as a side note LET statement also works.
In regards to lex , have done some work on that side as regards code completion for the likes of Elementary widgets + the lower level libs IE if statement = WINDOW , then result = rest of lines to complete the bits .
of EFL , EFL has a lot of low end libs that can fill the gap between where BACON is now and what M4 basic lacs at Present.
if one wants to use Elementary Widgets or just the Evas Canvas those libs are there at default.
M4BASIC + EFL looks like a good partnership .
End Result , very lightweight execs.
BR ALEX
|
|
|
M4BASIC
Sept 29, 2014 19:41:50 GMT 1
Post by Pjot on Sept 29, 2014 19:41:50 GMT 1
Hi Alex, Interesting that GNU M4 cannot handle more than 85 arguments in a macro! Obviously, this is an M4 limitation. Note that the original M4 cannot handle more than 9 arguments. BR Peter
|
|
|
M4BASIC
Sept 29, 2014 20:24:22 GMT 1
Post by alexfish on Sept 29, 2014 20:24:22 GMT 1
Hi Peter
those bits had me foxed , but at not sure to the actual limitation , is a stack size problem? may be worth looking up to see if it is.
anyway, thought would do a bit of daft Flex code , had already prepped this so posting for any user interested in Flex.
Very basic . so posting the whole antic as is , just kind of thinking M4BASIC code make light work of coding bits for Flex.
Have Fun + BR Alex ------------------------------- Hi Peter and All
thought show why use 'Flex'
for me one can structure the CONDITION code just like c ;
here have chopped up some so can see what going on as regards adding sub routines the condition code , very basic and none nonsensical , but there are not may examples of how to do it.
much same as m4 not that I want to start learning it either ! , but I find this easier than M4 hieroglyphs.
some code , compile commands then the code :: the a.out < points to the file to parse
flex myexample.l gcc lex.yy.c -lfl -o myexample ./myexample ./a.out < testfile.bac
some ridiculus code..
and examples test file
%{ #include <stdio.h> #include <string.h> #include "y.tab.h" #include <math.h>
%}
int num_lines = 0, num_chars = 0 , is_win=0 ; char* on = "ON";
%%
[a-z] printf( "%s", yytext ) ;
" " printf( "%s", yytext ) ;
"WINDOW" { printf( "%s%s", yytext," (" ) ; printf( "%s", " `" ) ; is_win=1;
void Do_Something(){ puts (" do something here:: Bye"); } if (is_win) { puts ("Parsing Window blagh blagh"); } Do_Something(); }
[0123456789]+ {printf( "%d",atoi( yytext ) ) ;}
\n puts ("");
%%
main(){
yylex();
}
a bit to test the out put
testfile.bac
win = WINDOW("window", 600 , 600)
chopping the bits
Bye For now
|
|