4

脚本语言中的代码的技术术语是什么,它不属于任何函数并且在导入脚本时首先执行?

例如,在 python 中:

import anything

#what is the technical name for this code?
a = 1
doABackFlip()

def myFunction():
  #Not this code since it is part of a function
  b = 2
  runSomething()

class myClass():
  #This is in a class so not this code either

在 JavaScript 中:

<script>
  //What is the technical name of this code?
  a = 1
  doABarrelRoll()

  function myFunction() {
    //Not this stuff. Part of a function again
    doSomethingCool()
    }
</script>

我正在专门为此代码寻找一两个词的术语。如果它是常用的描述符或更好的描述符,那将是最好的,这是在 60 年代的一些学术论文中创造的。

4

2 回答 2

1

我真的很喜欢你的问题,我无法给出明确的答案。但是,我想在这里解释一下。

当您为命令式语言编写解析器时,您会遇到类似StatementList-- 语句列表的内容。因此,周围“块”内的所有内容(即函数、方法,还有循环体或类似 c 语言的其他块{})都将表示为StatementList. 所以对我来说这里的问题是:抽象语法树(AST)中的周围节点是如何调用的。到目前为止,我所看到的只是:“程序”。

这也是这个语句列表在Pascal中的名称。

于 2013-05-28T22:52:18.090 回答
1

我不确定在函数之外运行的代码是否有一个特定的名称,但它们运行的​​“空间”在各种语言中确实有一个通用名称:它被称为全局范围

通常,在全局范围内运行的代码简称为“在全局范围内运行的代码”

于 2013-05-29T07:20:50.550 回答