simple

can somebody send me a way of crating com files . I have writen my own programing language called simple and iwant some help in witing a compilier for it.
MarktalbotAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mcriderCommented:
What is "simple" written in?
0
mark2150Commented:
COM files are a simple RAM image with an offset of 0100H. You can create a .COM file in the debugger simply by writing your code starting at offset 0100H and then saving it to disk. You're limited to one, 64kb segment for your entire program.

To write a compiler you need to figure out what the appropriate assembly language steps are for each of your programming languages statements. Your compiler can almost be a macro editor where the ASM is substitued for your "source" on a 1:1 basis. Then you use MASM to compile the ASM into the actual 1's and 0's or you directly write your own binary into the .COM file.

Is not hard conceptually, but can be *tough* to get "right".

mcriders comment notwithstanding, what you've written "simple" in is really immaterial. All you have to do is write a binary file with the equivalents of the ASM you'ld generate for each statement and there you are. Branching and looping are the tricky parts.

M
0
MarktalbotAuthor Commented:
simple is a vb module which i intend to create a full program out of
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

mark2150Commented:
If its in VB then you're going to have to use VB's tools to make the .EXE - not a .COM. IF you're talking about writing a compiler IN VB, that's ok, The *COMPILER* will be an .EXE that will, in turn, generate a .COM from your source files.

M
0
MarktalbotAuthor Commented:
this is the simple module. It is not quite finished(goto commands are needed)

Global v(255) As Integer
Public Sub parse(a As String)
Dim b As String
Dim c, d, e As String
Dim f As Integer
1 b = Left(a, 1)
Select Case b
Case "*"
c = Mid(a, 2, 1)
d = Mid(a, 3, 1)
e = Mid(a, 4, 1)
v(Asc(e)) = v(Asc(c)) * v(Asc(c))
Case "+"
c = Mid(a, 2, 1)
d = Mid(a, 3, 1)
e = Mid(a, 4, 1)
v(Asc(e)) = v(Asc(c)) + v(Asc(c))
Case "-"
c = Mid(a, 2, 1)
d = Mid(a, 3, 1)
e = Mid(a, 4, 1)
v(Asc(e)) = v(Asc(c)) - v(Asc(c))
Case "/"
c = Mid(a, 2, 1)
d = Mid(a, 3, 1)
e = Mid(a, 4, 1)
v(Asc(e)) = v(Asc(c)) / v(Asc(c))
Case "@"
c = Mid(a, 2, 1)
f = Mid(a, 3)
v(Asc(c)) = f
Case "S"
c = Mid(a, 2, 1)
f = Mid(a, 3)
v(Asc(c)) = Sin(f)
Case "C"
c = Mid(a, 2, 1)
f = Mid(a, 3)
v(Asc(c)) = Cos(f)
Case "T"
c = Mid(a, 2, 1)
f = Mid(a, 3)
v(Asc(c)) = Tan(f)
Case "s"
c = Mid(a, 2, 1)
f = Mid(a, 3)
v(Asc(c)) = Atn(f / Sqr(-f * f + 1))
Case "c"
c = Mid(a, 2, 1)
f = Mid(a, 3)
v(Asc(c)) = Atn(-f / Sqr(-f * f + 1)) + 2 * Atn(1)
Case "t"
c = Mid(a, 2, 1)
f = Mid(a, 3)
v(Asc(c)) = Atn(f)
Case "D"
c = Mid(a, 2, 1)
MsgBox (v(Asc(c)))
Case "I"
c = Mid(a, 2, 1)
f = CInt(InputBox("INPUT"))
v(Asc(c)) = f
Case "<"
c = Mid(a, 2, 1)
d = Mid(a, 3, 1)
If v(Asc(c)) < v(Asc(d)) Then
a = Mid(a, 4)
GoTo 1
End If
Case ">"
c = Mid(a, 2, 1)
d = Mid(a, 3, 1)
If v(Asc(c)) > v(Asc(d)) Then
a = Mid(a, 4)
GoTo 1
End If
Case "="
c = Mid(a, 2, 1)
d = Mid(a, 3, 1)
If v(Asc(c)) = v(Asc(d)) Then
a = Mid(a, 4)
GoTo 1
End If
End Select
End Sub
0
mark2150Commented:
That's simple alright. This is your "core" execution module - right? Ok, so you're writing an "interpritter", not a compiler. Your "source code" will be in an ASCII file that this piece of VB will read and take the appropriate actions.

A little constructive critism? Use labels instead of numbers (GOTO Top instead of GOTO 1)

Put lables on separate lines.

Indent statements between cases:

Select Case b
  Case "*"
    c = Mid(a, 2, 1)
    d = Mid(a, 3, 1)
    e = Mid(a, 4, 1)
    v(Asc(e)) = v(Asc(c)) * v(Asc(c))
  Case "+"
    c = Mid(a, 2, 1)
    d = Mid(a, 3, 1)
....

Use more descriptive variable names instead of A/B/C/D etc.

Put some *comments* in the code. A sub/function should have an explanation at the top along the lines of:

' Sub to do this and that
' Pass: a - expression to be evaluated
'   form is AxBCD where A is operator ...
' Returns: ...

VB style sheet with these and other guides for readable code is on my web page - www.cyberchute.com/rvbus/madmark

M
0
mcriderCommented:
You know, since your writing an interpreter in VB, you should probably just read the "simple" program and use the microsoft script control (MSSCRIPT.OCX) to execute it.

You can download it at:

http://msdn.microsoft.com/scripting/default.htm?/scripting/scriptcontrol/scdownfinish.htm 
 

Cheers!
0
MarktalbotAuthor Commented:
as i said the code is not finished and needs work but the whole idea of simple is that it is simple to the point that it is almost machine code. It is to be used in the analog sampling software that i am constructing to alow scripts to aply mathmatical functions to the tracee
0
MarktalbotAuthor Commented:
I want to create a compiled version of simple but i desigted that seing that i can`t do this at the moment i wrote the inteprited version.
0
mark2150Commented:
Ummm. I think you'll find that it is *NOT* "simple to the point that it is almost machine code" I've written compilers and interpritters (in .ASM) and let me tell you it can get *hairy* in a hurry. The fact that you're "language" syntax is simple has little to do with what it takes to write a *compiler* for it!

Your interpritter is *performing* the operations. What your compiler needs to do is translate the operations into *BINARY* and *then* write all of that to a file.

Also, have you given any thought to *IO*? How is "simple" going to accept input? Generate output? Will it talk to printers? At the DOS level or windows? How much DOS INT21 programming have you done? Do you anticipate doing any *disk* operations? The MATH part is almost trivial. Getting the values in and out is the *hard* part!

M
0
MarktalbotAuthor Commented:
commands i and d do the io
Case "D"
c = Mid(a, 2, 1)
MsgBox (v(Asc(c)))
Case "I"
c = Mid(a, 2, 1)
f = CInt(InputBox("INPUT"))
v(Asc(c)) = f
 when i said it is ment to be like machine code i ment the syntax of simple. All it is ment to do is do a mathmatical caclulation on an inputed variable (I and O are the two variables in question) and write a value to o and stop
0
mark2150Commented:
I see what you're coding in the interpritter, but have you given any thought as to how much .asm code it will take to duplicate that functionality?

M
0
MarktalbotAuthor Commented:
no i have never done asm programing and would like to now ether a good site on compiliers or asm to get this info from
0
mark2150Commented:
ASM programming is *NOT* for the faint hearted. You'll *need* a copy of the "80x86 Family Users Manual" from Intel, a copy of "DOS Programmers Reference" by Que as well as purchasing a copy of MASM from Microsoft. Web sites aren't going to be enough reference to write .ASM.

M
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MarktalbotAuthor Commented:
thanks you have given me enough information to get going thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.