Last active
July 30, 2019 01:33
-
-
Save rabidaudio/7f5e3d9fe760c26ab710e94e515fcd82 to your computer and use it in GitHub Desktop.
Experimenting with Antlr grammar syntax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grammar English; | |
paragraph: sentence+ EOF; | |
sentence: prepositionalPhrase* subject activeVerb directObject indirectObject? prepositionalPhrase* '.' | |
| prepositionalPhrase* subject? toBeVerb (directObject | adjective)? prepositionalPhrase* '.' | |
| toBeVerb subject (directObject | adjective)? prepositionalPhrase* '?'; | |
subject: nounPhrase; | |
directObject: nounPhrase; | |
indirectObject: nounPhrase; | |
nounPhrase: article? nounModifier* noun; | |
nounModifier: adjective | possesive; | |
prepositionalPhrase: preposition nounPhrase; | |
possesive: noun '\'s'; | |
noun: 'dog' | 'cat' | 'Alice' | 'Bob' | 'things'; | |
activeVerb: 'tells' | 'sees' | 'hears'; | |
toBeVerb: 'is'; | |
article: 'a' | 'the'; | |
adjective: 'bored' | 'shy' | 'sleepy'; | |
preposition: 'about' | 'from' | 'behind'; | |
WS: [ \t\f\n\r] -> skip; | |
//Alice tells sleepy Bob about the bored cat. | |
//Bob sees Alice's things behind the dog. | |
//Bob's cat is shy. | |
//behind the cat is a bored dog. | |
//a bored dog is behind the cat. | |
//Bob tells Alice things about the dog. | |
//Bob is sleepy from the things behind the dog. | |
//is Bob shy about sleepy Alice? | |
// abouttheBobboreddog'ssleepysleepysleepycattellsdogaAlicefromshycat. |
Author
rabidaudio
commented
Jul 30, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment