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

从编译器的角度来看,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 14: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 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题