private static void FromSetExpression(ChainBuilder chain, object[] expression, string sourceFile, int lineNumber) { if (expression.Length < 4 || !expression[2].Equals("=") || !(expression[1] is string name)) { throw new SyntaxError( $"A set command has the format [set name = value], which doesn't match the expression {Writer.TermToString(expression)}.", sourceFile, lineNumber); } if (DefinitionStream.IsGlobalVariableName(name)) { chain.AddStep(new AssignmentStep(StateVariableName.Named(name), FunctionalExpressionParser.FromTuple(chain.CanonicalizeArglist(expression), 3, sourceFile, lineNumber), null)); } else if (DefinitionStream.IsLocalVariableName(name)) { chain.AddStep(new AssignmentStep(chain.GetLocal(name), FunctionalExpressionParser.FromTuple(chain.CanonicalizeArglist(expression), 3, sourceFile, lineNumber), null)); } else { throw new SyntaxError( $"A set command can only update a variable; it can't update {expression[1]}", sourceFile, lineNumber); } }