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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:06:17+00:00 2026-06-14T13:06:17+00:00

I am trying to write a simple parser which creates a sxml-expression from a

  • 0

I am trying to write a simple parser which creates a sxml-expression from a string, e. g.

"This is a [Test]" ===> (item "This is a" (subitem "Test"))

Anybody who is wondering about the square brackets within the given example may have a look at the so called Leiden conventions.

This is the code I have written so far:

(define my-sequence '("this" "[" "is" "a" "]" "test"))

(define (left-square-bracket? item)
  (or (equal? item "[")
      (eq? item #\x005b)))

(define (right-square-bracket? item)
  (or (equal? item "]")
      (eq? item #\x005d)))

(define (parse-sequence sequence)
  (cond ((null? sequence) '())
        ((left-square-bracket? (car sequence))
         (let ((subsequence (get-subsequence (cdr sequence))))
           (list subsequence)))
        (else
         (cons (car sequence)
               (parse-sequence (cdr sequence))))))

(define (get-subsequence sequence)
  (if (right-square-bracket? (car sequence))
      '()
      (cons (car sequence)
            (get-subsequence (cdr sequence)))))

Evaluating (parse-sequence my-sequence) yields ("this" ("is" "a")). A nested expression has been created, but the program finished without having evaluated the last item "test". The question is, how do I return from get-subsequence to parse-sequence?

Any help is appreciated, many thanks in advance! 🙂

  • 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-14T13:06:18+00:00Added an answer on June 14, 2026 at 1:06 pm

    To address your initial questions, how to return multiple values: use the “values” form. Here is an example implementation where the inner procedure returns both the remaining list to be processed and the result so far. It recurses on opening brackets.

    (define (parse-sequence lst)
    
      (define (parse-seq lst)
        (let loop ((lst lst) (res null))
          (cond
            ((null? lst) (values null res))
            ((string=? (car lst) "[")
             (let-values ([(lst2 res2) (parse-seq (cdr lst))])
               (loop lst2 (append res (list res2)))))
            ((string=? (car lst) "]")
             (values (cdr lst) res))
            (else
              (loop (cdr lst) (append res (list (car lst))))))))
    
      (let-values ([(lst res) (parse-seq lst)])
        res))
    

    then

    (parse-sequence '("this" "is" "a" "test"))
    (parse-sequence '("this" "[" "is" "a" "]" "test"))
    (parse-sequence '("this" "[" "is" "[" "a" "]" "]" "test"))
    

    will yield

    '("this" "is" "a" "test")
    '("this" ("is" "a") "test")
    '("this" ("is" ("a")) "test")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple Textile parser and am trying to write a regular expression
I trying to write a simple function to call unmanaged code from managed code.
I am trying to write some simple code which will read a text file
I am trying to write a simple application in Python which uses SimpleCV for
So I'm trying to write a parser in ANTLR, this is my first time
I am trying to write a simple program using Lucene 2.9.4 which searches for
I'm trying to write the correct regular expression in PHP to parse a string
I am trying to write a simple RSS parser for my website. Although I
I'm trying to write a simple parser in lex and doing it in c++.
Im trying to write very simple HTML parser with ANTLR and Im facing problem,

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.