All Projects → taufique71 → node-c-parser

taufique71 / node-c-parser

Licence: other
A recursive decent parser for C programming language codes

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to node-c-parser

yellowpages-scraper
Yellowpages.com Web Scraper written in Python and LXML to extract business details available based on a particular category and location.
Stars: ✭ 56 (+69.7%)
Mutual labels:  parsing
yaml.sh
Read YAML files with only Bash
Stars: ✭ 30 (-9.09%)
Mutual labels:  parsing
BencodeNET
.NET library for encoding/decoding bencode and reading/writing torrent files
Stars: ✭ 133 (+303.03%)
Mutual labels:  parsing
NFlags
Simple yet powerfull library to made parsing CLI arguments easy. Library also allow to print usage help "out of box".
Stars: ✭ 44 (+33.33%)
Mutual labels:  parsing
Fashion-Clothing-Parsing
FCN, U-Net models implementation in TensorFlow for fashion clothing parsing
Stars: ✭ 29 (-12.12%)
Mutual labels:  parsing
DrawRacket4Me
DrawRacket4Me draws trees and graphs from your code, making it easier to check if the structure is what you wanted.
Stars: ✭ 43 (+30.3%)
Mutual labels:  parsing
CaptCC
A tiny C compiler written purely in JavaScript.
Stars: ✭ 175 (+430.3%)
Mutual labels:  parsing
pyrser
A PEG Parsing Tool
Stars: ✭ 32 (-3.03%)
Mutual labels:  parsing
BibleUtilities
Set of utilities to scan, parse, and work with Bible references.
Stars: ✭ 20 (-39.39%)
Mutual labels:  parsing
parson
Yet another PEG parser combinator library and DSL
Stars: ✭ 52 (+57.58%)
Mutual labels:  parsing
Syntax
Write value-driven parsers quickly in Swift with an intuitive SwiftUI-like DSL
Stars: ✭ 134 (+306.06%)
Mutual labels:  parsing
quick-csv-streamer
Quick CSV Parser with Java 8 Streams API
Stars: ✭ 29 (-12.12%)
Mutual labels:  parsing
bllip-parser
BLLIP reranking parser (also known as Charniak-Johnson parser, Charniak parser, Brown reranking parser) See http://pypi.python.org/pypi/bllipparser/ for Python module.
Stars: ✭ 217 (+557.58%)
Mutual labels:  parsing
masci-tools
Tools, utility, parsers useful in daily material science work
Stars: ✭ 18 (-45.45%)
Mutual labels:  parsing
JagTag
📝 JagTag is a simple - yet powerful and customizable - interpretted text parsing language!
Stars: ✭ 40 (+21.21%)
Mutual labels:  parsing
postcss-jsx
PostCSS syntax for parsing CSS in JS literals
Stars: ✭ 73 (+121.21%)
Mutual labels:  parsing
MathExpressions.NET
➗ Library for parsing math expressions with rational numbers, finding their derivatives and compiling an optimal IL code
Stars: ✭ 63 (+90.91%)
Mutual labels:  parsing
tdop.github.io
Reprinting Vaughan Pratt's Paper on Top Down Operator Precedence Parsing
Stars: ✭ 99 (+200%)
Mutual labels:  parsing
SteamLicenseParser
📦 Parsers your Steam licenses and generates some stats
Stars: ✭ 23 (-30.3%)
Mutual labels:  parsing
ltreesitter
Standalone tree sitter bindings for the Lua language
Stars: ✭ 62 (+87.88%)
Mutual labels:  parsing

node-c-parser

What is it?

Syntax parsing library for C programming language in Node.js. This node module uses node-c-lexer for lexical analysis purpose and accepts token stream formatted in the exact same format as it is in node-c-lexer. The parser takes this token stream as input and gives the parse tree as output. The parse tree is actually a javascript object. Further analysis on this JSON formatted parse tree can be run if necessary.

C programming language grammars are taken from here. Before implementation left recursion is removed from this grammar set. Final grammar set on which this parser is implemented can be found in GRAMMARS.md file of this project.

Installation

Can be installed through npm with npm install node-c-parser.

Usage

There is only one API endpoint to use for parsing if token stream is ready. Otherwise it is necessary to generate token stream before parsing. To generate token stream, lexical analyzer unit of this module have to be used.

Let following code to be parsed -

#include <stdio.h>

int main(){
    printf("Hello World!");
    return 0;
}
  1. Require the module:

    var parser = require("node-c-parser");
  2. Remove preprocessors: Before doing anything on source code at first preprocessors need to be removed. Suppose the code is saved to a file named a.c and the file resides in the same directory from where the script is run.

    parser.lexer.cppUnit.clearPreprocessors("./a.c", function(err, codeText){
        if(err){
            // Error occured during preprocessor removal. Handle it.
        }
        else{
            // codeText variable contains preprocessor free code. Do something with it.
        }
    });
  3. Tokenize:

    var tokens = parser.lexer.lexUnit.tokenize(codeText);
  4. Parse:

    var parse_tree = parser.parse(tokens);

Parse tree of the above C code would be like this.

Parse Tree Structure

As it is said earlier that the parse tree is actually a javascript object. Structure of parse tree is defined in following JSON-Schema.

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "definitions": {
        "token": {
            "type": "object",
            "properties": {
                "lexeme": {"type": "string"},
                "row": {"type": "integer", "minimum": 0},
                "col": {"type": "integer", "minimum": 0},
                "tokenClass": {"type": "string"},
                "parent": {"type": "null"},
                "children": {"type": "null"},
                "keyword": {"type": "boolean"}
            },
            "required": ["lexeme", "row", "col", "tokenClass", "parent", "children"]
        }
    },
    "type": "object",
    "properties": {
        "title": {"type": "string"},
        "children": {
            "type": "array",
            "items": {
                "oneOf": [
                    {"$ref": "#/definitions/token"},
                    {"$ref": "#"}
                ]
            }
        }
    }
}

Bug Report

The module is still very naive. There must be lots of bugs lurking in the code. Please report any bug by creating an issue with details. Or it would be better if you could create a pull request with the failed test case added to the unit tests. If you think the bug is in node-c-lexer then report it that repository in the mentioned way.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].