GithubHelp home page GithubHelp logo

adityavs / koi-reference-parser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aarongough/koi-reference-parser

0.0 0.0 0.0 122 KB

The reference parser implementation for the Koi programming language

Home Page: http://github.com/aarongough/koi-reference-parser

License: MIT License

Ruby 100.00%

koi-reference-parser's Introduction

koi-reference-parser

This is the reference parser implementation for the programming language Koi. The parser is implemented using a Parsing Expression Grammar (PEG) that is run by a PEG engine called Treetop.

Example

The parser takes a text string containing a program like:

test = 1 + 2

And turns it into an Abstract Syntax Tree (AST) that unambiguously represents the program’s structure and meaning. The AST is represented as a series of Ruby objects that subclass a generic SyntaxNode class. The code above transformed into AST would look like:

<Block "test = 1 + 2">
  <Statement "test = 1 + 2">
    <Assignment "test = 1 + 2">
      <Identifier "test">
      <AssignmentOperator "=">
      <Expression "1 + 2">
        <AdditiveExpression "1 + 2">
          <IntegerLiteral "1">
          <AdditionOperator "+">
          <IntegerLiteral "2">

The AST is also available in a far more portable format based on nested hashes by calling the to_hash method on the root AST node.

Installation

This parser is normally installed as part of Koi’s default toolchain. However if you would like to install it on it’s own you can do so by installing the gem like so:

gem install koi-reference-parser

Usage

require 'rubygems'
require 'koi-reference-parser'

include KoiReferenceParser

ast = Parser.parse( program_text )

# Get the AST as a portable nested hash
ast_hash = ast.to_hash

Author & Credits

Author

Aaron Gough

Copyright © 2010 Aaron Gough (thingsaaronmade.com), released under the MIT license

koi-reference-parser's People

Contributors

aarongough 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.