正在加载图片...
Variable scopes The same variable name can be used in the different parts of the program. The scope rules of the language determine which declaration of a name applies when the name appears in the program. An occurrence of a variable (a name)is: local:If that occurrence is in the same procedure in which that name is declared. non-local:Otherwise (ie.it is declared outside of that procedure) procedure p; var b:real; procedure p; var a:integer; a is local begin a :1;b 2;end; b is non-local begin ..end; CS308 Compiler Theory 8Variable Scopes • The same variable name can be used in the different parts of the program. • The scope rules of the language determine which declaration of a name applies when the name appears in the program. applies when the name appears in the program. • An occurrence of a variable (a name) is: – local: If that occurrence is in the same procedure in which that name is declared. – non-local: Otherwise (ie. it is declared outside of that procedure) procedure p; procedure p; var b:real; procedure p; var a: integer; var a: integer; a is local a is local begin a := 1; b := 2; end; b is non-local begin ... end; CS308 Compiler Theory 8
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有