Updated README.md
This commit is contained in:
parent
feae5d560a
commit
8763fa35dd
@ -1,12 +1,13 @@
|
||||
---
|
||||
BasedOnStyle: LLVM
|
||||
AlignConsecutiveShortCaseStatements:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: true
|
||||
IndentCaseLabels: true
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
IndentWidth: 4
|
||||
PointerAlignment: Left
|
||||
AlignAfterOpenBracket: BlockIndent
|
||||
|
17
README.md
17
README.md
@ -1,4 +1,4 @@
|
||||
# SCL: Simple Calculator Language
|
||||
# SCL: Simple CAS Language
|
||||
|
||||
## Syntax
|
||||
|
||||
@ -12,16 +12,24 @@ As one would expect, you can evaluate simple infix expressions:
|
||||
You can also define your own functions:
|
||||
|
||||
```scl
|
||||
> f(x) 2x
|
||||
> f(x) = 2x
|
||||
> f(2)
|
||||
= 4
|
||||
```
|
||||
|
||||
Symbolic algebra is done in the following manner:
|
||||
|
||||
```scl
|
||||
> f(x) = e^x
|
||||
> diff(f, x:sym, 2)
|
||||
= e^x
|
||||
```
|
||||
|
||||
SCL will dynamically decide on types, but you can state them explicitly as
|
||||
well:
|
||||
|
||||
```scl
|
||||
> f(x:int) 2x
|
||||
> f(x:int) = 2x
|
||||
> f(2.2)
|
||||
! f(x:int): x must be of type int.
|
||||
```
|
||||
@ -32,6 +40,5 @@ Variables can be defined, with several attributes:
|
||||
> a = 1 // Interpret type automatically.
|
||||
> b:int = 1 // Must be int.
|
||||
> c:const:int = 1 // Constant: value can never change.
|
||||
> d:lazy = (1 + 1) // Interpreter will wait as long as possible before
|
||||
// evaluating.
|
||||
> x:sym // Treated symbolicaly.
|
||||
```
|
||||
|
@ -26,7 +26,8 @@ void ast_destroy(AST* ast) {
|
||||
switch (ast->type) {
|
||||
case AST_TYPE_NUM: ast_num_data_destroy(ast->data); break;
|
||||
case AST_TYPE_CALL: ast_call_data_destroy(ast->data); break;
|
||||
default: log_dbgf("Unknown ast type %d (max: %d)", ast->type, AST_TYPE_MAX);
|
||||
default:
|
||||
log_dbgf("Unknown ast type %d (max: %d)", ast->type, AST_TYPE_MAX);
|
||||
}
|
||||
}
|
||||
|
||||
|
12
src/dstr.c
12
src/dstr.c
@ -25,8 +25,10 @@ void dstr_append(Dstr* dest, char* src, size_t ln) {
|
||||
// Double the buffer size when overflown.
|
||||
dest->bufsz *= 2;
|
||||
dest->buf = realloc(dest->buf, dest->bufsz);
|
||||
log_dbgf("dstr @ %p doubled from %ld to %ld", dest, dest->bufsz / 2,
|
||||
dest->bufsz);
|
||||
log_dbgf(
|
||||
"dstr @ %p doubled from %ld to %ld", dest, dest->bufsz / 2,
|
||||
dest->bufsz
|
||||
);
|
||||
}
|
||||
|
||||
// Overwrites the \0 at the end of the string, keeps the null from the given
|
||||
@ -40,8 +42,10 @@ void dstr_appendch(Dstr* dest, char ch) {
|
||||
// Double the buffer size when overflown.
|
||||
dest->bufsz *= 2;
|
||||
dest->buf = realloc(dest->buf, dest->bufsz);
|
||||
log_dbgf("dstr @ %p doubled from %ld to %ld", dest, dest->bufsz / 2,
|
||||
dest->bufsz);
|
||||
log_dbgf(
|
||||
"dstr @ %p doubled from %ld to %ld", dest, dest->bufsz / 2,
|
||||
dest->bufsz
|
||||
);
|
||||
}
|
||||
|
||||
// Overwrites the preexisting null terminator, and adds one of its own.
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "include/lexer.h"
|
||||
|
||||
@ -30,7 +30,8 @@ double acc_float(int c) {
|
||||
while (isdigit(*inp)) {
|
||||
// TODO:
|
||||
// Accumulate as int, divide once at end.
|
||||
// value = value + (((double)(*inp - '0'))/pow(10.0l, (double)(inp-oinp))); // Accumulate value.
|
||||
// value = value + (((double)(*inp - '0'))/pow(10.0l,
|
||||
// (double)(inp-oinp))); // Accumulate value.
|
||||
value = value * 10 + (*inp - '0'); // Accumulate value.
|
||||
dplaces++;
|
||||
inp++;
|
||||
|
11
src/main.c
11
src/main.c
@ -2,9 +2,9 @@
|
||||
|
||||
#include "include/ast.h"
|
||||
#include "include/dstr.h"
|
||||
#include "include/exec.h"
|
||||
#include "include/lexer.h"
|
||||
#include "include/util.h"
|
||||
#include "include/exec.h"
|
||||
|
||||
#include "../build/grammars/grammar.tab.h"
|
||||
|
||||
@ -31,7 +31,6 @@ int main(int argc, char** argv) {
|
||||
switch (c) {
|
||||
case EOF: dstr_destroy(ln); goto lnskip;
|
||||
case '\n': goto lnend;
|
||||
|
||||
default: dstr_appendch(ln, c); log_dbgf("cchar: %c", c);
|
||||
}
|
||||
} while (1);
|
||||
@ -41,12 +40,10 @@ int main(int argc, char** argv) {
|
||||
log_dbgf("cline: %s", ln->buf);
|
||||
|
||||
if (ln->ln > 0) {
|
||||
// I hope it's null-terminated.
|
||||
// I hope to god it's null-terminated.
|
||||
inp = ln->buf;
|
||||
if (yyparse() == 0)
|
||||
printf("Parsed successfully!\n");
|
||||
else
|
||||
printf("Parse error.\n");
|
||||
if (yyparse() == 0) printf("Parsed successfully!\n");
|
||||
else printf("Parse error.\n");
|
||||
|
||||
// exec_expr(root);
|
||||
ast_print(root);
|
||||
|
@ -2,8 +2,8 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "include/util.h"
|
||||
#include "include/stack.h"
|
||||
#include "include/util.h"
|
||||
|
||||
Stack* stack_init() {
|
||||
talloc(Stack, stack);
|
||||
|
Loading…
x
Reference in New Issue
Block a user