diff options
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); |