Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to do a code that will take some rules .Using these rules it will follow some process such as Addition or subtraction .After completing all of these process it will say that what sequences of rules it followed....How I can do this?
(one question mark is enough)
Posted
Updated 8-Oct-10 9:05am
v3

Create a new solution in Visual Studio, and start coding.
 
Share this answer
 
It is a big question you're posting. In general what you want is an engine that is capable of translating a finite state machine in code that is executed and then traced. You're better off looking for some library that provides such environment.
 
Share this answer
 
There are a lot of tools that can greatly help you on that.
Have a look at classic flex[^] and bison[^] or to 'modern' boost's spirit[^].
If you're not stuck with C/C++, then a look at (java-based) ANTLR[^] is worthy.
Finally, if you want to have even some fun, check out Lua[^] and its powerful LPeg library[^].
:)
 
Share this answer
 
This is a really huge thing that you are attempting but it is doable. How else do we have all the compilers that we use? Even their creators had to start somewhere.

Start writing a simple arithmetic expression parser. Try it by yourselves first before looking at a working code.

Then I suggest you read and understand a simple working code like that calculator example given in Strourstrup's The C++ Programming Language. That is what every compiler/interpreter must do.

You may then move on to something a bit more useful like an interpreter. There are scores of material to help you with that.

Compiler must be attempted only after these steps. It is more than just parsing text and taking actions. First, you must be very VERY good with the language for which you want to build the compiler(you can't implement proper rules without knowing them all properly). Then you must have understanding of the low level representation of high level code. There are more such advanced stuff you will encounter, all of which will appear more clear as you progress.
 
Share this answer
 
Here's another parser builder: Gold Parser Builder[^]. It's free; you give it a syntax document and it generates state machines that identify the tokens (keywords, constants, symbols, etc.) in the input and invokes your code that implements the rules of the grammar.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900