Sonic and Sega Retro Message Board: Building a compiler, need help! - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
Page 1 of 1
    Locked
    Locked Forum

Building a compiler, need help! prec ( 64 , 64 , 128 , 128 )

#1 User is offline Yoshimaster96 

Posted 15 June 2015 - 02:21 PM

  • Posts: 7
  • Joined: 06-July 14
  • Gender:Not Telling
  • Project:Super Monkey Ball hacking!
I'm building a compiler for a very simple language I made, targeted towards MIPS32. The entry point is always 0xC00000, and free RAM is from 0x50000-0x6BFFFF. Unfortunately, I'm not doing so well. I've tried C, C#, recursive descent, shunting-yard, pretty much everything. I am to my wits end. Anyone that can help me would be appreciated. Here are the specifications:

Pseudocode to parse tokens (does it work?):

get token
if token is _inc, parse include file
if token is _def, define constant
if token is _iff/_els, generate the following for _iff ( a op b ) { c } _els { d }:
evaluate a in assembly
evaluate b in assembly
branch to end if ( a op b ) is false
{ c }
j end2
end
{ d }
end2
if token is _jmp, generate the following for _jmp label
j label
if token is _ret, generate the following for _ret { r }
evaluate r in assembly
addu $v0, $r0, r
jr $ra
nop
else
if line is function call, generate the following for foo ( arg1 , arg2 , ... , argn )
decrease stack pointer to allocate args
load args to stack
jal foo
nop
increase stack pointer by same amount
if line is assignment, generate the following for a = { b }
evaluate b in assembly
sw b, 0(&a)

All variables are 1 word (32 bits).

All variable names, function names, labels, and control words
are exactly 4 characters in length, labels must end in underscore.

Variables cannot be initialized in their declarations.

Only integer values accepted.

Control word list:

_inc _def _iff _els _jmp _ret

Valid operations:

+ - * / %
& | ^
<< >>

Comparisons:

== != < <= > >=

Unaries:

- (negation of constants) $ (value at address)

Example code segment (prni prints integer, no syscall used):

test.r:

================
varb

main ( )
{
varb = 4
prni ( varb )
}
================

Page 1 of 1
    Locked
    Locked Forum

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users