From 5ba4e0e4751e69021fb180a859370609ec0f73e2 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Thu, 16 Dec 2021 17:52:34 +0800 Subject: 4.10 --- 4/10.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to '4/10.c') diff --git a/4/10.c b/4/10.c index 36f038a..39119d2 100644 --- a/4/10.c +++ b/4/10.c @@ -116,19 +116,29 @@ int getop(char s[]) { s[1] = 0; // special characters and operators - if (c == 0 || c == '+' || c == '*' || c == '/' || c == '%' || c == '=' || + if (c == 0 || c == '+' || c == '*' || c == '/' || c == '%' || (c == '-' && isdigit(line[idx + 1])) || c == EOF) return c; i = 0; - + if (isdigit(c) || c == '-' || (c == '.' && isdigit(line[idx + 1]))) { - while (isdigit((s[++i] = c = line[idx++])) || (c == '.' && isdigit(line[idx + 1]))) + while (isdigit((s[++i] = c = line[idx++])) || + (c == '.' && isdigit(line[idx + 1]))) ; return NUM; } - + if (isalpha(c) && line[idx + 1] == ' ' && line[idx + 2] == '=') { + idx += 2; + return '='; + } + + while (isalnum(s[++i] = c = line[idx++])) + ; + s[i] = 0; + + return strcmp("LOUT", s) == 0 ? VAR : FUN; } int sp = 0; -- cgit v1.2.3