public void ParseVarBindAssignmentTest() { //Create parser StatementParser statementParser = new StatementParser(Init("var1 = \"test\";")); VarBindAssignment parsedVarAssignment = statementParser.ParseVarBindAssignment(); //Test VarBindAssignment Assert.AreEqual("var1", parsedVarAssignment.GetIdentifier()); Assert.AreEqual(typeof(TextExpression), parsedVarAssignment.GetExpression().GetType()); Assert.AreEqual("\"test\"", parsedVarAssignment.GetExpression().ToString()); }
/// <summary> /// Parser for VarBindAssignment /// </summary> /// <returns>Parsed VarBindAssignment</returns> public VarBindAssignment ParseVarBindAssignment() { VarBindAssignment varBindAssignment = new VarBindAssignment(); //Parse identifier CurrentToken = TokenStream.NextToken(); varBindAssignment.SetIdentifier(CurrentToken.GetValue().ToString()); //Skip = token NextToken("=", "identifier = expression;", '='); //Parse expression varBindAssignment.SetExpression(expressionParser.ParseExpression()); //Skip ; token NextToken(";", "identifier = expression;", ';'); return(varBindAssignment); }
/// <summary> /// Interpret VarBindAssignment /// </summary> /// <param name="assignment">VarBindAssignment to interpret</param> public override void Visit(VarBindAssignment assignment) { //Add variable to SymbolTable SymbolTable.AddVariableDefinition(assignment.GetIdentifier(), assignment.GetExpression()); }
public virtual void Visit(VarBindAssignment assignment) { VisitSubNodes(assignment); }
/// <summary> /// Visit VarBindAssignment /// </summary> /// <param name="assignment">VarBindAssignment to check</param> public override void Visit(VarBindAssignment assignment) { assignment.GetExpression().AcceptVisitor(this); SymbolTable.AddVariableDefinition(assignment.GetIdentifier(), assignment.GetExpression()); }