Created
November 4, 2015 00:16
-
-
Save phase/c76f12b165637c48b7d8 to your computer and use it in GitHub Desktop.
English parsing crap
This file contains 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
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