Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a function to identify brace groups #3

Open
aroberge opened this issue Mar 1, 2020 · 0 comments
Open

Add a function to identify brace groups #3

aroberge opened this issue Mar 1, 2020 · 0 comments

Comments

@aroberge
Copy link
Owner

aroberge commented Mar 1, 2020

Consider the following example where we'd like to replace

x!
(x + 1)!

by

factorial(x)!
factorial(x + 1)!

Currently, the way to do this would be to process the string until we encounter a !, and then start backtracking workout out the logic.

Suppose we had access to groups of braces, perhaps something like:

braces = {"end_index": "begin_index"}

For example, the second case above would be

braces = {4:0}

when encoutering a ! at position index, we could simply do something like the following:

if tokens[index-1] == ")":
    begin_index = braces[index-1]
    tokens[begin_index].string = "factorial("
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant