public static bool hasValidSubExpressions(this string expr) { if (!expr.allCharsAreValid()) return false; int numOfOpenRoundBrakets = expr.Count(c => c == (int)'('); int numOfClosedRoundBrakets = expr.Count(c => c == (int)')'); int openRoundBraketIndexes = expr.nthIndexOf('(',2); List<Char> opList = new List<Char>(); foreach (ListOp op in Enum.GetValues(typeof(ListOp))) opList.Add((char)op); int numOfoperators = expr.Count(c => opList.Contains(c)); bool allOperatorsHaveEqualCardinality = new[] { numOfOpenRoundBrakets, numOfClosedRoundBrakets, numOfoperators }.All(v => v == numOfOpenRoundBrakets); if (!allOperatorsHaveEqualCardinality) return false; for (int i = 0; i < numOfOpenRoundBrakets; i++) if (expr.nthIndexOf('(', i) > expr.nthIndexOf(')', i)) return false; return true; }
public bool GetUIntList(string Name, List<uint> AList) { List list = Find(Name); if(list == null) return false; for(int i = 1; i < list.Length; ++i) { int v = (int) list[i]; AList.Add((uint) v); } return true; }
public bool GetStringList(string Name, List<string> AList) { List list = Find(Name); if(list == null) return false; for(int i = 1; i < list.Length; ++i) { try { AList.Add((string) list[i]); } catch(InvalidCastException) { AList.Add(((Lisp.Symbol)list[i]).Name); } } return true; }
public bool GetFloatList(string Name, List<float> AList) { List list = Find(Name); if(list == null) return false; for(int i = 1; i < list.Length; ++i) { if( list[i] is float) { AList.Add((float) list[i]); } else if(list[1] is int) { AList.Add((float) ((int) list[i])); } else { return false; } } return true; }
public bool GetStringList(string Name, List<string> AList) { List list = Find(Name); if(list == null) return false; for(int i = 1; i < list.Length; ++i) { AList.Add((string) list[i]); } return true; }
public static List<GameObject> getExponents() { List<GameObject> gameObjects = new List<GameObject>(); foreach (GameObject gameObject in exponents.Values) gameObjects.Add(gameObject); return gameObjects; }
/// <summary> /// Create List# Tree /// </summary> /// <param name="Item">Current list</param> /// <param name="expression">Tokenized source code.</param> /// <param name="cur">Current parsing position in tokenized source code.</param> /// <param name="sourceCode">Original source code.</param> /// <returns>Completed parsing position in tokenized source code.</returns> /// <exception cref="SyntaxError" /> /// <exception cref="SymbolizingError" /> /// <exception cref="ParenthesisError" /> /// <exception cref="NumberError" /> /// <exception cref="UnexpectedTokenError" /> static int TreeAnalyze(List<object> Item, Token[] expression, int cur, string sourceCode) { int i; if (expression[cur].Type != TokenType.OpenParenthesis) throw new ParenthesisError(expression[cur]); for (i = cur + 1; i < expression.Length; ++i) { switch (expression[i].Type) { case TokenType.OpenParenthesis: List<object> child = new List<object>(); Item.Add(child); i = TreeAnalyze(child, expression, i, sourceCode); break; case TokenType.CloseParenthesis: return i; case TokenType.Number: try { long result = 0; if (long.TryParse(expression[i].Value, out result)) { Item.Add(result); } else { Item.Add(double.Parse(expression[i].Value)); } } catch { throw new NumberError(expression[i]); } break; case TokenType.String: Item.Add(expression[i].Value); break; case TokenType.Symbol: Item.Add(new Symbol(expression[i].Value)); break; case TokenType.Unknown: throw new UnexpectedTokenError(expression[i]); } } return expression.Length; }
public void ResizeTo(int newWidth, int newHeight) { List<int> newTiles = new List<int>(); for (int i = 0; i < newWidth * newHeight; i++) newTiles.Add(0); for (int ty = 0; ty < newHeight; ty++) { for (int tx = 0; tx < newWidth; tx++) { newTiles[(newWidth * ty) + tx] = getTileAt(tx, ty); } } this.width = newWidth; this.height = newHeight; this.tiles = newTiles; }
public void OffsetBy(int offsetX, int offsetY) { List<int> newTiles = new List<int>(); for (int i = 0; i < width * height; i++) newTiles.Add(0); for (int ty = 0; ty < height; ty++) { for (int tx = 0; tx < width; tx++) { newTiles[(width * ty) + tx] = getTileAt((tx+2*width-offsetX)%width, (ty+2*height-offsetY)%height); } } this.tiles = newTiles; }