0

建议我如何将以下代码更改为 C++ 代码:

ROOTPROC VarUse
PROC VarUse
ROOT Cfile;
1 {
2 [
3 (?NameRef
4 (IF (AND (HAS-TYPE $parent Assignment) (IS-EQUAL $slot ``lhs''))
5 (THEN (PRINT stdout "Variable %s defined at %s" $token $location))
6 (ELSE (PRINT stdout "Name %s accessed at %s" $token $location))))]
7 }
4

1 回答 1

1

显然这个代码是“Algol 68 Genie”。这段代码并不完整,但从表面上看它必须等于下一个 c++ 代码:

if(parent->hasType('Assigment') and slot == lhs)
{
   std::cout << "Variable " << token << " defined at " << location << std::endl;
}
else
{
   std::cout << "Name " << token << " accessed at " << location << std::endl;
}

像 HAS-TYPE 这样的表达式没有直接的类比。有关此语言的更多信息,请参见Algol 68 Genie

于 2013-02-01T16:14:45.380 回答