Comments (3)
I agree with your take on this, below is a snippet of operator precedence from the SubC compiler
static int Prec[] = {
7, /* SLASH */
7, /* STAR */
7, /* MOD */
6, /* PLUS */
6, /* MINUS */
5, /* LSHIFT */
5, /* RSHIFT */
4, /* GREATER */
4, /* GTEQ */
4, /* LESS */
4, /* LTEQ */
3, /* EQUAL */
3, /* NOTEQ */
2, /* AMPER */
1, /* CARET */
0, /* PIPE */
};
and indeed we can see that the comparison operators have lesser precedence than the arithmetic operators, and the equality operators have lesser precedence than the comparison operators
from acwj.
I also meet this problem. When I input 2 + 7 < 9 the author's code return 3 rather than 0.
from acwj.
Yes, the author could have done the wrong thing. The precedence order is not consistent with this doc which is even mentioned by the author in Readme. In this chapter, the precedence table should be adjusted to the following.
// Operator precedence for each token. Must
// match up with the order of tokens in defs.h
// Larger ones should first be caculated.
static int OpPrec[] = {
0, // T_EOF
30, 30, // T_PLUS, T_MINUS
40, 40, // T_STAR, T_SLASH
10, 10, // T_EQ, T_NE
20, 20, 20, 20 // T_LT, T_GT, T_LE, T_GE
};
from acwj.
Related Issues (20)
- Failure to error on redefinition of variable as function
- Compilation error: data.h HOT 1
- does not generate correct code for Windows HOT 1
- 19_Arrays_pt1,cgarm is not correct
- Part 48 Static
- Misspells in Part 53
- 26 Function prototypes
- In section 19(Array), we should check the use of array name.
- Some Makefile issue in 03_Precedence HOT 1
- How does the spilling ensure that there are no register-name collisions? HOT 1
- Tuterial 17: HOT 1
- movzbl instruction can not compile in section 15_Pointers_pt1 and onward HOT 2
- Test output of 03_Precedence is not the same as what is in Readme
- A wrong nasm assembly instruction in cgn.c of 08_If_Statements HOT 1
- cg_arm.c in 19_Arrays_pt1 is out of sync
- The whole language bnf grammar HOT 2
- FYI: ApolloVM - A Multilingual portable VM with on-the-fly Wasm compilation. HOT 1
- Excellent work
- [BUG]: Test failed from 13 to 20
- I'm glad to tell you something about Part 28
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from acwj.