diff options
| author | 2022-10-09 22:25:25 +0200 | |
|---|---|---|
| committer | 2022-10-09 22:25:25 +0200 | |
| commit | 07392816b62731ba6226ca80dc3c7ba8147a50df (patch) | |
| tree | 4e3a9e58a4f56576be5ce9a4948be69759438aa6 /pez.c | |
| parent | f5fa6cde9e1d8157df86b34129c9e844d329329a (diff) | |
disallow keywords as identifiers
Diffstat (limited to 'pez.c')
| -rw-r--r-- | pez.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -2438,6 +2438,12 @@ flushconst(Comp *cm) } static bool +reserved(const char *s) +{ + return !strcmp(s, "FOR") || !strcmp(s, "RET"); +} + +static bool primaryexpr(Comp *cm) { char buf[NAMEMAX]; @@ -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 |