Code
This project will be to write an interpreter for a minimal form of BASIC. This minimal form of BASIC has only 1 data type, integer, and the only identifiers are single capital letters (i.e. there are only 26 possible identifiers). There are only 5 types of statements in this form of BASIC:
1) LET statement: LET {variable} = {expression}
2) IF statement: IF {boolean expression} GOTO {line number}
3) GOTO statement: GOTO {line number}
4) PRINT statement: PRINT {variable}
5) STOP statement
Each statement must be preceded by a line number. For convenience, each line number must be between 1 and 999. Also, the expressions will be either a variable, a constant, or an arithmetic expression. The boolean expressions are of the form: relative_operator operand operand where the 6 relative operators are equal to, less than, greater than, not equal to, less than or equal to, and greater than or equal to and an operand is either a constant or a variable. The interpreter will parse the BASIC program and build some intermediate data structures. These data structures will then be interpreted to execute the program. All tokens in this language are separated by white space. The parsing algorithm should detect any syntactical or semantic error. The first such error discovered should cause an appropriate error message to be printed, and then the interpreter should terminate. Run-time errors should also be detected with appropriate error messages being printed.
<program> → <statement_list>
<statement_list> → <statement> | <statement> <statement_list>
<statement> → <line_number> <basic_statement> EOLN
<basic_statement> → <let_statement> | <print_statement> | <goto_statement> | <if_statement> | <stop_statement>
<let_statement> → LET <id> = <expression>
<goto_statement> → GOTO <line_number>
<if_statement> → IF <boolean_expression> GOTO <line_number>
<print_statement> → PRINT <id>
<stop_statement> → STOP
<line_number> → 0 .. 999
<id> → 'A' .. 'Z'
<boolean_expression> → <relop> <expression> <expression>
<relop> → < | <= | > | >= | == | <>
<expression> → + <expression> <expression> | - <expression> <expression> | * <expression> <expression> | / <expression> <expression> | <id> | <constant>
<constant> → 0 .. “maxint”
i havent quite grasped the idea of terminals and not terminals so determining what classes i need to create is a bit of a challenge. can anyone help me grasp this idea so reading this grammar and writing my project will be a bit easier?