Re: Building Abstract Syntax Trees from LL(1) Grammars

thp@cs.ucr.edu
23 Aug 2002 11:05:15 -0400

          From comp.compilers

Related articles
Building Abstract Syntax Trees from LL(1) Grammars bart@dynarec.com (Bart T.) (2002-08-14)
Re: Building Abstract Syntax Trees from LL(1) Grammars no@mail.com (Capitaine Caverne) (2002-08-23)
Re: Building Abstract Syntax Trees from LL(1) Grammars thp@cs.ucr.edu (2002-08-23)
| List of all articles for this month |
From: thp@cs.ucr.edu
Newsgroups: comp.compilers
Date: 23 Aug 2002 11:05:15 -0400
Organization: University of California, Riverside
References: 02-08-056
Keywords: parse, syntax
Posted-Date: 23 Aug 2002 11:05:15 EDT

Bart T. <bart@dynarec.com> wrote:
[...[
: Assuming ^ is the exponent operator, 1^2^3^4 would get turned into:
: 1234^^^ (I believe this handles right associativity of the ^ operator
: correctly), and the tree constructed would be:


: ^
: / \
: 1 ^
: / \
: 2 ^
: / \
: 3 4


: Is this an acceptable solution? It sort of feels like cheating to me,
: because I just can't figure out a clean way to generate the tree in
: one pass. Another intermediate representation I wanted to do was a
: LISP-like prefix form:


: 9+5-2:


: (- (+ 9 5) 2)


: OR


: (+ 9 (- 5 2))


: However, it isn't possible to generate the operators prior to the
: operands in my grammar. :( At least I can't think of a way. There must
: be a way, though...


IMNSHO, forget LL(1) --- build your trees bottom up and translate them
top down.


Tom Payne


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.