https://github.com/seluj78/shellgrammargenerator
This shell script converts .yacc files into a parser friendly C file
https://github.com/seluj78/shellgrammargenerator
c shell shell-script yacc
Last synced: 3 months ago
JSON representation
This shell script converts .yacc files into a parser friendly C file
- Host: GitHub
- URL: https://github.com/seluj78/shellgrammargenerator
- Owner: Seluj78
- Created: 2017-05-29T08:10:09.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-09T11:26:58.000Z (over 7 years ago)
- Last Synced: 2025-01-06T01:54:28.638Z (4 months ago)
- Topics: c, shell, shell-script, yacc
- Language: Shell
- Homepage:
- Size: 190 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ShellGrammarGenerator (SGG for short)
### This script converts a yacc file into a 3D array and a header file for a modular C parser
#### SGG Usage example:
[](https://asciinema.org/a/65nymkq3pw2n61v354kz2ezo6)
#### Usage:
```bash
-i --input (required), used to specify the grammar file (in yacc format). If not set, will display an error
-o --output (optional), if not set, grammar_converter will output into grammar.c and grammar.h files
-h --help (help) Will display help
```#### Examples:
These two lines here are two ways to call the grammar converter
```bash
bash ShellGrammarGenerator.sh -i -o
./ShellGrammarGenerator.sh --input --output
```A grammar.yacc example file can be found [here](examples/grammar.yacc.example)
#### Writing a .yacc file for SGG
##### % Required:
Every `%` is on its own line. Example:
```bash
%token XXX
%token YYY
```
Is correct```bash
%token XXX YYY
%token XXX %token YYY
```
Isn't correctThe configuration `%token` and `%tokentemplate` are made to replace easily tokens with a template for your enum
```bash
%token WORD%tokentemplate E_TOKEN_
//Given this:
XXX XXX XXX WORD XXX//Will result in this:
XXX XXX XXX E_TOKEN_WORD XXX
```If you decide not to use `%token`, you need to also remove the `%tokentemplate` line
The `%fileincludename` is required to generate a header file to go along with your 3D array generated by SGG
```bash
%fileincludename XXX
```
Which will give the name for the header file generated.Example:
```bash
%fileincludename header
```
Will generate a file named
`header.h`The `%include` configuration is optional. It will add the include you want in the .c file generated
Example:
```bash
%include parser/parser.h
%include stdio.h
```
Will add these includes:
```objectivec
#include
#include
```If you dont want any include in the .c file, just place this :
```bash
%include
```
And SGG won't add any includes.You also need to specify the start of the program like this:
```bash
%start XXX
```
With XXX being the first token in the 3D arraythen you specify the end of the generator options by placing this:
Everything before %% in the grammar file is configuration
```bash
%%
```#### Contributing
I'm far from being a shell/C expert and suspect there are many ways to improve this converter– if you have ideas on how to make the ShellGrammarConverter easier to maintain (and faster), don't hesitate to fork and send pull requests!
You can also take a look through the open issues and help where you can.