Git Product home page Git Product logo

cau-compiler-parser's Introduction

Bottom-Up Parser

Our submission for 김효수's Compiler class' final term project: the realization of a bottom-up parser.

Authors

Installation

The source files can easily be compiled using make

make

if you ever need to recompile the software from scratch, you can just use:

make re

Documentation

The docs are available in the docs sub-directory.

Moreover we made sure to provide comments and Doxygen declaration to functions for ease of development/maintenance.

Running Tests

30 input sequences are available in the sample directory and are available to run tests. Running these tests with make will perform functional tests, checking if the return value is the one expected.

  make test

Usage/Examples

To run the syntax analyzer on an input sequence, create a file containing a sequence of token and run the following command

./syntax_analyzer [path_to_input_file]
}

If the input is accepted, the program will return EXIT_SUCCESS (0) and display the parse tree of the input sequence.

Parse tree example:

CODE
  DECLINIT
    vtype
    id
    DECLTYPE
      VDECL
        VDECLVAL
          ASSIGN
            assign
            RHS
              literal
        semi
  CODE
    DECLINIT
      vtype
      id
      DECLTYPE
        FDECL
          lparen
          ARG
            Ɛ
          rparen
          lbrace
          BLOCK
            STMT
              id
              ASSIGN
                assign
                RHS
                  EXPR
                    EXPR
                      TERM
                        FACTOR
                          id
                    addsub
                    TERM
                      FACTOR
                        id
              semi
            BLOCK
              Ɛ
          RETURN
            return
            RHS
              EXPR
                TERM
                  FACTOR
                    id
            semi
          rbrace
    CODE
      Ɛ

On the other hand, if it is not, an error report will be printed alongside the program return EXIT_FAILURE (1).

Error report example:

Syntax Error (token 364): Expected: addsub | rparen but got: semi.

Improvements

One of the easy way to improve this program would be by generating the LR parsing table on our own, meaning that provided a CFG, this program would work universally.

This would imply some changes however since the enums would not contain the same terminal and non-terminals anymore.

Creating a clearer view of the parse tree would globally improve this parser.

Final grade

This project received a 10/10 counting for 10% of the final grade of the Compiler class.

cau-compiler-parser's People

Contributors

mpellouin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.