From 07fe0f96352967457d64ff349f4383c5568bcd42 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Mon, 24 Jan 2022 18:58:45 +0000 Subject: Implement Dop's --- lexer.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lexer.c') diff --git a/lexer.c b/lexer.c index 4ba0a30..54e6e9b 100644 --- a/lexer.c +++ b/lexer.c @@ -113,8 +113,12 @@ lexline(InputStream *input, int toplevel) stmt->toks[stmt->ntoks].tag = FunctionTag; stmt->toks[stmt->ntoks].func.type = FunctypeDfn; stmt->toks[stmt->ntoks].func.dfn = runestrdup(buf); - }else - throwerror(L"Dops not implemented yet", ESyntax); + }else{ + stmt->toks[stmt->ntoks].tag = oplevel == 1 ? MonadicOpTag : DyadicOpTag; + stmt->toks[stmt->ntoks].operator.type = OperatortypeDop; + stmt->toks[stmt->ntoks].operator.dyadic = oplevel == 2; + stmt->toks[stmt->ntoks].operator.dop = runestrdup(buf); + } }else if(peek == '('){ int unclosed = 1; Rune buf[MAX_LINE_LENGTH]; @@ -173,7 +177,7 @@ get_digits: ungetrune(input); stmt->toks[stmt->ntoks].tag = ArrayTag; stmt->toks[stmt->ntoks].array = floating ? mkscalarfloat(atof(buf)) : mkscalarint(atoll(buf)); - }else if(runestrchr(L"⍺⍵", peek)){ + }else if(runestrchr(L"⍺⍵⍶⍹", peek)){ Rune name[2] = {peek, 0}; stmt->toks[stmt->ntoks].tag = NameTag; stmt->toks[stmt->ntoks].symbol = getsym(name, 1); @@ -245,7 +249,7 @@ syntax_error: free(stmt); throwerror(err, ESyntax); } - /*print("Got token: %S\n", ppdatum(stmt->toks[stmt->ntoks]));*/ + /* print("Got token: %S\n", ppdatum(stmt->toks[stmt->ntoks])); */ stmt->ntoks++; peek = getrune(input); } @@ -278,7 +282,7 @@ getrune(InputStream *i) else r = i->string[i->offset++]; } - /*print("Get rune: '%C' (%d)\n", r, r);*/ + /* print("Get rune: '%C' (%d)\n", r, r); */ i->last = r; return r; } @@ -286,7 +290,7 @@ getrune(InputStream *i) void ungetrune(InputStream *i) { - /*print("Unget rune: '%C' (%d)\n", i->last, i->last);*/ + /* print("Unget rune: '%C' (%d)\n", i->last, i->last); */ if(inputEOF(i)) return; -- cgit v1.2.3