public CodeObject Visit(ASTVerb verb) { Type verbType = this.metadataRetriever.GetVerbType(verb.VerbId); // Construct always true if block to wrap several statements CodeConditionStatement result = new CodeConditionStatement(); result.Condition = new CodePrimitiveExpression(true); // Process label if exists if (verb.LabelId != null) { // If namedVar is not exists already if (!this.namedVars.ContainsKey(verb.LabelId)) { this.CreateNewNamedVar(verb.LabelId); } // verb is Block if (typeof(AnyBlock).IsAssignableFrom(verbType)) { this.ReplaceExistingNamedVar(verb.LabelId); } } // Construct verb declaration CodeVariableDeclarationStatement verbDeclaration = new CodeVariableDeclarationStatement(); verbDeclaration.Type = new CodeTypeReference(verbType); verbDeclaration.Name = "verb"; verbDeclaration.InitExpression = this.CreateConstructorCallExpression(verbType, verb.Operands); result.TrueStatements.Add(verbDeclaration); // Construct Set label Id for Commands if (verb.LabelId != null) { if (typeof(AnyCommand).IsAssignableFrom(verbType)) { result.TrueStatements.Add(GenerationUtils.ConstructCallCommandSetIdMethod("verb", verb.LabelId)); } } // Construct AddVerb method call result.TrueStatements.Add(GenerationUtils.ConstructCallAddVerbMethod("verb")); // This is needed for Block labels assignment!!! if (typeof(AnyBlock).IsAssignableFrom(verbType)) { this.currentBlockNo++; } return(result); }
// <verb> ::= [ <id> ( <WHITE> )+ ] <qual-id> [ ( <WHITE> )+ <operands> ] // TODO: Temporary hack, <qual-id> for label private ASTVerb ExpectVerb() { ASTVerb verb = new ASTVerb(); string currentId = this.ExpectQualID(); if (!this.IsVerbId(currentId)) { // Verb has Label verb.LabelId = currentId; do { this.Expect(TokenType.WHITE); } while (this.Scanner.CurrentToken == TokenType.WHITE); currentId = this.ExpectQualID(); } verb.VerbId = this.ResolveVerbId(currentId); if(this.Scanner.CurrentToken == TokenType.WHITE) { do { this.Expect(TokenType.WHITE); } while (this.Scanner.CurrentToken == TokenType.WHITE); // Operands IList<ASTAnyExpression> operands = this.ExpectOperands(); foreach (var operand in operands) { verb.Operands.Add(operand); } } //// Operands //if (this.Scanner.CurrentToken == TokenType.LPAR // || this.Scanner.CurrentToken == TokenType.ID // || this.Scanner.CurrentToken == TokenType.INTEGER // || this.Scanner.CurrentToken == TokenType.MINUS // || this.Scanner.CurrentToken == TokenType.PLUS) //{ // IList<ASTAnyExpression> operands = this.ExpectOperands(); // foreach (var operand in operands) // { // verb.Operands.Add(operand); // } //} //Console.WriteLine(verb); return verb; }
public void Verb() { ASTVerb node = new ASTVerb(); node.LabelId = "SomeLabel"; node.VerbId = "START"; node.Operands.Add(new ASTLiteral() { LiteralType = LiteralType.Double, Value = 2.3 }); string result = node.Serialize(); Console.WriteLine(result); }