[antlr-interest] BNF to ANTLR grammar conversion

Alexey Demakov demakov at ispras.ru
Tue Dec 14 01:52:50 PST 2004


Hi Alex,

I don't know solution. Parser generated from BNF can't use 
custom actions as ANTLR lets. But you can convert BNF to ANTLR 
manually and use it for parser generation.
And you can generate html doc with BNF used by ANTLR using -html 
command line switch. I convert syntax of your grammar to ANTLR notation, 
but some conflicts should be resolved.

Regards,
Alexey

-----
Alexey Demakov
TreeDL: Tree Description Language: http://treedl.sourceforge.net
RedVerst Group: http://www.unitesk.com


class myParser extends Parser;

path : (SLASH)? (step SLASH)* step;
step : (AT)? property
      | property LB index_from_1 RB
      | property DOT index_from_0
      | reference LB attribute EQUAL value RB
      | DOTDOT;
property : NCName;      // may be simple or complex type
attribute : NCName;     // must be simple type
reference : NCName;      // must be DataObject type
index_from_0 : Digits;
index_from_1 : NotZero (Digits)?;
value : Literal 
      | Number
      | Boolean;

class myLexer extends Lexer;

SLASH : '/';

AT : '@';

LB : '[';

RB : ']';

DOT : '.';

DOTDOT : "..";

EQUAL : '=';

Literal : '"' (~'"')* '"'
      | "'" (~'\'')* "'";
Number : Digits ('.' (Digits)?)? 
      | '.' Digits;
Boolean : "true"
      | "false";
NotZero : '1'..'9';
Digits : ('0'..'9')+;

// leading '/' begins at the root
// ".." is the containing DataObject
// Only the last step have an attribute as the property

----- Original Message ----- 
From: "Alex J. Rodriguez" <alexjrodriguez at yahoo.com>
To: <antlr-interest at yahoogroups.com>
Sent: Saturday, December 11, 2004 3:12 AM
Subject: [antlr-interest] BNF to ANTLR grammar conversion


> 
> 
> 
> How do I go from BNF to ANTLR grammar programmatically? I am looking
> for a way to generate an XPath parser/evaluator from the following BNF
> (the syntax is pretty small, and is really a stripped down XPath 1.0
> syntax defined by the SDO spec):
> 
> path ::= '/'? (step '/')* step
> step ::= '@'? property
>       | property '[' index_from_1 ']'
>       | property '.' index_from_0
>       | reference '[' attribute '=' value ']'
>       | ".."
> property ::= NCName      ;; may be simple or complex type
> attribute ::= NCName     ;; must be simple type
> reference :: NCName      ;; must be DataObject type
> index_from_0 ::= Digits
> index_from_1 ::= NotZero (Digits)?
> value ::= Literal 
>       | Number
>       | Boolean
> Literal ::= '"' [^"]* '"'
>       | "'" [^']* "'"
> Number ::= Digits ('.' Digits?)? 
>       | '.' Digits
> Boolean ::= true
>       | false
> NotZero ::= [1-9]
> Digits ::= [0-9]+
> 
> ;; leading '/' begins at the root
> ;; ".." is the containing DataObject
> ;; Only the last step have an attribute as the property
> 
> 
> - Alex Rodriguez
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 
> 
> 



 
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