diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2023-02-28 22:16:22 -0800 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2023-02-28 22:16:22 -0800 |
| commit | a3af974ab4e079f9000c4c34cd5ff468986ca609 (patch) | |
| tree | a1a870b466fa36ed700cd0c37523d5dd0c9d5327 | |
| parent | 4af02258dbc1564e52a4ae9c75b3664384fcd89d (diff) | |
changed syntax to be a little more normal
| -rw-r--r-- | doc/precedent.1 | 10 | ||||
| -rw-r--r-- | examples/boolean.pcdt | 20 | ||||
| -rw-r--r-- | examples/boundedrecursion.pcdt | 16 | ||||
| -rw-r--r-- | examples/functest.pcdt | 9 | ||||
| -rw-r--r-- | examples/mathexamples.pcdt | 2 | ||||
| -rw-r--r-- | examples/recursion.pcdt | 2 | ||||
| -rw-r--r-- | src/parse.c | 113 | ||||
| -rw-r--r-- | stdlib/math.pcdt | 18 |
8 files changed, 99 insertions, 91 deletions
diff --git a/doc/precedent.1 b/doc/precedent.1 index 577fdb5..a974cf8 100644 --- a/doc/precedent.1 +++ b/doc/precedent.1 @@ -35,12 +35,12 @@ keys, and keys created with store(). A key may accept parameters, making it a fu .SH SYNTAX Spaces, tabs, newlines, and other forms of whitespace are ignored. -A literal value is defined by its termination with a semicolon. The following -are examples of literal values: [ 123; hello world; 9.81; ]. A key is defined by its -termination with a pair of parentheses. The following are examples of key references: -[ myVar() arg0() ]. A key reference may have any number of arguments, which may be +A literal value is either a number or wrapped in quotation marks. The following +are examples of literal values: [ 123, "hello world", 9.81 ]. A key without arguments +is simply stated as a word. The following are examples of key references: +[ myVar, arg0 ]. A key reference may have any number of arguments, which may be literals or key references. The following are examples of key references with arguments: -[ print(hello world;) print(myVar()) print(eq(1; 2;)) ]. +[ print("hello world"), print(myVar), print(eq(1, 2)) ]. .SH FUNCTIONS \fBroot() OR ()\fP diff --git a/examples/boolean.pcdt b/examples/boolean.pcdt index c77f152..de6f04f 100644 --- a/examples/boolean.pcdt +++ b/examples/boolean.pcdt @@ -1,18 +1,16 @@ -store(14; var1;) -store(14; var2;) +store(14, "var1") +store(14, "var2") -store( -eq(var1() var2()) -res;) +store(eq(var1, var2) "res") -print(var1()) +print(var1) -if(res() -print(equals;) +if(res + print("equals") ) -if(not(res()) -print(does not equal;) +if(not(res) + print("does not equal") ) -print(var2()) +print(var2) diff --git a/examples/boundedrecursion.pcdt b/examples/boundedrecursion.pcdt index 3187960..12981da 100644 --- a/examples/boundedrecursion.pcdt +++ b/examples/boundedrecursion.pcdt @@ -1,9 +1,11 @@ -store(1000; maxSize;) +store(1000, "maxSize"); store( ref(( - print(arg0()) - if(not(eq(arg0() maxSize())) incFunc(sum(1; arg0()))) - )) - incFunc; -) -incFunc(0;) + print(arg0); + if(not(eq(arg0, maxSize)) + incFunc(sum(1, arg0)); + ) + )); + "incFunc"; +); +incFunc(0); diff --git a/examples/functest.pcdt b/examples/functest.pcdt deleted file mode 100644 index ffa4531..0000000 --- a/examples/functest.pcdt +++ /dev/null @@ -1,9 +0,0 @@ -store( - ref(( - print(running function;) - eq(arg0() arg1()) - )) - myFunc; -) -print(equality?;) -print(myFunc(0; 0;)) diff --git a/examples/mathexamples.pcdt b/examples/mathexamples.pcdt index b5b4430..dba85c5 100644 --- a/examples/mathexamples.pcdt +++ b/examples/mathexamples.pcdt @@ -1,2 +1,2 @@ @../stdlib/math.pcdt -print(multiply(12; -5;)) +print(multiply(12, -5)) diff --git a/examples/recursion.pcdt b/examples/recursion.pcdt deleted file mode 100644 index 3f57a6e..0000000 --- a/examples/recursion.pcdt +++ /dev/null @@ -1,2 +0,0 @@ -store( ref((print(arg0()) incFunc(sum(1; arg0())))) incFunc;) -incFunc(0;) diff --git a/src/parse.c b/src/parse.c index d1b0f2e..3811eae 100644 --- a/src/parse.c +++ b/src/parse.c @@ -82,7 +82,7 @@ symset_t* parse_symbols(char** str) { symbolSet->count = 0; while (1) { /* clear whitespace */ - while (!isalnum(**str) && **str != '-' && **str != '(' && **str != ')' && **str != '\0') { + while (!isalnum(**str) && **str != '"' && **str != '-' && **str != '(' && **str != ')' && **str != '\0') { (*str)++; } if (**str == ')') { @@ -94,64 +94,85 @@ symset_t* parse_symbols(char** str) { } char* symbolName = calloc(30, sizeof(char)); char isFloat = 0; + char isString = 0; int i = 0; while (1) { symbolName[i] = **str; - if (**str == '.') { - isFloat = 1; + if (**str == '"') { + /* start quote */ + if (!isString) { + isString = 1; + } + /* end quote */ + else { + (*str)++; + symbolName[i] = '\0'; + /* offset by one to remove start quote */ + sym_t* symbol = init_sym_str(symbolName + 1); + symset_add_symbol(symbolSet, symbol); + break; + } } - else if (**str == ',' || **str == ';') { - (*str)++; - symbolName[i] = '\0'; - sym_t* symbol; - /* string */ - if (isalpha(symbolName[0])) { - symbol = init_sym_str(symbolName); + else if (!isString) { + if (**str == '.') { + isFloat = 1; } - /* int */ - else if (!isFloat) { - int v; - if (symbolName[0] == '-') { - v = atoi(symbolName + 1) * -1; + else if (!isalnum(**str) && **str != '-' && **str != '(') { + if (**str == ')') { + (*str)--; + } + (*str)++; + symbolName[i] = '\0'; + sym_t* symbol; + if (isalpha(symbolName[0])) { + /* reference */ + symbol = init_sym_key(symbolName); + } + /* int */ + else if (!isFloat) { + int v; + if (symbolName[0] == '-') { + v = atoi(symbolName + 1) * -1; + } + else { + v = atoi(symbolName); + } + symbol = init_sym_int(v); } else { - v = atoi(symbolName); + float v; + if (symbolName[0] == '-') { + v = atof(symbolName + 1) * -1; + } + else { + v = atof(symbolName); + } + symbol = init_sym_float(v); } - symbol = init_sym_int(v); + symset_add_symbol(symbolSet, symbol); + break; } - else { - float v; - if (symbolName[0] == '-') { - v = atof(symbolName + 1) * -1; + else if (**str == '(') { + (*str)++; + symbolName[i] = '\0'; + sym_t* symbol; + if (i > 1) { + symbol = init_sym_key(symbolName); } else { - v = atof(symbolName); + symbol = init_sym_key("root"); } - symbol = init_sym_float(v); - } - symset_add_symbol(symbolSet, symbol); - break; - } - else if (**str == '(') { - (*str)++; - symbolName[i] = '\0'; - sym_t* symbol; - if (i > 1) { - symbol = init_sym_key(symbolName); - } - else { - symbol = init_sym_key("root"); - } - symset_t* symbols = parse_symbols(str); - for (int s = 0; s < symbols->count; s++) { - symbol_add_arg(symbol, symbols->symbols[s]); - } - if (symbols->count > 0) { - free(symbols->symbols); + symset_t* symbols = parse_symbols(str); + for (int s = 0; s < symbols->count; s++) { + symbol_add_arg(symbol, symbols->symbols[s]); + } + if (symbols->count > 0) { + free(symbols->symbols); + } + free(symbols); + symset_add_symbol(symbolSet, symbol); + break; } - free(symbols); - symset_add_symbol(symbolSet, symbol); - break; } i++; (*str)++; diff --git a/stdlib/math.pcdt b/stdlib/math.pcdt index e4b0fe0..3f375ae 100644 --- a/stdlib/math.pcdt +++ b/stdlib/math.pcdt @@ -1,12 +1,10 @@ store( - ref(( - store(0; last;) - if(not(eq(arg0() 1;)) - ( - update(multiply(sub(arg0() 1;) arg1()) last;) - ) - ) - sum(arg1() last()) - )) - multiply; + ref(( + store(0, "last") + if(not(eq(arg0, 1)) + update(multiply(sub(arg0, 1), arg1), "last") + ) + sum(arg1, last) + )) + "multiply" ) |
