|
Yeah, that's not the problem. The problem is with a bottom up parse I don't know what I'm looking for until after it's too late. The reason being is the tree is build from the leaves to the root.
So you get a series of tokens
a
b
c
and then a reduce rule
A-> a b c
Which finally tells you what you need to push and pop
But again, it's not until after, so
a
#ERROR bc
???
???
You don't even know what to reduce at that point. However assume you did.
a
#ERROR bc
A-> a b c
Error, not enough tokens in the input. Expecting 3, got 2.
Real programmers use butterflies
|
|
|
|
|
Make the leaves leafs the root, and the root the leaves leafs! Then flip! Problem solved!
edit - doh!
|
|
|
|
|
well, i do already return multiple trees, but yeah no. =) I'm not flipping them
Real programmers use butterflies
|
|
|
|
|
More seriously, if I was to make a bottom-up parser, I would start with a 'statement' root node, and push the items into it as they get parsed. Once a 'statement was complete, I'd expect a single branch from that 'statement' node to a 'type of statement' node, from which a true tree would form.
|
|
|
|
|
I must be misunderstanding you because it seems like you're describing a top-down, not bottom up approach.
In the statement scenario you'd see like:
shift while
shift (
shift true
shift )
reduce WhileStart
reduce Statement
(not a real scenario, i made up the sequence there)
note how statement doesn't make it until the end after it has recognized the start of the while loop?
that's how bottom up works. If that's what you were describing then my mistake.
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: shift while
shift (
shift true
shift )
reduce WhileStart
reduce Statement
Isn't that top-down?
My understanding was that bottom-up was like:
parse the ')' to a rparen and build a 'rparen' leaf
parse the 'true' and place it in the tree
parse the '(' to a lparen and insert it
... 'while' ...
reduce WhileStart
reduce Statement
So my approach would be to start with a blank statement at the beginning
add the rparen to it, so the tree is: Statement -> RParen
add the 'true' to it, so the tree is now: Statement -> True -> RParen
add the lparen to it, so: Statement -> LParen -> True -> RParen
the LParen can trigger a reduction at this step if you want
add the 'while': Statement -> While -> LParen -> True -> RParen
and reduce everything there if you want.
It would be a pretty straight tree in this case, but so be it. Maybe my understanding about top-down and bottom-up is incorrect.
|
|
|
|
|
No you got it, I just misunderstood you at first
Real programmers use butterflies
|
|
|
|
|
That's why parsers have some sort of synchronise system, when an error occurs they just eat tokens until they can get back to a safe state - simple ones just chew away until they hit a keyword.
|
|
|
|
|
I have that.
The issue is further downstream, and has to do with building the tree upward in the event of missing nodes (missing due to an error)
Edit: I should add, I've fixed it since.
Real programmers use butterflies
|
|
|
|
|
Stupid person is confused, or amusing? (9)
|
|
|
|
|
I'm going to ignore musefan today, as I posted yesterdays.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Very good.
And 88% is a pass where I come from
|
|
|
|
|
|
Generally, I use either 26 or 29 (Welsh has some English doesn't, and vice versa) - but some are infrequent visitors to my screen.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
IGNORAMUS is the answer because it fits Stupid person/"Ignore" comment form OG.
But No idea about the solution.
cheers,
Super
------------------------------------------
Too much of good is bad,mix some evil in it
|
|
|
|
|
Looks like an anagram of "or amusing" to me.
I suspect you're up tomorrow.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
IGNOReMUSfan
IGNORAMUS == OR AMUSING confused (anag)
I think it's you tomorrow!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Yes.
And an anagram, as the others have suggested.
|
|
|
|
|
|
|
Yeah, but seriously: Who reads the Insider News???
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- Never argue with a fool. Onlookers may not be able to tell the difference. Mark Twain
|
|
|
|
|
True, it's too much like documentation.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
TTFN - Kent
|
|
|
|
|
|
If he came up with the shortcut keys too he is burning in hell.
Real programmers use butterflies
|
|
|
|