3 ms·
Care to give a little more explanation on how it works?
by philfreo 16y ago
Care to give a little more explanation on how it works?
- Xk 16y agoSure. I'm assuming you know what parsing is, and what syntax-directed translation is. If not, the wikipedia articles (http://en.wikipedia.org/wiki/Parsing http://en.wikipedia.org/wiki/Parsing and http://en.wikipedia.org/wiki/Syntax-directed_translation http://en.wikipedia.org/wiki/Syntax-directed_translation) offer a reasonable explanation. The grammar file is generally laid out as follows: Question ::= Phrase1 | Phrase2 | Phrase3 ... Phrase1 ::= 'if' 'the' Noun 'is' Color 'what' 'color' 'is' 'it' [and now return the word which matched Color] Noun ::= [sequence of characters] Color ::= 'red' | 'blue' ... The trickiest part of it was getting it to correctly interpret numbers like 'twenty one thousand eight hundred and ninety nine' That part is basically laid out as Number ::= Number QuantifiedNumber | Number 'and' QuantifiedNumber | QuantifiedNumber QuantifiedNumber ::= NumberGroup | NumberGroup Quantifier NumberGroup ::= SingleNumber SingleNumber | SingleNumber SingleNumber ::= 'one' | 'two' | ... 'twenty' | 'thirty' | ...