Re: Parsing an If...End If construct (VBDis)
19 Nov 2004 00:54:06 -0500

          From comp.compilers

Related articles
Parsing an If...End If construct (2004-11-17)
Re: Parsing an If...End If construct (Scott Nicol) (2004-11-19)
Re: Parsing an If...End If construct (2004-11-19)
Re: Parsing an If...End If construct (Chris F Clark) (2004-11-20)
| List of all articles for this month |

From: (VBDis)
Newsgroups: comp.compilers
Date: 19 Nov 2004 00:54:06 -0500
Organization: AOL Bertelsmann Online GmbH & Co. KG
References: 04-11-047
Keywords: parse
Posted-Date: 19 Nov 2004 00:54:06 EST (Michael) schreibt:

>If X=10
> Print "Ten"
>Else If X=20
> Print "Twenty"
>Else If X=30
> Print "Thirty"
> End ' <-------- are you sure that this is acceptable???
>End If

Perhaps you misunderstood the "End" token as a statement?
At least I'd try to treat "End" as a special keyword, distinct from statements.

And I'd also try to convert "End If" into a single token, different from both
"End" and "If". AFAIR typical Basic byte code uses a single token herefore,
that's only displayed with a space inside the keyword.

IMO you also should handle NEWLINE appropriately. In Basic syntax the line ends
almost are significant parts of the syntax, serving e.g. as statement
separators. In your grammar a NEWLINE is not allowed within "statements", so
that an "Else" would be illegal at the begin of a line. I'd define an
statement_separator as either ":", or as NEWLINE possibly followed by an label.

All in all I'd implement an handcrafted lexer and parser for Basic, which
allows to handle the special conditions in a Basic syntax easier than with
general lexer/parser generators. I'd also look at the source code of an open
source Basic interpreter, in order to find out more about the Basic grammar,
lexers and parsers.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.