public override Func <T> CreateModifyFunction <T>(object value, CompilerData cdata, Token.Type operation) { Type rtype = CompilerUtility.GetReturnType(value); Operation.BinaryOperationDelegate del = cdata._assembly.GetBinaryOperation(operation, type, rtype); // This section was made for runtime type inference // May cause some weird issues, definitely check this out if there are problems if (del == null && type != typeof(Object) && rtype == typeof(Object)) { del = cdata._assembly.GetBinaryOperation(operation, type, type); } if (del == null && type == typeof(Object) && rtype != typeof(Object)) { del = cdata._assembly.GetBinaryOperation(operation, rtype, rtype); } if (del == null) { throw new CompilationException("Cannot perform the operation " + operation.ToString() + " on " + type.Name + " and " + rtype.Name); } object func = del(this, value, cdata); Type returnType = CompilerUtility.GetReturnType(func); TypeDef returnTypeDef = cdata._assembly.GetTypeDef(returnType); return(() => { object ob = returnTypeDef.CallFunction(func); cdata._environment[_environmentIndex].data = ob; return (T)ob; }); }
private string Match(Token.Type t) { if (currentToken.GetType() == t) { currentToken = lexer.Next(); } else { Error(t.ToString()); } return(currentToken.GetValue()); }
public override Func <T> CreateModifyFunction <T>(object value, CompilerData cdata, Token.Type operation) { Type rtype = CompilerUtility.GetReturnType(value); Operation.BinaryOperationDelegate del = cdata._assembly.GetBinaryOperation(operation, type, rtype); // This section was made for runtime type inference // May cause some weird issues, definitely check this out if there are problems if (del == null && type != typeof(Object) && rtype == typeof(Object)) { del = cdata._assembly.GetBinaryOperation(operation, type, type); } if (del == null && type == typeof(Object) && rtype != typeof(Object)) { del = cdata._assembly.GetBinaryOperation(operation, rtype, rtype); } if (del == null) { throw new CompilationException("Cannot perform the operation " + operation.ToString() + " on " + type.Name + " and " + rtype.Name); } Func <object> targetFunc = CompilerUtility.ForceGetFunction <object>(_targetObject, cdata); object func = del(this, value, cdata); Type returnType = CompilerUtility.GetReturnType(func); TypeDef returnTypeDef = cdata._assembly.GetTypeDef(returnType); if (targetFunc == null) { return(() => { object ob = returnTypeDef.CallFunction(func); return (T)RunTimeUtility.SetMemberValue(_targetObject, _identifer, cdata, ob); }); } else { return(() => { object ob = returnTypeDef.CallFunction(func); return (T)RunTimeUtility.SetMemberValue(targetFunc(), _identifer, cdata, ob); }); } }
ParserException Expected(Token.Type tt) { return(Expected(tt.ToString())); }
public LinkedList <object> Tokenize() { while (start < end) { char cur = input[start]; //number literals if (cur == '0' || cur == '1' || cur == '2' || cur == '3' || cur == '4' || cur == '5' || cur == '6' || cur == '7' || cur == '8' || cur == '9') { //if there is no carry - that means that this is an integer if (carryType == Token.Type.EOS) { carryType = Token.Type.Integer; } } switch (cur) { //saperators case ' ': BreakCarry(); break; case ',': BreakCarry(); break; case '\t': BreakCarry(); break; case '\n': BreakCarry(); break; //full stop saperator case '.': //if the point is comming after idHead that is mean that you got idtail after this token if (carryType == Token.Type.IdHead) { BreakCarry(Token.Type.IdTail); } //if you are now carrying tail - that means that there is more tail after him else if (carryType == Token.Type.IdTail) { BreakCarry(Token.Type.IdTail); } //it may be inside of an integer-then it converts to doublee. else if (carryType == Token.Type.Integer) { carryType = Token.Type.Double; carry += '.'; } else { throw new Exception("You cannot place '.' after " + carryType.ToString()); } break; //operators case ';': BreakCarry(); output.AddLast(new Token(";", Token.Type.Operator)); break; case '+': BreakCarry(); output.AddLast(new Token("+", Token.Type.Operator)); break; case '-': BreakCarry(); output.AddLast(new Token("-", Token.Type.Operator)); break; case '*': BreakCarry(); output.AddLast(new Token("*", Token.Type.Operator)); break; case '/': BreakCarry(); output.AddLast(new Token("/", Token.Type.Operator)); break; case '{': BreakCarry(); output.AddLast(new Token("{", Token.Type.Operator)); break; case '}': BreakCarry(); output.AddLast(new Token("}", Token.Type.Operator)); break; //indexer case '[': Next(); BreakCarry(Token.Type.Indexer); while (input[start] != ']') { carry += input[start]; Next(); } BreakCarry(); break; //string literals case '\"': BreakCarry(Token.Type.String); Next(); while (input[start] != '\"') { //if it is an escape charecter. if (input[start] == '\\') { //TODO: escape charecter extantion for hex dec and other stuff. switch (LookAhead()) { case 'n': carry += '\n'; break; case 't': carry += '\t'; break; case '\"': carry += '\"'; break; case '\'': carry += '\''; break; default: throw new Exception("unrecognized charecter after escape charecter"); } Next(); } else { carry += input[start]; } Next(); } BreakCarry(); break; //escape charecters //function call case '<': BreakCarry(); if (LookAhead() == '-') { Next(); } output.AddLast(new Token("<-", Token.Type.Operator)); BreakCarry(); break; //default default: if (carryType == Token.Type.EOS) { carryType = Token.Type.IdHead; } carry += cur; break; } Next(); } BreakCarry(); return(output); }