Is there any way I can execute a block of code in a loop, like so:

[ some code goes here ]

Where the delimiters are "[" and "]", and also allowing for nested blocks, i.e.:

[the user can create another loop[]]

I am creating a parser for a language that implements such semantics, and it reads the code one byte/character at a time since the commands are all single characters (which is fairly important), and I am currently stuck in this loop thing.

Any help (in Python, possibly) is appreciated!

Use an existing parser generator module. There are tenth of them in python.A very interesting one, and easy to use is parcon. See also the parcon blog.

I'm just worried that it wouldn't be happy with single-character tokens, because my syntax has some funny and weird stuff like ~++ $--#.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.