flat assembler
Message board for the users of flat assembler.

flat assembler > Main > Converting arithmetic expressions to Assembly

Author
Thread Post new topic Reply to topic
UniverseIsASimulation



Joined: 23 Sep 2016
Posts: 18
Hey, guys!
I am trying to impress my informatics teacher by making a web-app that converts arithmetic expressions to the i486-compatible assembly. You can check my work here:
Arithmetic expressions to assembly converter
So, does it produce correct results? I've tried to test it, and to me it looks like it does, but I'll ask some experts on those things.
Post 11 Feb 2018, 14:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15871
Location: 162173 Ryugu
I wanted to try this, but without JS it does nothing for me. However when examining the source the code looks good, indented and commented.
Post 11 Feb 2018, 18:20
View user's profile Send private message Visit poster's website Reply with quote
UniverseIsASimulation



Joined: 23 Sep 2016
Posts: 18
Well, yes, I've done everything in JavaScript (the webapp doesn't communicate with the server at all). Which browser are you using? I've tested it in Internet Explorer 6 and it works.
Post 11 Feb 2018, 19:27
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15871
Location: 162173 Ryugu
Not having JS is a choice I made.
Post 12 Feb 2018, 04:21
View user's profile Send private message Visit poster's website Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 714
Overflows the stack:
Code:
a+(b+(c+(d+(e+(f+(g+(h+(i+(j)))))))))

Reads past depth of stack (TBH, the AST is not right):
Code:
a+-b a*-b

In general, I would say the parser has a problem with unary minus, and "a^b" can't be used in place of "pow(a,b)"
If you can solve the problem of unary minus, would you like to contribute to my project?
Post 12 Feb 2018, 11:05
View user's profile Send private message Reply with quote
UniverseIsASimulation



Joined: 23 Sep 2016
Posts: 18
Quote:
Overflows the stack

Thanks for pointing that out! I think I fixed it, there was an error in my implementation of the DFS algorithm (which is attempting to avoid the stack overflow by compiling the "deepest" parts of the expression first). Could you test it again, please?
Quote:
a+-b

What's that supposed to do? As far as I know, it should issue a syntax error (and I haven't tried to implement that yet). Do you think it should parse the same as "a+(-b)"? That would be quite tough to implement.
Quote:
If you can solve the problem of unary minus, would you like to contribute to my project?

Sorry, my knowledge of C and C++ is minimal.
Post 12 Feb 2018, 19:41
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 714
Good, now it does the inner first. However, it is impossible to avoid spill code. Some expressions simply need more than 8 registers. Consider a sum of 256 terms with the parenthesis placed so that the ast is a complete binary tree.

Any school girl the age of at least 7 knows that 2*-3 is -6 and not a "syntax error"
Post 12 Feb 2018, 20:09
View user's profile Send private message Reply with quote
UniverseIsASimulation



Joined: 23 Sep 2016
Posts: 18
Quote:
Consider a sum of 256 terms with the parenthesis placed so that the ast is a complete binary tree.

I must admit I don't know what you are talking about.
Quote:
Any school girl the age of at least 7 knows that 2*-3 is -6 and not a "syntax error"

Anyway, I've modified the tokenizer to tokenize the expressions such as "2*-3" as "2*(-3)". It does so by "splicing" those parentheses into the array. I don't know if that's possible in C++ though.
Post 13 Feb 2018, 08:08
View user's profile Send private message Reply with quote
UniverseIsASimulation



Joined: 23 Sep 2016
Posts: 18
revolution wrote:
Not having JS is a choice I made.

Well, the code in that app is just 600 lines of JavaScript, so you can see for yourself that it's not a spyware, if you don't want to run it because you think it might be. Better yet, use a browser that doesn't do JIT compilation of JavaScript (such as the Internet Explorer 6), so that it's impossible to do the Meltdown or the Spectre attack. The less JavaScript a browser supports, the harder it is to make a spyware using the JavaScript it provides.
Post 15 Feb 2018, 20:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15871
Location: 162173 Ryugu
UniverseIsASimulation wrote:
revolution wrote:
Not having JS is a choice I made.

Well, the code in that app is just 600 lines of JavaScript, so you can see for yourself that it's not a spyware, if you don't want to run it because you think it might be. Better yet, use a browser that doesn't do JIT compilation of JavaScript (such as the Internet Explorer 6), so that it's impossible to do the Meltdown or the Spectre attack. The less JavaScript a browser supports, the harder it is to make a spyware using the JavaScript it provides.
It is not you that I doubt at all. But there are so many other actors in the game, and we have to trust every one of them even when we don't know who they are.

Anyhow, this off-topic might be best left to that other thread.
Post 16 Feb 2018, 02:45
View user's profile Send private message Visit poster's website Reply with quote
UniverseIsASimulation



Joined: 23 Sep 2016
Posts: 18
Does Tomasz mind me naming my website after Flat Assembler? Sorry I didn't ask before. It was supposed to be a metaphore. Like, if you write in assembly, you mustn't be sufficed with "surface" explanations, and I am supposed to give people a "deeper" perspective on some things. The domain assembler.000webhostapp.com was already taken, so I've chosen the domain name flatassembler.000webhostapp.com.
Post 17 Feb 2018, 20:11
View user's profile Send private message Reply with quote
UniverseIsASimulation



Joined: 23 Sep 2016
Posts: 18
Anyway, the web-app has been improved in many ways since I last posted here. I've implemented the error-handling (hopefully all syntax errors are covered and reacted to with an useful error message) and I've implemented some simple syntax-highlighting algorithm for assembly.
Post 28 Jun 2018, 11:19
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 714
Ok. I will try to break it again. Laughing
Btw, when really parsing, the approach of "splicing parenthesis in" doesnt seem like the best way to go.
Post 28 Jun 2018, 20:53
View user's profile Send private message Reply with quote
UniverseIsASimulation



Joined: 23 Sep 2016
Posts: 18
Did you find some error? It's hard to believe there are none.
Post 11 Jul 2018, 16:19
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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 cannot attach files in this forum
You can download files in this forum


Copyright © 2004-2018, Tomasz Grysztar.

Powered by rwasa.