BNF for a BASIC compiler

"Michael Ness" <mness1978@hotmail.com>
29 Sep 2002 16:59:34 -0400

          From comp.compilers

Related articles
BNF for a BASIC compiler mness1978@hotmail.com (Michael Ness) (2002-09-29)
Re: BNF for a BASIC compiler snicol@apk.net (Scott Nicol) (2002-10-13)
Re: BNF for a BASIC compiler michael@moria.de (Michael Haardt) (2002-10-13)
Re: BNF for a BASIC compiler the-xogos@ifrance.com (antoine) (2002-10-13)
| List of all articles for this month |
From: "Michael Ness" <mness1978@hotmail.com>
Newsgroups: comp.compilers
Date: 29 Sep 2002 16:59:34 -0400
Organization: Compilers Central
Keywords: Basic, parse, question
Posted-Date: 29 Sep 2002 16:59:34 EDT

Here is my first attempt at a defining a grammer using BNF. Is this the
way BNF should look? Can anyone point out any mistakes I'm making? One
thing that I am concerned about is the two token statment "END IF". Is
this legal in a LALR(1) parser? What about the <identifier> =
<expression> assignment with a single "="? Is it possible to not
confuse this with the <expression> = <expression> boolean test?


------------------------------------------------------------------------


<program> ::= <lines>


<lines> ::= <line><lines> |
<line>


<line> ::= NUM <statements> CR |
LABEL <statements> CR |
<statements> CR |
CR


<statements> ::= <statement> COLON <statements> |
<statement>


<statement> ::= IF <boolean> GOTO <label> [ ELSE <statements> ] |
IF <boolean> THEN <statements> [ ELSE <statements> ] |
IF <boolean> <statements> [ ELSE <statements> ] ENDIF |
FOR <identifier> = <expression> TO <expression> [ STEP <expression> ] |
WHILE <boolean> <statements> WEND |
REPEAT <statements> UNTIL <boolean> |
DO <statements> LOOP |
EXIT IF <expression> |
INPUT <identifier> |
PRINT <expression> |
? <expression> |
GOTO <label> |
LET <identifier> = <expression> |
<identifier> = <expression> |
END |
<empty>


<empty> ::= NULL


<label> ::= <expression> |
<identifier>


<expression> ::= <term> + <expression> |
<term> - <expression>


<term> ::= <factor> * <term> |
<factor> / <term>


<factor> ::= ( <expression ) |
<identifier> |
<number>


<identifier> ::= <letter> { <letter> | <number> } |


<letter> ::= A-F | a-f | "_"
<number> ::= 0-9


<boolean> ::= <expression> > 0 |
<expression> = <expression> |
NOT <identifier> = <identifier> |
<expression> > <expression> |
<expression> < <expression> |
<expression> >= <expression> |
<expression> <= <expression>


------------------------------------------------------------------------


Thanks,


Mike


Post a followup to this message

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