A short tutorial on grammars for any computer language, introducing my way of writing LLM-friendly grammars using EBNF and Regular Definitions
![](https://programming.dev/pictrs/image/8140dda6-9512-4297-ac17-d303638c90a6.png)
![Writing Grammars: Mixing Regular Definitions with EBNF](https://programming.dev/pictrs/image/f4b150ab-abf3-46c3-93dd-aecfd73e2ebd.png?format=jpg&thumbnail=256)
gist.github.com
This since I don't have a blog and I don't know how to make a blog I will post my way of defining a grammar using EBNF and Regular Definitions in Gist form.
I have used my method with ChatGPT to generate Lex and Yacc files before. One language I have been implementing for about several months is AWK. I am now making an AWK to C translator (the more uninformed would call it a 'transpiler' but this term is NOT correct at all, it's not very theoretical, transpilers are just [syntax-directed] translators). So anyways please read this document if you wanna learn about grammars, Chomsky type 2 and type 3, Lexical and Syntactic grammar, etc.
I also have a table that teaches you how to read EBNF. For the lazy, I will cite the table here:
Enclosed Right | Enclosed Left | Meaning |
---|---|---|
Single Quote | Single Quote | Single character |
Double Quote | Double Quote | Byte-sequence string |
Right Bracket | Left Bracket | What's within is optional |
Right Curly | Left Curly | What's within is repeatable |
Right Paren | Left Paren | What's within is grouped |
Thanks.
No comments yet. You could be first!