How to make a method call a correct expression?

SyntaxEditor .NET Languages Add-on for Windows Forms Forum

Posted 14 years ago by Joe
Avatar
Hello!
Well...I currently try to extend the Simple Add-on language.
I wrote a function which expects two arguments. The first one is a string, the second one is a number. The method could return a string so I'd like to make the following one a correct statement: Method(Method("string1", 23), 10);

Method("string", 34); --> this is a correct expression.

Any ideas or hints?

Comments (2)

Posted 14 years ago by Joe
Avatar
Here is my code:

protected bool MatchMethodExpression(out Expression expression)
{
      expression = null;
      if (!this.Match(SimpleTokenID.MethodID))
           return false;
      if (!this.Match(SimpleTokenID.OpenParenthesis))
           return false;
      if (!this.Match(SimpleTokenID.Text) && !this.Match(SimpleTokenID.Identifier))
           return false;
      if (!this.Match(SimpleTokenID.Comma) &&!this.Match(SimpleTokenID.Whitespace))
           return false;
      if (!this.Match(SimpleTokenID.Number)&& !this.MatchMethodExpression(outexpression))
           return false;
      if (!this.Match(SimpleTokenID.CloseParenthesis))
           return false;

      return true;                     
} 
I always get a number expected message. But i don't get a false back in this code.
What could be wrong??
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Joe,

From your first post, it sounds like you'd want to update the grammar to allow FunctionParameterList to accept more than just Identifiers. It would have to support NumberExpression and a new StringExpression, as well as a FunctionAccessExpression.

From your second post, it appears like you might be writing the semantic parser code by hand. Is that the case? If so that's not good. You should be modifying the grammar XML file and then using our Grammar Designer to generate the C# code from it. It's much easier to do, especially when you eventually get into really complex scenarios.

I'd recommend you go back and implement everything in the grammar XML as I said and then regenerate as that may solve your problems.


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.