Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

RACKET By parsing strings, turn some word into its number couterpart (\"one\" ->

ID: 3675123 • Letter: R

Question

RACKET

By parsing strings, turn some word into its number couterpart ("one" -> "1")

Here is the grammar:

S zero | L

L T | TD | TDL

T H | A hundred H | A hundred

H A | B | C | CA

A one | two | ... | nine B ten | eleven | ... | nineteen C twenty | thirty | ... | ninety

D thousand | million | billion | ... | decillion.

Here is the code I am having difficulty with.

My total output for everything <999 works just fine. But anything >1000 doesn't print out right. Again I am trying to use an exponential function to raise numbers paised on powers depending on how large the number is (IE, 1000= 10^3.)
For some reason "eight thousand" just gives me "8"

Explanation / Answer

(S [(zero) $1]
   [(L) $1])
(zero [(ZERO) 0])
**(L [(T) $1]
   [(T D) (expt (thousands-number $1) 10)]
   [(T D L) $1])**
(T [(H) $1]
   [(A HUNDRED H) (+ (* $1 100)^ $3)]
                                               ======
   [(A HUNDRED) (* $1 100)])
(H [(B) $1]
   [(C) $1]
   [(C B) (+ $1 $2)])
(A [(UNDERTEN) (undertwenty-number $1)])
(B [(UNDERTWENTY) (undertwenty-number $1)]
   [(A) $1])
(C [(TENS) (tens-number $1)])
(D [(THOUSANDS) (thousands-number $1)])
)
)
)