I've never understood the crazy demand for people collecting books which should teach about
how to write a compiler
and then they simply invoke
lord Bison
and
mistress Lex
during their laboratory activities.
Sure there's enough software and hardware floating around now that you can mess about and possibly crank out something good with them on linux (which has the above tools), but ... I wonder how many knowledgeable people have really eaten a salad of math.
These yet another compiler - tools are good but … they tend to hide all the magic behind. While the math is rigorous and well defined, in computer science you can have cold drinks of various mixtures of raw or cooked fruits. That's the real fun.
See the following expression
eval has said …. it's a "good expression" ... ohhh my goodness, certainly a bug in my source code, but what a delicious salad, let me offer a shake of different kinds, floating points with hex, logical with arithmetic and evil code
(it's a lie, it's not a good expression, it's simply a bug)
Reading books like " dragon book " and " computer science algorithms for dummies " I was tempted to do my best to produce the worst code, so I have been playing with lexers , parsers , and RPN for weeks. The result is a black mass. The lexer is working good, but It was extremely difficult to make it to understand floating point notation, I was tempted to reinvent the wheel, then I grabbed the idea from SCI and ENG notations. It's used in CASIO pocket calculators . It was also more difficult to play with stack to make the engine to understand operators, their precedence and associativity
now it seems it's beginning to work
but …. as you can see in the first eval above, the calculator has also learnt how to tell "lies"
this happens because in computer science you have to care about
and certainly other things.
Today I have implemented a few mechanisms to handle functions. Probably I am too strong data type addicted because I used Pascal and ADA for too long.
I am considering the RPN method as the hypothetical way to transform a math expression into machine opcodes, crazy idea for AS. I do not like methods like Recursive Descent .
recipes of lexers, parsers, interpreters, compilers
anybody is cooking its own salad of math ?
let me know
- Bison: YACC-compatible Parser Generator
- Lex: Lexical Analyzer Generator
- Yacc: Yet Another Compiler-Compiler
- Flex: Fast scanner generator
- Coco/R Compiler Generator
Sure there's enough software and hardware floating around now that you can mess about and possibly crank out something good with them on linux (which has the above tools), but ... I wonder how many knowledgeable people have really eaten a salad of math.
These yet another compiler - tools are good but … they tend to hide all the magic behind. While the math is rigorous and well defined, in computer science you can have cold drinks of various mixtures of raw or cooked fruits. That's the real fun.
See the following expression
Code: Select all
# eval 1+(2.2*3.0E9+ ( 0xdeadbeaf logicalAnd 0xffffffff ) )
eval has said …. it's a "good expression" ... ohhh my goodness, certainly a bug in my source code, but what a delicious salad, let me offer a shake of different kinds, floating points with hex, logical with arithmetic and evil code
Code: Select all
yards analysis: PASSED
stack analysis: PASSED
rpn_v[]={ 0 3 5 4 8 10 9 6 1 }
[1] 1 token_DecValue, type12
[2.2] 1 token_FloatinPointENGValue, type15
[3.0E9] 1 token_FloatinPointSCIValue, type16
[*] -1 token_Asterisk, type55
[0xdeadbeaf] 1 token_HexValue, type13
[0xffffffff] 1 token_HexValue, type13
[logicalAnd] -1 token_LogicalAnd, type41
[+] -1 token_Plus, type53
[+] -1 token_Plus, type53
#########################
# good expression #
#########################
(it's a lie, it's not a good expression, it's simply a bug)
Reading books like " dragon book " and " computer science algorithms for dummies " I was tempted to do my best to produce the worst code, so I have been playing with lexers , parsers , and RPN for weeks. The result is a black mass. The lexer is working good, but It was extremely difficult to make it to understand floating point notation, I was tempted to reinvent the wheel, then I grabbed the idea from SCI and ENG notations. It's used in CASIO pocket calculators . It was also more difficult to play with stack to make the engine to understand operators, their precedence and associativity
Code: Select all
/*
* precedence operators associativity
* ---------------------------------------------
* 1 ! right to left
* 2 * / % left to right
* 3 + - left to right
* 4 = right to left
*/
now it seems it's beginning to work
Code: Select all
# eval 1.1 + 2.2 * 3.0E9
yards analysis: PASSED
stack analysis: PASSED
rpn_v[]={ 0 2 4 3 1 }
[1.1] 1 token_FloatinPointENGValue, type15
[2.2] 1 token_FloatinPointENGValue, type15
[3.0E9] 1 token_FloatinPointSCIValue, type16
[*] -1 token_Asterisk, type55
[+] -1 token_Plus, type53
#########################
# good expression #
#########################
Code: Select all
# eval 1+2+
yards analysis: PASSED
stack analysis: FAILED
#########################
# bad expression #
#########################
Code: Select all
# eval 1+2+(2+3
Error: parentheses mismatched/case1
yards analysis: FAILED
stack analysis: PASSED
#########################
# bad expression #
#########################
but …. as you can see in the first eval above, the calculator has also learnt how to tell "lies"
this happens because in computer science you have to care about
- data size (8bit, 16bit, 32bit, ...)
- data type (integer, floating point, ...)
- data sign (unsigned, signed, ...)
and certainly other things.
Today I have implemented a few mechanisms to handle functions. Probably I am too strong data type addicted because I used Pascal and ADA for too long.
Code: Select all
# eval Fa(Fb(1,2,3,4,5),Fc(6,7,8,9),0)
yards analysis: PASSED
stack analysis: PASSED
function_pool has 3 functions
+ function1 [Fa] { typeRet typeRet type12 } 3 args
+ function2 [Fb] { type12 type12 type12 type12 type12 } 5 args
+ function3 [Fc] { type12 type12 type12 type12 } 4 args
rpn_v[]={ 4 6 8 10 12 2 17 19 21 23 15 26 0 }
[1] 1 token_DecValue, type12
[2] 1 token_DecValue, type12
[3] 1 token_DecValue, type12
[4] 1 token_DecValue, type12
[5] 1 token_DecValue, type12
[Fb] -4 token_StrictAlphaNum, type19
[6] 1 token_DecValue, type12
[7] 1 token_DecValue, type12
[8] 1 token_DecValue, type12
[9] 1 token_DecValue, type12
[Fc] -3 token_StrictAlphaNum, type19
[0] 1 token_DecValue, type12
[Fa] -2 token_StrictAlphaNum, type19
#########################
# good expression #
#########################
I am considering the RPN method as the hypothetical way to transform a math expression into machine opcodes, crazy idea for AS. I do not like methods like Recursive Descent .
recipes of lexers, parsers, interpreters, compilers
anybody is cooking its own salad of math ?
let me know
Some prowling the streets, looking for sweets from their Candyman
,
I'm Looking for a new IP30/Octane2
My machine got the Xbow damaged, so I swapped for a second hand Rigol-DG1032Z WaveGen/DDS@30Mhz
IP30 purposes : linux (kernel development), Irix Scientific Apps { Ansys, Catia, Pro/E, FiberSIM, AutoDYNþ }
Other Projects : { Cerberus , Woody Box , 68K-board, SWI_DBG }, discontinued Console hacks { GB , PSX1 }
Wanted Equipments : { U1732C LCR meter by Keysight, alternatives are the welcome }
My machine got the Xbow damaged, so I swapped for a second hand Rigol-DG1032Z WaveGen/DDS@30Mhz
IP30 purposes : linux (kernel development), Irix Scientific Apps { Ansys, Catia, Pro/E, FiberSIM, AutoDYNþ }
Other Projects : { Cerberus , Woody Box , 68K-board, SWI_DBG }, discontinued Console hacks { GB , PSX1 }
Wanted Equipments : { U1732C LCR meter by Keysight, alternatives are the welcome }