hlc

High level language for lli
Log | Files | Refs

commit d5d9ba503bddab9fd6da4d1b06ebbdad85d09ea2
parent 75b1868517b633d8dec332fefc4ae697539687ba
Author: thing1 <l.standen@posteo.com>
Date:   Tue,  7 Oct 2025 13:21:57 +0100

added addtional lexers

Diffstat:
Mlex.c | 61++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Mspec.md | 4++++
2 files changed, 60 insertions(+), 5 deletions(-)

diff --git a/lex.c b/lex.c @@ -35,6 +35,14 @@ peekc(FILE *in) { } lex_val * +lex_char(char c, lex_type t) { + if (getchr(input) != c) return &lex_error; + lv.type = t; + lv.data = NULL; + return &lv; +} + +lex_val * lex_type(void) { switch (peekc(input)) { case 'b': @@ -60,6 +68,51 @@ lex_type(void) { return &lv; } + + +lex_val * +lex_comma() { + return lex_char(',', COMMA); +} + +lex_val * +lex_semi() { + return lex_char(';', SEMI); +} + +lex_val * +lex_assign() { + return lex_char('=', ASSIGN); +} + +lex_val * +lex_sym() { + switch (getchr(input)) { + case '<': + switch (peekc(input)) { + case '=': getchr(input); lv.type = LTE; break; + default: lv.type = LT; break; + } + return lv; + case '>': + switch (peekc(input)) { + case '=': getchr(input); lv.type = GTE; break; + default: lv.type = GT; break; + } + return lv; + case '!': + lv.type = LT; break; + case '+': lv.type = LT; break; + case '-': lv.type = LT; break; + case '/': lv.type = LT; break; + case '*': lv.type = LT; break; + case '&': lv.type = LT; break; + } +} + + + +/* TODO: make this execpt pointer derefs at the start of a name */ lex_val * lex_name(void) { static char name[32] = { 0 }; @@ -72,10 +125,9 @@ lex_name(void) { lv.data = name; lv.type = NAME; - /* switch (peekc(input)) { - case '=': nextfn = &lex_assign; break; CHECK FOR == and = - case ',': nextfn = &lex_comma; break; + case '=': nextfn = &lex_assign; break; /* CHECK FOR == and = */ + case ',': nextfn = &lex_comma; break; /* leads to lex_type */ case ';': nextfn = &lex_semi; break; case '<': @@ -84,13 +136,12 @@ lex_name(void) { case '+': case '-': case '/': - case '*': CHECK FOR MUL AND PTR + case '*': /* CHECK FOR MUL AND PTR */ case '&': nextfn = &lex_sym; break; break; default: return &lex_error; } - */ return &lv; } diff --git a/spec.md b/spec.md @@ -45,6 +45,7 @@ The syntax for the language can be defined in the following BNF notation expr ::= NUM ||= '"' STRING '"' + ||= var ||= dec ||= expr '+' expr ||= expr '-' expr @@ -58,3 +59,6 @@ The syntax for the language can be defined in the following BNF notation ||= expr '<=' expr ||= '*' expr ||= '&' expr + + var ::= NAME + || '*' var