Formal Grammars for Pyre
September 21, 2024
Today, I narrowed down the syntax of my new language. It was a little difficult to think of a concept that I enjoyed. The main focus of my language will be to focus on the order of which logic happens. Instead of "returning" values, it will emit values so that the next set of instructions can use that value. The grammar is quite long so I may not post it here, I verified the grammar with Chat GPT by asking it to write an example program using this grammar so hopefully it's mostly correct!
Grammar Notes
- Non-terminals are like the "token types"
- e.g. <Noun> <Verb> <Adjective>
- Terminals are like the "token values"
- e.g. Patrick is cute
- Terminals terminate the process of generattion and non-terminals don't terminal, they define the options
- Generation process for example above
- <Sentence> -> <Noun> <Verb Phrase>
- <Verb Phrase> -> <Verb> <Adjectivee>
- <Noun> -> Patrick | Johnny
- <Verb> -> is | runs
- <Adjective> -> cute | fast
- So grammar can be defined through (N, T, P, S) where N = non-terminals, T = terminals, P = production rules (like above), S = start of derivation (Sentence in above example). This formal definition was created by Chomsky
- He also said:
- N is finite, non-empty set of non-terminals
- T is finite, non-empty set of terminals
- N ∩ T = Φ (set of non terminals and terminals joined and don't have anything in common.
- S is a special non-terminal ( S ∈ N)called start symbol
- P is a finite set whose elements are of the form, Α -> Β and alpha has to have at least one terminal