Object subclass: #Joy instanceVariableNames: 'machine' classVariableNames: '' poolDictionaries: '' category: 'Joy-UI'! !Joy methodsFor: 'as yet unclassified' stamp: 'e-itoh 10/6/2007 21:04'! initialize machine := JoyMachine new! ! !Joy methodsFor: 'as yet unclassified' stamp: 'e-itoh 10/7/2007 22:01'! machine: aJoyMachine machine := aJoyMachine! ! !Joy methodsFor: 'as yet unclassified' stamp: 'e-itoh 10/6/2007 21:04'! recover machine recover! ! !Joy methodsFor: 'as yet unclassified' stamp: 'e-itoh 10/7/2007 20:50'! run: aString | array | array := (JoyParser onString: aString) apply: #factors. array do: [:each1 | (each1 isKindOf: JoyNode) ifTrue: [machine exec: each1] ifFalse: [each1 do: [:each2 | machine library addDefinition: each2]]]. ^ machine stack! ! !Joy methodsFor: 'as yet unclassified' stamp: 'e-itoh 10/6/2007 21:04'! stack ^ machine stack! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! Joy class instanceVariableNames: ''! !Joy class methodsFor: 'examples' stamp: 'e-itoh 10/8/2007 10:06'! sample1 | j | j := Joy new. j run: 'DEFINE fact == [dup null] [pop 1] [dup pred fact *] ifte.'. j run: '10 fact'. ^ j stack! ! OMeta subclass: #JoyParser instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Joy-UI'! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 22:12'! comment ::= (~ )* ! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 22:09'! define ::= ! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 22:14'! definition ::= :name :body => [JoyDefinition newName: name code: body]! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 22:18'! definition2 ::= :e $; => [e]! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 22:19'! definitions ::= *:e1 :e2 $. => [e1 copyWith: e2] ! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 22:12'! eq ::= ! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 20:47'! factor ::= ( | | | | | | | )! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 20:43'! factors ::= *:e! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 20:43'! factors2 ::= *:e => [self class makeNodes: e]! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 20:40'! joyBoolean ::= => [JoyBoolean true] | => [JoyBoolean false]! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 20:43'! joyList ::= :e => [e]! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 20:28'! joyName ::= :name => [JoyModule newFrom: name]! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 20:37'! joyNumber ::= +:ip ( $. +:fp => [(String withAll: ip), '.', (String withAll: fp)] | => [String withAll: ip]):s => [JoyNumber newFrom: s asNumber]! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 20:29'! joyPrimitive ::= :c ( | )*:s ?[(JoyParser checkPrimitive: ((String with: c), (String withAll: s)))] => [JoyPrimitive newFrom: ((String with: c), (String withAll: s)) asSymbol]! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 20:40'! joySpecial ::= :s => [JoyPrimitive newFrom: s]! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 21:08'! joyString ::= $" (~$" )*:s $" => [JoyString newFrom: (String withAll: s) asString]! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 20:40'! lbrack ::= $[! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 20:24'! moduleName ::= :c ( | )*:s ?[(JoyParser checkPrimitive: ((String with: c), (String withAll: s))) not] => [((String with: c), (String withAll: s)) asSymbol]! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 20:40'! rbrack ::= $]! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 22:27'! spaces ::= ( | )*! ! !JoyParser methodsFor: 'productions' stamp: 'e-itoh 10/6/2007 20:18'! special ::= $+ => [#plus] | $- => [#minus] | $* => [#mul] | $/ => [#div] | $= => [#eql] | ! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! JoyParser class instanceVariableNames: ''! !JoyParser class methodsFor: 'testing' stamp: 'e-itoh 10/6/2007 20:25'! checkPrimitive: aSymbol ^ JoyStepper selectors includes: aSymbol asSymbol! ! !JoyParser class methodsFor: 'accessing' stamp: 'e-itoh 10/10/2007 22:17'! makeNodes: anArray | node | node := JoyList joyNil. anArray reverseDo: [:each | node := JoyList new: each next: node]. ^ node! !