|
|
1.1 ! root 1: /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */ ! 2: static char rcsid[] = "$Header: lexi.c,v 2.4 84/10/26 12:01:34 guido Exp $"; ! 3: ! 4: /* ! 5: * B editor -- Lexical elements (identifiers, keywords, numbers etc.) ! 6: */ ! 7: ! 8: #include <ctype.h> ! 9: ! 10: #include "b.h" ! 11: #include "bobj.h" ! 12: #include "node.h" ! 13: #include "gram.h" ! 14: ! 15: ! 16: /* ! 17: * Table defining lexical elements. ! 18: * ! 19: * ********** Indexed by (symbol-LEXICAL). ! 20: */ ! 21: ! 22: Hidden char lowercase[] = "0123456789'\"abcdefghijklmnopqrstuvwxyz"; ! 23: Hidden char uppercase[] = "0123456789'\"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; ! 24: Hidden char digits[] = "0123456789"; ! 25: ! 26: Hidden struct { ! 27: string l_start; ! 28: string l_continue; ! 29: } chclass[] = { ! 30: {lowercase+12, lowercase,}, /* IDENT */ ! 31: {uppercase+12, uppercase,}, /* KEYWORD */ ! 32: {digits, digits,}, /* NUMBER */ ! 33: {"\\", "^",}, /* COMMENT */ ! 34: {"^`'", "^`'",}, /* TEXT1 */ ! 35: {"^`\"", "^`\"",}, /* TEXT2 */ ! 36: {".+-*/#^~@|<=>", "",}, /* OPERATORS */ ! 37: {"^", "^",}, /* RAW_INPUT */ ! 38: {"", "",}, /* SUGGESTION (dummy) */ ! 39: }; ! 40: ! 41: #define NCHCLASS (sizeof(chclass)/sizeof(chclass[0])) ! 42: ! 43: ! 44: /* ! 45: * Test whether character `c' may start a lexical element with ! 46: * symbolic name `lex'. ! 47: */ ! 48: ! 49: Visible bool ! 50: maystart(c, lex) ! 51: char c; ! 52: int lex; ! 53: { ! 54: string cp; ! 55: ! 56: lex -= LEXICAL; ! 57: Assert(lex >= 0); ! 58: if (lex >= NCHCLASS || !isascii(c) || c != ' ' && !isprint(c)) ! 59: return No; ! 60: cp = chclass[lex].l_start; ! 61: if (*cp == '^') ! 62: return !index(cp+1, c); ! 63: return index(cp, c) != 0; ! 64: } ! 65: ! 66: ! 67: /* ! 68: * Test whether character `c' may continue a lexical element with ! 69: * symbolic name `lex'. ! 70: */ ! 71: ! 72: Visible bool ! 73: maycontinue(c, lex) ! 74: char c; ! 75: int lex; ! 76: { ! 77: string cp; ! 78: ! 79: lex -= LEXICAL; ! 80: Assert(lex >= 0); ! 81: if (lex >= NCHCLASS || !isascii(c) || c != ' ' && !isprint(c)) ! 82: return No; ! 83: cp = chclass[lex].l_continue; ! 84: if (*cp == '^') ! 85: return !index(cp+1, c); ! 86: return index(cp, c) != 0; ! 87: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.