Re: Work around ambiguities in LL(1) assembler parser
- From: SM Ryan <wyrmwif@xxxxxxxxx>
- Date: Mon, 07 Jan 2008 01:57:03 -0000
=?iso-8859-1?b?RnLpZOlyaWM=?= <m@xxxxx> 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.
.
- References:
- Work around ambiguities in LL(1) assembler parser
- From: Frédéric
- Work around ambiguities in LL(1) assembler parser
- Prev by Date: Re: Formal grammar & syntax of formal languages
- Next by Date: Re: Formal grammar & syntax of formal languages
- Previous by thread: Work around ambiguities in LL(1) assembler parser
- Next by thread: Re: Work around ambiguities in LL(1) assembler parser
- Index(es):
Relevant Pages
|
|