It is quite impossible to give a tutorial on parsing in an e-mail. You
should fist express your grammar in a formal way. The most popular
formalism for expressing context-free grammars is BNF. This grammar
defines how each construct in the language is constructed. Then you
should define semantic actions for each construct. If you want a realy
quick and dirty start, you can check the bison info file. bison is a
parser generator from an attributed grammar definition. The info file
can give you some idea on how to parse such simple grammars. If you use
it, you will also need to use lex (or flex), the lexical analyzer
generator. But if you want to learn the theory, you should read about
finite automata, languages and regular expressions.
If you don't want to learn the theory, you should read something about
these anyway.

Bill cheng wrote:

>  Hello,
> I am studying compiling principle of C programming, but I have no idea
> where I can start with. For example, how can it parse the text input
> by a user?
> To make the problem clearer, I will take an example. Say you have an
> expression, like "(a<1.5) OR (b='abc') AND (2 of (c>0, NOT(d>1),
> (e='cde') AND (f+g*h/i<1))......". (the expression: 2 of (c>0,
> NOT(d>1), (e='cde') AND (f+g*h/i<1) means when 2 expressions in the
> brackets are true, the expression is true). When input by user, those
> a, b, c,d will be replaced by real value, like "(1<1.5) OR
> ('cde'='abc') AND (2 of (1>0, NOT(5>1), ('cde'='cde') AND
> (4+8*2/3<1))". You must compute the result of the expression. Do you
> know what I mean?
> What I want to know is whether you could kindly give me some
> enlightenment. I really do not know what technique to use to parse the
> expression, and how to use some data structure to compute the result,
> (using a linked list, or something else, and also paying attention to
> the priority of the operator.)
> Any real implementation or information resource will be
> appreciated.  Bill Cheng


Reply via email to