Related articles |
---|
introduction to BNF, concrete syntax trees markww@gmail.com (markww) (2006-09-25) |
Re: introduction to BNF, concrete syntax trees mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2006-09-25) |
From: | "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> |
Newsgroups: | comp.compilers |
Date: | 25 Sep 2006 17:05:31 -0400 |
Organization: | cbb software GmbH |
References: | 06-09-133 |
Keywords: | parse, syntax |
Posted-Date: | 25 Sep 2006 17:05:31 EDT |
On 25 Sep 2006 01:16:28 -0400, markww wrote:
> I'm just starting to look at BNF. I have to take a simple expression
> like:
>
> (A + B * C) * D
>
> and create a concrete syntax tree of it. Before I start writing my
> application to parse the above, I need to understand how to do this on
> a piece of paper. My first thought is to tokenize (by whitespace) every
> component of the statement, then label its type. I have 3 types to
> choose from:
>
> f = factor
> t = term
> e = expression
>
> with the following rules:
>
> expression ::= exp "+" exp |
> exp "-" exp |
> term
>
> term ::= term "*" factor |
> term "\" factor |
> factor
>
> factor ::= number |
> identifier |
> "(" expression ")"
There could be other ways to classify lexical tokens of an expression. For
example:
<expression> ::=
<prefix><operand><postfix>[<infix><expression>]
<prefix> ::= <prefix>[<prefix>]
<postfix> ::= <postfix>[<postfix>]
<prefix> ::= <unary> | <left-bracket>
<infix> ::= <dyadic> | <left-index> | <comma>
<postfix> ::= <unary> | <right-bracket>
Also, priorities and association need not to be necessarily handled on the
grammar level. See, for further information:
http://www.dmitry-kazakov.de/ada/components.htm#7.2
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
Return to the
comp.compilers page.
Search the
comp.compilers archives again.