[antlr-interest] How to Creating an end of file rule for **-| DFHMSD TYPE=FINAL END as per my BMS
Joan Pujol
joanpujol at gmail.com
Sun Aug 29 22:27:30 PDT 2004
Hi,
I think that is better to don't send the same message severeal times.
On Mon, 30 Aug 2004 04:40:09 -0000, din_wins <din_wins at yahoo.com> wrote:
>
> Dear Friends,
>
> I am writing grammar for BMS Mainframe. I am struck with the
> following issues.
I think that your big problem is that you use all the power of the lexer.
>
> 1) Spaces inside of a quoted string
Define a token in the lexer similar to
QUOTEDSTRING: '\'' ~('\'')* '\'';
> 2) Creating an end of file rule for **-| DFHMSD TYPE=FINAL END
The same that 1:
FINALTOKEN: "**-| DFHMSD TYPE=FINAL END";
If you have some token that starts with * you will have to use
syntatic predicates.
> 3) The actual non-readable character at he the end of file
I have no time to look at this.
> 4) The header should also include | IDENTIFIER IDENTIFIER
> assign. Once
> this is fixed it may actually correct #2 as well.
2 is corrected ;)
And, don't use the Console.Write(XXX) to debug in the parser. ANTLR
has the option -traceParcer that does it for you and you have a
cleanaer more redeable grammar.
Cheers,
>
> below is my grammar file.
>
> =========================================================
>
> options {
> language = "CSharp";
> namespace = "Worksoft.Parsers";
> }
> class BMSLexer extends Lexer;
> options
> {
> k = 2;
> }
> IDENTIFIER
> :
> ( 'a'..'z'
> |'A'..'Z'
> |'0'..'9'
> |'.'|'/'
> |'~'|'`'|'!'|'@'|'#'|'$'|'%'|'^'|'&'|'*'|'-'|'_'|'+'
> |'['|']'|'{'|'}'|'\\'|'|'
> )+
> ;
> /*
> NEWLINE : '\r' '\n' | '\n'
> ;
> */
> QUOTATION : '\"'
> ;
>
> TICK : '\''
> ;
>
> COMMA : ','
> ;
> EQUAL : '='
> ;
>
> LPAREN : '('
> ;
> RPAREN : ')'
> ;
>
> WS : ( ' '
> | '\t'
> | '\r' '\n'
> | '\n')
> { $setType(Token.SKIP); }
> ;
> class BMSParser extends Parser;
> options
> {
> k = 3;
> }
> {
> private ParserHelper _parserHelper = new ParserHelper();
> }
> main returns [string xml = string.Empty]
> :
> (
> file
> )
> {
> xml = _parserHelper.ToString();
> }
> ;
>
> file :
> {
> _parserHelper.Start();
> Console.WriteLine("Start file");
> }
> (head body EOF)
> {
> Console.WriteLine("End file");
> _parserHelper.End();
> }
> ;
>
> head :
> {
> Console.WriteLine("start head");
> }
> (a:IDENTIFIER b:IDENTIFIER assigngroup)
> {
> Console.WriteLine("End head - " + a.getText() + " - " + b.getText
> ());
> }
> ;
>
> body :
> {
> Console.WriteLine("Start body");
> }
> (parent)*
> {
> Console.WriteLine("End body");
> }
> ;
>
> assigngroup :
> {
> Console.WriteLine("Start assigngroup");
> }
> (assign (COMMA a:IDENTIFIER assign)*)+
> {
> Console.WriteLine("End assigngroup = " + a.getText());
> }
> ;
>
> assign :
> {
> Console.WriteLine("Start assign");
> }
> a:IDENTIFIER EQUAL value
> {
> Console.WriteLine("End assign - " + a.getText());
> }
> |
>
> b:IDENTIFIER EQUAL valuegroup
> {
> Console.WriteLine("End assign - " + b.getText());
> }
> ;
>
> valuegroup :
> {
> Console.WriteLine("Start valuegroup");
> }
> LPAREN value (COMMA value)* RPAREN
> {
> Console.WriteLine("End valuegroup");
> }
> ;
>
> value :
> {
> Console.WriteLine("Start value");
> }
> a:IDENTIFIER
> {
> Console.WriteLine("End value = " + a.getText());
> }
> |
> TICK b:IDENTIFIER TICK
> {
> Console.WriteLine("End value = '" + b.getText() + "'");
> }
> ;
> parent :
> {
> Console.WriteLine("Start parent");
> }
> a:IDENTIFIER (obj)+
> {
> Console.WriteLine("End parent - " + a.getText());
> }
> ;
>
> obj :
> {
> Console.WriteLine("Start obj");
> }
> a:IDENTIFIER assigngroup
> {
> Console.WriteLine("End obj - " + a.getText());
> }
> ;
>
> ========================
>
> below is my .bms file.
> ==========================
> CHCM001 DFHMSD
> TYPE=MAP, X
>
> MODE=INOUT, x
>
> LANG=COBOL, x
>
> CTRL=FREEKB, X
>
> STORAGE=AUTO, x
>
> TERM=3270, x
> TIOAPFX=YES
> CHCM001 DFHMDI MAPATTS=
> (COLOR,PS,HILIGHT,VALIDN), x
> DSATTS=
> (COLOR,PS,HILIGHT,VALIDN), X
> SIZE=(24,80)
> DFHMDF POS=
> (1,1), x
>
> LENGTH=007, x
>
> COLOR=YELLOW, X
>
> ATTRB=ASKIP, x
> INITIAL='CHCM001'
> DFHMDF POS=
> (1,29), x
>
> LENGTH=022, x
>
> COLOR=YELLOW, X
>
> ATTRB=ASKIP, x
> INITIAL='CHC PERSONNEL TRACKING'
> SYSDATE DFHMDF POS=
> (1,71), x
>
> LENGTH=008, x
>
> COLOR=YELLOW, X
> ATTRB=(ASKIP,BRT)
> DFHMDF POS=
> (4,26), x
>
> LENGTH=031, x
>
> COLOR=YELLOW, X
>
> ATTRB=ASKIP, x
> INITIAL='1. PERSONNEL LISTING'
> DFHMDF POS=
> (6,26), x
>
> LENGTH=031, x
>
> COLOR=YELLOW, X
>
> ATTRB=ASKIP, x
> INITIAL='2. PERSONNEL INQUIRY'
> DFHMDF POS=
> (8,26), x
>
> LENGTH=031, x
>
> COLOR=YELLOW, X
>
> ATTRB=ASKIP, x
> INITIAL='3. PERSONNEL MAINTENANCE'
> DFHMDF POS=
> (10,26), x
>
> LENGTH=031, x
>
> COLOR=YELLOW, X
>
> ATTRB=ASKIP, x
> INITIAL='4. PERFORMANCE INQUIRY'
> DFHMDF POS=
> (12,26), x
>
> LENGTH=031, x
>
> COLOR=YELLOW, X
>
> ATTRB=ASKIP, x
> INITIAL='5. PERFORMANCE MAINTENANCE'
> DFHMDF POS=
> (14,26), x
>
> LENGTH=031, x
>
> COLOR=YELLOW, X
>
> ATTRB=ASKIP, x
> INITIAL='6. PERFORMANCE HISTORY'
> DFHMDF POS=
> (18,26), x
>
> LENGTH=031, x
>
> COLOR=YELLOW, X
>
> ATTRB=ASKIP, x
> INITIAL='12. PREVIOUS MENU/EXIT FUNCTION'
> MSG DFHMDF POS=
> (24,1), x
>
> LENGTH=079, x
> ATTRB=
> (ASKIP,IC,BRT), X
>
> COLOR=RED, X
> INITIAL='HIT PFKEY FOR CORRESPONDING MENU SELECTION'
> **-|
> DFHMSD TYPE=FINAL
> END
>
> ============
>
> Regards,
> P.Srinivasa Dinesh.
>
>
> Yahoo! Groups Links
>
>
>
>
>
--
Joan Jesús Pujol Espinar
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