Giter VIP home page Giter VIP logo

cool-parser's Introduction

Cool Parser

A parser for the cool language. The program outputs what would be a AST for a given cool code. Further information about this project can be found in tp3-ingles.pdf and tp4-ingles.pdf. Documentation about the Cool language is available here.

Instalation

To build from source, run:

$ cd src/
$ ./gen 

this will generate the file system specific files into your src folder, including the executable myparser. After running the command, your src folder should look like this:

Makefile                -> [cool dir]/src/parser/Makefile
README
cool.y                  -> bison file
bad.cl                  -> syntax error examples
good.cl                 -> program examples
cool-tree.handcode.h
cool-tree.cc            -> [cool dir]/src/parser/cool-tree.cc
cool-tree.aps           -> [cool dir]/src/parser/cool-tree.aps
dumptype.cc             -> [cool dir]/src/parser/dumptype.cc
handle_flags.c          -> [cool dir]/src/parser/handle_flags.cc
parser-phase.cc         -> [cool dir]/src/parser/parser-phase.cc
stringtab.cc            -> [cool dir]/src/parser/stringtab.cc
tokens-lex.cc           -> [cool dir]/src/parser/tokens-lex.cc
tree.cc                 -> [cool dir]/src/parser/tree.cc
utilities.cc            -> [cool dir]/src/parser/utilities.cc
*.d                     dependency files
*.*                     other generated files

Run make on the src folder to rebuild myparser after making any changes to the source code.

Dependencies

In order to build the project, you will need to have the following packages installed in your environment:

as well as some x86 packages that can be installed in debian systems by running:

$ sudo dpkg --add-architecture i386
$ sudo apt-get update
$ sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386

Running

To parse a Cool program, simply run:

$ ./src/myparser program.cl

which will output the AST on the stdout.

Testing

To run the parser over a set of test inputs execute the script located at src/run-test. A set of default tests is available at src/examples/. Each file tries to cover one part of cool's grammar as defined in cool.y. Nevertheless, you can run the parser over any set of .cl files by running:

$ ./src/run-test path/to/example/folder/

Examples

Consider the input:

class A {
  name: String <- "Jhon";
};

class BB__ inherits A {

  foo(): String {
    {
      "Helo";
      "World!";
    }
  };
};

it will produce the following output:

#1
_program
  #1
  _class
    A
    Object
    "good.cl"
    (
    #2
    _attr
      name
      String
      #2
      _assign
        name
        #2
        _string
          "Jhon"
        : _no_type
      : _no_type
    )
  #5
  _class
    BB__
    A
    "good.cl"
    (
    #7
    _method
      foo
      String
      #8
      _block
        #9
        _string
          "Helo"
        : _no_type
        #10
        _string
          "World!"
        : _no_type
      : _no_type
    )

cool-parser's People

Contributors

luizppa avatar yowgf avatar

Stargazers

 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.