6 Replies - 2708 Views - Last Post: 15 May 2012 - 05:46 PM

#1 infinite080  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-May 12

Racket Project

Posted 13 May 2012 - 05:45 PM

This is my Racket Project description



Implementation suggestions:

The stages of evaluation are as follows:

Tokenization:: input a string and output a list of strings and numbers; for example, The 17-character string "(= (+ 3 55) 21)" should yield the following list of eight strings: (list "(" "=" "(" "+" 3 55 ")" 21 ")"). This can be done using a finite state machine with side effects; but you can do it any way you like.
Parsing: Input a list of strings and numbers, and output a nested list reflecting its original structure. For example, the input (list "(" "=" "(" "+" 3 55 ")" 21) should yield the output (list "=" (list "+" 3 5) 21). This can be done using a push down automaton; but you can do it any way you like.
Evaluate: Input a nested list of strings and numbers and output a number or true or false. For example, the input (list "=" (list "+" 3 5) 21)should yield an output of false. This can be done using recursion (there is no other reasonable way).
This means in Racket your eval function should look like this:
(def (eval s) (evaluate (parse (tokenize s))))

Email your commented source code as a single file to discrete.homework@gmail.com by midnight on May 15.
Grading will be as follows:
correct tokenizer: 25%
correct parser: 25%
correct evaluator: 25%
clear, concise documentation: 25%
Your documentation should include instructions on how to compile and test your program. If your project is incomplete, include in your documentation a description of which parts work and how to test them.


and this a pseudo code given for tokenizer

1 Input string
2 Variables: state = 'empty', chars = [], tokens = [], nextSate, nextChar (last two have no initial value)
3 while string is not empty:
Set nextChar equal to the first character of string
Set nextState equal to trans(state, nextChar) (trans is a helper function you must write)
If pushChar(state, nextState) then
push nextChar onto the back of chars. (pushCar is a Boolean helper function you must write)
If pushToken(state, nextState) then
push maketoken(chars) onto the back of tokens (maketoken is a helper function you must write. It converts strings to either strings or numbers).
set chars to the empty list
remove the first character from string
set state equal to nextState
4 return tokens

#lang racket

(define read-input(string))
(define state "empty")
(define chars '())
(define tokens '())
(define nextChar " " )
(define nextState " ")

(define (trans state nextChar) 
  (cond 
    [(equal? state " ")
  (cond
    [(equal? nextChar #\i) "i-if"]
    [(equal? nextChar #\+)  "addition"]
    [(equal? nextChar #\*)  "multiplication"]
    [(equal? nextChar #\=)  "equals"]
    [(char-numeric? nextChar) "num"]
    [else "error"])]
    [(equal? state "number") (if (char-numeric? nextChar) "number" " ")]
    [(equal? state "i-if") (if (equal? nextChar #\f) "f-if" "error")]
    [else "error"]
    ))

;(define (pushChar state nextState)




;)/>

;(define (maketoken chars)

;)/>
    
;(define (pushToken state nextState)


;)/>
  


I am having trouble implementing

the functions above that have been commented out, can someone tell how to make sense of the pseudocode for part 3 4 and 5.

Is This A Good Question/Topic? 0
  • +

Replies To: Racket Project

#2 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,355
  • Joined: 02-June 10

Re: Racket Project

Posted 13 May 2012 - 06:23 PM

View Postinfinite080, on 13 May 2012 - 06:45 PM, said:

This is my Racket Project description


Like tennis racket... Or 1950's slang for shadey work i.e racketeering ?

Oh.. Wait.. Is 'racket' the coding language? You might want to say that clearly right off the bat considering its kinda obscure.

View Postinfinite080, on 13 May 2012 - 06:45 PM, said:

can someone tell how to make sense of the pseudocode for part 3 4 and 5.


Isn't that exactly what the homework assignment is: Turn the psuedo code into working code?
We're not going to do your homework for you.


View Postinfinite080, on 13 May 2012 - 06:45 PM, said:

I am having trouble implementing

What does "I need help" and "I'm having trouble" mean? Those are really vague statements.



What part of what you have tried isn't working and in what way is not not working?
"It doesn't work" and "its broke" isn't good enough.
Was This Post Helpful? 0
  • +
  • -

#3 infinite080  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-May 12

Re: Racket Project

Posted 13 May 2012 - 06:33 PM

What I need help with is part 3 of the pseudocode this is the code I have implemented for it

(define (pushChar state nextState)
  (cons chars nextChar)
  
 )


Can you tell me if I am on the right direction, I am sorry this is my first time posting here I dont want anyone do my homework for me rather an idea I am putting work in with my code.

This post has been edited by macosxnerd101: 13 May 2012 - 06:54 PM
Reason for edit:: Removed quote

Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,355
  • Joined: 02-June 10

Re: Racket Project

Posted 13 May 2012 - 06:44 PM

View Postinfinite080, on 13 May 2012 - 07:33 PM, said:

What I need help with is part 3 of the pseudocode this is the code I have implemented for it

(define (pushChar state nextState)
  (cons chars nextChar)
  
 )


Can you tell me if I am on the right direction, I am sorry this is my first time posting here I dont want anyone do my homework for me rather an idea I am putting work in with my code.


Part 3 instructions:

Quote

  • 3 while string is not empty:
    • Set nextChar equal to the first character of string
    • Set nextState equal to trans(state, nextChar) (trans is a helper function you must write)
    • If pushChar(state, nextState) then
    • push nextChar onto the back of chars. (pushChar is a Boolean helper function you must write)
    • If pushToken(state, nextState) then
    • push maketoken(chars) onto the back of tokens (maketoken is a helper function you must write. It converts strings to either strings or numbers).
    • set chars to the empty list
    • remove the first character from string
    • set state equal to nextState


Part 3 has 9 pieces of instruction and you've got 2 lines of code. Right path, wrong path... You haven't stepped on a path yet.

My email is being flooded with messages about this thread. I don't know if you're making numerous changes or what... But over 20 emails have come in during the last 10 seconds. I'm going to unsubscribe from this thread.

Hopefully someone with Racket experience will be able to jump in.
Was This Post Helpful? 0
  • +
  • -

#5 GunnerInc  Icon User is online

  • "Hurry up and wait"
  • member icon




Reputation: 856
  • View blog
  • Posts: 2,246
  • Joined: 28-March 11

Re: Racket Project

Posted 13 May 2012 - 06:46 PM

Please don't double post the same post.

As tlhIn`toq mentioned, the language is a bit obscure. I did a search and found this: http://docs.racket-l...ce/strings.html might help you out a bit.

As Racket is not a widely known language (I never heard of it till now), you will have to try your code to see if you are going in the right direction. What happens when you try your code?
Was This Post Helpful? 0
  • +
  • -

#6 infinite080  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-May 12

Re: Racket Project

Posted 13 May 2012 - 06:49 PM

Ok thanks for the consideration and advice.

View PostGunnerInc, on 13 May 2012 - 06:46 PM, said:

Please don't double post the same post.

As tlhIn`toq mentioned, the language is a bit obscure. I did a search and found this: http://docs.racket-l...ce/strings.html might help you out a bit.

As Racket is not a widely known language (I never heard of it till now), you will have to try your code to see if you are going in the right direction. What happens when you try your code?



I am currently writing a tokenizer so I have no way to test until finishing my parser and evaluator, but I am compiling with no errors.
Was This Post Helpful? 0
  • +
  • -

#7 GWatt  Icon User is offline

  • member icon

Reputation: 262
  • View blog
  • Posts: 3,054
  • Joined: 01-December 05

Re: Racket Project

Posted 15 May 2012 - 05:46 PM

I guess I'll step in. Racket is (was) primarily a scheme implementation. I believe it's become a platform for several languages.
For more scheme help you can check out TSPL (The Scheme Programming Language)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1