How to skip the incorrect token when parsing?

SyntaxEditor for Windows Forms Forum

Posted 8 years ago by Peter Luo - AIMNEXT
Version: 4.0.0285
Avatar
Hi,

I defined a semantic parser for a language(it looks a bit like PASCAL or VB.NET) with the grammar designer, and the "If" statement like this:
If condition Then
  [statemtns]
EndIf
But if the user typed like this:
If True xxxx Then

EndIf
The "xxxx" is invalid, after parsing there will be a red squiggle under the "xxxx", and the tip is "Then expected.", but the "Then" is existing.

And my grammar xml like this:
'IF<-->'
"LogicalExpression<@ out expression @><-->"
<%
if(expression == null)
  this.ReportSyntaxError(ResourceTools.GetResourceString("Condition") + 
        ResourceTools.GetResourceString("SemanticParserError_Expected"));
%>
'THEN<- ->'
["StatementList<@ out exeStatementList @><- ->"]
'ENDIF'
Is there any way to resolve this? Or how did you resolve this problem in your VB.NET add-on?

Thanks a lot!

Comments (1)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Peter,

In that case I think the "Then expected." error is somewhat correct since a Then is expected where the xxxx is. Offhand I believe that is what you'd see in the VB.NET add-on language, although there we also have to handle single-line If statements so it does work out a bit different.

One thing that can help you is if you do some 'if' checks in code for the look-ahead token like with this condition:
this.TokenIs(this.LookAheadToken, VBTokenID.Then)
That will return true if the next token is a Then.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.