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) |
From: | "Capitaine Caverne" <no@mail.com> |
Newsgroups: | comp.compilers |
Date: | 23 Aug 2002 11:03:08 -0400 |
Organization: | Guest of ProXad - France |
References: | 02-08-056 |
Keywords: | syntax, analysis |
Posted-Date: | 23 Aug 2002 11:03:08 EDT |
"Bart T." <bart@dynarec.com> a écrit news:02-08-056@comp.compilers:
>
> 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...
Hello, I'm certainly the last person to listen in this newsgroup as I'm a
complete newbie... However in my try to implement a stack based machine
compiler I have the same problem : I can't handle operators and operands
in a way I would like (was not a problem when I implemented my own poor
parser some years ago).
The solution I've found is to use two stacks : an operand stack and an
operator stack.
For 9+3*2
Thus instead of generating (generated code is not in the source order)
PUSH VAL 3
PUSH VAL 2
MUL
PUSH 9
ADD
I do :
PUSH VAL 3 (generated code is in source order)
PUSHOP MUL
PUSH VAL 2
CALC
PUSH VAL 9
PUSHOP ADD
CALC
This is less efficient but it works... At least it seems ;-)
Not sure it answer your question, once again I'm a newbie...
Return to the
comp.compilers page.
Search the
comp.compilers archives again.