@@ -38,13 +38,13 @@ public virtual Value execute(Qontext context) {
38
38
reset ( ) ;
39
39
returning = false ;
40
40
head = new Node ( ) ;
41
- Node end = build ( context ) ;
42
- Log . spam ( "executing node:\n " + end ) ;
41
+ Node tail = build ( context , new Node ( ) ) ;
42
+ Log . spam ( "executing node:\n " + tail ) ;
43
43
Value r = Value . Null ;
44
- if ( end . empty ( ) && ! head . empty ( ) ) {
44
+ if ( tail . empty ( ) && ! head . empty ( ) ) {
45
45
r = head . execute ( ) ;
46
46
} else {
47
- r = end . execute ( ) ;
47
+ r = tail . execute ( ) ;
48
48
if ( ! head . empty ( ) ) {
49
49
head . right = r ;
50
50
head . execute ( ) ;
@@ -90,12 +90,28 @@ protected virtual Node build(Qontext context, Node node = null) {
90
90
}
91
91
}
92
92
if ( node . ready ( ) ) {
93
- Node next = new Node ( node , null , op ) ;
94
- node = build ( context , next ) ;
93
+ Log . spam ( "comparing operators to chain nodes" ) ;
94
+ if ( op . compare ( node . op ) > 0 )
95
+ node . right = build ( context , new Node ( node . right , null , op ) ) ;
96
+ else
97
+ node = build ( context , new Node ( node , null , op ) ) ;
98
+ } else if ( head . op == null && (
99
+ op . symbol == Operator . ASSIGN_VALUE ||
100
+ op . symbol == Operator . ASSIGN_REFERENCE ) ) {
101
+ head . op = op ;
102
+ } else if ( node . left == null || ( node . op != null && node . right == null ) ) {
103
+ if ( op . symbol == Operator . CALCULATE_ADD ) continue ;
104
+ else if ( op . symbol == Operator . CALCULATE_SUBTRACT ) {
105
+ var neg = new Segment ( new Token [ ] {
106
+ Token . create ( ValueType . Number , "-1" ) ,
107
+ Token . create ( ValueType . Operator , Operator . CALCULATE_MULTIPLY ) ,
108
+ digest ( ) } ) ;
109
+ Log . spam ( "created negating segment: " + neg . ToString ( ) ) ;
110
+ if ( node . left == null ) node . left = neg . execute ( context ) ;
111
+ else node . right = neg . execute ( context ) ;
112
+ } else throw new ParseException ( "unexpected operator " + op . symbol + " at start of expression" , t ) ;
95
113
} else if ( node . left != null ) {
96
114
node . op = op ;
97
- } else if ( head . op == null ) {
98
- head . op = op ;
99
115
} else throw new ParseException ( "sorry, manipulation operators (operators without left-hand value) are not yet implemented. :/" , t ) ;
100
116
} else if ( t . check ( ValueType . Struqture , "(" ) ) {
101
117
if ( node . ready ( ) ) throw new ParseException ( "can not open new segment without prior operator." , t ) ;
@@ -176,15 +192,8 @@ public bool put(object value) {
176
192
}
177
193
178
194
public override string ToString ( ) {
179
- if ( empty ( ) ) return "{ }" ;
180
- string r = "{\n " ;
181
- r += " " + ( right is Node ? left ? . ToString ( ) : right ? . ToString ( ) ) + " " + op ? . symbol ;
182
- if ( ready ( ) ) {
183
- string [ ] s = ( right is Node ? right ? . ToString ( ) : left ? . ToString ( ) ) . Split ( new char [ ] { '\n ' } ) ;
184
- r += " " + s [ 0 ] + " " ;
185
- for ( int i = 1 ; i < s . Length ; i ++ ) r += "\n " + s [ i ] ;
186
- }
187
- return r += "\n }" ;
195
+ if ( empty ( ) ) return "{ void }" ;
196
+ return "{ " + ( left ?? "null" ) + " " + ( op == null ? "NaO" : op . symbol ) + " " + ( right ?? "null" ) + " }" ;
188
197
}
189
198
}
190
199
}
0 commit comments