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

标签 compiler-errors comments smalltalk

我试图注释掉作业中的所有代码。但是,当我尝试编译(或正在发生的任何事情;我严重不知道)时,有一种尝试在引号内编译代码。根据我正在使用的书(“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/

相关文章:

c - 如何注释掉,一段被注释掉的代码

smalltalk - 规范 - 我想替换 SpPanedLayout 中的第一个演示者

c# - C#模板化结构: Cannot implicitly convert

c - 一个文件中注释的字符数(C编程)

visual-studio-2010 - C++ Visual Studio中的 “C3145”和 “C2061”错误

python - 使用 emacs 将 python 文档字符串突出显示为注释

smalltalk - 抓取 ETOY PlayingCardDeck

compilation - 编译 'hello, world' GNU smalltalk

c++ - 错误 c2065 :'LONG64' : undeclared identifier

java - 只使用 <= 和 >= 形式(不包括 =< 和 =>)进行比较的原因是什么?