/// <summary> /// Visits a struct expression /// </summary> /// <param name="structExpression"></param> protected virtual void VisitStructExpression(StructExpression structExpression) { if (structExpression.Structure != null) { VisitExpression(structExpression.Structure); } foreach (KeyValuePair <Designator, Expression> pair in structExpression.Associations) { if (pair.Key != null) { VisitDesignator(pair.Key); } if (pair.Value != null) { VisitExpression(pair.Value); } } }
/// <summary> /// Provides the indented expression text /// </summary> /// <param name="indentLevel"></param> /// <returns></returns> private string ToString(int indentLevel) { string retVal = Structure.ToString(); string indentAccolade = ""; for (int i = 0; i < indentLevel; i++) { indentAccolade += " "; } string indentText = indentAccolade + " "; bool first = true; retVal = retVal + "\n" + indentAccolade + "{"; foreach (KeyValuePair <string, Expression> pair in Associations) { if (first) { retVal = retVal + "\n" + indentText; first = false; } else { retVal = retVal + ",\n" + indentText; } StructExpression expression = pair.Value as StructExpression; if (expression != null) { retVal = retVal + pair.Key + " => " + expression.ToString(indentLevel + 1); } else { retVal = retVal + pair.Key + " => " + pair.Value.ToString(); } } retVal = retVal + "\n" + indentAccolade + "}"; return(retVal); }
/// <summary> /// Gets the reference according to a struc expression /// </summary> /// <param name="structExpression"></param> protected override void VisitStructExpression(StructExpression structExpression) { if (ShouldCheck(structExpression)) { bool stopLooking = false; // Perform the analysis on the expressions providing the values of the structure value foreach (KeyValuePair <Designator, Expression> pair in structExpression.Associations) { if (pair.Value != null && ShouldCheck(pair.Value)) { stopLooking = true; VisitExpression(pair.Value); break; } } // In all other cases, provide the structure itself if (!stopLooking) { Context = structExpression.Structure.Ref; } } }
/// <summary> /// Evaluates the current input as a structure /// </summary> /// <returns></returns> public Expression EvaluateStructure() { StructExpression retVal = null; int backup = Index; Expression structureId = DerefExpression(); if (structureId != null) { if (LookAhead("{")) { Match("{"); Dictionary <string, Expression> associations = new Dictionary <string, Interpreter.Expression>(); if (LookAhead("}")) { Match("}"); retVal = new StructExpression(Root, structureId, associations); } else { while (true) { string id = Identifier(); if (id != null) { Match("=>"); Expression expression = Expression(0); if (expression != null) { associations[id] = expression; } else { Root.AddError("Cannot parse expression after " + id + " => "); break; } } else { if (Index < Buffer.Length) { Root.AddError("Identifier expected, but found " + Buffer[Index]); } else { Root.AddError("Identifier expected, but EOF found "); } break; } if (LookAhead(",")) { Match(","); continue; } else if (LookAhead("}")) { Match("}"); retVal = new StructExpression(Root, structureId, associations); break; } else { if (Index < Buffer.Length) { Root.AddError(", or } expected, but found " + Buffer[Index]); } else { Root.AddError(", or } expected, but EOF found "); } break; } } } } } if (retVal == null) { Index = backup; } return(retVal); }
/// <summary> /// Visits a struct expression /// </summary> /// <param name="structExpression"></param> protected virtual void VisitStructExpression(StructExpression structExpression) { if (structExpression.Structure != null) { VisitExpression(structExpression.Structure); } foreach (KeyValuePair<Designator, Expression> pair in structExpression.Associations) { if (pair.Key != null) { VisitDesignator(pair.Key); } if (pair.Value != null) { VisitExpression(pair.Value); } } }
/// <summary> /// Evaluates the current input as a structure /// </summary> /// <returns></returns> public Expression EvaluateStructure() { StructExpression retVal = null; SkipWhiteSpaces(); int start = Index; Expression structureId = DerefExpression(); if (structureId != null) { if (LookAhead("{")) { Match("{"); Dictionary<Designator, Expression> associations = new Dictionary<Designator, Expression>(); if (LookAhead("}")) { Match("}"); retVal = new StructExpression(Root, RootLog, structureId, associations, start, Index); } else { while (true) { SkipWhiteSpaces(); int startId = Index; string id = Identifier(); if (id != null) { Designator designator = new Designator(Root, RootLog, id, startId, startId + id.Length); string assignOp = LookAhead(AssignOps); if (assignOp != null) { Match(assignOp); Expression expression = Expression(0); if (expression != null) { associations[designator] = expression; } else { RootLog.AddError("Cannot parse expression after " + id + " " + assignOp + " "); break; } } else { throw new ParseErrorException("<- or => expected", Index, Buffer); } } else { if (Index < Buffer.Length) { RootLog.AddError("Identifier expected, but found " + Buffer[Index]); } else { RootLog.AddError("Identifier expected, but EOF found "); } break; } if (LookAhead(",")) { Match(","); } else if (LookAhead("}")) { Match("}"); retVal = new StructExpression(Root, RootLog, structureId, associations, start, Index); break; } else { if (Index < Buffer.Length) { RootLog.AddError(", or } expected, but found " + Buffer[Index]); } else { RootLog.AddError(", or } expected, but EOF found "); } break; } } } } } if (retVal == null) { Index = start; } return retVal; }
/// <summary> /// Gets the reference according to a struc expression /// </summary> /// <param name="structExpression"></param> protected override void VisitStructExpression(StructExpression structExpression) { if (ShouldCheck(structExpression)) { bool stopLooking = false; // Perform the analysis on the expressions providing the values of the structure value foreach (KeyValuePair<Designator, Expression> pair in structExpression.Associations) { if (pair.Value != null && ShouldCheck(pair.Value)) { stopLooking = true; VisitExpression(pair.Value); break; } } // In all other cases, provide the structure itself if (!stopLooking) { Context = structExpression.Structure.Ref; } } }
/// <summary> /// Evaluates the current input as a structure /// </summary> /// <returns></returns> public Expression EvaluateStructure() { StructExpression retVal = null; int backup = Index; Expression structureId = DerefExpression(); if (structureId != null) { if (LookAhead("{")) { Match("{"); Dictionary<string, Expression> associations = new Dictionary<string, Interpreter.Expression>(); if (LookAhead("}")) { Match("}"); retVal = new StructExpression(Root, structureId, associations); } else { while (true) { string id = Identifier(); if (id != null) { Match("=>"); Expression expression = Expression(0); if (expression != null) { associations[id] = expression; } else { Root.AddError("Cannot parse expression after " + id + " => "); break; } } else { if (Index < Buffer.Length) { Root.AddError("Identifier expected, but found " + Buffer[Index]); } else { Root.AddError("Identifier expected, but EOF found "); } break; } if (LookAhead(",")) { Match(","); continue; } else if (LookAhead("}")) { Match("}"); retVal = new StructExpression(Root, structureId, associations); break; } else { if (Index < Buffer.Length) { Root.AddError(", or } expected, but found " + Buffer[Index]); } else { Root.AddError(", or } expected, but EOF found "); } break; } } } } } if (retVal == null) { Index = backup; } return retVal; }