Page 1 of 1
just a mindless "branfart"...
Posted: Wed Sep 22, 2004 8:26 pm
by jakykong
ok i am working on a translator for the first pass of a compiler i am designing. and since Qbasic is by far much easier to deal with strings in than C, even though using qbasic will add one more pass to the compiling routine, i am using it for the sake of ease.
the problem is(and it's a really stupid problem...), i can't remember how to tell where the end of a line in a file is!
unless i have a way to delineate the end of a file(the language is puctuation-free, so there is no way to use the syntax to do so), the first pass of the compiler will not know the difference between a new command and a parameter in a command... HELP!
please note: all i need to do is read a line at a time into a string from a file
Posted: Wed Sep 22, 2004 11:41 pm
by Dr_Davenstein
LINE INPUT
Returns all characters into a string variable up to a carriage return.
LOF
Give you the length of a file in bytes.
EOF
Returns true if you have reached the end of an open file.
If I understand you correctly, those are what you need.
Posted: Thu Sep 23, 2004 6:03 am
by jakykong
yup that pretty much solves the problem.
Posted: Thu Sep 23, 2004 6:38 am
by jakykong
well got it done... thanks to you i remembered how to read a line. really was a stupid "brainfart"! i have devided to take a little different path to the compiler. The passes are as follows the way i was going to go about it before:
1: remove REMS and spaces before lines.
2: deal with compiler directives(INCLUDEs)
3: translate to BASIC
4: translate to C
5: translate to ASM
6: assemble
but there are some major efficency flaws in that. For one thing, it was translated to BASIC before it was translated to C. However, the language depends on "spaghetti code" to work with loops and so forth, and C has almost no support for spaghetti code. But i have aready developed a BASIC-C translator, so all i needed was to make it into BASIC to get the rest done. But translating between the multiple levels of programming to get it into machine code took overall about a minute(54.6 seconds to be more exact, i always include a compile time display while developing a compiler) to compile from my language to the machine code. that is a long time! especially since the code in the source file was only about 10 lines long. a simple hello world example in the applications due to *extremely* limited string support. Actually, no string support. you need ASCII to do charactors. i have 2 text functions built into it to put charactors on the screen from a variable. arrays have some support, but are definately limited. Anyway, i have one about changing my logic:
1: translate to BASIC
2: compile using BASIC compiler(bc.exe)
and that will get me to an executable file.
However, i have run onto a problem: i have never once used the bc.exe file directly, and know of no documentation on the topic. So, i need to know one more thing: what is the command line for the bc.exe compiler?