flat assembler
Message board for the users of flat assembler.

Index > Examples and Tutorials > EXP^ASM - Expression Parser, Dis/Assembler

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



Joined: 17 Jan 2012
Posts: 369
uart777
An example expression parser.

EXP^ASM converts a standard "Infix" expression to "Reverse Polish Notation" (RPN) then to ASM with machine code. Dis/assembles code as you type.

Expression.INC uses a single-pass algorithm that produces 3+ times more effecient code than the popular "Let's Build a Compiler" tutorials by Jack Crenshaw (good introduction for beginners). ASM code must be rescanned and optimized (which is another subject that would take an entire book to explain considering the infinite number of ways that code can be written).

No time for questions. ASM experience is assumed. Designed in 1024x600/768 resolution. Includes 2 examples that are not graphical.

Image

Download: http://sungod777.zxq.net/expression.zip


Description:
Download
Filename: expression.zip
Filesize: 132.87 KB
Downloaded: 237 Time(s)



Last edited by uart777 on 27 Aug 2013, 03:19; edited 1 time in total
Post 28 Mar 2013, 14:53
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
uart777,

How about common subexpressions and such? Wink
Post 28 Mar 2013, 15:08
View user's profile Send private message Reply with quote
uart777



Joined: 17 Jan 2012
Posts: 369
uart777
baldr: Most optimizations can be performed while in RPN format - example: resolve constant subexpressions, re-order cumulative operations, etc - before conversion to ASM. In any case, this provides an interface for creating/testing expression algorithms.
Post 28 Mar 2013, 15:15
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
uart777,

Constant expressions aren't good to show power of parser (they're constant and should be replaced with equivalent constants during compilation, right?).

Show me parser that will replace 1+2+3+...+n with n(n+1)/2 (when n is a run-time value), and I'll eat my hat. Wink

Gauss was able to do that in his teen ages (as anecdote says).
Post 28 Mar 2013, 15:38
View user's profile Send private message Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6029
Location: Poland
MHajduk
I like the whole idea but also agree with baldr that your expression parser would be far more usable if you would allow use of symbolic constants inside the input field. Smile

I've noticed an issue when I tried to enter some number of leading zeros before the digit. There is something that should be fixed, IMO (remove the unneeded leading zeros should be enough), see the attached screenshot:

Image
Post 28 Mar 2013, 15:56
View user's profile Send private message Visit poster's website Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6029
Location: Poland
MHajduk
Another thing: seems that your expression parser doesn't allow to use of negative numbers? See the screenshot:

Image
Post 28 Mar 2013, 16:03
View user's profile Send private message Visit poster's website Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6029
Location: Poland
MHajduk
Even use of parentheses doesn't help here:

Image
Post 28 Mar 2013, 16:09
View user's profile Send private message Visit poster's website Reply with quote
KevinN



Joined: 09 Oct 2012
Posts: 161
KevinN
it's cool how it is imo
Post 28 Mar 2013, 16:52
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:14; edited 1 time in total
Post 28 Mar 2013, 17:32
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
HaHaAnonymous,

There is no specification, use the source, Luke. Wink

It's incorrect in common sense, yet it may be some obscure way to signify "too exact one".
Post 28 Mar 2013, 20:13
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:14; edited 1 time in total
Post 28 Mar 2013, 21:27
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
HaHaAnonymous,

OK, I'll explain. There is no specification this program adheres to, so the only chance to understand its behavior is to read program's source (in fact, it is even if specification exists). Though due to its highly macroed nature it's easier to use debugger.

1 to -119 translation is weird (and somewhat unstable), "too exact one" was intened pun, like 1.(0)
Post 29 Mar 2013, 06:52
View user's profile Send private message Reply with quote
uart777



Joined: 17 Jan 2012
Posts: 369
uart777
KevinN: Thanks. Your inquiries about compiler creation are what motivated me to upload this. Writing an expression is, by far, the greatest challenge in creating a HL compiler and I don't think most programmers here realize this.

Sorry, no time to explain.


Last edited by uart777 on 07 Aug 2013, 19:14; edited 2 times in total
Post 29 Mar 2013, 07:41
View user's profile Send private message Reply with quote
uart777



Joined: 17 Jan 2012
Posts: 369
uart777
[ Post removed by author. ]


Last edited by uart777 on 07 Aug 2013, 19:18; edited 1 time in total
Post 29 Mar 2013, 07:55
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
uart777 wrote:
Wrong Smile Your statement indicates that you know nothing about expression parsers and have never written one in your lifetime, not the simplest one in the highest level language.
I'm too old to know everything.
Do you practice mind reading? Wink Stop that, "it's bad for ya" © George Carlin.
uart777 wrote:
Any expression parser - whether it produces a constant or variable result - can be replaced with [m] and runtime instructions.
This ought to be clarified. Do you mean parsed? And, indeed, everything is replaced with runtime instructions (or else we get 42 every time).
uart777 wrote:
In addition, please note that with [m] operands, HL compilers generally assume that function calls alter all registers and volatile variables (example, a pointer to system clock) can change from one instruction to the next.
HL compilers can (and SHOULD) assume that registers are safe from [m] accesses (though I remember PDP-11 memory-maps them, near memory top). As to function calls, it's all the matter of calling conventions. Or, moreso, specifications. Function's specs should clearly identify what it requires/alters/results in.

Please, tell me why pointer to system clock should be considered as volatile? SMP, or maybe the value it's pointing to?
uart777 wrote:
Sorry, no time to explain.
Well, get back to your demanding projects. Your efforts are awesome, though language is quite arrogant. Wink

P.S. !#name.$type='c' in LANGUAGE.INC::function macro should be !#name#.$type='c', probably.
Post 29 Mar 2013, 09:06
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 721
tthsqe
Quote:
How about common subexpressions and such?

if the code contains no branches this is a rather straightforward procedure
I am trying to implement general partial redundancy eliminations on jumpy code (for my calculator) and it is messy...
Post 29 Mar 2013, 10:04
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:14; edited 1 time in total
Post 29 Mar 2013, 13:33
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1398
Location: Toronto, Canada
AsmGuru62
It IS otherwise!..
Post 29 Mar 2013, 14:04
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16904
Location: In your JS exploiting you and your system
revolution
Reading and learning another persons macros takes a lot of time and effort. I also find it easier to read the actual assembly since I already know and understand that without having to refer to other things. I don't feel it is good use of my time to decode a set of complex macros for a one time task.

[rant]Just like with custom UI layout and format. So much time wasted trying to find the right button. Why do music player programmers (and now Windows 8) all seem to feel the need to build completely unfamiliar skins? All I need is basic menus and buttons. I don't need them all fancy colours, or weird shapes and sizes, in crazy positions, and other what-not.[/rant]
Post 29 Mar 2013, 14:31
View user's profile Send private message Visit poster's website Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:09; edited 1 time in total
Post 29 Mar 2013, 15:33
View user's profile Send private message 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 cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.