private void ArrayEndSignal() { // pop the right number of values and add them to a new object of array type AST_ArrayEndSignal arrayEndSignal = CurrentNode as AST_ArrayEndSignal; SortedDictionary <KeyWrapper, object> array = new SortedDictionary <KeyWrapper, object>(); object[] values = new object[arrayEndSignal.ArraySize]; for (int i = 0; i < arrayEndSignal.ArraySize; i++) { values[i] = PopValue(); } //for(int i = 0; i < arrayEndSignal.ArraySize; i++) { for (int i = arrayEndSignal.ArraySize - 1; i >= 0; i--) { array.Add(new KeyWrapper(arrayEndSignal.ArraySize - i - 1), values[i]); } PushValue(array); }
private void ArrayEndSignal() { // pop the right number of values and add them to a new ReturnValue of array type AST_ArrayEndSignal arrayEndSignal = CurrentNode as AST_ArrayEndSignal; SortedDictionary <int, ReturnValue> array = new SortedDictionary <int, ReturnValue>(); ReturnValue[] values = new ReturnValue[arrayEndSignal.ArraySize]; for (int i = 0; i < arrayEndSignal.ArraySize; i++) { values[i] = PopValue(); } //for(int i = 0; i < arrayEndSignal.ArraySize; i++) { for (int i = arrayEndSignal.ArraySize - 1; i >= 0; i--) { array.Add(arrayEndSignal.ArraySize - i - 1, values[i]); } PushValue(new ReturnValue(array)); }
private AST arrayCreation() { #if WRITE_DEBUG_INFO Console.WriteLine("array"); #endif match(Token.TokenType.BRACKET_LEFT); AST_ArrayEndSignal arrayTree = new AST_ArrayEndSignal(new Token(Token.TokenType.ARRAY_END_SIGNAL, "<ARRAY>")); int length = 0; if (lookAheadType(1) != Token.TokenType.BRACKET_RIGHT) { while (true) { arrayTree.addChild(expression()); length++; if (lookAheadType(1) == Token.TokenType.BRACKET_RIGHT) { break; } else { match(Token.TokenType.COMMA); } } arrayTree.ArraySize = length; } else { // "array a = []" scenario arrayTree.ArraySize = 0; } match(Token.TokenType.BRACKET_RIGHT); return(arrayTree); }
private AST dotNotationExpression() { #if WRITE_DEBUG_INFO Console.WriteLine("dot notation expression"); #endif AST lhs = parenthesisExpression(); if ( lookAhead(1).getTokenType() == Token.TokenType.DOT) { match (Token.TokenType.DOT); #if WRITE_DEBUG_INFO Console.WriteLine("It's a dot notation expression!!! for example: object.f(a, b)"); #endif Token nameToken = match(Token.TokenType.NAME); AST functionCallTree = new AST_FunctionCall(new Token(Token.TokenType.FUNCTION_CALL, "RemoteFunctionCall", nameToken.LineNr, nameToken.LinePosition)); // These are the argument sent through the remote function call AST innerArgumentList = FunctionArgumentList (); // The call to RemoteFunctionCall always takes three args: <id>, <functionName> & <args> AST argumentList = new AST (new Token (Token.TokenType.NODE_GROUP, "<ARGUMENT_LIST>")); // <ID> argumentList.addChild (lhs); // use whatever is on the left side of the dot in the function (method rather) call (.) //Console.WriteLine ("Method call ID: "); //(new ASTPainter()).PaintAST(lhs); // <FunctionName> Token functionNameToken = new TokenWithValue ( Token.TokenType.QUOTED_STRING, nameToken.getTokenString (), nameToken.LineNr, nameToken.LinePosition, nameToken.getTokenString()); argumentList.addChild (new AST(functionNameToken)); // <args> AST_ArrayEndSignal argsArray = new AST_ArrayEndSignal(new Token(Token.TokenType.ARRAY_END_SIGNAL, "<ARRAY>")); //Console.WriteLine ("Inner args:"); foreach (var child in innerArgumentList.getChildren()) { //Console.WriteLine (child.getTokenString ()); argsArray.addChild (child); } argsArray.ArraySize = innerArgumentList.getChildren().Count; // DAMNIT DON'T FORGET THIS ONE argumentList.addChild (argsArray); // send the arguments as an array to RemoteFunctionCall functionCallTree.addChild(argumentList); return functionCallTree; } else { return lhs; } }
private AST arrayCreation() { #if WRITE_DEBUG_INFO Console.WriteLine("array"); #endif match(Token.TokenType.BRACKET_LEFT); AST_ArrayEndSignal arrayTree = new AST_ArrayEndSignal(new Token(Token.TokenType.ARRAY_END_SIGNAL, "<ARRAY>")); int length = 0; if(lookAheadType(1) != Token.TokenType.BRACKET_RIGHT) { while(true) { var expr = expression (); if (expr == null) { var token = lookAhead (1); throw new Error("Problem with an expression in the array", Error.ErrorType.SYNTAX, token.LineNr, token.LinePosition); } arrayTree.addChild(expr); length++; if(lookAheadType(1) == Token.TokenType.BRACKET_RIGHT) { break; } else if(lookAheadType(1) == Token.TokenType.COMMA) { match(Token.TokenType.COMMA); } else { // whitespace is enough! i.e. [1 2 3] } } arrayTree.ArraySize = length; } else { // "array a = []" scenario arrayTree.ArraySize = 0; } match(Token.TokenType.BRACKET_RIGHT); return arrayTree; }
private AST arrayCreation() { #if WRITE_DEBUG_INFO Console.WriteLine("array"); #endif match(Token.TokenType.BRACKET_LEFT); AST_ArrayEndSignal arrayTree = new AST_ArrayEndSignal(new Token(Token.TokenType.ARRAY_END_SIGNAL, "<ARRAY>")); int length = 0; if(lookAheadType(1) != Token.TokenType.BRACKET_RIGHT) { while(true) { arrayTree.addChild(expression()); length++; if(lookAheadType(1) == Token.TokenType.BRACKET_RIGHT) { break; } else { match(Token.TokenType.COMMA); } } arrayTree.ArraySize = length; } else { // "array a = []" scenario arrayTree.ArraySize = 0; } match(Token.TokenType.BRACKET_RIGHT); return arrayTree; }