diff options
author | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-12 19:42:14 +0000 |
---|---|---|
committer | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-12 19:42:14 +0000 |
commit | d152639e4495089cabbbf7a16e5bc5129af78bfa (patch) | |
tree | b1f63531e0f02b850ae84721fd5799a4827f64db /lexer.c | |
parent | fe3ef88c4147c4188066873e570f56212ffeebfd (diff) |
Add dfn parsing, but not evaluation yet
Diffstat (limited to 'lexer.c')
-rw-r--r-- | lexer.c | 29 |
1 files changed, 21 insertions, 8 deletions
@@ -23,24 +23,36 @@ lexline(Rune *line, Symtab *symtab) if(isspacerune(line[offset])){ offset++; continue; - }else if(runestrchr(L"(){}[]←⋄⍝", line[offset])){ + }else if(runestrchr(L"()[]←⋄⍝", line[offset])){ switch(line[offset]){ case '(': stmt->toks[stmt->ntoks].tag = LParTag; break; case ')': stmt->toks[stmt->ntoks].tag = RParTag; break; - case '{': stmt->toks[stmt->ntoks].tag = LCurlTag; break; - case '}': stmt->toks[stmt->ntoks].tag = RCurlTag; break; case '[': stmt->toks[stmt->ntoks].tag = LBracketTag; break; case ']': stmt->toks[stmt->ntoks].tag = RBracketTag; break; case L'←': stmt->toks[stmt->ntoks].tag = ArrowTag; break; - case L'⋄': - stmt->next = lexline(&line[offset+1], symtab); - goto end; - case L'⍝': - goto end; + case L'⋄': stmt->next = lexline(&line[offset+1], symtab); goto end; + case L'⍝': goto end; } offset++; + }else if(line[offset] == L'{'){ + Rune buf[MAX_LINE_LENGTH]; + Rune *p = buf; + offset++; + while(line[offset] != L'}' && offset < len){ + *p = line[offset]; + p++; + offset++; + } + if(line[offset] != L'}') + goto syntax_error; + *p = 0; + offset++; + stmt->toks[stmt->ntoks].tag = FunctionTag; + stmt->toks[stmt->ntoks].func.type = FunctypeDfn; + stmt->toks[stmt->ntoks].func.dfn = runestrdup(buf); }else if(p = runestrchr(primfuncnames, line[offset])){ stmt->toks[stmt->ntoks].tag = FunctionTag; + stmt->toks[stmt->ntoks].func.type = FunctypePrim; stmt->toks[stmt->ntoks].func.code = p-primfuncnames; offset++; }else if(p = runestrchr(primmonopnames, line[offset])){ @@ -77,6 +89,7 @@ lexline(Rune *line, Symtab *symtab) stmt->toks[stmt->ntoks].tag = NameTag; stmt->toks[stmt->ntoks].symbol = getsym(symtab, buf); }else{ +syntax_error: print("Can't lex: %S\n", &line[offset]); free(stmt->toks); free(stmt); |