From 07392816b62731ba6226ca80dc3c7ba8147a50df Mon Sep 17 00:00:00 2001 From: lemon Date: Sun, 9 Oct 2022 22:25:25 +0200 Subject: disallow keywords as identifiers --- pez.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'pez.c') diff --git a/pez.c b/pez.c index 1ad9670..2864444 100644 --- a/pez.c +++ b/pez.c @@ -2437,6 +2437,12 @@ flushconst(Comp *cm) return 1; } +static bool +reserved(const char *s) +{ + return !strcmp(s, "FOR") || !strcmp(s, "RET"); +} + static bool primaryexpr(Comp *cm) { @@ -2492,6 +2498,10 @@ primaryexpr(Comp *cm) // identifier *buf = c; TRY(readident(cm, buf + 1, sizeof buf - 1)); + if (reserved(buf)) { + comperr(cm, *buf, "'%s' is a reserved keyword", buf); + return 0; + } Ident: local = findlocal(cm, buf); if (local) { @@ -3325,6 +3335,10 @@ decl(Comp *cm, Local **pl, bool nofold) return 0; } TRY(readident(cm, name, sizeof name)); + if (reserved(name)) { + comperr(cm, *name, "'%s' is a reserved keyword", name); + return 0; + } eatspaces(cm); switch ((c = nextchr(cm))) { case ':': // constant -- cgit v1.2.3