[antlr-interest] How to describe this in ANTLR?

mzukowski at yci.com mzukowski at yci.com
Wed Jan 14 17:23:55 PST 2004


You may be better off recognizing

a: (b | c | d | e | f)* ; 

and then have an action that checks that they came in the right order.
However, your solution should work too.  

On the other hand, ANTLR will do the right thing with your original even
though it is non-deterministic.  Inspect the generated code and see.

For the second question, again ANTLR will do the right thing and match if it
can in the paragraph rule, otherwise it would be matched in the section
rule.  This is the same problem as with if/else statements.  By the way,
your grammar for paragraph/footnote doesn't quite make sense with
footnoteRef being matched twice in a row.  

Monty


-----Original Message-----
From: Daniel Shane [mailto:lachinois at hotmail.com] 
Sent: Wednesday, January 14, 2004 12:58 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] How to describe this in ANTLR?

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/ 


 

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