my parseBlock
Paul Dufresne
dufrp at hotmail.com
Sun Jun 1 11:12:41 PDT 2003
I took parseBlock and removed all what I did not understood. :-)
The result is that (don't worry, I won't commit it).
p@(Compiler Parser traits) parseBlock: block
[| token statements lineNumber |
lineNumber: p lexer lineNumber.
block freeVariables: Dictionary newEmpty.
block localVariables: Dictionary newEmpty.
block inputVariables: Dictionary newEmpty.
block parentScope: p currentScope.
block depth: (p currentScope ifNil: [0] ifNotNil: [p currentScope depth +
1]).
p currentScope: block.
token: p nextToken.
token traits == Compiler BeginVariablesToken traits
ifTrue:
[
token: p nextToken.
[
token traits == Compiler BeginVariablesToken traits
]
whileFalse:
[| variable name tmpname|
token traits == Compiler SelectorToken traits
ifFalse:
[error: 'Line ' ; p lexer lineNumber print ; ': Bad
variable declaration'].
name: token selector.
variable: Compiler VariableNode clone.
variable scope: block.
name isUnarySelector
ifTrue:
[
variable name: name.
block localVariables at: name put: variable
]
ifFalse:
[
name: (token selector as: String).
(name at: 0) = $:
ifFalse:
[error: 'Line ' ; p lexer lineNumber print ; ': Bad
input variable declaration'].
tmpname: ((name copyFrom: 1 to: name size - 1) as:
Symbol).
tmpname isUnarySelector
ifFalse:
[error: 'Line ' ; p lexer lineNumber print ; ': Bad
input variable declaration'].
variable name: name.
block inputVariables at: name put: variable
].
[
token: p nextToken.
token traits == Compiler TypeToken traits
]
whileTrue:
[variable type: p parseAtom].
]
]
ifFalse:
[p undoToken: token].
statements: (WriteStream newOn: {}).
[
token: p peekToken.
token traits == Compiler EndBlockToken traits
]
whileFalse:
[
(token traits == Compiler EndParenthesisToken traits
or: [token traits == Compiler EndArrayToken traits]
or: [token traits == Compiler EndStreamToken traits])
ifTrue:
[error: 'Line ' ; p lexer lineNumber print ; ': Expected ] for [
at line ' ; lineNumber print].
statements nextPut: p parseStatement
].
p nextToken.
p currentScope: block parentScope.
block statements: statements contents.
block
].
Mostly change the code about input variables. Is it ridiculous?
_________________________________________________________________
MSN Messenger : discutez en direct avec vos amis !
http://messenger.fr.msn.ca/
More information about the Slate
mailing list