[GoLUG] [parse] Line-izer preprocessor

Steve Litt slitt at troubleshooters.com
Sun Nov 19 15:37:06 EST 2023


David Billsbrough said on Sun, 19 Nov 2023 19:38:22 +0000

>Original Message:
>  Once upon a time, Steve Litt <slitt at tro.....com> wrote:
>
>> Hi all,  
>
>> In my opinion, in today's world of gigabytes of RAM, there's no
>> reason why operations shouldn't be done in-memory. Therefore, to
>> make Lexical Analysis *much* easier, I made a preprocessor to change
>> every space and every newline to printable strings, so the entire
>> program could be done in one line. I did very little "helpful" stuff
>> such as condensing multiple spaces into one or inserting "blankline"
>> symbols. The only "helpful" stuff I did are:  
>
>   {--- Trimmed ---}
>
>> Hope you all like it.  
>
>
>SteveT,
>
>While this is very 'borrowed' code from this previously mentioned
>tutorial:
>
>   https://ruslanspivak.com/lsbasi-part6/
>
>I tried adding another token (^) to act as a 'Square' function and it
>sort of works but the syntax is *very* wrong mathematically!

The customary exponentiation operator is either ^N or **N where N is an
exponent

>
>But the code does parse (lex) with the grammar of 'expr', 'term', and
>'factor'.and then interprets to do simple math from a string input to
>'stdin'.
>
>Check out:   https://github.com/kc4zvw/simplecalc/blob/main/calc6.py
>
>-=-=-=-
>Script started on Sun Nov 19 17:03:44 2023
>
>~kc4zvw: calc6.py
>Simple Calculator (integers only) - version 6 (beta)
>  type ^D to exit program
>
>calc> 4 + 2 * 3 - 6 / 2  
>7.0
>calc> 2 + 2  
>4
>calc> ^6  
>36
>calc> 1 + 2 + 3  
>6
>calc> ^36  
>1296
>calc> ^D    <---  (that's really a control-D)  
>Finished.
>~kc4zvw: echo "Did it, dude\!"
>
>Did it, dude!
>
>Script done on Sun Nov 19 17:05:17 2023
>-=-=-=-
>
>References:
>
>   My basics notes so far on this topic:
> https://www.billsbrough.org/wiki/index.php?title=Basic_Compiler_Studies
> GitHub archive of simple_calc:
> https://github.com/kc4zvw/simplecalc/tree/main
>
>
>regards,
>
>David
>
>-- David Billsbrough (KC4ZVW)
>QTH: Chuluota, FL -- grid: EL98kp
>
>


SteveT

Steve Litt 

Autumn 2023 featured book: Rapid Learning for the 21st Century
http://www.troubleshooters.com/rl21



More information about the GoLUG mailing list