打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
2. Lexical analysis

The indentation levels of consecutive lines are used to generate INDENT andDEDENT tokens, using a stack, as follows.

Before the first line of the file is read, a single zero is pushed on the stack;this will never be popped off again. The numbers pushed on the stack willalways be strictly increasing from bottom to top. At the beginning of eachlogical line, the line’s indentation level is compared to the top of the stack.If it is equal, nothing happens. If it is larger, it is pushed on the stack, andone INDENT token is generated. If it is smaller, it must be one of thenumbers occurring on the stack; all numbers on the stack that are larger arepopped off, and for each number popped off a DEDENT token is generated. At theend of the file, a DEDENT token is generated for each number remaining on thestack that is larger than zero.

Here is an example of a correctly (though confusingly) indented piece of Pythoncode:

def perm(l):        # Compute the list of all permutations of l    if len(l) <= 1:                  return [l]    r = []    for i in range(len(l)):             s = l[:i] + l[i+1:]             p = perm(s)             for x in p:              r.append(l[i:i+1] + x)    return r
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Session中ArrayList对象的传递方法
Eclipse下Debug时breakpoint 报错
一种获取过程调用堆栈信息的简单方法
Eclipse中显示line number
Stack overflow at line:0是什么意思?如何解决
浏览网页时出现stack overflow at line 0
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服