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 9174297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:43:41+00:00 2026-06-17T16:43:41+00:00

I’m making a lexer and a parser to parse one data format to another

  • 0

I’m making a lexer and a parser to parse one data format to another (partly as an exercise), and I have a question:

Let’s say we have 3 different data types, and these data types are identified by their delimiters:

  1. a|b #we’ll call this type “segments”

  2. a~b #we’ll call this type “array”

  3. a^b #we’ll call this type “components”

You can also mix them like this:

hey~there|how~are~you

which would correspond to something like this in pseudo-code:

[["hey", "there"], ["how", "are", you"]]

and

hey~there^you~guy|hi|hehe

which would correspond to:

[[["hey", "there"], ["you", "guy"]], "hi", "hehe"]

Now my question is, in my lexer do I look ahead to see what type of data we’re dealing with so that I can emit the token type first before all the strings and delimiters get emitted? Or do I make the parser try to figure it out by the delimiter tokens it gets?

Example for hey~there^you~guy|hi|hehe:

(segment)
(component)
(array)
(string "hey")
(array_delim "~")
(string "there")
(component_delim "^")
(component)
(array)
(string "you")
(array_delim "~")
(string "guy")
(segment_delim "|")
(string "hi")
(segment_delim "|")
(string "hehe")

versus

(string "hey")
(array_delim "~")
(string "there")
(component_delim "^")
(string "you")
(array_delim "~")
(string "guy")
(segment_delim "|")
(string "hi")
(segment_delim "|")
(string "hehe")

In the first case the parser would know a component or array is coming, and make the right data structures ahead of time. In the second example it would kind of have to backtrack what it did, since it figures out what data structure it is later.

  • 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-06-17T16:43:41+00:00Added an answer on June 17, 2026 at 4:43 pm

    I believe the second example is really what you want to use. From the looks of it your syntax has the following precedence.

    segments = 0
    components = 1
    array = 2
    

    With that in mind you can implement an Operator-precedence parser. Which would process your tokens like this:

    shift (string "hey")
    shift (array_delim "~")
    shift (string "there")
    reduce array1
    shift array1
    shift (component_delim "^") 
    shift (string "you")
    shift (array_delim "~")
    shift  (string "guy")
    reduce array2
    reduce component1 
    shift component1 
    shift (segment_delim "|")
    shift (string "hi")
    reduce segment1 
    shift segment1 
    shift (segment_delim "|") 
    shift (string "hehe")
    reduce segment2
    done
    

    This will result in a parse tree like this.

    segment
        segment
            component
                array
                    string(hey)
                    string(there)
                array
                    string(you)
                    string(guy)
            string(hi)
        string(hehe) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am using jsonparser to parse data and images obtained from json response. When
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.