private Expression ParseKeyword_RETURN(string Keyword) { return(Expression.Block(Contextual.Peek().Type, VarAutExpression.VariableAccess("Return-store").Setter(ParseBoolean(false).ConvertTo(Contextual.Peek().Type)) , Contextual.Peek())); /*VarSynchronisation.Add(); * return Contextual.Peek();*/ }
private Expression ParseUltraPrimary() { ConsumeWS(); char ch = Read()[0]; string szTemp; Expression Ret; switch (ch) { case ']': throw new AutoitException(AutoitExceptionType.UNBALANCEDSUBSCRIPT, LineNumber, Cursor); case '(': Ret = ParseBoolean(); if (Peek() != ")") { throw new AutoitException(AutoitExceptionType.UNBALANCEDPAREN, LineNumber, Cursor); } Consume(); return(Ret); case ')': throw new AutoitException(AutoitExceptionType.UNBALANCEDPAREN, LineNumber, Cursor); case ';': return(null); case '$': szTemp = Getstr(Reg_AlphaNum); Type t; if (szTemp == "") { throw new AutoitException(AutoitExceptionType.LEXER_BADFORMAT, LineNumber, Cursor); } List <Expression> SubScript = new List <Expression>(); while (TryParseSubscript(out Ret)) { SubScript.Add(Ret); } TryParseCast(out t); ConsumeWS(); return(VarAutExpression.VariableAccess(szTemp, null, t, SubScript.ToArray())); case '@': var CPos = Cursor - 1; szTemp = Getstr(Reg_AlphaNum); if (szTemp == "") { throw new AutoitException(AutoitExceptionType.LEXER_BADFORMAT, LineNumber, Cursor); } return(Expression.Call(BasicMacro.GetMacroInfo, Expression.Constant(szTemp, typeof(string)))); case '"': case '\'': SeekRelative(-1); return(Expression.Constant(Lexer_CSString(), typeof(string))); default: SeekRelative(-1); szTemp = GetNbr(); if (szTemp != "") { if (szTemp.Contains(".") || Math.Abs(double.Parse(szTemp, CultureInfo.InvariantCulture)) > long.MaxValue) { return(Expression.Constant(double.Parse(szTemp, CultureInfo.InvariantCulture), typeof(double))); } else if (Math.Abs(double.Parse(szTemp, CultureInfo.InvariantCulture)) > int.MaxValue) { return(Expression.Constant(long.Parse(szTemp, CultureInfo.InvariantCulture), typeof(long))); } else { return(Expression.Constant(int.Parse(szTemp, CultureInfo.InvariantCulture), typeof(int))); } } szTemp = Getstr(Reg_Any); if (szTemp != "") { if (szTemp.Contains(".")) { var AType = Included.SelectMany(x => x.ExportedTypes).Concat(IncludedType).FirstOrDefault( x => { var Nr = x.FullName.ToUpper().Split('.'); return(Nr.SequenceEqual(szTemp.ToUpper().Split('.').Take(Nr.Count()))); }); if (AType != default(Type)) { SeekRelative(AType.FullName.Length - szTemp.Length); return(Expression.Constant(null, AType.GetTypeInfo().IsValueType ? typeof(Nullable <>).MakeGenericType(AType) : AType)); } } else { return(ParseKeywordOrFunc(szTemp)); } } throw new AutoitException(AutoitExceptionType.LEXER_NOTRECOGNISED, LineNumber, Cursor, "" + ch); } }
private Expression ParseKeyword_FOR(string Keyword) { Expression InitVal, LastVal, Step; string ForVarName; ForVarName = (ParsePrimary() as VarAutExpression).Name; ConsumeWS(); if (Peek(1).ToUpper() != "=") { throw new AutoitException(AutoitExceptionType.FORWITHOUTTO, LineNumber, Cursor); } Consume(); ConsumeWS(); InitVal = ParseBoolean().ConvertToNumber(); ConsumeWS(); if (Peek(2).ToUpper() != "TO") { throw new AutoitException(AutoitExceptionType.FORWITHOUTTO, LineNumber, Cursor); } Consume(2); ConsumeWS(); LastVal = ParseBoolean().ConvertTo(InitVal.Type); ConsumeWS(); if (Peek(4).ToUpper() == "STEP") { Consume(4); ConsumeWS(); Step = ParseBoolean().ConvertTo(InitVal.Type); } else { Step = Expression.Constant(1, typeof(int)).ConvertTo(InitVal.Type); } if (!INTERCATIVE) { var @break = Expression.Label("break"); var @continue = Expression.Label("continue"); var @DownTo = VarAutExpression.VariableAccess("downto-" + Contextual.Count, false); var @LoopVar = VarAutExpression.VariableAccess(ForVarName, false); Contextual.Push(Expression.Goto(@break)); Contextual.Push(Expression.Goto(@continue)); List <Expression> Instruction = new List <Expression>(); if (Step is ConstantExpression) { Instruction.Add(@DownTo.Setter((ConstantExpression)Expression.Constant((dynamic)(Step as ConstantExpression).Value < 0, typeof(bool)))); } else { Instruction.Add(@DownTo.Setter(Expression.LessThan(Step, Expression.Constant(0, InitVal.Type)))); } Instruction.Add(@LoopVar.Setter(InitVal)); Instruction.Add(Expression.Label(@continue)); Instruction.Add(Expression.IfThen( Expression.OrElse( Expression.AndAlso( @DownTo.Getter(typeof(bool)), Expression.LessThan(@LoopVar.Getter(InitVal.Type), LastVal)), Expression.AndAlso( Expression.Not(@DownTo.Getter(typeof(bool))), Expression.GreaterThan(@LoopVar.Getter(InitVal.Type), LastVal))) , Expression.Goto(@break))); Instruction.AddRange(ParseBlock(true)); Instruction.Add(Expression.Assign( @LoopVar.Getter(InitVal.Type), Expression.Add(@LoopVar.Getter(InitVal.Type), Step))); Instruction.Add(Expression.Goto(@continue)); Instruction.Add(Expression.Label(@break)); Contextual.Pop(); Contextual.Pop(); return(Expression.Block(Instruction.ToArray())); } else { throw new AutoitException(AutoitExceptionType.MULTILINEININTERACTIVE, LineNumber, Cursor, Keyword); } }