|
Wow.. nothing gotta stop you now!
|
|
|
|
|
I knew I'd nail it eventually. This is what I wrote Parsley for - to parse Slang.
It's bigger than a hand generated parser would be by a fair bit, but also my hand rolled parser barely did any error checking, and what it did report was dodgy.
Adding: I keep forgetting it's the new year. Happy new year!
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Yes, error checking isn't usually added until it starts to "work", so it can cause upheaval. But it's so much easier to debug if the parser--and also what is basically an interpreter, for me--can pinpoint where they failed, with a message that makes sense. And keep going, so that you don't have to uncover one problem at a time.
|
|
|
|
|
Greg Utas wrote: And keep going, so that you don't have to uncover one problem at a time.
That's one thing I haven't figured out how to do in recursive descent parsing - error recovery.
My PCK project does it but not this. Maybe down the road.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
To parse an expression, I call this:
bool Parser::GetCxxExpr(ExprPtr& expr, size_t end, bool force)
end is the position of the delimiter where the expression ends. It's found by doing a lookahead for the closing punctuation, which is one of ;},)]:= depending on the context. If something goes wrong while parsing the expression, a log containing the expression is generated and the parse resumes after end . I guess that makes it LL(*) if I remember correctly.
modified 1-Jan-20 8:25am.
|
|
|
|
|
LL(*) is top down left derivation parsing with arbitrary lookahead, so if you're using lookahead i think that qualifies?
Cast expressions would be very simple if it weren't for the ambiguity with subexpressions.
It's just
CastExpression = "(" Type ")" Expression;
But yeah.
SubExpression = "(" Expression ")";
Complicates things.
An LL(k) parser could solve it.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
You got me thinking, and what if you could use EBNF/XNBF/whatever to define error handling? I'm just now coming up with it, i don't even know if it will work but like:
PanicDefault<collapsed> = { #ERROR } "}";
PanicTypeDecl<collapsed,recover="TypeDecl"> = PanicDefault;
PanicMethod<collapsed,recover="Method"> = PanicDefault;
PanicArgList<collapsed,recover="ArgList"> = { #ERROR } (")"|",");
Something like that... I'll have to think on it.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Well done, but watch out: the devil is in the detail
|
|
|
|
|
Ah yes, the 90-10 rule. That last 10% takes 90% of the time. The curse of our existence.
|
|
|
|
|
Greg Utas wrote: Ah yes, the 90-10 rule. Man are you optimist... I would have said 95-5 or even 98-2
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
And the 90% is mostly spent walking back and forth to the coffee machine.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
I had to cut back on coffee after I finally realized that drinking too much of it gave me a chronic lightheaded feeling, the kind you get after staying in bed too long while ill.
So now I spend the entire 90% talking to my rubber duck. 🦆
modified 1-Jan-20 11:02am.
|
|
|
|
|
Recursive descent parsers are the cat's ass! Others are inscrutable by comparison. In our compiler course, we had a choice of what kind of parser to implement. I was the only one who chose recursive descent. It was easy to enhance, so it ended up handling a larger subset of Algol than the others. But boy, was it slow! It was written in Simula-67, running on a PDP-10, and probably backtracked too much. Adding backtracking statistics would have revealed if it was doing something silly.
|
|
|
|
|
Did you know Raymond Burr had a brother that was a lumber jack?
His name was Tim!
Ok I'm bored, I promise this will be the last joke this year!
Did a little mechanic work today.
Put a rear end in a recliner!
JaxCoder.com
|
|
|
|
|
Plausible. He was born in British Columbia!
|
|
|
|
|
|
That will be enough of that. There is an expectation of no more Raymond Burr or Ray Charles references in the lounge in the new year...
That's right - we need Ray Bans to protect our 2020 vision.
Hey Mike - get my coat while you are over there getting yours.
I, for one, like Roman Numerals.
|
|
|
|
|
luberjack is in fact a very honorable profession,
after all:
they help us all to see the forest by removing the trees that are in the way.
<< Signature removed due to multiple copyright violations >>
|
|
|
|
|
He had loads of brothers:
Har became a sailor.
Bom joined the air force.
Lim taught Yoga.
Fib became a politician.
Rob went to jail.
Cob moved to Oz.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You forgot the rest of the family:
Bar became a hair stylist
Dub became a sound technician
and Num became an accountant.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
I knew you wood take a crack at this.
/ravi
|
|
|
|
|
Yeah I FELL for it!
Did a little mechanic work today.
Put a rear end in a recliner!
JaxCoder.com
|
|
|
|
|
As reported in Paging-Mr-Cthulhu[^] I'm dealing with "bad" HTML (not that any HTML is truly good).
The first attempt used a Regular Expression to grab the TH and TD elements (within TR elements of course). Hence the above reference. It works.
The second attempt used HtmlAgilityPack with good results, but I doubt I can get it installed on the server, and it didn't provide as much feedback as I'd like. It works.
Sooo... yesterday and today were spent implementing an HTML-to-XML process. Using a Regular Expression to grab anything which looks roughly like a tag.
Then the process iterates the tags, matching end tags with start tags, and figuring out how to deal with unmatched start and end tags (and firing events for such aberrations).
The result is an XmlDocument, which enforces well-formed XML (but not necessarily valid XHTML).
It works.
|
|
|
|
|
Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn!
|
|
|
|
|
PIEBALDconsult wrote: (not that any HTML is truly good) Only a dev could make that complaint.
Programming languages are for nerds like us; HTML makes room for everyone else.
Besides, it's HTML that made the Internet; without HTML there would be no Internet, so it's one of the most important inventions in the entire history of the world.
My God!
I just envisioned a dev-only Internet -- CP, SO, 10,000,000 blogs bitching about the latest Star Wars movie, endless rants about preferred coding standards, and everything else about why one programming language is supreme, and the rest are all garbage.
Not a pretty sight...
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|