Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: yrinfish on June 15, 2011, 10:31:31 am

Title: The Happy Parser
Post by: yrinfish on June 15, 2011, 10:31:31 am
This is my happy thread ;)

CURRENTLY REWRITING THE WHOLE THING.
Because it became a mess, and I got some new ideas to make it better. (Learn While Doing lol)

I am working on a programming language for the 83 etc, (But it is easily retargetable, so anyone who knows er, ti-nspire asm for example, could edit some strings and is ready!!)

I made it with JavaScript (I have a strange relation with that language)

working on a C++ version, so there is an exe for the winows guys coming!!

Current Features:
-Nice name (Happy)
-Operator Precedence
-Somewhat optimized expressions (Crenshaw hates me now)
-Really platform-independent because it's made with JS
-Nothing more yet...

To show what it is currently able to do:
Spoiler For Input and Output:
4+-(5+~3)

is translated to:

   ld hl, 4
   push hl
   ld hl, 5
   ld de, 3
   ld a,e
   cpl
   ld e,a
   ld a,d
   cpl
   ld d,a
   add hl, de
   pop de
   ex de,hl
   ld a,e
   cpl
   ld e,a
   ld a,d
   cpl
   ld d,a
   inc de
   add hl, de



That may seem much, but most of it is the super inefficient unary operator - and ~.
It is able to do * and / too, but that's not a z80 command, and I have no libs yet...


It also optimizes a VERY little bit: for example, it doesn't fall for this one:
(Which is also good to have no precedence)

((((2+3)*4)+5)/7)

is translated to:

   ld hl, 2
   ld de, 3
   add hl, de
   ld de, 4
   call multiply
   ld de, 5
   add hl, de
   ld de, 7
   call divide

Isn't that nice?

Spoiler For Log::
10-06-2011 Started development with a Crenshaw tutorial.
13-06-2011 Because of the horrible output quality, I started rewriting everything.
14-06-2011 Announced it here, posted a poll about precedence. Almost finished the expression parser the same day.
15-06-2011 Getting the pushes and pops right was harder than expected.
16-06-2011 Adding variables (sort-of) and function calls, Still fighting with pushes and pops.
17-06-2011 Still fighting with those #$%^pushes and pops, made a website for it. v0.0.2
18-06-2011 Assignments!! I think I finally fixed the pushes and pops. v0.0.3
19-06-2011 A few things that I want to make better, and going to make it MULTILINE YAY
Between:     v0.0.4
21-06-2011 It was slowly turning into a mess, so I decided to start over. REWRITING YAY
Until now: rewriting almost complete, rewriting it in C++ so it is more usable

Spoiler For Syntax:
var1,var2=nn-nn+(nn--nn)*~nn/var3

nn is a number 0<nn<65535
var is a variable

Link (http://yrinfish.webuda.com/prj/ti84/happy/index.php) to test it yourself (Please do that!!)
Title: Re: Happy programming!!
Post by: Spyro543 on June 15, 2011, 10:39:31 am
Cool :D I could've never even done that ;D Have fun with * and /. I'm suprised those aren't in asm.
Title: Re: Happy programming!!
Post by: yrinfish on June 15, 2011, 11:08:47 am
It is not hard (ok, sometimes it is) but it is A LOT of work (I really respect Quigibo, he made Axe YAY)

I placed a link to it, so you can test it...
Title: Re: Happy programming!!
Post by: Ashbad on June 15, 2011, 02:06:01 pm
This is looking like it's going quite well :) good luck!

However, I also notice some bugs with expression handling:

1. 5 + -(5) produces:

Code: [Select]
ld hl,5

2. many times, the expression starts with a push HL, but never pops it ;) that would be very dangerous over time.
Title: Re: Happy programming!!
Post by: yrinfish on June 15, 2011, 02:10:38 pm
It doesn't support whitespace yet... And please give an example of 2?


How do I save the content of HL to a pointer?
Title: Re: The Happy Parser
Post by: yrinfish on June 17, 2011, 01:19:10 pm
By the way, who wants a compiler tutorial? I could make one...

(without pushes and pops, I hate them (But I think I got them right now (I already said that 42 times (I already said that on irc (Or ommon(Is there any difference between those two?))))))
Title: Re: The Happy Parser
Post by: yrinfish on June 22, 2011, 03:17:27 pm
Ok, I am working on a new version. which will be designed top-down (that means, first get the parsing large things right, then the smaller ones).
Currently this is valid:

Code: [Select]
{
    if() {
        ;
        ;
    } else {
        ;
        ;
    }
}
yup, that's right, nothing yet...  To see what it actually does, type dev in the options box.
But if I would merge it with the old parser, I would have an almost working one!
However, I don't want to  ;D, because I'm going to add support for data types and so on...

some questions:
default signed or unsigned? (or 16bit signed and 8bit unsigned)
C or am I allowed to make it more calc-specific and consistent?

I'll keep you updated via the first post and my sig.
Title: Re: The Happy Parser
Post by: yrinfish on July 19, 2011, 09:29:46 am
Ok, because noone wanted to answer any question (Don't worry, I'm used to that  <_<) I asked some of them on irc, and I've got a new version:

0.0.5!!!!

And it supports even more than the previous one:
Code: [Select]
{
    if !() {
        while () {
           
        }
    } else if () {
        while !() {
           
        }
    }
}

Yup, still no expression support, or anything else, but I have to start somewhere.
Happy has output too now:
Code: [Select]
;Happy 0.0.5
#include ti83plus.inc
.org $9D93
.db t2ByteTok, tAsmCmp
;[EXPRESSION PLACEHOLDER]
jp nz, lbl1
lbl3:
;[EXPRESSION PLACEHOLDER]
jp z, lbl4
jp lbl3
lbl4:
jp lbl2
lbl1:
;[EXPRESSION PLACEHOLDER]
jp z, lbl5
lbl7:
;[EXPRESSION PLACEHOLDER]
jp nz, lbl8
jp lbl7
lbl8:
lbl5:
lbl2:

Try it at my website (http://yrinfish.webuda.com/prj/ti84/happy/ver/0.0.5/)
Title: Re: The Happy Parser
Post by: Munchor on July 24, 2011, 10:39:11 am
I actually thought Happy was gonna be coded in C++ from now on :S Javascript has no classes which makes it quite harder.
Title: Re: The Happy Parser
Post by: Ashbad on July 24, 2011, 10:43:34 am
Well, technically you could write a OOP language compiler in brainfuck, since it doesnt matter the language that handles it.  Usually when writing a compiler for an OOP language, you won't use the OOP features of the language you're writing it in anyways, since you'll need to think of classes more as of structs than as actual abstract frameworks for instances.
Title: Re: The Happy Parser
Post by: yrinfish on July 25, 2011, 05:10:38 am
@ephan, I will, if somebody can provide me the c++ code for my getChar, and scan routines

(or load the source into an array of char's, who can help me?)

That's what I hate about some programming languages, simple things take so long in the beginning...

BTW, I'm working on it right now (the js version)
Title: Re: The Happy Parser
Post by: yrinfish on August 24, 2011, 04:28:09 am
Project update: working on return values, so you can have a function that retuns a 8-bit number in A and a different function return a 16-bit number in HL.

BTW: IN C++, so finally a 'real' compiler!
Title: Re: The Happy Parser
Post by: DJ Omnimaga on August 24, 2011, 11:50:51 pm
Nice to see you are working on this again :)