I recently made a toy programming language using C, Bison, Flex, and this post as a starting point. It looks a lot like Python except there's no colons or whitespace rules.
The code is here, but it's less important than the concept/algorithm I'm stuck on.
I designed my abstract syntax tree just like Rudi did in the post linked above.
The trick is, I can't think of a great way to return from user-defined functions, or break out of loops. If I require only a single return
statement at the end of a user-defined function, it's doable (actually this is what currently works for user-defined functions).
Example:
i = 0
while 1 do
if i > 15 then
break
end
done
Example 2:
def mean(somelist)
if len(list) == 0 then
return 0 # throw error
else
return sum(somelist) / len(somelist)
end
end