• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Allegro X PCB Editor
  3. S-expression (sexp) parser

Stats

  • Replies 2
  • Subscribers 160
  • Views 13355
  • Members are here 0
More Content

S-expression (sexp) parser

EvanShultz
EvanShultz over 5 years ago

Has anyone written an s-expression parser in SKILL and would like to share it? I found https://community.cadence.com/cadence_technology_forums/f/custom-ic-skill/29018/skill-api-to-read-sexp-file/1333078 and https://community.cadence.com/cadence_technology_forums/f/custom-ic-skill/23546/read-next-line-if-first-charcter-is-semicolon/1314699 on this topic, but nothing that was ready-to-go. And I'm sure it would be easier for me if there was reliable, tested code rather than what I would come up with. :)

Using the simple example file in the first link above I am able to read in the given file without any issues. But that is a simple example and I would like to support a more complicated input file like what is shown at https://rosettacode.org/wiki/S-Expressions. For example:

(
(data "quoted data" 123 4.5)
(data (123 (4.5) "(more" "data)"))
)

  • Sign in to reply
  • Cancel
Parents
  • EvanShultz
    EvanShultz over 5 years ago

    Oops. The example above wasn't the one that gave me trouble. This is the next step which gave me issues:

    (root test (property Blue) (attribute 7F6GJ4N7)
    (name value)
    (data "quoted data" 123 4.5 (children Alice Bob (grandchildren Jack Jill)))
    (data (123 (4.5) "(more" "data)"))
    )

    The error is:

    SYNTAX ERROR found at line 0 column XX of file XXXXXXXXXXXXXXXXXXXXXX

    *Error* lineread/read: syntax error encountered in input

    Interestingly, I noticed if I removed the leading number from attribute, making it "F6GJ4N7", then I was able to read in the file. Not sure what is the issue there.

    But even then, what is the best way to access elements? I found that using "->", at least as I expected, doesn't work. Probably I'm doing something wrong.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • EvanShultz
    EvanShultz over 5 years ago

    Oops. The example above wasn't the one that gave me trouble. This is the next step which gave me issues:

    (root test (property Blue) (attribute 7F6GJ4N7)
    (name value)
    (data "quoted data" 123 4.5 (children Alice Bob (grandchildren Jack Jill)))
    (data (123 (4.5) "(more" "data)"))
    )

    The error is:

    SYNTAX ERROR found at line 0 column XX of file XXXXXXXXXXXXXXXXXXXXXX

    *Error* lineread/read: syntax error encountered in input

    Interestingly, I noticed if I removed the leading number from attribute, making it "F6GJ4N7", then I was able to read in the file. Not sure what is the issue there.

    But even then, what is the best way to access elements? I found that using "->", at least as I expected, doesn't work. Probably I'm doing something wrong.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • B Bruekers
    B Bruekers over 5 years ago in reply to EvanShultz

    I think the issue with (attribute 7F6GJ4N7) is that the value is being read as a symbol. Symbols cannot start with a digit, so the value should be between quotes. 

    For the second issue: if a list list contains a symbol as first element (nil, t or any other) and each successive pair starts with a symbol, you can access the elements with ->.

    For example:

    a = list( nil 'field1 "this is the first field" 'field2 "this is the second field")

    a->?  should return:

    field1

    field2

    so a->field1 contains "this is the first field".

    Bram

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Cadence Guidelines

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information