[antlr-interest] How to describe this in ANTLR?
Daniel Shane
lachinois at hotmail.com
Wed Jan 14 12:58:07 PST 2004
Hi, I have two cases I'm trying to solve using ANTLR..
First, what is the best way of writting this so that its deterministic?
a: b? c? d? e? f? b?
Is this the best way?
a: (b (c | d | e | f)) => b c? d? e? f? b?
| (c | d | e | f) => c? d? e? f? b?
| b?
Secondly, I'm trying to recognize text which contain footnotes. For example:
Section
This is paragraph 1 * <- footnote Reference
This is paragraph 2 ** <- footnote Reference
** footnote 2
* footnote 1
A section can end with a footnote as well as paragraphs. If the footnote is
for the preceding paragraph, then it goes with it, else it goes at the end
of the section.
section: paragraph+ footnote*
paragraph: text footnoteRef? footnote*
footnote: footnoteRef text
The problem is that stated this way the grammar is non deterministic,
however, by matching the footnoteRef to the footnote it is possible to know
if a footnote goes in the section or at the end of a paragraph.
In the above example, here is the tree that should be recognized:
<Section>
<Paragraph><text>This is paragraph
1</text><footnoteRef>*</footnoteRef></Paragraph>
<Paragraph><text>This is paragraph 2</text><footnoteRef>**</footnoteRef>
<footnote><footnoteRef>**</footnoteRef> footnote 2</footnote>
</Paragraph>
<footnote><footnoteRef>*</footnoteRef> footnote 1</footnote>
</Section>
Is there a way to accomplish this using semantic predicates? If I understand
semantic predicate will return an error and parsing will fail if the
condition evaluates to anything but true right? So I can place a semantic
predicate that would try to match the footnote with the right footnoteRef?
Daniel Shane
_________________________________________________________________
MSN Search, le moteur de recherche qui pense comme vous !
http://fr.ca.search.msn.com/
Yahoo! Groups Links
To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list