Skip to content

Instantly share code, notes, and snippets.

@phase
Created November 4, 2015 00:16
Show Gist options
  • Save phase/c76f12b165637c48b7d8 to your computer and use it in GitHub Desktop.
Save phase/c76f12b165637c48b7d8 to your computer and use it in GitHub Desktop.
English parsing crap
String text = "attack 500." //description of card
String[] sentences = text.split("."); //each sentence will be parsed as a command
ArrayList<Token> tokens = new ArrayList<Token>(); //each sentence translates to a set of tokens
for(String s : sentences)
for(String word : s.split(" "))
if(word.equalsIgnoreCase("attack"))
tokens.add(new AttackToken()); //add attack token if the word is Attack
else if(word.matches("[0-9]+"))
tokens.add(new NumberToken(Interger.parseInt(word)));
if(tokens.get(0) instanceof AttackToken && tokens.get(1) instanceof NumberToken)
generateCode("attack " + tokens.get(1).getNumber())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment