Skip to content

kkadhith/tinyBASIC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

TinyBASIC

BASIC is a custom programming language compiled with our custom compiler, Caveman. We use GNU Bison to process our custom CFGs and Lex to parse tokens. You can find examples of using our language in the examples directory.

Language & Compiler Specification

  • Programming Language Name: BASIC
  • Extension: .simp
  • Compiler Name: Caveman
Language Features and Code Examples
Language Feature Code Example
Integer scalar variable var : int; var, otherVar : int;
One Dimensional Arrays of Integers a = array[1000] type int;
Assignment statements var ?= 10;
Arithmetic operators +,-,*,/
Comparison operators <,<=,==,>,>=,!=
While Loops while (i < n) beginwhile
doSomething
endloop;
If-then-else statements if (i < n) then
doSomething
endif
else then
doSomethingElse
endelse
Read and Write statements input n;, print n;
Comments $comment
Functions with multiple parameters and return exactly one single scalar result function sumOfTwoNumbersPlusFive;
beginparams
endparams
beginlocals
a = int;
b = int;
endlocals
beginfuncbody
input a;
input b;
return a + b + 5;
endbody
Language Symbols and Token Names
Symbol in Language Token Name
; SEMICOLON
: COLON
int INT
== EQUALS
array ARRAY
function FUNCTION
return RETURN
?= ASSIGN
type TYPE
+ ADD
- SUBTRACT
* MULT
/ DIV
true TRUE
false FALSE
< LESS_THAN
<= LESS_THAN_EQ
> GREAT_THAN
>= GREAT_THAN_EQ
!= NOT_EQ
$ (No token, this is a comment)
( LEFT_PAREN
) RIGHT_PAREN
[ LEFT_SQUARE_BRACKET
] RIGHT_SQUARE_BRACKET
newline NEWLINE
input READ
print WRITE
beginwhile BEGIN_LOOP
endwhile END_LOOP
beginparams BEGIN_PARAMS
endparams END_PARAMS
beginfuncbody BEGIN_FUNC_BODY
endfuncbody END_FUNC_BODY
beginlocals BEGIN_LOCAL_VAR
endlocals END_LOCAL_VAR
(Identifier like a, b, etc.) IDENT XXXXX
Number (like 1, 2, 3) NUM X
if IF
else ELSE
then THEN
endif END_IF
while WHILE
ff BREAK

Comments

  • Comments start after $ and end after a newline. Comments can begin on any line, and only the characters after the $ will be ignored.

Valid Identifiers

  • Identifiers must begin with an alphabet character. The identifier can include a number and/or lowercase/uppercase letters. However, identifiers cannoot contain special characters. For instance, abc : int and h3lLo : int would be accepted, but the following would not:
    @bc : int
    h@llo : int.

Case Sensitivity

  • Our language is case sensitive. Identifiers will not match with identifiers that have the same letters, but different case. For example:
    hello : int
    Hello = 1

The above would throw an error because the h is different.

Additionally, keywords are case sensitive. Declaring an integer can only be done by using int, and not Int.

Whitespace

  • Our language ignores whitespace in most cases. For example, the following block of code would be valid:
function doSomething; beginparams endparams beginlocals endlocals beginfuncbody return 3; endbody

Would be valid, and doSomething would still return 3.

One case where whitespace is ignored is comments (as specified earlier). Everything that comes after a $ will be ignored.

About

The TinyBASIC programming language and Caveman compiler

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published