Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/x39/xcg
X39s Code Generator - Creating your CST (Concrete-Syntax-Tree) with ease
https://github.com/x39/xcg
code-generation code-generator cpp cst generator parser parser-generator syntax-tree
Last synced: 4 months ago
JSON representation
X39s Code Generator - Creating your CST (Concrete-Syntax-Tree) with ease
- Host: GitHub
- URL: https://github.com/x39/xcg
- Owner: X39
- Created: 2018-07-31T01:50:51.000Z (over 6 years ago)
- Default Branch: rewrite
- Last Pushed: 2024-06-20T21:53:51.000Z (8 months ago)
- Last Synced: 2024-06-21T16:35:44.401Z (7 months ago)
- Topics: code-generation, code-generator, cpp, cst, generator, parser, parser-generator, syntax-tree
- Language: C#
- Homepage:
- Size: 627 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# How it looks
```
token integer
require plus { 0-9 }token scalar
require once { integer }
require once .
require once { integer }token roundO: "("
require once (
token roundC: ")"
require once )
token slash: "/"
require once /
token star: "*"
require once *
token plus: "+"
require once +
token minus: "-"
require once -production expC
alternatives
match "(" @[value]expA ")"
match @[value]scalar
match @[value]integerleft-recursive expB
match @[left]expB "/" @[right]expC
set capture op '/'
match @[left]expB "*" @[right]expC
set capture op '*'
match @[left]expCleft-recursive expA
match @[left]expA "+" @[right]expB
set capture op '+'
match @[left]expA "-" @[right]expB
set capture op '-'
match @[left]expBproduction main
match @[root]expA
```# Using XCG
`xcg -i .\input.xcg -g cpp -o output --options -s namespace:xcg::parser`
```
-i PATH ..., --input=PATH ... Required. Declares a single input xcg file.-g GENERATOR, --generator=GENERATOR Required. Sets the generator to use. Might be a path to a file or one of the build-in ones.
-o PATH, --output=PATH (Default: output) Set the output filepath to where the generated file(s) should be generated to.
-s OPTION:VALUE ..., --set=OPTION:VALUE ... Allows to change generator-dependant settings.
--options Lists all options of a given generator.
-d, --dry-run Will not generate any output files if set.
--help Display this help screen.
--version Display version information.
```# Available generators
- `cpp`
# FAQ
## Why .Net Core
Answering this question is quite simple:I chose .net core because the whole project started out as a draft of ideas
and it was clear that i needed a solid string type which is easy to work with,
some no-f-given memory management (aka garbage collection) because generating a parser is hard enough
so making a tree structure should not take as much time as building the parser
plus it allows fast prototyping with checked typing.The project itself was needed because writing the parser i desired myself
failed multiple times due to basic mistakes i did that would
require changing the whole syntax file because i only noticed in the end
(yes, i know about bison ... but bison + ambiguous grammar = nono).
This project allowed me to toy around with those ideas, make
things work fast and so on.The ***TL;DR*** thus is probably ... because i can