Related articles |
---|
Work around ambiguities in LL(1) assembler parser m@il.it (=?iso-8859-1?b?RnLpZOlyaWM=?=) (2008-01-06) |
Re: Work around ambiguities in LL(1) assembler parser wyrmwif@tsoft.org (SM Ryan) (2008-01-07) |
Re: Work around ambiguities in LL(1) assembler parser DrDiettrich1@aol.com (Hans-Peter Diettrich) (2008-01-07) |
Re: Work around ambiguities in LL(1) assembler parser gene.ressler@gmail.com (Gene) (2008-01-07) |
From: | SM Ryan <wyrmwif@tsoft.org> |
Newsgroups: | comp.compilers |
Date: | Mon, 07 Jan 2008 01:57:03 -0000 |
Organization: | Quick STOP Groceries |
References: | 08-01-015 |
Keywords: | parse, LL(1) |
Posted-Date: | 06 Jan 2008 22:47:01 EST |
=?iso-8859-1?b?RnLpZOlyaWM=?= <m@il.it> wrote:
# Writing an assembler, I'm stuck with ambiguities with my syntax. The
# syntactic analysis is a simple LL(1) recursive descent parser. Here is
# the issue (look at the "(" as a FIRST)
#
# LDA (data),Y ; #1 Indirect address indexed by Y
#
# index EQU 123
# LDA (index-1)*3,Y ; #2 Absolute address indexed by Y
# LDA 3*(index-1),Y ; Equivalent but non ambiguous
#
# An except of the grammar :
#
# line = mnemonic oper
# oper = "(" addr ")" "," "Y"
# | addr "," "Y"
# addr = ["+"|"-"] term { ["+"|"-"] term }
# ... etc
#
# The "(" of the _oper_ rule conflicts with the one from the _addr_
# expression. Do I get this right ?
I don't see a conflict unless you're allowing
a term production to be generate (...) without oper.
If you cannot distinguish which production goes with '('
without passing indefinitely far into the right context,
then it's not LL(k) for any k. One possibility is to
not distinguish in the syntax, just note the parenthesised
thingie in the parse tree, and then relabel the parse tree
when you have the wider context. This will work if the
problem parentheses are only the beginning and end of the
productions, so that you know the (...) encloses a
syntactically meaningful object, you just don't know which
one yet.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
I have no idea what you just said.
I get that a lot.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.