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

  • Home
  • SEARCH
  • 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 6328241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:25:25+00:00 2026-05-24T17:25:25+00:00

I have a log file in the form: begin; x1 begin; y1 end; y1

  • 0

I have a log file in the form:

begin; x1
begin; y1
end; y1
begin; z1
begin; z2
end; z2
end; z1
end;x1

I am looking to parse this file into a data structure that could look like the following:

x1 >
    y1
    z1 >
        z2

so the x1 event contains the y1 & z1 events and the z1 event contains the z2 event.

Is there a standard algorithm that might be of use in this situation?

I’m thinking perhaps recursion might be able to help me here by branching on each ‘begin’ statement to correctly parse all sub-events. Any suggestions would be gratefully received.

Edit:
The ultimate goal for this will be to display the events on a GUI within a hierarchical ListView-type component. I am hoping that by being able to display the log files like this it will be possible to better visualize sequence of events within my system.

  • 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-24T17:25:27+00:00Added an answer on May 24, 2026 at 5:25 pm

    I would go for a recursive descent parser.

    LogTree Parse()
    {
        LogTree current = new LogTree();
        if (!ReadBegin(current))
            return null;
        LogTree child = null;
        while ((child = Parse()) != null)
        {
            current.Chilren.Add(Child);
        }
        if (!ReadEnd(current))
            return null;
        return current;
    }
    
    bool ReadBegin(LogTree current)
    {
        if (nexttoken != "begin")
            return false;
        readNextToken();
        current.Name = nexttoken;
        readNextToken();
        return true;
    }
    
    bool ReadEnd(LogTree current)
    {
        if (nexttoken != "end")
            return false;
        readNextToken();
        if (current.Name != nexttoken)
            return false;
        readNextToken();
        return true;
    }
    

    etc.

    Here we have

    class LogTree
    {
        public string Name;
        public List<LogTree> Children = new List<LogTree>();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a log file in SqlServer that stores the time an application started,
I have a transaction log file in CSV format that I want use to
I have lines in a log file, appended chronologically. For example, it could be
I might be looking at this the wrong way, but I have a form
I have this problem that my .php file is presented as clear text in
I have an interesting log file format and I would like to parse it
I have an error that keeps popping up in my application log file every
I have a log file with lines like this: ...timestamp...(id=1234)..GO... ...timestamp...(id=1234)..DONE... Facts: timestamps are
I have a simple feedback form that allows my users to log feedback and
I have a form that uses Ajax for client-side verification. The end of the

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.