void PushValueFromToken() { /*#if DEBUG * if (CurrentNode == null) { * throw new Exception("Current node is null"); * } #endif*/ TokenWithValue t = CurrentNode.getToken() as TokenWithValue; if (t == null) { throw new Exception("Can't convert current node to TokenWithValue: " + CurrentNode + ", it's of type " + CurrentNode.getTokenType()); } PushValue(t.getValue()); }
private AST CreateAssignmentTreeFromInitValue(string pVariableName, ReturnValue pInitValue) { Token.TokenType tokenType; switch(pInitValue.getReturnValueType()) { case ReturnValueType.BOOL: tokenType = Token.TokenType.BOOLEAN_VALUE; break; case ReturnValueType.STRING: tokenType = Token.TokenType.QUOTED_STRING; break; case ReturnValueType.NUMBER: tokenType = Token.TokenType.NUMBER; break; case ReturnValueType.ARRAY: tokenType = Token.TokenType.ARRAY; break; case ReturnValueType.VOID: throw new Error("Can't assign void to variable"); default: throw new Exception("Forgot to implement support for a type?"); } Token initValueToken = new TokenWithValue(tokenType, pInitValue.ToString(), pInitValue); AST assignmentTree = new AST_Assignment(new Token(Token.TokenType.ASSIGNMENT, "="), pVariableName); assignmentTree.addChild(initValueToken); return assignmentTree; }
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; } }