Skip to content

Instantly share code, notes, and snippets.

@cyhsutw
Last active August 29, 2015 14:02
Show Gist options
  • Save cyhsutw/269b5d77097e700cf4bc to your computer and use it in GitHub Desktop.
Save cyhsutw/269b5d77097e700cf4bc to your computer and use it in GitHub Desktop.

Assignment-2

This document is written in GitHub flavoured markdown syntax. You may view this document here.


  1. Selected C syntax subset

    • variable declaration/variable initialization
      • int
      • float
      • char
    • simple statements
    • branches
      • if / if-else
        • supports binary operation as condition
      • loop
        • supports only while loop
    • functions
    • basic arithmetics
      • +, -, *, /
  2. Defined tokens and output format

    • Defined tokens
      • %token <_symbol> ID
      • %token <_doubleVal> DOUBLE
      • %token <_intVal> INT
      • %token <_type> TYPE
      • %token <_string> STRING
      • %type <_doubleVal> stmt_list
      • %type <_doubleVal> stmt
      • %type <_doubleVal> element
      • %type <_doubleVal> term
      • %type <_doubleVal> factor
      • %type <_doubleVal> declaration
      • %type <_doubleVal> arg_list
      • %type <_doubleVal> arg
      • %type <_type> branch_list
      • %type <_type> branch_condition
      • %type <_type> func_args
      • %token IF WHILE FOR
      • %left <_intVal> GT
      • %left <_intVal> LT
      • %left <_intVal> GEQ
      • %left <_intVal> LEQ
      • %left <_intVal> EQ
      • %left <_intVal> NEQ
      • %left <_intVal> OR
      • %left <_intVal> AND
      • %nonassoc IFX
      • %nonassoc ELSE
    • Output format
      • this parser follows the output format shown on the p.41 of the assignment explanation slides. The Lex part will also check if a symbol exists or not and perform the corresponding actions such as insert a new key into the symbol table.
  3. Implementation obstacles

    • This assignment is much harder than the previous one. It takes me for about few weeks to finish it.
    • Designing a proper grammar is a challenging task for me, which is also the main task of this assignment.
    • The co-working between YACC and LEX also took me a lot of time.
  4. Known Bugs

    • Does NOT support for loop.
      • the condition part of for loop is way complicated than I've ever imagined, so I gave up eventually.
  5. Anything worth to be mentioned

    • I'm still thinking...XD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment