Click here to Skip to main content
14,487,309 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: goodBye camel Pin
musefan2-Jan-20 22:11
Membermusefan2-Jan-20 22:11 
GeneralRe: goodBye camel Pin
Nand322-Jan-20 22:54
MemberNand322-Jan-20 22:54 
GeneralRe: goodBye camel Pin
Mark_Wallace2-Jan-20 23:47
MemberMark_Wallace2-Jan-20 23:47 
JokeRe: goodBye camel Pin
Joan M2-Jan-20 23:47
professionalJoan M2-Jan-20 23:47 
GeneralRe: goodBye camel Pin
Marc Clifton3-Jan-20 2:28
mvaMarc Clifton3-Jan-20 2:28 
GeneralRe: goodBye camel Pin
dandy723-Jan-20 3:48
Memberdandy723-Jan-20 3:48 
GeneralRe: goodBye camel Pin
W Balboos, GHB3-Jan-20 5:56
mveW Balboos, GHB3-Jan-20 5:56 
GeneralIn defense of goto Pin
honey the codewitch2-Jan-20 20:45
mvahoney the codewitch2-Jan-20 20:45 
Okay, so I don't like to use goto, but it is sometimes if not necessary, then efficient.

I'm running into a problem right now that is very similar to the problem of supporting multiple optional parameters in a stored proc.

Basically for an LL(k) parse in a recursive descent parser, for every k>1 value the number of IFs grows exponentially.

if(firstSym==lparen)
{
   if(secondSym==rbracket) {
   } else if(secondSym==intLiteral || secondSym==floatLiteral || secondSym==identifier) {
   } else if(secondSym==...) {
      ...
   } else ...

} else if(firstSym==lbracket) {
  else if(firstSym==...) {
  ....
  } else ...
...
}


for each additional k value i need to add a thirdSym, fourthSym, and accompanying nested ifs.

Meanwhile, if I rewrite this as a state machine I can use gotos, and then recycle similar paths.

This is really hard to show you an example of because the result is spaghetti but it's easy to generate programmatically, or to graph visually. (i don't want to break out graphviz right now though - it's late)

However, being able to recycle those paths as they converge can dramatically reduce the amount of code you need, but you have to be able to bounce between the different branches, the way an if won't.

You can do similar using goto case albeit less efficiently than a goto based baked state machine overall.
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.

GeneralRe: In defense of goto Pin
OriginalGriff2-Jan-20 21:54
mveOriginalGriff2-Jan-20 21:54 
GeneralRe: In defense of goto Pin
honey the codewitch2-Jan-20 22:00
mvahoney the codewitch2-Jan-20 22:00 
GeneralRe: In defense of goto Pin
Member 79891222-Jan-20 23:40
MemberMember 79891222-Jan-20 23:40 
GeneralRe: In defense of goto Pin
honey the codewitch3-Jan-20 3:59
mvahoney the codewitch3-Jan-20 3:59 
GeneralRe: In defense of goto Pin
Member 79891223-Jan-20 4:54
MemberMember 79891223-Jan-20 4:54 
GeneralRe: In defense of goto Pin
honey the codewitch3-Jan-20 4:58
mvahoney the codewitch3-Jan-20 4:58 
GeneralRe: In defense of goto Pin
Member 79891223-Jan-20 5:27
MemberMember 79891223-Jan-20 5:27 
GeneralRe: In defense of goto Pin
honey the codewitch3-Jan-20 5:29
mvahoney the codewitch3-Jan-20 5:29 
GeneralRe: In defense of goto Pin
pkfox3-Jan-20 1:24
professionalpkfox3-Jan-20 1:24 
GeneralRe: In defense of goto Pin
Member 79891222-Jan-20 22:43
MemberMember 79891222-Jan-20 22:43 
GeneralRe: In defense of goto Pin
honey the codewitch2-Jan-20 22:50
mvahoney the codewitch2-Jan-20 22:50 
GeneralRe: In defense of goto Pin
jsc422-Jan-20 23:15
professionaljsc422-Jan-20 23:15 
GeneralRe: In defense of goto Pin
honey the codewitch3-Jan-20 5:05
mvahoney the codewitch3-Jan-20 5:05 
GeneralRe: In defense of goto Pin
Member 79891223-Jan-20 0:14
MemberMember 79891223-Jan-20 0:14 
GeneralRe: In defense of goto Pin
honey the codewitch3-Jan-20 3:56
mvahoney the codewitch3-Jan-20 3:56 
GeneralRe: In defense of goto Pin
Member 79891223-Jan-20 5:16
MemberMember 79891223-Jan-20 5:16 
GeneralRe: In defense of goto Pin
honey the codewitch3-Jan-20 5:23
mvahoney the codewitch3-Jan-20 5:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.