don't click here

Building a compiler, need help!

Discussion in 'Technical Discussion' started by Yoshimaster96, Jun 15, 2015.

  1. Yoshimaster96


    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
    { d }
    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
    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
    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:

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


    == != < <= > >=


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

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



    main ( )
    varb = 4
    prni ( varb )