|
No 6502 for me. But I do have a book which covers it as well as a few others from that era. Saved from being scrapped.
|
|
|
|
|
For reasons I have to hand implement a parser for JSON numbers that can operate over a stream parsing part of the number with each fetch. It's kind of difficult, so I fired up my Visual FA C# project and fed it this code
var number = FA.Parse(@"(0|-?([1-9][0-9]*))((\.[0-9]+[Ee]\-?[1-9][0-9]*)?|\.[0-9]+)");
var dgo = new FADotGraphOptions();
dgo.HideAcceptSymbolIds = true;
number = number.ToMinimizedDfa();
number.RenderToFile(@"..\..\..\number.jpg",dgo);
which gave me this which I can use to guide my hand rolled implementation:
DFA state diagram[^]
Bam! Now it makes it easy to write what is pretty complicated code by following this graph.
The code that I need to write to be clear, must be able to parse a very long number. For example 3.14159265358979462643 and parse it using say, 8 bytes of memory for the capture, so it can parse 8 characters at a time. Real world those figures would be larger, but the principle is the same.
If you have an easier way, put it in the replies. I'd love to hear them, honestly. Otherwise I'm sticking with my regex solution because I can't think of a more direct route from A to B.
Edit: Aaand my regex was wrong (not quite JSON spec) so I since fixed it but haven't updated this post to reflect the changes. Still, it was easy to change.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
modified 27-Mar-24 7:45am.
|
|
|
|
|
I'm with you - I use regex a lot if I can...
"If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization." ― Gerald Weinberg
|
|
|
|
|
Is indeed astounding about the brain which first conceived the regex. And the first coder who implemented it.
Ordinary users like me make mistakes in formulating regular expressions; just imagine how rock solid must be the code which does the parsing.
|
|
|
|
|
Parsing it is a lot easier than it seems. The thing about a regular language is it's very ... regular. The code is predictable to write, which makes things much smoother.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
|
I find their railway diagram to be much harder to follow than my state diagram.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
Ha! That's proof positive that you didn't play enough with model trains when you were little.
Mircea
|
|
|
|
|
I hate regexp.
Mostly because I only have a need for it once every decade and I forget about it.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
I like your Visual FA project.
You don't want to allow -0.xxx ?
|
|
|
|
|
That regex is in error, and I've since updated it, but not the post.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
I only hate it because I can't understand it. I have yet to find the tutorial that explains it in a way I can understand it.
There are no solutions, only trade-offs. - Thomas Sowell
A day can really slip by when you're deliberately avoiding what you're supposed to do. - Calvin (Bill Watterson, Calvin & Hobbes)
|
|
|
|
|
I think I would have probably created the state machine from scratch instead of trying to describe the valid input with that regex!
FormerBIOSGuy
|
|
|
|
|
It's nothing to do with love or hate. I recognise regular expressions' utility, but simply don't use (or need) them often enough to be comfortable with them.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
You wouldn't be one of the haters I was referring to then.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
(not read all replies so it might been discussed already)
How about being able to parse leading zero's?
They do not occur often, but these are valid ascii representations of numbers.
E.g. -000123.456 or 0000042 may not be efficient but very well parsable.
Supporting leading zeros would add two edges to your dfa.
|
|
|
|
|
Not valid JSON, IIRC.
Though my regex has since been updated. The one in the original post was not compliant.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
|
rob tillaart wrote: integers starting with a 0 are considered OCTAL in many programming languages (except zero itself). Why would that be an exception? What would happen if 0 were interpreted as octal zero?
Religious freedom is the freedom to say that two plus two make five.
|
|
|
|
|
> What would happen if 0 were interpreted as octal zero?
answer 1: Nothing
answer 2: unless the parser expects additional digits {0..7}
|
|
|
|
|
Anything that can be used to distinguish between us, who master it, and them, the primitive people who do not master it, is great!
That goes for all sorts of technology, philosophy, culture, ... Whatever. Anything that let you excel over others is essential to your self image. If it were so simple to understand that your old mother (and grandmother) could easily understand it, then you could impress noone with it.
Religious freedom is the freedom to say that two plus two make five.
|
|
|
|
|
Personally I'm more about the utility and mathematical purity of it.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
I see in my mailbox the last weekly news letter is from January 2024.
Is this now abandoned?
|
|
|
|
|
|
For those who enjoyed playing The hunter: call of the wild or for people who like such laid back games, the fishing version of the game is available for free on epic until tomorrow.
|
|
|
|