flat assembler
Message board for the users of flat assembler.

Index > Heap > Best way to write a compiler?

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
I'm not even sure where I'd begin to start actually coding a compiler, and that's something I've wanted to do for quite some time.
Sad

I know that I need a certain set of logic definitions (code words) to use in order for it to be worth anything, but for actually coding what would I do?
Post 08 Dec 2007, 06:04
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2914
Location: [RSP+8*5]
bitRAKE
First write an expression parser - to correctly calculate results of function like: Y=(7+6)*3 + 2; or Y=Add[Mul[Add[7,6],3],2]. That will give you some idea of complexity. Then support multiple equations and symbolic names instead of just numbers and operations: X=3, Y=Z*X+2, Z=7.

...that is the front end of a compiler. Now you need to write a translator from your internal data structures to an output format: FASM source, or binary code, etc.

Not very much is needed to make a language. Take a look at: Brainfuck. Or are you looking to create a compiler for an existing language?
Post 08 Dec 2007, 18:40
View user's profile Send private message Visit poster's website Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Possibly something along the lines of a BASIC.
Post 08 Dec 2007, 18:48
View user's profile Send private message Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue
Read the first chapters of crenshaws tutorial and translate the asm to x86 as you go.
Post 08 Dec 2007, 20:08
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
Do your users a favor... Add an option to remove type checking on a particular line or completely. I just started coding a simple client-server example in C++ today and it resulted in more type casts than variables (or so it seems). I havn't even started on the sockets yet, i'm spending over 12 hours on just the interface because alot of it needs typecasted.
Post 09 Dec 2007, 03:06
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2914
Location: [RSP+8*5]
bitRAKE
I'd see that as bad interface design and nothing to do with the language.
Post 09 Dec 2007, 08:58
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
kohlrak wrote:
Do your users a favor... Add an option to remove type checking on a particular line or completely. I just started coding a simple client-server example in C++ today and it resulted in more type casts than variables (or so it seems). I havn't even started on the sockets yet, i'm spending over 12 hours on just the interface because alot of it needs typecasted.


This is not a language problem, but either

a) you're a sucky coder
b) you're using Microsoft's PlatformSDK which is very clearly written for C, and pretty horrible to use with C++ code (casts ahoy!)

When dealing with PSDK in C++ code, encapsulate the lower-level PSDK calls once, get over the horrible casting, and use your abstractions and don't worry.

_________________
Image - carpe noctem
Post 09 Dec 2007, 11:56
View user's profile Send private message Visit poster's website Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue
Don't include the typecasts at all is my suggestion. They are evil.
Post 09 Dec 2007, 13:30
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
rhyno_dagreat wrote:
Possibly something along the lines of a BASIC.
I think it would be best if you start with a basic interpreter, then move on to a compiler.

Here are some basic examples, for DexOS, by Roboman and me, that may help.
http://www.dex4u.com/basic/tinyb.zip
http://www.dex4u.com/basic/dbasic.zip

Note: They are just simple demos, to give a starting point.
Post 09 Dec 2007, 19:00
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Thanks!

I have finals to worry about this week, however after they are complete I will take the time to fully read through your code. It looks good though.
Post 10 Dec 2007, 05:32
View user's profile Send private message Reply with quote
0.1



Joined: 24 Jul 2007
Posts: 474
Location: India
0.1
kohlrak wrote:
Do your users a favor... Add an option to remove type checking on a particular line or completely. I just started coding a simple client-server example in C++ today and it resulted in more type casts than variables (or so it seems). I havn't even started on the sockets yet, i'm spending over 12 hours on just the interface because alot of it needs typecasted.

kohlrak, can you please show me your code?

_________________
Code:
 o__=-
 )
(\
 /\  
    
Post 10 Dec 2007, 05:38
View user's profile Send private message Reply with quote
peter



Joined: 09 May 2006
Posts: 63
peter
You may find my tutorial on expression evaluators useful:

http://smallcode.weblogs.us/2007/02/18/writing-a-simple-expression-evaluator/
Post 11 Dec 2007, 00:40
View user's profile Send private message Visit poster's website Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Hey Peter! That was helpful just from quick glance! I was wondering about how to work with the order of operations.
Post 11 Dec 2007, 02:01
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Sorry for off-topic a little: I am the only one that experiment full physical memory consumption with peter's blog? It is the second time (the first time was at the SSE4 thread), that when I enter into the blog the browser starts to allocate lots of memory till there is no more available (perhaps earlier but allocates enough to fully deplete the physical memory). One time was with IE 7 (WinXP SP2 32-bit) and now with Firefox 2.0.0.11 (64-bit on Ubuntu 7.10 AMD64).

It is not something that happens every time I enter since by closing the tab and entering again I solve the problem. The main problem is that while the browser is busy depleting your memory it is completely unresponsive and the system starts to be really slow due to the excessive swapping.
Post 11 Dec 2007, 03:45
View user's profile Send private message Reply with quote
Mr_Silent



Joined: 25 Apr 2006
Posts: 30
Mr_Silent
2 Loco: My antivirus (Trend Micro IS2006) says there is a virus there.
This one.
Post 11 Dec 2007, 05:15
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
Quote:
kohlrak, can you please show me your code?


The server side isn't done yet, but the client side is. If you want the visual studio project, PM me and i'll send it to you.
Post 11 Dec 2007, 05:21
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: behind the arc
Picnic
Dex4u wrote:
Here are some basic examples, for DexOS, by Roboman and me, that may help..

Thanks for the examples Dex4u.


Last edited by Picnic on 15 Jan 2020, 09:15; edited 1 time in total
Post 11 Dec 2007, 19:37
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Thanks Thimis!
Post 12 Dec 2007, 00:38
View user's profile Send private message Reply with quote
peter



Joined: 09 May 2006
Posts: 63
peter
The blog is infected with trojan, and I cannot fix it. All blame is on Weblogs.Us admins, who has bad security policies (because of them, the site was infected). I wrote a letter to them.

Please check your computer with antivirus if you visited my page with IE. I'm very sorry for these problems. Probably, I will change the hoster for my blog.
Post 12 Dec 2007, 06:57
View user's profile Send private message Visit poster's website Reply with quote
peter



Joined: 09 May 2006
Posts: 63
peter
I apologize to LocoDelAssembly, Mr_Silent, thimis, and other readers of my blog for these problems. JD, weblogs.us admin, helped me a lot in removing the virus.

Weblogs.us is not responsible for the infection; I'm very sorry for accusing them. It was my own fault: I did not updated the blog software, and some malicious hacker broke into the site.

The virus is fully removed now. I'm taking all possible measures to prevent such disasters in future.
Post 15 Dec 2007, 09:28
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
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 can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.