Skip to content

ariofrio/cs160-simple

Repository files navigation

While this code is open source, you may not use it or even look at it if you are taking CS 160 or a similar compilers course. You have been warned.

Andres Riofrio ariofrio@cs.ucsb.edu

Changelog

Add test harness: Feb 2-3

  • ./simple --only-scanner outputs a space-separated list of tokens
  • make test compares generated tokens with expected tokens
  • make test ensures parser accepts valid programs (there's no output)
  • make test ensures parser rejects invalid programs (there is output)
  • Added tests for each new feature introduced

Implement scanner: Feb 3

  • The rule for octal numbers is above the rule for decimal numbers
  • Tokens that are not single-character operators get a %token declaration in parser.ypp
  • Used a start condition to implement multi-line, non-greedy comments

Implement parser: Feb 3

Implement AST generator: Feb 17

  • Add harness files from class website
  • Add actions to parser rules to construct the AST
  • Separate Assignment parser rule into Assignment and ArrayAssignment; likewise with FunctionCall
  • Add Identifier and Number parser rules that have an action that creates a Primitive() instead of adding the code to create a Primitive() every time IDENTIFIER and NUMBER are used.
  • Set yylval in lexer rules to propagate integer values and symbol names
  • Check that each test passes (done manually: test harness not updated)

Implement type checking and semantic analysis: Mar 5-12

  • Replace my code with harness files from class website
  • Remove --only-scanner option and associated tests
  • Add semantic tests from class website
  • Implement type checker, including checking that operators like magnitude get integers as their inner expression
  • Implement constant folding
    • BOTTOM propagates in order to catch errors more easily
    • Division by zero gives zero

Implement code generation: Mar 17-20

  • Test that correct programs compile and produce expected output
  • Literals and identifiers push a value to the stack
  • Operators pop one or two values from the stack and push the result
  • Comparison operators implemented with SETcc %eal followed by ANDL $255 %eax
  • Function arguments are copied to occupy the same space as local variables, for ease of access
  • Constants are folded (behave as literal integers/booleans)
  • if statements with constant values only output the selected branch
  • while statements with constant values either eliminate the statement or simplify the infinite loop

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published