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条)

报告相同问题?

悬赏问题

  • ¥20 R语言单细胞测序 对seurat对象进行标准化时出现问题
  • ¥15 Anaconda navigator updateor一直更新
  • ¥15 请问如何在matlab里使用raven工具?
  • ¥100 关于ios手游充值到一定金额,再点充值提示公众号的问题。
  • ¥15 求一个stm32串口控制程序
  • ¥20 Windows 驱动开发版本疑问相关
  • ¥15 MAC 未能打开磁盘映像
  • ¥15 fastcap使用,二维导体输入问题
  • ¥15 hosts修改后不能访问
  • ¥15 关于化学反应速率C++编译问题/FLUENT