dcsimg
Help me God, please! I’m learning Antlr.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Arumugam_Rajarethinam
Posted On:   Saturday, October 6, 2001 07:20 PM

Hi gurus, I just start to learn Antlr ( Oh boy!), Could some one give me a grammar to parse an EDI Stream? I’ve given a sample EDI stream. GS*PO*123*321*927003*1203*1112*T*004010~ ST*850*0001~ .. .. Where, the first one – three characters in every line should be called “TAG” (i.e. TAG=”GS”), after the “*” delimited strings should be called SEGMENTs, that mean PO, 123, 321 etc are called SEGEMENT. Every line is delimited by “~”. Could some one please. Thanks in advance for any help you can provide. -Aru    More>>


Hi gurus,


I just start to learn Antlr ( Oh boy!), Could some one give me a grammar to parse an EDI Stream? I’ve given a sample EDI stream.


GS*PO*123*321*927003*1203*1112*T*004010~


ST*850*0001~
..
..


Where, the first one – three characters in every line should be called “TAG” (i.e. TAG=”GS”), after the “*” delimited strings should be called SEGMENTs, that mean PO, 123, 321 etc are called SEGEMENT. Every line is delimited by “~”.


Could some one please.


Thanks in advance for any help you can provide.



-Aru

   <<Less

Re: Help me God, please! I&#146;m learning Antlr.

Posted By:   frigot_eric  
Posted On:   Friday, October 12, 2001 03:45 AM


It could be something like that :


class JavaScriptParser extends Parser;


options {


k = 1; // tree
token lookahead


exportVocab = EDIstream; // Call its vocabulary "EDIstream"


defaultErrorHandler = false; // Don't generate parser error handlers


buildAST = true; // uses CommonAST by default


}


stream : (line)* ;


line : TAG (SEP TAG)* ENDLINE ;



class JavaScriptLexer extends Lexer;


options {


charVocabulary = '3'..'377';


exportVocab = EDIstream; // call the vocabulary "EDIstream"


k = 2; // Setting the lookahead deapth of the Lexer


}



// Space


WhiteSpace : ( ' ' | ' ' | 'f'
| ( "
" // DOS.
| '
' // Macintosh.
| '
' // Unix.
)
{ newline(); }
)
{ _ttype = Token.SKIP; } // to skip it.
;



ENDLINE : '~' { System.out.println("ENDLINE"); } ;
SEP : '*' { System.out.print("SEP"); } ;



TAG : ( ~('~' | '*' | ' ' | ' ' | '
' | '
' | 'f' ) )+
{ System.out.print("TAG("+$getText+")"); }
;

About | Sitemap | Contact