gpt4 book ai didi

compiler-errors - 注释中的代码正在编译

转载 作者:行者123 更新时间:2023-12-02 10:44:05 24 4
gpt4 key购买 nike

我试图注释掉作业中的所有代码。但是,当我尝试编译(或正在发生的任何事情;我严重不知道)时,有一种尝试在引号内编译代码。根据我正在使用的书(“On On Smalltalk”-Winston),Smalltalk会忽略初始的双引号,此双引号和下一个双引号之间的所有字符,最后它也忽略了下一个双引号。为什么这在这里不起作用?

我尝试将整个代码放在一组双引号中,结果更糟。

我专门使用Smalltalk/X。我只需要任何引起评论错误的帮助。

代码编译时出现的错误是:

===> Parser [error]: undeclared variable: Removes when compiling/evaluating for UndefinedObject while reading C:\Users\Discouraged\Desktop\blank.st at or near line 3 [relative to chunk start]

===> Parser [error]: undeclared variable: pop when compiling/evaluating for UndefinedObject while reading C:\Users\Discouraged\Desktop\blank.st at or near line 4 [relative to chunk start]

===> "[" unexpected. (missing ".", ":" or selector before it ?) when compiling/evaluating for UndefinedObject while reading C:\Users\Discouraged\Desktop\blank.st at or near line 5 [relative to chunk start]

===> unexpected end-of-input in String when compiling/evaluating for >UndefinedObject while reading C:\Users\Discouraged>\Desktop\blank.st at or near line 1 [relative to chunk start]



编码:
" 
Build a stack based (RPN - Reverse Polish Notation) calculator for rational
numbers

Smalltalk at: #maxStackSize put: 32

Object subclass: #Stack
instanceVariableNames: 'stackArray stackTop'
classVariableNames: ''
poolDictionaries: ''
!
Stack class comment: '
Redundant stack class
'
!

!Stack methodsFor: 'initialize'!

new
^ super new.
!

init
stackArray := Array new: maxStackSize.
stackTop := -1.
! !
"
"
!Stack class methodsFor: 'manipulating the stack'!
"
"
Removes the top entry from the stack.
pop
[self empty
ifTrue: [
Transcript
cr;
show: 'Stack is EMPTY!';
cr.]
ifFalse: [stackTop := stackTop - 1].
]
!
"

最佳答案

您正在尝试使用fileout格式对Smalltalk进行编码,该格式仅用于记录和传输代码,而不用于开发。因此,难怪您会感到沮丧。相反,您应该加载IDE并使用浏览器来编写代码。 Smalltalk IDE是编写,测试和运行的令人愉悦的环境。

您的归档有一些问题。例如,您不能嵌套注释(“s”)。此外,您缺少尾随句号,注释引用不匹配,并且在字符串中应包含!时应将其转义为!!,这是已更正的文件输出下面。

但是,最重要的是,加载并使用IDE。您会发现使用IDE进行类分配将更加有趣。

" 
Build a stack based (RPN - Reverse Polish Notation) calculator for rational
numbers
"

Smalltalk at: #maxStackSize put: 32.

Object subclass: #Stack
instanceVariableNames: 'stackArray stackTop'
classVariableNames: ''
poolDictionaries: ''
!
Stack class comment: '
Redundant stack class
'
!

!Stack methodsFor: 'initialize'!

new
^ super new.
!

init
stackArray := Array new: maxStackSize.
stackTop := -1.
! !

!Stack methodsFor: 'manipulating the stack'!

pop
"Removes the top entry from the stack."
self empty
ifTrue: [
Transcript
cr;
show: 'Stack is EMPTY!!';
cr.]
ifFalse: [stackTop := stackTop - 1].
!

关于compiler-errors - 注释中的代码正在编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29593527/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com