diff options
| -rw-r--r-- | core/lexer.c | 30 | ||||
| -rw-r--r-- | core/parser.c | 23 | ||||
| -rw-r--r-- | include/cescal/token.h | 1 |
3 files changed, 43 insertions, 11 deletions
diff --git a/core/lexer.c b/core/lexer.c index 617ba41..26ab451 100644 --- a/core/lexer.c +++ b/core/lexer.c @@ -183,6 +183,27 @@ lexer_check_kw(struct cescal_state *state, struct token *res) } } +/* + * Skip anything after a comment + * + * @state: Compiler state + */ +static void +lexer_skip_comment(struct cescal_state *state) +{ + char c; + + if (state == NULL) { + return; + } + + while ((c = lexer_consume_single(state, false)) != '\n') { + if (c == '\0') { + break; + } + } +} + int lexer_nom(struct cescal_state *state, struct token *res) { @@ -210,6 +231,15 @@ lexer_nom(struct cescal_state *state, struct token *res) res->type = TT_COMMA; res->c = c; return 0; + case '/': + if (lexer_consume_single(state, true) == '/') { + res->type = TT_COMMENT; + res->c = c; + lexer_skip_comment(state); + return 0; + } + + return -1; default: if (lexer_scan_ident(state, c, res) == 0) { lexer_check_kw(state, res); diff --git a/core/parser.c b/core/parser.c index a584a56..3b3e91b 100644 --- a/core/parser.c +++ b/core/parser.c @@ -30,17 +30,18 @@ * Converts numeric tokens into human readable strings */ static const char *toktab[] = { - [TT_NONE] = symtok("none"), - [TT_IDENT] = symtok("ident"), - [TT_INTLIT] = symtok("number"), - [TT_LPAREN] = qtok("("), - [TT_RPAREN] = qtok(")"), - [TT_COMMA] = qtok(","), - [TT_RETURN] = qtok("return"), - [TT_PUB] = qtok("pub"), - [TT_PROC] = qtok("proc"), - [TT_BEGIN] = qtok("begin"), - [TT_END] = qtok("end") + [TT_NONE] = symtok("none"), + [TT_IDENT] = symtok("ident"), + [TT_COMMENT] = symtok("comment"), + [TT_INTLIT] = symtok("number"), + [TT_LPAREN] = qtok("("), + [TT_RPAREN] = qtok(")"), + [TT_COMMA] = qtok(","), + [TT_RETURN] = qtok("return"), + [TT_PUB] = qtok("pub"), + [TT_PROC] = qtok("proc"), + [TT_BEGIN] = qtok("begin"), + [TT_END] = qtok("end") }; int diff --git a/include/cescal/token.h b/include/cescal/token.h index 990df77..eb9fc39 100644 --- a/include/cescal/token.h +++ b/include/cescal/token.h @@ -12,6 +12,7 @@ typedef enum { TT_NONE, /* [none] */ TT_IDENT, /* [identifier] */ + TT_COMMENT, /* [comment : ignored] */ TT_INTLIT, /* [0-9]+ */ TT_LPAREN, /* '(' */ TT_RPAREN, /* '( */ |
