7 Replies - 777 Views - Last Post: 27 October 2012 - 10:53 AM

#1 nomnomnomplant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-October 12

I was brainstorming and realized I don't know anything.

Posted 18 October 2012 - 06:33 PM

I am currently working on a project (this isn't for school, so it is not homework or anything) that involves the user being able to "code" commands in. I'm not really asking for programming help as much as logic help (language dosen't matter, I will adapt).

My ultimate goal is to get a program where the user can create variables and functions that control the inner components of the program. Also, I want a set of built in functions (api) that control the program.

But when I got to the fundamentals of it, I got lost on how I will actually be able to interpret the code... should I make a 'reader' that takes the user input and stores it in a data structure for later use? Or should all of their functions be automatically put into a class file that interacts directly with the main program (I was thinking this could cause problems).

I don't want the user to be concerned about where the files go, the setup (classes, etc), it should just be the user opening up a window, typing in his program, whether it is to make something move or count to 100, and being able to run it.

Again, I'm not asking for code, but maybe some help in brainstorming how this could be made. (I want to make it myself, for obvious reasons)

I'm not sure if I'm making any sense, if not I will try to elaborate/explain in greater detail what I am trying to do.
Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: I was brainstorming and realized I don't know anything.

#2 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 710
  • View blog
  • Posts: 2,033
  • Joined: 20-March 10

Re: I was brainstorming and realized I don't know anything.

Posted 18 October 2012 - 08:04 PM

Hi,

What you are talking about is parser's and interpreters

There are basic examples of these in the DIC Tutorial section

or google 'parser' or 'interpreter'

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#3 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7293
  • View blog
  • Posts: 12,119
  • Joined: 19-March 11

Re: I was brainstorming and realized I don't know anything.

Posted 18 October 2012 - 08:25 PM

Chapter 4 of Structure and Interpretation of Computer Programs details the construction of a lisp interpreter, in lisp. Might be worth a look. Lisp is great fun. SICP is not an easy book, especially if you're math-phobic, but it's worth digging into it. The course based on the book is available at MIT's open courseware site.

The cpython source might also be interesting, but you're pretty much on your own there. It's in C, though, so that might feel more like home.

You could also just start playing in the python interpreter and see if that feels a little like what you were dreaming of.
Was This Post Helpful? 0
  • +
  • -

#4 nomnomnomplant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-October 12

Re: I was brainstorming and realized I don't know anything.

Posted 18 October 2012 - 08:41 PM

Thanks^^
This is exactly what I was looking for
Was This Post Helpful? 0
  • +
  • -

#5 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7293
  • View blog
  • Posts: 12,119
  • Joined: 19-March 11

Re: I was brainstorming and realized I don't know anything.

Posted 18 October 2012 - 09:00 PM

Glad to hear it. Prepare to have your mind blown, both lisp and python do tend to do that to you a little bit.

This post has been edited by jon.kiparsky: 18 October 2012 - 09:00 PM

Was This Post Helpful? 0
  • +
  • -

#6 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1907
  • View blog
  • Posts: 3,953
  • Joined: 11-December 07

Re: I was brainstorming and realized I don't know anything.

Posted 19 October 2012 - 05:27 AM

Another option is to embed an already existing scripting language in your application. Lua is often used for this and is the language responsible for getting computer game modders into programming. Javascript can also be embedded and there are doubtless many more.
Was This Post Helpful? 1
  • +
  • -

#7 stackoverflow  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 164
  • View blog
  • Posts: 545
  • Joined: 06-July 11

Re: I was brainstorming and realized I don't know anything.

Posted 27 October 2012 - 09:42 AM

I would embed a scripting language in whatever language you are doing it in. If you want to write your own scripting language you can do that too, but it's a lot more work. Wouldn't you rather use a nice scripting language and focus more on the application? :)
Was This Post Helpful? 0
  • +
  • -

#8 marty617  Icon User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • Posts: 33
  • Joined: 14-October 12

Re: I was brainstorming and realized I don't know anything.

Posted 27 October 2012 - 10:53 AM

I have had past success using ANTLR.

http://www.antlr.org/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1