Skip to content
Tutorial on using flex/Bison to build a BASIC interpreter
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Makefile
README.md
basic.cpp
basic.h
basic.l
basic.y
data.cpp
data.h
doubleexpression.cpp
doubleexpression.h
end.cpp
end.h
expression.cpp
expression.h
for.cpp
for.h
goto.cpp
goto.h
ifthen.cpp
ifthen.h
let.cpp
let.h
next.cpp
next.h
operatorexpression.cpp
operatorexpression.h
parenexpression.cpp
parenexpression.h
print.cpp
print.h
program.cpp
program.h
read.cpp
read.h
stringexpression.cpp
stringexpression.h
variableexpression.cpp
variableexpression.h

README.md

basic

Tutorial on using flex/bison to build a BASIC interpreter

grammar

statements: /* empty */
| statement
| statements statement
;

statement: iStatement
| LINENUM iStatement
| LINENUM forStmt
| LINENUM nextStmt
| LINENUM endStmt
;

iStatement: letStmt
| readStmt
| dataStmt
| printStmt
| gotoStmt
| ifStmt
| error
;

ids: ID
| ids ',' ID
;

exprs: expr
| exprs ',' expr
;

exprsAndLabels: exprOrLabel
| exprsAndLabels ',' exprOrLabel
;

exprOrLabel: expr
| STRING
;

expr: addend
| addend '+' addend
| addend '-' addend
;

addend: multiplicand
| multiplicand '*' multiplicand
| multiplicand '/' multiplicand
;

multiplicand: expt
| expt '^' expt
;

expt: NUM
| ID
| '(' expr ')'
;

letStmt: "LET" ID '=' expr;

readStmt: "READ" ids;

dataStmt: "DATA" exprs;

printStmt: "PRINT" exprsAndLabels;

gotoStmt: "GOTO" LINENUM;

ifStmt: "IF" relExpr "THEN" LINENUM;

relExpr: expr '=' expr
| expr '<' expr
| expr '>' expr
| expr ">=" expr
| expr "<=" expr
| expr "<>" expr
;

forStmt: "FOR" ID '=' expr "TO" expr
| "FOR" ID '=' expr "TO" expr "STEP" expr
;

nextStmt: "NEXT" ID;

endStmt: "END";

You can’t perform that action at this time.