douran6443 2014-11-13 05:53
浏览 627
已采纳

从编译器的角度来看,Expression,Statement和Declaration有什么区别?

I am going through the Go source code of ast.go at here,and there are 3 types of interfaces that are Expression,Statement and Declaration. But only with the source code I couldn't figure out the difference between them.What I could figure out is that expression results in a object that could be assigned or compared or used as parameter,while statements are some flow control like if-else or for loop. But I found some definitions like

    // An IncDecStmt node represents an increment or decrement statement.
    IncDecStmt struct {
            X      Expr
            TokPos token.Pos   // position of Tok
            Tok    token.Token // INC or DEC
    }

shouldn't it be a expression?I feel confused how to distinguish expressions and statements,are there any rules?

  • 写回答

2条回答 默认 最新

  • dqv84329 2014-11-13 06:02
    关注

    The Golang spec uses those terms:

    • Expressions: specifies the computation of a value by applying operators and functions to operands.
    • Statements: control execution
    • Declarations (and scope): binds a non-blank identifier to a constant, type, variable, function, label, or package

    The IncDecStmt is specified as

    IncDecStmt = Expression ( "++" | "--" ) .
    

    The "++" and "--" statements increment or decrement their operands by the untyped constant 1.

    It uses an expression, but remains a statement (don't produce a new value).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部