I need to implement a lexical analyzer and I need a data structure to save the keywords. I was advised to use a hash table to keep the keywords and one suggestion was to use C# Hash Table form System.Collections. But I have a problem: to use this hash table I need a key and an item. I have only the keyword. Should I use the keyword as key or as item,or as both? And since the keywords are different can I use another data structure, for example a binary tree? My real interest is this: how does a compiler implement this issue?
Which is the key and which is the item for a keywords hash table?
284 views Asked by Radu Mardari At
1
There are 1 answers
Related Questions in C#
- How to call a C language function from x86 assembly code?
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- How to crop a BMP image in half using C
- How can I get the difference in minutes between two dates and hours?
- Why will this code compile although it defines two variables with the same name?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Why can't I use the file pointer after the first read attempt fails?
- #include Header files in C with definition too
- OpenCV2 on CLion
- What is causing the store latency in this program?
- How to refer to the filepath of test data in test sourcecode?
- 9 Digit Addresses in Hexadecimal System in MacOS
- My server TCP doesn't receive messages from the client in C
- Printing the characters obtained from the array s using printf?
Related Questions in DATA-STRUCTURES
- Why is the runtime for this O(n)?
- Purpose of last 2 while loops in the merge algorithm of merge sort sorting technique
- What is the problem in my "sumAtBis" code?
- Asking code suggestions about data structure and algorithm
- What would be the most efficient way to store multiple sets of fixed arrays (std::vector)?
- About Suffix Trees features
- Getting wrong answer in Binary Search solution
- Are there techniques to mathematically compute the amount of searching in greedy graph searching?
- AVL tree Nth largest operation - How to have all my tests pass? JAVA
- Why does the map size change?
- Complexity in Union of disjointed sets with lists
- Hash collisions in Golang map resolving
- C++ ordered map optimized with index access
- How to sort this list of strings along with the strings and output the result as expected?
- Why deleting an element in a linkedlist costs O(1)
Related Questions in COMPILER-CONSTRUCTION
- Reference: Crafting Interpreters. Print statement is not able to evaluate expression. Help me fix this (details below)
- Load function written in amd64 assembly into memory and call it
- I have implemented till Statements and State in Tree Walk Interpreter. I am pissed with an error
- Resolve shift/reduction conflict in grammar for expressions in PLY for calls to embedded functions
- Grammar for access to properties and calls to embedded functions
- LLVM code generation causes problems with pointer arithmetic
- what does react compiler mean actually?
- Errors on Recursive Descent Parsing Java
- Java CUP produces Shift-Reduce conflict when parsing a grammar for a C++ type language
- Three-Address-Code (TAC) and Conjunction/Disjunction
- How do I write an implicit cast for my strongly typed interpreter? (C++)
- Yacc parser not reducing specific production rules as intended
- Why is the function version tag consistently "Base" in HDF5 library?
- Sly parser, how are recursively defined types implemented?
- Does a non terminal token need an explicit definition?
Related Questions in COMPILATION
- I am trying to run java application in Eclipse, When I try to do Run > Run as > Java Application it starts to show little processing but nothing happe
- Unable to run get .exe file from assembly NASM
- Javascript to Java
- How to compile only the changed files in Verilator?
- Why does the .exe file become locked after compiling?
- Installing the C compiler for LC3
- compile syzkaller fuzzer failed without any error or warning
- Solved: Create standalone executable for MacOS with OpenCV and libmagic
- How to work around the "collect2: error: ld returned 1 exit status" error when running simple fortran files with the gfortran command?
- how to add a compiler type supported for sccache?
- Vulkan ‘VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR’ was not declared in this scope
- Rust newbie compile error (for (key: String, value: String) in | ^ expected one of `)`, `,`, `@`, or `|`)
- latest version of redshift with crazy compile times
- Problem compiling out-dated Typescript code
- What is appropriate substitution for configurations.compile in newer gradle e.g. version 8.7?
Related Questions in LEXICAL-ANALYSIS
- Syntactic or Lexical Error in writing an interpret
- Parse an expression with non whitespace seperated operators
- C Lexical Analyzer Bug: Pointer Value Reset
- Creating a static unordered_set from keys of a static unordered_map
- ANTLR 4 lexer rule to skip combination of backslash and newline?
- Regex to remove Key/Value in a JSON Object
- How does tokenization relates to formalism, lexical grammar, and regular language?
- Issue with identifying invalid lexemes in C initialization statement
- How do I search and print for invalid lexemes and assign to it an appropriate error message
- Typing /0 (not \0) into a lex program causes unexpected behavior
- Is there relatively simple way to find all exported names from JavaScript text
- lex file not executing
- Regex in java for semicolon and comma as delimiter but also considered in the string
- how can the syntactic analyzer ignore white space in the input
- Why does my lexical analyser behave as if there are no line-endings?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
In general, keywords have only syntactic value, so in most compilers they are only used to select an appropriate grammatical rule. Their "value", as such, is consumed immediately. Since their identity is the only useful information, it is probably more appropriate to use a
HashSetthan aHashMap.However, there might be a set of keywords which are syntactically identical, forming what is effectively an enumeration type. In such cases, the enumeration value could be the value associated with the keyword.
For a handbuilt lexical analyzer, the use of a hashset or other such datastructure may prove simple, but most compilers will actually compile the keywords along with the other lexical token patterns into a finite state automaton. This allows the keywords to be recognized during the lexical scan, without any external datastructure.
Regardless, in almost all languages the set of keywords is fixed and so it is most appropriate to use an efficient datastructure compiled into the lexical scanner. For example, instead of a binary tree, it would be reasonable to use a sorted static vector of strings which could be binary searched. Alternatively, a preconstructed trie could be used; this would be almost equivalent to the finite state automaton referred to above.