Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Turing/c++ help
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MattyGG




PostPosted: Tue Apr 05, 2005 10:39 am   Post subject: Turing/c++ help

Is there any possible way to translate a turing program into c++ (other than the long and boring manual way)?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Apr 05, 2005 10:46 am   Post subject: (No subject)

I've never tried this personally... but try decompiling Turing's executable. Wink
Martin




PostPosted: Tue Apr 05, 2005 12:02 pm   Post subject: (No subject)

Write a program to do it for you, it's not that hard.
wtd




PostPosted: Tue Apr 05, 2005 12:22 pm   Post subject: (No subject)

martin wrote:
Write a program to do it for you, it's not that hard.


Have you written a Turing parser? Smile
Tony




PostPosted: Tue Apr 05, 2005 12:26 pm   Post subject: (No subject)

wtd wrote:
Have you written a Turing parser? Smile

I know someone who has Laughing
wtd




PostPosted: Tue Apr 05, 2005 12:37 pm   Post subject: (No subject)

tony wrote:
wtd wrote:
Have you written a Turing parser? Smile

I know someone who has Laughing


That was actually a really amateurish attempt. I should have known better. Regular expressions simply can't do that job. I am thinking of trying again, but this time using Parsec.
wtd




PostPosted: Tue Apr 05, 2005 3:32 pm   Post subject: (No subject)

Success! Parsing a basic Turing declaration.

code:
module TuringParser where

import Text.ParserCombinators.Parsec

identifier = (do
  l <- letter
  r <- many (letter <|> digit <|> char '_')
  return (l : r)) <?> "identifier"

basicDeclaration = do
  vars <- sepBy1 identifier (try sep <|> return "")
  typeSep
  typeName <- identifier
  return (typeName, vars)
 where
  sep = many space >> char ',' >> many space
  typeSep = many space >> char ':' >> many space


Then running it:

code:
insaneones@ubuntu:~/Programming/Parse $ ghci TuringParser
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.2.2, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Compiling TuringParser     ( TuringParser.hs, interpreted )
Ok, modules loaded: TuringParser.
*TuringParser> parse basicDeclaration "" "foo, bar, baz : int"
Right ("int",["foo","bar","baz"])
bugzpodder




PostPosted: Thu Apr 07, 2005 6:31 pm   Post subject: (No subject)

I've written a SL compiler as a CS assignment (its basic C++ with variables declared in the beginning) using JLex and believe me, that is painful. martin will do it soon... hey martin, you interested in some of the CS books i've got?? Razz
Sponsor
Sponsor
Sponsor
sponsor
rizzix




PostPosted: Thu Apr 07, 2005 8:30 pm   Post subject: (No subject)

JLex eh? i believe javacc is the more popular one use now-a-days..
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: