|Parsing an If...End If construct firstname.lastname@example.org (2004-11-17)|
|Re: Parsing an If...End If construct email@example.com (Scott Nicol) (2004-11-19)|
|Re: Parsing an If...End If construct firstname.lastname@example.org (2004-11-19)|
|Re: Parsing an If...End If construct cfc@shell01.TheWorld.com (Chris F Clark) (2004-11-20)|
|Date:||19 Nov 2004 00:54:06 -0500|
|Organization:||AOL Bertelsmann Online GmbH & Co. KG http://www.germany.aol.com|
|Posted-Date:||19 Nov 2004 00:54:06 EST|
email@example.com (Michael) schreibt:
> Print "Ten"
>Else If X=20
> Print "Twenty"
>Else If X=30
> Print "Thirty"
> End ' <-------- are you sure that this is acceptable???
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.
Return to the
Search the comp.compilers archives again.