Specifying Semantic Actions in YACCTopYACCSemantic Actions, Semantic Records and All That

Semantic Actions, Semantic Records and All That

  1. Given an "automatic parser generator" like YACC, we need a way to indicate what "(semantic) actions" should be associated with each grammar rule when it is used in a parse to produce the desired intermediate form.
  2. A grammar can be annotated to indicate where semantic processing should occur by naming the actions and including the names at appropriate places in the grammar.
  3. A semantic action will typically produce a value to be associated with a node in the parse tree (not the syntax tree). It may need to access the values associated with the children of the node it is to label with a value.
  4. The parser should (can, must) help by keeping track of the values produced by semantic actions as the parser proceeds.
  5. The parser generator should (can, must) provide a way that actions can access values associated with terminals and non-terminals in the handle and specify the value to be associated with the non-terminal to which the handle is reduced.

Computer Science 434
Department of Computer Science
Williams College

Specifying Semantic Actions in YACCTopYACCSemantic Actions, Semantic Records and All That