601.428/628 (F23):
Resources

x86-64 assembly language resources

Example code

Precedence climbing example

prec-climb.zip is an example implementation of precedence climbing. The Parser::parse_work function in prec_climb.cpp is the implementation of the algorithm. It’s written in a purely-recursive way, which might make it easier to understand than the pseudo-code in the Wikipedia article on precedence climbing.

Note that the lexer requires spaces between tokens. (E.g., a+b would be considered one token, so you should type a + b instead.)

Example run (user input in bold):

$ ./prec_climb
a + b * 3 - 4 * 2 ^ b ^ 3
OP_MINUS[-]
+--OP_PLUS[+]
|  +--IDENT[a]
|  +--OP_TIMES[*]
|     +--IDENT[b]
|     +--NUMBER[3]
+--OP_TIMES[*]
   +--NUMBER[4]
   +--OP_EXP[^]
      +--NUMBER[2]
      +--OP_EXP[^]
         +--IDENT[b]
         +--NUMBER[3]

Please let me know if you find bugs in this code!

Exam review materials

Note that in Fall 2020 the exams were take-home exams, so the format is different than what you will see when you take Exam 1 in class. However, the questions should still be useful for review purposes. The Fall 2021 exams were in-person, and the questions are more representative of the kinds of questions you will see in this course’s exams.

For Exam 1:

For Exam 2:

For Exam 3: