DM565 - Formal Languages and Data Processing
 
Fall 2023
Kim Skak Larsen

Home Innovation

Exercises
  1. Appel 3.15 ("Yacc" means "bison").
  2. We have considered a grammar for expressions with rules for '+', '-', '*', '/', id, num, and parentheses. Expand this grammar with boolean operators (and, or, not) and comparisons (==, <=, etc.) in such a way that you get the usual precedence and associativity. Use Tiny Expressions as your staring point.
  3. Currently in SCIL, minus is implemented as a binary operation only (as defined by the grammar). Extend SCIL with unary minus using so-called syntactic sugar. This means that you do not have to take care of the construction all the way through the compiler. Instead, you simply handle it in the parsing phase: You extend the grammar to allow for unary minus, but when you recognize a unary minus, MINUS expression, you build the parser tree pretending that you had just recognized 0 MINUS expression; and the compiler already know how to deal with that. Extend the function p_expression, adding a new right-hand side, expression_unary. Then write a new function p_expression_unary that recognizes unary minus and handles it as described. Test it by running the compiler on input using unary minus in different ways.

 


   Data protection at SDUDatabeskyttelse på SDU