Skip to content

Help wanted. Matching pairs of parens. Parse sexps out of string. #216

Answered by noprompt
rgkirch asked this question in Q&A
Discussion options

You must be logged in to vote

There are many ways to solve this problem and one of the ways — when performance is not important — is to use a step-wise approach in the spirit of an abstract machine. With this approach we utilize a State object and Step function. The Step function is used to map a State, input, to another State, output. The State object contains a string to be parsed s; an instruction, k, for what to do when s alone cannot be mapped to an output state; and a stack of values v which hold all of the parsed values. If the output of Step function is equal to its input, then the output state is terminal.

Step = StateState
State ::= [s, k, v]
sString
k ∈ { [:void], [:error, k, s], [:make-list, k, v], [:…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@rgkirch
Comment options

@rgkirch
Comment options

Answer selected by rgkirch
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants