Skip to content

babanomania/JS-BASIC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JS-BASIC

A javascript based minimal basic toy compiler and runtime envionment

example-site

Objectives

  • Create a frontend only minimal UI
  • Striped Editor where code will be written
  • Emulated Terminal, that can print
  • Emulated Terminal, that can handle input with callbacks
  • Run/Clear Button
  • Create a lexer, that can parse raw code and generated tokenised code
  • Create a parser, that can parse tokenised code and generated op code
  • Create a runtime, that can run op code and interact with emulated terminal for output and input
  • Debugging Controls
  • Show variable and call stack while debugging mode
  • Show syntax errors

Supported Commands

The runtime should be able to handle the below basic commands

Data manipulation:

  • LET—assigns a value (which may be the result of an expression) to a variable.
  • DATA—holds a list of values which are assigned sequentially using the READ command.
  • READ-reads data from DATA statements into variables

Program flow control:

  • IF ... THEN ... {ELSE}—used to perform comparisons or make decisions.
  • FOR ... TO ... {STEP} ... NEXT—repeat a section of code a given number of times. A variable that acts as a counter is available within the loop.
  • WHILE ... WEND—repeat a section of code while the specified condition is true. The condition may be evaluated before each iteration of the loop.
  • REPEAT ... UNTIL—repeat a section of code while the specified condition is true. The condition may be evaluated after each iteration of the loop.
  • DO ... LOOP {WHILE} or {UNTIL}—repeat a section of code Forever or While/Until the specified condition is true. The condition may be evaluated before each iteration of the loop, or after.
  • GOTO—jumps to a numbered or labelled line in the program.
  • GOSUB—jumps to a numbered or labelled line, executes the code it finds there until it reaches a RETURN Command, on which it jumps back to the operator following the GOSUB – either after a colon, or on the next line. This is used to implement subroutines.
  • ON ... GOTO/GOSUB—chooses where to jump based on the specified conditions. See Switch statement for other forms.

Input and output:

  • PRINT—displays a message on the screen or other output device.
  • INPUT—asks the user to enter the value of a variable. The statement may include a prompt message.

List of functions:

  • ABS—Absolute value
  • ATN—Arctangent value (result in radians)
  • COS—Cosine value (argument in radians)
  • EXP—Exponential value
  • INT—Integer value
  • LOG—Natural Logarithmic value
  • RND—Random value
  • SIN—Sine value (argument in radians)
  • SQR—Square root value
  • TAN—Tangent value (argument in radians)

About

A javascript based minimal basic toy compiler and runtime envionment

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published