From f26421445f691528992bdb2a2c52538bcdb70b18 Mon Sep 17 00:00:00 2001 From: mar77i Date: Thu, 21 Nov 2024 09:48:39 +0100 Subject: [PATCH] skip shell-style '#' comments --- parser.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/parser.c b/parser.c index 8ef121b..a11ec69 100644 --- a/parser.c +++ b/parser.c @@ -51,6 +51,17 @@ static inline int read_ident_or_keyword( return 0; } +static inline int is_newline(int c) { + return c == '\n'; +} + +static inline void skip_comment(FILE *fh) { + int c; + while ((c = getc(fh)) != EOF) + if (is_newline(c)) + return; +} + int parse_input(FILE *fh, struct program *p) { int c; struct ast_item ai; @@ -90,6 +101,9 @@ int parse_input(FILE *fh, struct program *p) { case '/': ai.type = AST_ITEM_DIVIDE; goto add_item; + case '#': + skip_comment(fh); + continue; } if (isdigit(c)) { ai.type = AST_ITEM_INT; -- 2.47.0