Skip to content

Commit

Permalink
v1.3: operator .prog is no longer required, added identification il
Browse files Browse the repository at this point in the history
  • Loading branch information
Centrix14 committed Jan 2, 2020
1 parent 20c3430 commit b8b6c98
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
+ specifically for saol, I wrote a preprocessor called ssp (standard SAOL preprocessor), it runs separately from the main interpreter, and has the following features:
+ `.link <file_1> <file_2> ... <file_n>` -- connecting third-party files
+ `.macro <name> <expr>` -- creates a macro named name, the next time it is encountered, expr will be substituted for it
+ `.prog` -- end of the preprocessor command block and start of the program
+ `.prog` -- end of the preprocessor command block and start of the program (in version 1.3 and higher it is not necessary)

### Template for using a preprocessor in a program
```
Expand Down
8 changes: 6 additions & 2 deletions arr_lib.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Saol interpreter library v1.2 31/12/2019 by Centrix */
/* Saol interpreter library v1.3 02/01/2020 by Centrix */

#include <stdio.h>
#include <stdlib.h>
Expand All @@ -18,7 +18,11 @@ int len = 25;
int pred = 1;

void ini(char *arg) {
if (isint(arg))
if (!strcmp(arg, "il")) {
arr[pos] = end - start - 1;
return ;
}
else if (isint(arg))
arr[pos] = atoi(arg);
else
arr[pos] = arg[0];
Expand Down
10 changes: 7 additions & 3 deletions ssp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

/*
* ssp - standard saol preprocessor
* v1.2
* 31/12/2019
* v1.3
* 02/01/2020
* by Centrix
*/

Expand All @@ -17,6 +17,7 @@ void macro(char *arg), link(char *arg), prog(char *arg), copy(char *arg);
char macro_names[1024][256], macro_codes[1024][256];
int len = 3, code = 3, pos = 0;
FILE *src, *dst;
int is_end = 0;

int main(int argc, char *argv[]) {
char line[1024], *tok = "";
Expand All @@ -30,6 +31,7 @@ int main(int argc, char *argv[]) {
dst = fopen(argv[2], "w");

while (fgets(line, 1024, src) != NULL) {
code = 3;
pos = 0;
tok = ssp_tok(line, &pos);

Expand All @@ -46,7 +48,7 @@ int main(int argc, char *argv[]) {
fclose(src);
fclose(dst);

return 0;
return is_end;
}

char *ssp_tok(char *str, int *pos) {
Expand Down Expand Up @@ -108,6 +110,7 @@ void macro(char *arg) {
sprintf(macro_codes[pos++], "%s", arg);
state = 0;
}
is_end++;
}

void link(char *arg) {
Expand All @@ -130,6 +133,7 @@ void link(char *arg) {
putc('\n', dst);

fclose(from);
is_end++;
}

void prog(char *arg) {
Expand Down

0 comments on commit b8b6c98

Please sign in to comment.