Skip to content

Commit 85bdda0

Browse files
committed
some stuff, docs changes
1 parent bb42335 commit 85bdda0

File tree

9 files changed

+166
-2
lines changed

9 files changed

+166
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
BScript is a coding language that is terrible.
44

5-
[Syntax](docs/SYNTAX.md)
5+
[Read the documentation here.](docs/Basics.md)
66

77
All you get is simple variables that can only be added or subtracted to (only one), basic loops, really nothings else. It's probably easier than Brainfuck, though.
807 Bytes
Binary file not shown.

compiler.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ def compile(self, code: str) -> str:
4848
i += 1
4949
continue
5050

51+
# assignment: a = 123; or a = b;
52+
m = re.match(r'([a-zA-Z_]\w*)\s*=\s*([a-zA-Z_]\w*|\d+);', line)
53+
if m:
54+
var, value = m.groups()
55+
if var not in self.vars:
56+
raise Exception(f"Variable '{var}' used before declaration")
57+
58+
if value.isdigit():
59+
# Assign a constant number
60+
self.c_lines.append(f'{self.indent()}{var} = {int(value)} % 256;')
61+
elif value in self.vars:
62+
# Assign from another variable
63+
self.c_lines.append(f'{self.indent()}{var} = {value};')
64+
else:
65+
raise Exception(f"Invalid assignment value '{value}'")
66+
i += 1
67+
continue
68+
5169
# increment/decrement
5270
m = re.match(r'([a-zA-Z_]\w*)\s*([+-]);', line)
5371
if m:
@@ -68,7 +86,7 @@ def compile(self, code: str) -> str:
6886
if expr == 'str':
6987
self.c_lines.append(f'{self.indent()}printf("%s", str);')
7088
elif expr in self.vars:
71-
self.c_lines.append(f'{self.indent()}printf("%c", {expr});')
89+
self.c_lines.append(f'{self.indent()}printf("%d", {expr});')
7290
else:
7391
# assume string literal with quotes
7492
literal = expr.strip('"').strip("'")

docs/Advanced.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Advanced
2+
3+
These are advanced functions for speicial use cases.
4+
5+
## Single String to ASCII
6+
7+
Sets the the ASCII value of the index of the string to a variable.
8+
9+
````
10+
ascii 0,a
11+
````
12+
(Do note the indexes start at 0)
13+
14+
## ASCII to Single String
15+
16+
Adds the ASCII value to the String.
17+
18+
````
19+
revascii a
20+
````
21+
22+
(Do note the strings do not reset when you call this. You may have to call `string ""` if you want this to work correctly.)
23+
24+
[ < Previous Page](Advanced.md)

docs/Basics.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Basics
2+
3+
PLEASE NOTE DOCUMENTATION IS UNDER ACTIVE CONSTRUCTION. COMMANDS MARKED WITH (X) AREN'T SUPPORTED BY THE COMPILER AT THE MOMENT.
4+
5+
## Printing<br>
6+
````
7+
print "At least we have support for basic strings!";
8+
````
9+
<br>Or a variable:<br>
10+
````
11+
print a;
12+
````
13+
<br>You can even use the single string! (More on that later.)<br>
14+
````
15+
print str;
16+
````
17+
18+
## Creating Variables:<br>
19+
````
20+
var a;
21+
````
22+
<br>(always starts at 0)
23+
24+
## Setting Variables
25+
26+
````
27+
a=5; //Setting to an integer
28+
a=b; //Setting to another variable
29+
````
30+
31+
## Adding/subtracting to variables
32+
33+
````
34+
a +; //Addition by 1
35+
b -; //Subtraction by 1
36+
````
37+
(Do note that if a variables goes above the number 256, it resets to 0)
38+
39+
## Loops
40+
````
41+
(a,b) {
42+
//loops until the first variable is equal to the second.
43+
}
44+
````
45+
46+
## The Single String:
47+
In BScript, you get access to a single string, `str`. You can set it using:
48+
````
49+
str "something";
50+
````
51+
52+
## Inputs
53+
54+
This simply sets a user input to the Single String
55+
56+
````
57+
input;
58+
````
59+
60+
[Next Page >](Functions.md)

docs/ExampleFunctions.bs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//Some functions to use in BScript.
2+
3+
//Function that takes two parameters and returns their sum
4+
func add x, y {
5+
var w;
6+
7+
(w, y) {
8+
x +;
9+
w +;
10+
}
11+
12+
return x;
13+
}

docs/Functions.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Functions
2+
3+
Cool enough, custom functions are possible in this language. You can even return things. Nice, right?
4+
5+
## Defining a function (X)
6+
7+
You can define a function using
8+
9+
````
10+
func myFunction arg1,arg2 {
11+
//Code here
12+
}
13+
````
14+
15+
Simple enough, right? After a function has been defined, you can reuse these anywhere, like this.
16+
17+
````
18+
myFunction 1,2; //Variables, strings, and integers supported as arguments
19+
````
20+
21+
## Returning a value (X)
22+
23+
You can return value using this.
24+
25+
````
26+
func addOne number {
27+
return number +;
28+
}
29+
````
30+
31+
Returned functions can be set to as variables or the Single String.
32+
33+
````
34+
a=addOne 1; //a equals 2 now.
35+
36+
str someStringFunction str; //This does whatever this string function does
37+
````
38+
39+
Functions can do a lot, and since I'm nice I'll provide some functions you can put into your own code!
40+
41+
[You can see them here!](ExampleFunctions.bs)
42+
43+
[< Previous Page](Basics.md) | [Next Page >](ScreenFunctions.md)

docs/ScreenFunctions.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Screen Functions
2+
3+
Under construction!
4+
5+
[< Previous Page](Functions.md) | [Next Page >](Advanced.md)

0 commit comments

Comments
 (0)