Skip to content

Instantly share code, notes, and snippets.

@rabidaudio
Last active July 30, 2019 01:33
Show Gist options
  • Save rabidaudio/7f5e3d9fe760c26ab710e94e515fcd82 to your computer and use it in GitHub Desktop.
Save rabidaudio/7f5e3d9fe760c26ab710e94e515fcd82 to your computer and use it in GitHub Desktop.
Experimenting with Antlr grammar syntax
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.
@rabidaudio
Copy link
Author

parseTree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment