/* %Z%%M% %I% %E% */ /* * Copyright (c) 1990, 1991, 1992, 1994, 1995, 1999 by Wayne C. Gramlich. * All rights reserved. * * Permission to use, copy, modify, distribute, and sell this software * for any purpose is hereby granted without fee provided that the above * copyright notice and this permission are retained. The author makes * no representations about the suitability of this software for any purpose. * It is provided "as is" without express or implied warranty. */ /* This file contains code for dealing with keywords: */ #ifndef ERROR_EXPORTS_H #include "error_exports.h" #endif #ifndef KEYWORD_DEFS_H #include "keyword_defs.h" #endif #ifndef LINT_H #include "lint.h" #endif #ifndef STR_EXPORTS_H #include "str_exports.h" #endif #ifndef UNIX_STDIO_H #include "unix_stdio.h" #endif #ifndef TABLE_EXPORTS_H #include "table_exports.h" #endif LOCAL Str keyword_unparse(Keyword); /* * keyword_unparse(keyword) * This routine will return the string associated with "keyword". */ LOCAL Str keyword_unparse( Keyword keyword) { switch (keyword) { case Key_all: return "all"; case Key_assert: return "assert"; case Key_body: return "body"; case Key_break: return "break"; case Key_case: return "case"; case Key_continue: return "continue"; case Key_default: return "default"; case Key_define: return "define"; case Key_else: return "else"; case Key_else_if: return "else_if"; case Key_enumeration: return "enumeration"; case Key_eol: return ""; case Key_eval: return "eval"; case Key_export: return "export"; case Key_external: return "external"; case Key_extract: return "extract"; case Key_for: return "for"; case Key_generate: return "generate"; case Key_identify: return "identify"; case Key_if: return "if"; case Key_import: return "import"; case Key_initialize: return "initialize"; case Key_iterator: return "iterator"; case Key_loop: return "loop"; case Key_module: return "module"; case Key_needs: return "needs"; case Key_needs_nothing: return "needs_nothing"; case Key_none: return ""; case Key_no_side_effects: return "no_side_effects"; case Key_object: return "object"; case Key_procedure: return "procedure"; case Key_record: return "record"; case Key_reswitch: return "reswitch"; case Key_return: return "return"; case Key_returns: return "returns"; case Key_returns_never: return "returns_never"; case Key_returns_nothing: return "returns_nothing"; case Key_routine: return "routine"; case Key_routine_types: return "routine_types"; case Key_signal: return "signal"; case Key_signals: return "signals"; case Key_switch: return "switch"; case Key_to: return "to"; case Key_tag: return "tag"; case Key_takes: return "takes"; case Key_takes_nothing: return "takes_nothing"; case Key_type: return "type"; case Key_type_get: return "type_get"; case Key_type_non_set: return "type_non_set"; case Key_type_other: return "type_other"; case Key_type_set: return "type_set"; case Key_until: return "until"; case Key_version: return "version"; case Key_variant: return "variant"; case Key_while: return "while"; case Key_yield: return "yield"; case Key_yields: return "yields"; default: return ""; } } /* * keyword_table_get(heap) * This will return a table of keywords allocated from "heap". */ Table(Str, Keyword) keyword_table_get( Heap heap) { int index; Keyword keyword; Table(Str, Keyword) keywords; Str text; keywords = table_create(Str, Keyword, (int)Key_last, strequal, strhash, Key_none, heap); for (index = 0; index < (int)Key_last; index++) { keyword = (Keyword)index; if (keyword == Key_none) { continue; } text = keyword_unparse(keyword); if (strcmp(text, "") == 0) { error_abort("Missing keyword"); continue; } (void)table_insert(Str, Keyword, keywords, text, keyword); } return keywords; }