Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6642213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:54:15+00:00 2026-05-25T23:54:15+00:00

I’ve got an large bunch of legacy code in an old self-conceived scripting language

  • 0

I’ve got an large bunch of legacy code in an old self-conceived scripting language that we compile/translate into javascript.

That language has a conditional jump, jumping to a label. Difference to common goto statement is, that no backward jumps are possible. There are no nested if statements nor loops in that language.

As goto does not exist in javascript, I’m looking for an algorithm that transforms goto mylabeland mylabel: into semantically equivalent structure.

I thought of using ifs but found it not trivial because of the arbitrary nesting of the goto labels.

Example:

if cond1 goto a
do something1
if cond2 goto b
do something2
a:
do something3
if cond3 goto c
do something4
c:
do something5
b:

Could be rewritten as:

lbl_b=false;
lbl_c=false;

lbl_a = cond1;
if (!cond1) {
  do something1;
  lbl_b = cond2;
  if (!lbl_b) {
    do something2;
  }
}
if (!lbl_b) {
  do something3;
  lbl_c = cond3;
  if (!lbl_c) {
    do something4;
  }
  do something5;
}

However, I was not able to derive a general algorithm from that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:54:16+00:00Added an answer on May 25, 2026 at 11:54 pm

    This is usually called Goto Removal, we had just once a student work where the task was to implement it for C. In general you have to work with loops (sadly we did not put that work online). But as you have the restriction that you can only jump forward it is relatively easy:

    Parse once over all lines and collect all labels. Create for every label a flag “skip_to_label”. Initialize at beginning all flags to false. When you meet the conditional goto for label X you now prepend every single line , up to the label line with “if not skip_to_label” and set the flag to true.

    This should be already enough and work, but is of course not very optimal.

    How you can optimize it: Instead of prepanding the if, just maintain a set of flags for every line, and instead of setting something to false, just add for the lines the corrosponding flag in the set.

    Now you can make the if for a group that contains all lines, where the set does not change, and the condition are the boolean flags of the set.

    Example with your given code:

    set                    your code
    empty                  if cond1 goto a 
    skip_to_a,             do something1
    skip_to_a,             if cond2 goto b
    skip_to_a, skip_to_b   do something2
    skip_to_a, skip_to_b   a:
    skip_to_b              do something3
    skip_to_b, skip_to_c   if cond3 goto c
    skip_to_b, skip_to_c   do something4
    skip_to_b, skip_to_c   c:
    skip_to_b              do something5
    skip_to_b              b:
    

    Now you write in front of each line either the if(s) or you start at the top and make an if block as long as the set remains the same.

    So when you start you get your first at empty, its a conditional goto so instead you set your flag

    if cond1 goto skip_to_a=true;
    

    now the set changes, and you introduce your block with the if of the set:

    if (!skip_to_a) BEGIN
       do something1
       if cond2 skip_to_b=true;
       END
    

    next change in set, so new if block:

    if (!skip_to_a and !skip_to_b) BEGIN
       do something2
       END
    

    and so on (I guess you get now the idea).

    EDIT: As one can nicely see with the sets in the example it is in general not possible to model it with nested ifs, as e.g. the lines with skip_to_a and the ones with skip_to_b overlap, but neither contains the other complete.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.