flat assembler
Message board for the users of flat assembler.
Index
> Main > sorting the mathematical operations like this 2+10-2*4/3 Goto page Previous 1, 2 |
Author |
|
uart777 13 Jul 2013, 00:21
Quote: Still pondering a simple way to add support for parenthesis (to collapse common sub-expressions manually) My EXPRESSION.INC demonstrates the mechanics of a simple recursive descent parser. I couldn't think of a way to do this with macros. References: * Famous "red dragon compiler book": http://www.amazon.com/Compilers-Principles-Techniques-Alfred-Aho/dp/0201100886 * Recursive descent parser: http://en.wikipedia.org/wiki/Recursive_descent_parser * Shunting yard algorithm: http://en.wikipedia.org/wiki/Shunting-yard_algorithm |
|||
13 Jul 2013, 00:21 |
|
l_inc 14 Jul 2013, 11:41
bitRAKE
I think, you're trying to parse it in a wrong way. The TS has already asked me the same question over PM in March. What I suggested was to use this macro as a starting point, but instead of displaying the expression to store the expression into a virtual section and to parse it using the load directive. This would be a much simpler way of parsing. I also provided the following macro (for a little different purpose): Code: ;Displays all tokens of an expression, delimiting them ;with a specified string ;usage: dispExp ' ', y = 17, x = 2*y+(y mod 12) shl 7 macro dispExp delim*,[exp] { common match \exp,exp \{ _rest equ \exp irps sym,\exp \\{ display \\`sym match head tail, _rest \\\{ restore _rest _rest equ tail display delim \\\} \\} restore _rest \} } See any similarity to the first post? _________________ Faith is a superposition of knowledge and fallacy |
|||
14 Jul 2013, 11:41 |
|
bitRAKE 14 Jul 2013, 12:24
Using the assembler directives would be a much easier approach.
|
|||
14 Jul 2013, 12:24 |
|
l_inc 14 Jul 2013, 12:25
bitRAKE
Yes. That's what I said. _________________ Faith is a superposition of knowledge and fallacy |
|||
14 Jul 2013, 12:25 |
|
tthsqe 14 Jul 2013, 14:07
So is this post trying to evaluate expressions involving mathematical operators (no asignments or flow controls, ect.) purely through fasm's macros? You need a few stacks, which fasm has, but more importantly, you need to be able actually do the arithmetic operations, which fasm doesn't have for floating point. How is this being accomplished?
|
|||
14 Jul 2013, 14:07 |
|
bitRAKE 15 Jul 2013, 00:26
I was under the impression Roman is trying to create a some sort of code generator, or rather I assumed that when he switched to using SSE instructions. Before that the goal was too vague, imho. Since others have already written parsers using assembler directives, thought I'd push the preprocessor method.
|
|||
15 Jul 2013, 00:26 |
|
uart777 15 Jul 2013, 04:58
Quote: ... parse it using the load directive. This would be a much simpler... Code: text: db \ ; example text 'abcdef', 0 i=0 ; initialize c=1 ; counters while c<>0 ; while not 0 load c byte \ ; get c from text+i if c>='a' & c<='z' ; lowercase? c=c-32 ; convert end if store byte c \ ; store result at text+i i=i+1 ; next c end while Quote: ... calculations are not really preformed in precedence order. No ++/-- or assignment bullshit. New ML in development: Future Macro Language. Ultimate ML that replaces C/C++/C#/Java. Easiest, most compact, highest production speed, direct memory access (for LL/systems programmers), C-style &address/*value, 100% FASM (not a backend or separate program), type safety and portability (X86+ARM). Code: ; Future Macro Language... ! rgb(byte r, g, b) - color . r1=r, r2=g, r1<<16, r2<<8, r1|r2, r1|b, end! ! strlen(string s) . r1=s, while *s, s++, endw, s-r1, s--, end! s ! strcpy(string a, b) . while *b, *a++=*b++, endw, *a=0, end! a ! strcat(string a, b) . strlen(a), r1+a, strcpy(r1, b), end! ! strcmp(string a, b) . while *a=*b and *a|*b, a++, b++, endw,\ r1=*a, r1-*b, end! ! strchr(string s, char c) . while *s, ? *s=c : return s, s++, endw, end! 0 macro strequ a, b { . strcmp(a, b), ~r1 } ! memcpyb(void *a, *b, u32 n) . repeat n, (u8) *a++=*b++, endr, end! ! memsetb(void *p, byte v, u32 n) . repeat n, (u8) *p++=v, endr, end! ; optional function/endf keywords ; (for IDEs with syntax coloring). ; all statements may be written on ; individual lines... function rgb(byte r, g, b) - color . r1=r, r2=g, r1<<16, r2<<8, r1|r2, r1|b endf function strlen(string s) . r1=s . while *s, s++, endw . s-r1, s-- endf s function strcpy(string a, b) . while *b, *a++=*b++, endw . *a=0 endf a function strcmp(string a, b) . while *a=*b and *a|*b . a++, b++ . endw . r1=*a, r1-*b endf |
|||
15 Jul 2013, 04:58 |
|
Goto page Previous 1, 2 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.