How do you distinguish between the token sequence "op_Minus" "number" and simple a negative number?
Compiler Design: How do you distinguish between "op_Minus number" and "negativeNumber"?
419 Views Asked by Jonathan Allen At
1
There are 1 best solutions below
Related Questions in COMPILER-CONSTRUCTION
- Is the compiler Xcode uses to produce Assembly code a bad compiler?
- How do compilers store hundreds of variables in only a few registers?
- Where to patch back the information gathered during program analysis
- Assignment Insertion in ROSE compiler after AssignOp
- memory layout of a multiple-inherited object in C++
- How to use my written compiler to read files on web?
- a LEX program to identify keywords and convert it into uppercase
- Identifier terminal except certain keywords
- Calling Scala compiler's AST from Java
- Computing the FOLLOW() set of a grammar
- JavaCC and Unicode issue. Why \u696d cannot be managed in JavaCC although it belong to the range "\u4e00"-"\u9fff"
- Three-address code and symbol tables
- Delegate caching behavior changes in Roslyn
- Get delimiter in Irony
- Compiler Errors including initializer before '<' token
Related Questions in LANGUAGE-DESIGN
- Why do the const accessors of std::string return a reference?
- String Concatenation Operator + Ambiguity
- Why do local variables require initialization, but fields do not?
- Why is it allowed to have 2 identical method signatures apart from an optional parameter?
- Why doesn't ByteArrayOutputStream overrride the write(byte[]) method?
- How is calling a function on a subtype implemented?
- Accessing global variables via the window object
- is this good to have pointers in programming languages such as golang,C or C++?
- Golang inferred interfaces
- Why does std::optional not have a specialization for reference types?
- Why does Python have `reversed`?
- Is there a reason Ruby/Rails has not made nested indexing safe?
- Why do you have to 'import' Python Standard Library functions?
- Why is there no `elsunless` statement in Ruby?
- Small Spreadsheet-like language interpreter for web application
Related Questions in COMPILER-THEORY
- Is performance of "less/greater than than" better than "less/greater than or equal to"
- Does evolution of microprocessors warrants evolution of compilers and language standards?
- What's the difference between parse trees and abstract syntax trees (ASTs)?
- Is there a way to compile C++ to C Code?
- Why are C and C++ different even after compilation?
- Is it possible to convert low level languages to high level ones?
- Identifying the next character in a string is capital or not
- Compiler Design: How do you distinguish between "op_Minus number" and "negativeNumber"?
- Programming Language Translation
- How to get the context-free grammar and its corresponding PDA ?
- How to construct parsing table for LL(k>1)?
- Compiler Optimization, Thread Safe?
- What language features are required in a programming language to make a compiler?
- Write a compiler for a language that looks ahead and multiple files?
- Pac-Man representation with Finite State Automaton
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)
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?
I would think it's context dependent and dependent on the number of operands you encounter while parsing the source code.
Depending on the type of syntax you choose/encounter, you either have something like this when you're dealing with subtraction:
or if your language uses prefix notation, you'll end up with something like this:
In both cases you should be able to either deduce from the previous token (in the case of infix notation) or from the lookahead to the next token/next two tokens) if you're dealing with a subtraction or a negative number, given that the latter would only have a single operand.