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: about 1 month 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 7 years ago)
- Default Branch: rewrite
- Last Pushed: 2024-06-20T21:53:51.000Z (almost 2 years ago)
- Last Synced: 2025-02-04T15:47:14.178Z (about 1 year 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]integer
left-recursive expB
match @[left]expB "/" @[right]expC
set capture op '/'
match @[left]expB "*" @[right]expC
set capture op '*'
match @[left]expC
left-recursive expA
match @[left]expA "+" @[right]expB
set capture op '+'
match @[left]expA "-" @[right]expB
set capture op '-'
match @[left]expB
production 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