https://github.com/m4gnv5/cparse
C parser in pure JavaScript
https://github.com/m4gnv5/cparse
c javascript lexer parser
Last synced: 6 months ago
JSON representation
C parser in pure JavaScript
- Host: GitHub
- URL: https://github.com/m4gnv5/cparse
- Owner: M4GNV5
- Created: 2016-01-19T17:50:03.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-12-06T18:02:08.000Z (almost 5 years ago)
- Last Synced: 2025-03-26T09:04:33.643Z (7 months ago)
- Topics: c, javascript, lexer, parser
- Language: JavaScript
- Homepage: https://m4gnv5.github.io/cparse/demo/
- Size: 23.4 KB
- Stars: 49
- Watchers: 4
- Forks: 13
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cparse
C parser in pure JavaScript## Installation
`TODO put this on npm`
## Usage
### CommonJS
```javascript
var cparse = require('./cparse.js');
var ast = cparse("void main() { int answer = 6 * 7; }");
console.log(JSON.stringify(ast, undefined, 4));
```### Browser
```htmlvar ast = cparse("void main() { int answer = 6 * 7; }");
console.log(JSON.stringify(ast, undefined, 4));```
## AST Format
Parsing code:
```C
int answer = 6 * 7;
```outputs following AST (the positions of each AST entry have been removed to reduce size):
```JSON
[
{
"type": "GlobalVariableDeclaration",
"defType": {
"type": "Type",
"modifier": [],
"name": "int"
},
"name": "answer",
"value": {
"type": "BinaryExpression",
"operator": "*",
"left": {
"type": "Literal",
"value": 6,
},
"right": {
"type": "Literal",
"value": 7,
},
}
}
]
```## License
```
"THE BEER-WARE LICENSE":Jakob Löw wrote this code. As long as you retain this notice you
can do whatever you want with this stuff. If we meet some day, and you think
this stuff is worth it, you can buy me a beer in return.
```