

* and be sure to MAKE sure somewhere to add a * parserArea is the JTextBox used to grab input outputArea should be a non-editable JTextArea to display our results Public static String parsed = new String It strips out unwanted characters except leaves A-Z and 0-9 as well as the question mark (for a "help" command shortcut): // put these as global variables just after your main class definition If you have the patience to do it you can easily write up a parser in Java using the Tokenizer class.Įxample I wrote using a global JTextArea and a global String array. The problem with Inform7 for programmers is as famous as "guess the verb" is for players of text adventures in that if you don't write your sentences VERY carefully you're going to break the game.
TEXT ADVENTURE CODE
If you're a programmer Tads3 will be tons easier to code things faster than Inform7, which I've used before as well.

It's more for computer programmers though but a very powerful language. I used the Tads3 (engine for some of the text adventures I wrote. This could change the context and thus the same sentence could no longer be semantically correct (for instance there could be no man to eat) If also the semantics is correct then you can, for instance, change the world according to it.
TEXT ADVENTURE FREE
The type of grammar you need is a Context Free Grammar and there are tools which automatically generate a parser starting from a synthetic description of the grammar such as ANTLR (The parser only checks whether a sentence is correct or not and produce an Abstract Syntax Tree (AST) of the sentence which is a navigable representation of the sentence where each word has the role you specified in the grammar.īy navigating the AST you have to add the code that assess what is the semantics each word takes when playing that role with respect to the other words in the sentence and verify whether the semantics is correct.įor instance the sentence 'The stone eats the man' is syntactically correct but not necessarily semantically correct (unless in your world stones, maybe magic stones, can eat men). To this end you have to define a grammar for your language (vocabulary and syntax). You need to define a domain specific language that is all the sentences which are correct in your game.

Notably the base world model is available, but the natural language parser is not.
TEXT ADVENTURE GENERATOR
Anyway, you can use a parser generator to generate code to parse this grammar, or write your own fairly easily if your language has decent string handling. The above is a variant on Backus-Naur form, the standard way of representing grammars. Noun = "north" | "south" | "east" | "west" | "house" | "dog" A grammar might be something simple like this: sentence = verb object Typically you can start out with a simple grammar and vocabulary, then write a parser for it. However, bear in mind that formal methods are designed to try and understand real world texts, whereas you only usually need something that works for a limited subset of your natural language. The term you want is 'natural language processing', or NLP.
