[antlr-interest] ANTLR v4 progress

kferrio at gmail.com kferrio at gmail.com
Wed May 26 19:07:50 PDT 2010


Way cool!  Just curious...is the modal state variable automatically accessible to the parser?  Perhaps on a subchannel synced with the token stream?  Sorry to be tuning in late...always interested in new paths to semiosis.  :)   Anyway...I need to take a look at girhub and think up a fun use.

Kyle

Sent from my Verizon Wireless BlackBerry

-----Original Message-----
From: Terence Parr <Parrt at cs.usfca.edu>
Date: Wed, 26 May 2010 16:18:28 
To: antlr-interest at antlr.org interest<antlr-interest at antlr.org>
Subject: [antlr-interest] ANTLR v4 progress

Just passing along an example HTML subset lexer/parser using ANTLR v4; thanks to  debugging and moral support from Oliver Zeigermann, we got the code generation and runtime support working sufficiently to use the following grammars.   generate some really nice code indeed. You will note that, except for the enhancement of the lexer modes, the grammars are backward compatible with v3 :)

I still have a long way to go, but it's looking more & more useful (only does LL(1) code generation at this point).

Ter
---------------------------
lexer grammar HTMLLexer;

TAG_START : '<' {pushMode(INSIDE);} ;

COMMENT : '<!--' .* '-->' {skip();} ;

TEXT : ~'<'+ ;

mode INSIDE;

TAG_STOP : '>' {popMode();} ;

END_TAG : '/' ID '>' {popMode();} ;

ID : ('A'..'Z'|'a'..'z'|'0'..'9'|'_'|'#')+ ;

EQ : '=' ;

STRING : '"' .* '"'
       ;

WS : ' '+ {skip();} ;

------------------------

parser grammar HTMLParser;

options { tokenVocab=HTMLLexer; }

file : ( TAG_START (starttag | endtag) | TEXT)+ EOF ;

starttag : ID attr* TAG_STOP ;

attr : ID (EQ (ID|STRING))? ;

endtag
	:	 END_TAG
	;


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address


More information about the antlr-interest mailing list