3 ms·
> You can generate the Python code off from the AST, but it dosnt always imply the resulting Python code is runable. I believe this is incorrect. Can you show
by CGamesPlay 12y ago
> You can generate the Python code off from the AST, but it dosnt always imply the resulting Python code is runable.
I believe this is incorrect. Can you show an example of a valid abstract syntax tree that could not be represented in the grammar of the original language?
- breuleux 12y agoI know that variable names in Python's AST can be any string, so for instance you could declare and use a variable named "+a-b$ $$?", even though that's not valid Python code. That's pretty minor, though, so I'm curious if there's anything more significant.
- Foxboron 12y agoWe got this very "problem" in Hy. AST allows for several characters as Names, where python does not. A great example is with gensym, here we will make an ast.Name node with a prefix ":", if you run astor over this, you produce AST containing that very character. What happens if you try run this Python code? Syntax error. There is also a few other cases i can't think off right now.