examples
authorClaus Gittinger <cg@exept.de>
Sat, 27 Apr 1996 20:07:21 +0200
changeset 265 a8617dc49bbf
parent 264 f10298cba622
child 266 6c6c1d5a3d9d
examples
Parser.st
Scanner.st
--- a/Parser.st	Thu Apr 25 19:50:04 1996 +0200
+++ b/Parser.st	Sat Apr 27 20:07:21 1996 +0200
@@ -849,7 +849,7 @@
     ^ parser
 
     "Created: 24.4.1996 / 13:13:06 / cg"
-    "Modified: 24.4.1996 / 13:31:41 / cg"
+    "Modified: 27.4.1996 / 16:58:02 / cg"
 !
 
 parseMethodArgAndVarSpecificationSilent:aString
@@ -2432,91 +2432,82 @@
      empty (or comment only) input is accepted and returns nil.
 
      methodBodyOrNil ::= '<' st80Primitive '>'
-			 | '<' st80Primitive '>' methodBodyVarSpec statementList
-			 | <empty>
+                         | '<' st80Primitive '>' methodBodyVarSpec statementList
+                         | <empty>
     "
 
-    |stats pos wmsg|
-
-    ((tokenType == #BinaryOperator) and:[tokenName = '<']) ifTrue:[
-	"an ST-80 primitive - parsed but ignored"
-	pos := tokenPosition.
-	self nextToken.
-	primitiveNr := self parseST80Primitive.
-	(primitiveNr == #Error) ifTrue:[^ #Error].
-	primitiveNr < 0 ifTrue:[
-	    WarnST80Directives == true ifTrue:[
-		wmsg := 'ST-80 directive ignored'.
-	    ].
-	    primitiveNr := nil.
-	] ifFalse:[
-	    wmsg := 'ST-80 primitive may not work'
-	].
-	wmsg notNil ifTrue:[self warning:wmsg position:pos]
-    ].
+    |stats|
 
     (self parseMethodBodyVarSpec == #Error) ifTrue:[^ #Error].
 
     (tokenType ~~ #EOF) ifTrue:[
-	stats := self statementList
+        stats := self statementList
     ].
     ^ stats
+
+    "Modified: 27.4.1996 / 16:57:56 / cg"
 !
 
 parseMethodBodyVarSpec
-    "parse a methods local variable specification. 
+    "parse a methods local variable specification, handling
+     possible primitive or resourceSpecs.
+     . 
      Leave spec of locals in methodLocals as a side effect.
      Return #Error or nil.
 
      methodBodyVarSpec ::= '|' { IDENTIFIER } '|'
-			    | <empty>
+                            | <empty>
     "
 
     |var pos msg|
 
+    ((tokenType == #BinaryOperator) and:[tokenName = '<']) ifTrue:[
+        self parsePrimitiveOrResourceSpecOrEmpty.
+    ].
+
     (tokenType == $|) ifTrue:[
-	"memorize position for declaration in correction"
-	localVarDefPosition := tokenPosition.
-	self nextToken.
-	pos := tokenPosition.
-	[tokenType == #Identifier] whileTrue:[
-	    var := Variable name:tokenName.
-	    methodVars isNil ifTrue:[
-		methodVars := Array with:var.
-		methodVarNames := Array with:tokenName
-	    ] ifFalse:[
-		(methodVarNames includes:tokenName) ifTrue:[
-		    self parseError:'redefinition of ''' , tokenName , ''' in local variables'
-			   position:tokenPosition to:tokenPosition + tokenName size -1.
-		] ifFalse:[
-		    methodVars := methodVars copyWith:var.
-		    methodVarNames := methodVarNames copyWith:tokenName
-		]
-	    ].
-	    methodArgNames notNil ifTrue:[
-		(methodArgNames includes:tokenName) ifTrue:[
-		    self warning:'local variable ''' , tokenName , ''' hides argument.'
-			position:tokenPosition 
-			      to:(tokenPosition + tokenName size - 1)
-		]
-	    ].
-	    self nextToken.
-	    pos := tokenPosition
-	].
-	(tokenType ~~ $|) ifTrue:[
-	    (#(True False Self Nil Super ThisContext) includes:tokenType) ifTrue:[
-		msg := 'Reserved keyword in local var declaration' 
-	    ] ifFalse:[
-		msg := 'Identifier or | expected in local var declaration' 
-	    ].
-	    self syntaxError:msg position:tokenPosition to:source position-1.
-	    ^ #Error
-	].
-	self nextToken
+        "memorize position for declaration in correction"
+        localVarDefPosition := tokenPosition.
+        self nextToken.
+        pos := tokenPosition.
+        [tokenType == #Identifier] whileTrue:[
+            var := Variable name:tokenName.
+            methodVars isNil ifTrue:[
+                methodVars := Array with:var.
+                methodVarNames := Array with:tokenName
+            ] ifFalse:[
+                (methodVarNames includes:tokenName) ifTrue:[
+                    self parseError:'redefinition of ''' , tokenName , ''' in local variables'
+                           position:tokenPosition to:tokenPosition + tokenName size -1.
+                ] ifFalse:[
+                    methodVars := methodVars copyWith:var.
+                    methodVarNames := methodVarNames copyWith:tokenName
+                ]
+            ].
+            methodArgNames notNil ifTrue:[
+                (methodArgNames includes:tokenName) ifTrue:[
+                    self warning:'local variable ''' , tokenName , ''' hides argument.'
+                        position:tokenPosition 
+                              to:(tokenPosition + tokenName size - 1)
+                ]
+            ].
+            self nextToken.
+            pos := tokenPosition
+        ].
+        (tokenType ~~ $|) ifTrue:[
+            (#(True False Self Nil Super ThisContext) includes:tokenType) ifTrue:[
+                msg := 'Reserved keyword in local var declaration' 
+            ] ifFalse:[
+                msg := 'Identifier or | expected in local var declaration' 
+            ].
+            self syntaxError:msg position:tokenPosition to:source position-1.
+            ^ #Error
+        ].
+        self nextToken
     ].
     ^ nil
 
-    "Modified: 18.11.1995 / 16:32:51 / cg"
+    "Modified: 27.4.1996 / 16:58:28 / cg"
 !
 
 parseMethodSpec
@@ -2584,6 +2575,31 @@
     "Modified: 20.4.1996 / 20:05:52 / cg"
 !
 
+parsePrimitiveOrResourceSpecOrEmpty
+    "parse a methods primitive or resource spec"
+
+    |pos wmsg|
+
+    ((tokenType == #BinaryOperator) and:[tokenName = '<']) ifTrue:[
+        "an ST-80 primitive - parsed but ignored"
+        pos := tokenPosition.
+        self nextToken.
+        primitiveNr := self parseST80Primitive.
+        (primitiveNr == #Error) ifTrue:[^ #Error].
+        primitiveNr < 0 ifTrue:[
+            WarnST80Directives == true ifTrue:[
+                wmsg := 'ST-80 directive ignored'.
+            ].
+            primitiveNr := nil.
+        ] ifFalse:[
+            wmsg := 'ST-80 primitive may not work'
+        ].
+        wmsg notNil ifTrue:[self warning:wmsg position:pos]
+    ].
+
+    "Created: 27.4.1996 / 16:55:55 / cg"
+!
+
 parseST80Primitive
     "parse an ST-80 type primitive as '< primitive: nr >';
      return primitive number or #Error.
@@ -3451,6 +3467,6 @@
 !Parser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.77 1996-04-25 17:05:50 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.78 1996-04-27 18:06:40 cg Exp $'
 ! !
 Parser initialize!
--- a/Scanner.st	Thu Apr 25 19:50:04 1996 +0200
+++ b/Scanner.st	Sat Apr 27 20:07:21 1996 +0200
@@ -703,74 +703,75 @@
     |nextChar string firstChar|
 
     hereChar == $_ ifTrue:[
-	"/
-	"/ no need to check for AllowUnderscoreInIdentifier here;
-	"/ could not arrive here if it was off
-	"/
-	nextChar := source nextPeek.
-	(nextChar isAlphaNumeric or:[nextChar == $_]) ifFalse:[
-	    "oops: a single underscore is an old-style assignement"
-	    self warnOldStyleAssignmentAt:tokenPosition.
-	    source next.
-	    tokenType := $_.
-	    ^ tokenType
-	].
-	string := '_'.
-	self warnUnderscoreAt:tokenPosition.
-	[nextChar == '_'] whileTrue:[
-	    string := string copyWith:$_.
-	    nextChar := source nextPeek.
-	].
-	string := string , source nextAlphaNumericWord.
+        "/
+        "/ no need to check for AllowUnderscoreInIdentifier here;
+        "/ could not arrive here if it was off
+        "/
+        nextChar := source nextPeek.
+        (nextChar isAlphaNumeric or:[nextChar == $_]) ifFalse:[
+            "oops: a single underscore is an old-style assignement"
+            self warnOldStyleAssignmentAt:tokenPosition.
+            source next.
+            tokenType := $_.
+            ^ tokenType
+        ].
+        string := '_'.
+        self warnUnderscoreAt:tokenPosition.
+        [nextChar == $_] whileTrue:[
+            string := string copyWith:$_.
+            nextChar := source nextPeek.
+        ].
+        string := string , source nextAlphaNumericWord.
     ] ifFalse:[
-	string := source nextAlphaNumericWord "self nextId".
+        string := source nextAlphaNumericWord "self nextId".
     ].
     nextChar := source peek.
 
     AllowUnderscoreInIdentifier ifTrue:[
-	nextChar == $_ ifTrue:[
-	    self warnUnderscoreAt:(source position).
-	].
-	[nextChar == $_] whileTrue:[
-	    string := string copyWith:nextChar.
-	    nextChar := source nextPeek.
-	    (nextChar isAlphaNumeric) ifTrue:[
-		string := string , source nextAlphaNumericWord.
-		nextChar := source peek.
-	    ]
-	].
+        nextChar == $_ ifTrue:[
+            self warnUnderscoreAt:(source position).
+        ].
+        [nextChar == $_] whileTrue:[
+            string := string copyWith:nextChar.
+            nextChar := source nextPeek.
+            (nextChar isAlphaNumeric) ifTrue:[
+                string := string , source nextAlphaNumericWord.
+                nextChar := source peek.
+            ]
+        ].
     ].
 
     (nextChar == $:) ifTrue:[
-	source next.
-	(source peek == $=) ifFalse:[
-	    tokenName := string copyWith:nextChar.
-	    tokenType := #Keyword.
-	    ^ self
-	].
-	peekChar := $:.
-	peekChar2 := $=.
+        source next.
+        (source peek == $=) ifFalse:[
+            tokenName := string copyWith:nextChar.
+            tokenType := #Keyword.
+            ^ self
+        ].
+        peekChar := $:.
+        peekChar2 := $=.
     ].
     tokenName := string.
     firstChar := string at:1.
     (firstChar == $s) ifTrue:[
-	(string = 'self') ifTrue:[tokenType := #Self. ^self].
-	(string = 'super') ifTrue:[tokenType := #Super. ^self]
+        (string = 'self') ifTrue:[tokenType := #Self. ^self].
+        (string = 'super') ifTrue:[tokenType := #Super. ^self]
     ].
     (firstChar == $n) ifTrue:[
-	(string = 'nil') ifTrue:[tokenType := #Nil. ^self]
+        (string = 'nil') ifTrue:[tokenType := #Nil. ^self]
     ].
     (firstChar == $t) ifTrue:[
-	(string = 'true') ifTrue:[tokenType := #True. ^self].
-	(string = 'thisContext') ifTrue:[tokenType := #ThisContext. ^self]
+        (string = 'true') ifTrue:[tokenType := #True. ^self].
+        (string = 'thisContext') ifTrue:[tokenType := #ThisContext. ^self]
     ].
     (firstChar == $f) ifTrue:[
-	(string = 'false') ifTrue:[tokenType := #False. ^self]
+        (string = 'false') ifTrue:[tokenType := #False. ^self]
     ].
     tokenType := #Identifier.
     ^ tokenType
 
     "Created: 13.9.1995 / 12:56:42 / claus"
+    "Modified: 27.4.1996 / 16:16:31 / cg"
 !
 
 nextMantissa:radix
@@ -1141,6 +1142,6 @@
 !Scanner class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.42 1996-04-25 17:50:04 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.43 1996-04-27 18:07:21 cg Exp $'
 ! !
 Scanner initialize!