[antlr-interest] writing a simple tool
Edwards, Waverly
Waverly.Edwards at genesys.com
Fri Jan 18 10:22:11 PST 2008
Thank you Johannes. With your helpd and a LOT of effort, I was able to
get out of the hole I had dug.
I'm hoping to get further assistance. I am getting the following errors
when testing my grammar
line 1:16 no viable alternative at input ';'
line 2:8 no viable alternative at input '='
line 2:14 no viable alternative at input '|'
line 2:18 no viable alternative at input ']'
line 2:32 no viable alternative at input '}'
line 3:5 no viable alternative at input '='
line 3:31 no viable alternative at input '}'
line 3:47 no viable alternative at input ']'
using this at my input source
digit = "0".."9";
integer = ["+"|"-"] digit {digit};
real = integer "." digit {digit} [ "E" integer ];
I'm REALLY hoping someone can see what I'm doing wrong.
I've been trying for a few days to get this correct without success.
This is the closest I've gotten so far.
Thank you,
W.
Oh, I found a simplified text that explains first and follow
sets simply enough that I'm *starting* to understand how to
Compute them.
grammar EBNF_V8;
options {
k = 1; // force myself to keep grammar LL(1)
}
/*
REFERENCE
www.cs.bris.ac.uk/Teaching/Resources/COMS30122/lectures/02_Scanning.p.pd
f
Grammar symbols
Here is a 'standard' set of symbols for this unit The first four are
BNF, the rest EBNF
Symol or Expr ,// MEANING
:: // is (is defined as)
| // OR
& // AND
; // end of definition
?, '[' expression ']' // optional
*, '{' expression '}' // zero or more times
+ // one or more times
'(' expression ')' // bracketing (subrule)
NOT GOING TO BE IMPLEMENTED ( & )
*/
//fragment
//CHAR_LITERAL : '\'' (~(ESC_CHAR))* '\'' ;
CHAR_LITERAL : '\'' (~('\r\n'|'\r'|'\n'))* '\'' ;
//fragment
STR_LITERAL : '"' ((~ESC_CHAR))* '"' ;
//STR_LITERAL : '"' (~('\r\n'|'\r'|'\n'))* '"' ;
fragment
DIGIT : '0'..'9' ;
fragment
LETTER : 'a'..'z' | 'A'..'Z' ;
fragment
HEX_DIGIT : 'A'..'Z'|'a'..'z'|'0'..'9';
fragment
ESC_CHAR : ('\b' | '\f' | '\n' | '\r' | '\t' | '\'' | '\"' |
'\\');
// | '\u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT;
BECOMES : '=' | '::' | ':' ;
RANGE : '..';
ID : ( LETTER | '_' ) ( LETTER | DIGIT | '_' )* ;
//WS : (' ' | '\t' | '\n' | '\r' )+ { skip(); };
WS : ( ' ' | '\t' )+ { $channel=HIDDEN; };
NL : ( '\n' | '\r') { $channel=HIDDEN; };
start_ebnf : rule* ;
rule : ID BECOMES expression ';' ;
expression : and_expression ( '|' expression ) ;
and_expression : expression_value ( and_expression ) ;
expression_value : ID qualifier?
| terminal qualifier?
| RANGE // RANGE ("0".."9" |
"A".."Z")
| '(' expression ')' qualifier?
| '{' expression '}' // ZERO OR MORE
BLOCK
| '[' expression ']' // OPTIONAL BLOCK
;
terminal : STR_LITERAL | CHAR_LITERAL ;
qualifier : '*' | '+' | '?'; // ZERO OR MORE, ONE
OR MORE, OPTIONAL
-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Johannes Luber
Sent: Wednesday, January 16, 2008 6:23 AM
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] writing a simple tool
Edwards, Waverly schrieb:
> I am currently attempting to write what I hope is a simple tool to
> validate an ebnf grammar and export the first and follow set.
> Unfortunately, no amount of reading has enabled perform the 'easy' (to
> others) task of generating this first and follow set. I have read
> multiple books and texts on the subject. So I've embarked on a
> mission to start by first validating an ebnf grammar and moving
> forward from there.
>
> My first stumbling block came early in writing an ebnf grammar. In my
> effort to separate my parser rules so I can apply some type of action
> I have created recursive definitions. I know what they are but I've
> been unable figure out how to dig myself out of this hole.
>
> Any and all help will be greatly appreciated.
I also happen to have an unpublished tutorial about the very kind of
problem you have (before anyone asks - no, I don't have any more lurking
on the harddrive ;). I've attached it to this email. I'd also appreciate
any of feedback here.
Johannes
More information about the antlr-interest
mailing list