[antlr-interest] how can i return a string including a regular express?

Su Zhang westlifezs at gmail.com
Sat Nov 22 18:31:12 PST 2008


HI everyone,

the problem is, I want to return a string which includes a regular
express, like  i1=id1'(' i2=id1 ( ',' i3=id1)* ')', on the left of
equals are label variables which are not included in the return
string, and I use the method {String k=','+$i3.text;
$p=$i1.text+'('+$i2.text + k*+')';} to assemble the return value p,
but it won't work, it says that the * cannot be applied in this kind
of express, so does everyone know a method to handle this kind of
problem?

Thank you!

Su

2008/11/22, antlr-interest-request at antlr.org <antlr-interest-request at antlr.org>:
> Send antlr-interest mailing list submissions to
> 	antlr-interest at antlr.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://www.antlr.org/mailman/listinfo/antlr-interest
> or, via email, send a message with subject or body 'help' to
> 	antlr-interest-request at antlr.org
>
> You can reach the person managing the list at
> 	antlr-interest-owner at antlr.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of antlr-interest digest..."
>
>
> Today's Topics:
>
>    1. Re: How to get the last token type just recognized in the
>       lexer? (Gavin Lambert)
>    2. Java Grammar (Simon)
>    3. Could the AST of ANTLR be used to write an	Interpreter?
>       (chain one)
>    4. Lexer rule with alternatives (Newbie question)
>       ( ?????? ????????? )
>    5. Re: Lexer rule with alternatives (Newbie question)
>       (John B. Brodie)
>    6. Re: Lexer rule with alternatives (Newbie question)
>       (Johannes Luber)
>    7. Re: Lexer rule with alternatives (Newbie question)
>       ( ?????? ????????? )
>    8. Re: Lexer rule with alternatives (Newbie question)
>       (John B. Brodie)
>    9. Why waiting timeout? why cannot find symbol? (Su Zhang)
>   10. Re: Lexer rule with alternatives (Newbie question)
>       ( ?????? ????????? )
>   11. Write comments to templates (Chris Sekszczynska)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sat, 22 Nov 2008 09:45:21 +1300
> From: Gavin Lambert <antlr at mirality.co.nz>
> Subject: Re: [antlr-interest] How to get the last token type just
> 	recognized in the lexer?
> To: "chain one" <chainone at gmail.com>, antlr-interest
> 	<antlr-interest at antlr.org>
> Message-ID: <20081121204543.C4ABF11EAED at www.antlr.org>
> Content-Type: text/plain; charset="us-ascii"; format=flowed
>
> At 02:30 22/11/2008, chain one wrote:
>>INT
>>:    (DIGIT)+
>>;
>>
>>FLOAT
>>:    '.' (DIGIT)+ (('e' | 'E') ('+' | '-')? (DIGIT)+)?
>>|    '.' ('e' | 'E') ('+' | '-')? (DIGIT)+
>>      ;
>>
>>DIGIT
>>:'0'..'9'
>>;
> [...]
>>So it seems that the only solution is to predict the last token
>>just recognized, if the last token is a INT, then FLOAT rule
>>should be followed.
>>
>>so I need to know what the last token is.
>>calling function LA(-1) could do this, however LA(-1) is only
>>available in parser not in lexer
>
> You're asking the wrong question.  Instead of trying to work out
> INTs followed by FLOATs, simply recognise it as a FLOAT in the
> first place:
>
> protected DIGIT: '0'..'9';
>
> protected EXPONENT: ('e' | 'E') ('+' | '-')? (DIGIT)+;
>
> FLOAT
>    : '.' (DIGIT)+ (EXPONENT)?
>    ;
>
> INT
>    : (DIGIT)+
>      ( FLOAT { $setType(FLOAT); }
>      | EXPONENT { $setType(FLOAT); }
>      )?
>    ;
>
> (".e16" by itself shouldn't be recognised as a float anyway.)
>
>
>
> ------------------------------
>
> Message: 2
> Date: Fri, 21 Nov 2008 21:56:37 +0100
> From: Simon <cocoa at gmx.ch>
> Subject: [antlr-interest] Java Grammar
> To: antlr-interest Interest <antlr-interest at antlr.org>
> Message-ID: <1B35796C-F70C-446B-BA7B-737EA04A144D at gmx.ch>
> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
>
> hi
>
> I'm trying to build an AST for a Java like language. The hardest part
> (if you want to built a meaningful AST) is the section of
> unaryExpressionNotPlusMinus (see grammar fragments at end or the
> Java.g grammar on antlr.org).
>
> I have successfully built ASTs for the following constructs (using
> semantic predicates based on a symbol table)
>
>    ^(FIELD_ACCESS target Identifier)
>    ^(INVOKE target Identifier arguments)
>    ^(ARRAY_ACCESS target expr)
>
> However, I'm struggling with fully qualified type names, such as those
> in
>
>    java.lang.Integer.parseInt("123")
>
> Of course, I want something like
>
>    ^(INVOKE ^(TYPE_REFERENCE ...) arguments)
>
> The problem is that I somehow have to look ahead to detect whether it
> is a qualified type name (don't know how the precedence is if there is
> a variable named java with a field named lang that has a field named
> Integer that has method named parseInt, but that's another problem). I
> could write my own semantic predicate method that looks ahead in the
> input to detect a qualified type name. Is there an easier way to do
> that? Or am I approaching the problem from the wrong side?
>
> I've tried to look at the Java grammar from langtools recently posted
> in this list, but didn't get any smarter (they rely heavily on the
> existing javac classes).
>
> Thanks
> Simon
>
>
>
> unaryExpressionNotPlusMinus
>      :   ...
>      |   primary selector* ('++'|'--')?
>      ;
>
> primary
>      :   parExpression
>      |   literal
>      |   'new' creator
>      |   Identifier ('.' Identifier)* identifierSuffix?   // this is
> the hard / interesting part
>      |   primitiveType ('[' ']')* '.' 'class'
>      |   'void' '.' 'class'
>      ;
>
> identifierSuffix
>      :   ('[' ']')+ '.' 'class'
>      |   ('[' expression ']')+ // can also be matched by selector, but
> do here
>      |   arguments
>      |   '.' 'class'
>      ;
>
> selector
>      :   '.' Identifier arguments?
>      |   '[' expression ']'
>      ;
>
>
>
> ------------------------------
>
> Message: 3
> Date: Sat, 22 Nov 2008 13:50:40 +0800
> From: "chain one" <chainone at gmail.com>
> Subject: [antlr-interest] Could the AST of ANTLR be used to write an
> 	Interpreter?
> To: antlr-interest <antlr-interest at antlr.org>
> Message-ID:
> 	<5a92ffb60811212150w4396fb05j1c256acf749ada87 at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> I mean the Abstract Syntax Tree interpreters
>
> Has anybody ever used ANTLR to write this kind of interpreter?
>
> If yes, could you drop me some material related to this? Thanks.
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://www.antlr.org/pipermail/antlr-interest/attachments/20081122/14c46fe8/attachment-0001.html
>
> ------------------------------
>
> Message: 4
> Date: Sat, 22 Nov 2008 18:49:16 +0300
> From: " ?????? ????????? " <gmdidro at gmail.com>
> Subject: [antlr-interest] Lexer rule with alternatives (Newbie
> 	question)
> To: antlr-interest <antlr-interest at antlr.org>
> Message-ID:
> 	<1dcb5c470811220749u46bf38bwa43ed521a4470350 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hello,
> why such grammar doesn't work properly:
> --------------------------------------------------------------------------------------
> expr	:
>         operand ((oper) operand)*
>       	;
> //Correct operands
> operand	:
> 	INT
> 	;
> OPER: ('+'|'-'|'*'|'/')
> 	;
> INT	:	
> 	('0'..'9')+
> 	;
> --------------------------------------------------------------------------------------
>> t+1
> line 0:3 mismatched input '+' expecting EOF
>
> But if I replace the Lexer rule by Parser rule:
>
> oper: ('+'|'-'|'*'|'/');
>
> All work as it should. Why I should't use Lexer rule with alternatives ?
>
> Thank you
>
>
> ------------------------------
>
> Message: 5
> Date: Sat, 22 Nov 2008 11:23:58 -0500
> From: "John B. Brodie" <jbb at acm.org>
> Subject: Re: [antlr-interest] Lexer rule with alternatives (Newbie
> 	question)
> To: antlr-interest at antlr.org
> Message-ID: <200811221123.58695.jbb at acm.org>
> Content-Type: text/plain; charset="iso-8859-1"
>
>> Hello,
>
> Greetings!
>
>> why such grammar doesn't work properly:
>> ---------------------------------------------------------------------------
>>----------- expr????:
>> ? ? ? ? operand ((oper) operand)*
>                             ^^^^^^
> I assume you mean the lexer rule OPER here?
>> ? ? ? ??;
>> //Correct operands
>> operand?:
>> ????????INT
>> ????????;
>> OPER: ('+'|'-'|'*'|'/')
>> ????????;
>> INT?????:???????
>> ????????('0'..'9')+
>> ????????;
>> ---------------------------------------------------------------------------
>>-----------
>>
>> > t+1
>     ^^^
> your grammar does specify anything for how to handle the character 't'
>
>>
>> line 0:3 mismatched input '+' expecting EOF
>>
>> But if I replace the Lexer rule by Parser rule:
>>
>> oper: ('+'|'-'|'*'|'/');
>>
>> All work as it should. Why I should't use Lexer rule with alternatives ?
>>
>
> works for me with the following changes: (1) changed reference to oper to be
> OPER in the rule expr, and (2) changed the test input to be "1+1"
>
> i am using ANTLR v3.1 from 12 August 2008.
>
> my test source grammar is this:
>
> //-----cut here-----
>
>> Thank you
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://www.antlr.org/pipermail/antlr-interest/attachments/20081122/27413b7a/attachment-0001.html
>
> ------------------------------
>
> Message: 6
> Date: Sat, 22 Nov 2008 17:26:12 +0100
> From: Johannes Luber <jaluber at gmx.de>
> Subject: Re: [antlr-interest] Lexer rule with alternatives (Newbie
> 	question)
> To: ?????? ????????? 	<gmdidro at gmail.com>
> Cc: antlr-interest <antlr-interest at antlr.org>
> Message-ID: <492832A4.1010705 at gmx.de>
> Content-Type: text/plain; charset=UTF-8
>
> ?????? ????????? schrieb:
>> Hello,
>> why such grammar doesn't work properly:
>> --------------------------------------------------------------------------------------
>> expr	:
>>         operand ((oper) operand)*
>>       	;
>> //Correct operands
>> operand	:
>> 	INT
>> 	;
>> OPER: ('+'|'-'|'*'|'/')
>> 	;
>> INT	:	
>> 	('0'..'9')+
>> 	;
>> --------------------------------------------------------------------------------------
>>> t+1
>> line 0:3 mismatched input '+' expecting EOF
>>
>> But if I replace the Lexer rule by Parser rule:
>>
>> oper: ('+'|'-'|'*'|'/');
>>
>> All work as it should. Why I should't use Lexer rule with alternatives ?
>
> The problem with your example is that in the expr rule you use oper, but
> define OPER as rule. Did you overlook this while posting or does even
>
> expr	:
>          operand (OPER operand)*
>        	;
>
> not work? Nonetheless, the usual way to define operands is to create a
> single rule for each operand and reference those lexer rules in a single
> parser rule for convenience. As "oper: ('+'|'-'|'*'|'/');" creates
> implicit lexer rules doing it this way simulates the described approach,
> but there can be problems as '+' used in to different rules will create
> two distinct token types which will cause a MismatchedTokenTypeException
> later.
>
> Johannes
>>
>> Thank you
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe:
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
>
>
>
> ------------------------------
>
> Message: 7
> Date: Sat, 22 Nov 2008 19:50:40 +0300
> From: " ?????? ????????? " <gmdidro at gmail.com>
> Subject: Re: [antlr-interest] Lexer rule with alternatives (Newbie
> 	question)
> To: antlr-interest <antlr-interest at antlr.org>
> Message-ID:
> 	<1dcb5c470811220850v61e3f3d9n92d47d6f8fdd0ec9 at mail.gmail.com>
> Content-Type: text/plain; charset=KOI8-R
>
> Sorry for many misprints. I experiment with grammar and post
> intermediate variant.
>
> My question is below:
> I have a grammar:
>
> expr	:
> 	(operand) (OPER operand)*
> 	;
> operand	:
> 	ID|INT
> 	;
> OPER	:
> 	('+'|'-'|'*'|'/')
> 	;
> INT	:	
> 	('0'..'9')+
> 	;
> ID	:
> 	('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
> 	;
>
> And for the input "t+1", I have the error:
> line 1:4 mismatched input '+'
>
> But when I switch "OPER" to "oper", All work as it should. I don't
> understand Why it's so.
>
> Thank you
>
> 2008/11/22 Johannes Luber <jaluber at gmx.de>:
>> ?????? ????????? schrieb:
>>> Hello,
>>> why such grammar doesn't work properly:
>>> --------------------------------------------------------------------------------------
>>> expr  :
>>>         operand ((oper) operand)*
>>>               ;
>>> //Correct operands
>>> operand       :
>>>       INT
>>>       ;
>>> OPER: ('+'|'-'|'*'|'/')
>>>       ;
>>> INT   :
>>>       ('0'..'9')+
>>>       ;
>>> --------------------------------------------------------------------------------------
>>>> t+1
>>> line 0:3 mismatched input '+' expecting EOF
>>>
>>> But if I replace the Lexer rule by Parser rule:
>>>
>>> oper: ('+'|'-'|'*'|'/');
>>>
>>> All work as it should. Why I should't use Lexer rule with alternatives ?
>>
>> The problem with your example is that in the expr rule you use oper, but
>> define OPER as rule. Did you overlook this while posting or does even
>>
>> expr    :
>>         operand (OPER operand)*
>>        ;
>>
>> not work? Nonetheless, the usual way to define operands is to create a
>> single rule for each operand and reference those lexer rules in a single
>> parser rule for convenience. As "oper: ('+'|'-'|'*'|'/');" creates
>> implicit lexer rules doing it this way simulates the described approach,
>> but there can be problems as '+' used in to different rules will create
>> two distinct token types which will cause a MismatchedTokenTypeException
>> later.
>>
>> Johannes
>>>
>>> Thank you
>>>
>>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>>> Unsubscribe:
>>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>>
>>
>>
>
> ------------------------------
>
> Message: 8
> Date: Sat, 22 Nov 2008 12:16:48 -0500
> From: "John B. Brodie" <jbb at acm.org>
> Subject: Re: [antlr-interest] Lexer rule with alternatives (Newbie
> 	question)
> To: antlr-interest at antlr.org
> Message-ID: <200811221216.48631.jbb at acm.org>
> Content-Type: text/plain; charset="iso-8859-1"
>
>> My question is below:
>> I have a grammar:
>>
>> expr????:
>> ????????(operand) (OPER operand)*
>> ????????;
>> operand?:
>> ????????ID|INT
>> ????????;
>> OPER????:
>> ????????('+'|'-'|'*'|'/')
>> ????????;
>> INT?????:???????
>> ????????('0'..'9')+
>> ????????;
>> ID??????:
>> ????????('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
>> ????????;
>>
>> And for the input "t+1", I have the error:
>> line 1:4 mismatched input '+'
>>
> works for me. no errors reported. using the attached test rig under ANTLR
> v3.1, August 12, 2008.
>
>> But when I switch "OPER" to "oper", All work as it should. I don't
>> understand Why it's so.
>>
>> Thank you
> Hope this helps.
> --
> John B. Brodie
>
> //---------------------begin attachment-------------------------
> grammar Test;
>
> options {
> 	output = AST;
> 	ASTLabelType = CommonTree;
> }
>
> @members {
>     private static final String [] x = new String[]{
>         "1+1", "t+1"
>     };
>
>     public static void main(String [] args) {
>         for( int i = 0; i < x.length; ++i ) {
>             try {
>                 System.out.println("about to parse:`"+x[i]+"`");
>                 TestLexer lexer = new TestLexer(new
> ANTLRStringStream(x[i]));
>                 CommonTokenStream tokens = new CommonTokenStream(lexer);
>
>                 TestParser parser = new TestParser(tokens);
>                 TestParser.expr_return p_result = parser.expr();
>
>                 CommonTree ast = p_result.tree;
>                 if( ast == null ) {
>                    System.out.println("resultant tree: is NULL");
>                 } else {
>                    System.out.println("resultant tree: " +
> ast.toStringTree());
>                 }
>                 System.out.println();
>             } catch(Exception e) {
>                 e.printStackTrace();
>             }
>         }
>     }
> }
>
> expr    :
>         (operand) (OPER operand)*
>         ;
> operand :
>         ID|INT
>         ;
> OPER    :
>         ('+'|'-'|'*'|'/')
>         ;
> INT     :
>         ('0'..'9')+
>         ;
> ID      :
>         ('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
>         ;
> //---------------------end of attachment------------------------
>
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://www.antlr.org/pipermail/antlr-interest/attachments/20081122/694a8c9c/attachment-0001.html
>
> ------------------------------
>
> Message: 9
> Date: Sat, 22 Nov 2008 11:36:39 -0600
> From: "Su Zhang" <westlifezs at gmail.com>
> Subject: [antlr-interest] Why waiting timeout? why cannot find symbol?
> To: antlr-interest at antlr.org
> Message-ID:
> 	<e2842950811220936g10dd156fweadfecac7d77cd6b at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi all,
>
> I meet two very strange problems when debugging my program,the first
> one is "timeout waiting connect remote parser", the other is cannot
> find symbol
> [11:17:54] symbol  : variable b64
> [11:17:54] location: class assignment6Parser
> [11:17:54]             b64=i.getText();
> is anybody have solutions to similar problems?
> here is my grammar just for common tree
> :
>
> grammar assignment6;
>
> options {
>     output=AST;
>     ASTLabelType=CommonTree;
>     k=*;
>     memoize = true;
> }
>
> tokens {
>         CredentialHeader  = '-----BEGIN MPKI CREDENTIAL-----';
>         CredentialEnd  = '-----END MPKI CREDENTIAL-----';
>         PublicKeyHeader  = '-----BEGIN PUBLIC KEY-----';
>         PublicKeyEnd = '-----END PUBLIC KEY-----';
>         SignatureHeader  = '-----BEGIN SIGNATURE-----';
>         SignatureEnd  = '-----END SIGNATURE-----';
>         ValidityHeader  = '-----BEGIN VALIDITY-----';
>         ValidityEnd = '-----END VALIDITY-----';
>         CertHeader = '-----BEGIN MPKI CERTIFICATE-----';
>         CertEnd  = '-----END MPKI CERTIFICATE-----';
>         ChallengeHeader  = '-----BEGIN MPKI CHALLENGE-----';
>         ChallengeEnd = '-----END MPKI CHALLENGE-----';
>         ResponseHeader = '-----BEGIN MPKI CHALLENGE RESPONSE-----';
>         ResponseEnd  = '-----END MPKI CHALLENGE RESPONSE-----';
>         RequestHeader = '-----BEGIN REPOSITORY CLIENT REQUEST-----';
>         RequestEnd = '-----END REPOSITORY CLIENT REQUEST-----';
>         ReplyHeader  = '-----BEGIN REPOSITORY SERVER REPLY-----';
>         ReplyEnd  = '-----END REPOSITORY SERVER REPLY-----';
>         NotBefore  = 'Not before:';
>         NotAfter  = 'Not after:';
>         DAYTIME = 'daytime';
>         Read = 'read';
>         Write = 'write';
>         Commit = 'commit';
>         //Says = 'says';
>        // Granted = 'granted';
>         //Denied = 'denied';
>        // request = 'request';
>
> }
>
> @header {
>
> }
>
> @lexer::header {
> //package certificate;
>
> }
> prog    :    credential
>     ;
>
> credential
>     :    CredentialHeader publicKey certificate* CredentialEnd
>     ;
>
> certificate returns [ String cert ]
>     :   CertHeader clause+ validity? publicKey signature CertEnd
>         { /*cert = 74*/}
>     ;
>
> signature
>     :  SignatureHeader b=base{}	 SignatureEnd
>      // { isTypeName(b.getText()); }
>     ;
>
> validity  returns [String v]
>     : ValidityHeader NotBefore tb= timeTuple NotAfter ta= timeTuple
> ValidityEnd
>     { /*v= tb + ta;*/ }
>     ;
>
> timeTuple  returns [String time]
>     : 'datime' '('t1= num ','t2= num ','t3= num ','t4= num ','t5= num
> ','t6= num ')' '.'
>     {//time= new timeTuple(t1, t2, t3, t4, t5 ,t6);
>     // time = "daytime" + '(' + t1 + ','+ t2 +','+ t3 +',' + t4+',' +
> t5+',' +t6 + ')';
>     }
>     ;
>
> //num    returns [String t]
>       //  :n = Num
>        // {/*t = n.getText();*/}
>        // ;
>
> clause    : literal '.' | literal ':-' literal (',' literal)* '.'
>     ;
>
> literal    : predicate | 'says' '(' id ',' predicate')'
>     ;
>
>
> predicate
>     : id'(' id ( ',' id)* ')'
>     ;
>
>
> publicKey
>     :    PublicKeyHeader b=base PublicKeyEnd
>      // { isTypeName(b.getText()); }
>     ;
>
> challenge
>     :     ChallengeHeader base ChallengeEnd
>     ;
> response
>     :     ResponseHeader b= base ResponseEnd
>           //  { isTypeName(b.getText()); }
>     ;
>
> //Base64Block
> //       : s =Base64Block
> //           {isType(s.getText())}? Base64Block
> //       ;
> base  returns [String b64 ]	
>      : i= ID {!(i.getText().contains("-"))
> }?{!(i.getText().contains("_"))}? {b64=i.getText();}
>      ;
> id  returns [String identification]	
>      : ident= ID
> {!(ident.getText().contains("+"))}?{!(ident.getText().contains("="))}?{!(ident.getText().contains("/"))}?
>  {identification= ident.getText();}
>      ;
> num  	  returns [String no]
>         :	n= ID {no=
> n.getText();}{n.getText().contains("0")}?{n.getText().contains("1")}?{n.getText().contains("2")}?{n.getText().contains("3")}?{n.getText().contains("4")}?{n.getText().contains("5")}?{n.getText().contains("6")}?{n.getText().contains("7")}?{n.getText().contains("8")}?{n.getText().contains("9")}?
>         ;
> request
>     :     RequestHeader 'request' '('op ',' ID ')' RequestEnd
>     ;
> op      :    'read' | Write | Commit
>     ;
> reply      :     ReplyHeader result ReplyEnd
>     ;
> result  :     'granted' | 'denied'
>     ;
>
> ID   :	  ('a'..'z' | 'A'..'Z' | 'O'..'9' | '/' | '+' | '='| '-'| '_'|':')*
>      ;
> //Id   :     ( 'a'..'z' | 'A'..'Z' | '_' ) ( 'a'..'z' | 'A'..'Z' | '_'
> |'-'| '0'..'9' ) *;
> //Base64Block      : ('a'..'z' | 'A'..'Z' | 'O'..'9' | '/' | '+' | '=')*;
> //ChallengeBlock   : ( 'a'..'z' | 'A'..'Z' | 'O'..'9'| ':')* ;
> //Num   :     ( '0'..'9' ) * ;
> //fragment
> WS  :  (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}
>     ;
>
> thanks alot!
>
>
> 2008/11/21, antlr-interest-request at antlr.org
> <antlr-interest-request at antlr.org>:
>> Send antlr-interest mailing list submissions to
>> 	antlr-interest at antlr.org
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>> 	http://www.antlr.org/mailman/listinfo/antlr-interest
>> or, via email, send a message with subject or body 'help' to
>> 	antlr-interest-request at antlr.org
>>
>> You can reach the person managing the list at
>> 	antlr-interest-owner at antlr.org
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of antlr-interest digest..."
>>
>>
>> Today's Topics:
>>
>>    1. StringTemplates in C? (Robert Soule)
>>    2. Re: StringTemplates in C? (Sam Harwell)
>>    3. Does it make sense to use Antlr for interactive	parsing?
>>       (Vishwanath Hawargi)
>>    4. Re: StringTemplates in C? (Jim Idle)
>>    5. Re: Does it make sense to use Antlr for interactive parsing?
>>       (Jim Idle)
>>    6. Updated vim syntax highlighter (Davyd Madeley)
>>    7. Re: Maven builds, hudson continuous (Jean Bovet)
>>    8. How to get the last token type just recognized in	the lexer?
>>       (chain one)
>>    9. Re: Updated vim syntax highlighter (Jim Idle)
>>   10. Re: Updated vim syntax highlighter (Terence Parr)
>>
>>
>> ----------------------------------------------------------------------
>>
>> Message: 1
>> Date: Thu, 20 Nov 2008 15:38:27 -0500
>> From: "Robert Soule" <robert.soule at gmail.com>
>> Subject: [antlr-interest] StringTemplates in C?
>> To: antlr-interest at antlr.org
>> Message-ID:
>> 	<d1316fd70811201238x5fc18f9aga508c3764ed1421a at mail.gmail.com>
>> Content-Type: text/plain; charset=ISO-8859-1
>>
>> Hi,
>>
>> Is there a port of StringTemplates to C? I would like to have my
>> tree grammar with C target language output templates, but I can't
>> seem to compile my grammar, The www.stringtemplate.org
>> website only says "with ports for C# and Python", which makes
>> me suspect I'm in for some bad news...
>>
>> -Robert
>>
>>
>> ------------------------------
>>
>> Message: 2
>> Date: Thu, 20 Nov 2008 14:52:28 -0600
>> From: "Sam Harwell" <sharwell at pixelminegames.com>
>> Subject: Re: [antlr-interest] StringTemplates in C?
>> To: "Robert Soule" <robert.soule at gmail.com>,
>> 	<antlr-interest at antlr.org>
>> Message-ID:
>> 	<86403CA0939415448BCCB83855EFE09A64E911 at Bloodymary.ironwillgames.com>
>> Content-Type: text/plain;	charset="us-ascii"
>>
>> StringTemplate relies heavily on features that would be extremely
>> difficult to duplicate in C. If there was ever a "port" of
>> StringTemplate to C, it would altered to the point of being a different
>> product.
>>
>> Sam
>>
>> -----Original Message-----
>> From: antlr-interest-bounces at antlr.org
>> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Robert Soule
>> Sent: Thursday, November 20, 2008 2:38 PM
>> To: antlr-interest at antlr.org
>> Subject: [antlr-interest] StringTemplates in C?
>>
>> Hi,
>>
>> Is there a port of StringTemplates to C? I would like to have my
>> tree grammar with C target language output templates, but I can't
>> seem to compile my grammar, The www.stringtemplate.org
>> website only says "with ports for C# and Python", which makes
>> me suspect I'm in for some bad news...
>>
>> -Robert
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe:
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-addr
>> ess
>>
>>
>>
>> ------------------------------
>>
>> Message: 3
>> Date: Thu, 20 Nov 2008 15:13:11 -0600
>> From: "Vishwanath Hawargi" <vhawargi at gmail.com>
>> Subject: [antlr-interest] Does it make sense to use Antlr for
>> 	interactive	parsing?
>> To: antlr-interest at antlr.org
>> Message-ID:
>> 	<4c63b36c0811201313k31488297rd9f85bb99415674a at mail.gmail.com>
>> Content-Type: text/plain; charset=ISO-8859-1
>>
>> Hello,
>>  Another dumb question from me.
>>
>> I am looking for parsing an expression from the command line. Each of
>> these expressions are syntactically correct.
>> Instead of having a input file, i am having one expression at a time
>> to  be processed.
>> In this situation is it optimal/ ok to use antlr to validate and
>> generate the tokens?
>>
>> Also, how do i process input arg instead of input file?
>>
>> please let me know.
>>
>> thank you.
>> vishwa
>>
>>
>> ------------------------------
>>
>> Message: 4
>> Date: Thu, 20 Nov 2008 14:44:28 -0800
>> From: Jim Idle <jimi at temporal-wave.com>
>> Subject: Re: [antlr-interest] StringTemplates in C?
>> To: Robert Soule <robert.soule at gmail.com>
>> Cc: antlr-interest at antlr.org
>> Message-ID: <1227221068.22288.53.camel at jimi.temporal-wave.com>
>> Content-Type: text/plain; charset="us-ascii"
>>
>> On Thu, 2008-11-20 at 15:38 -0500, Robert Soule wrote:
>>
>>> Hi,
>>>
>>> Is there a port of StringTemplates to C? I would like to have my
>>> tree grammar with C target language output templates, but I can't
>>> seem to compile my grammar, The www.stringtemplate.org
>>> website only says "with ports for C# and Python", which makes
>>> me suspect I'm in for some bad news...
>>
>>
>> Stringtemplate is object based, so there is no way to create a C port,
>> at least as the design stands. Something similar could be created but
>> would probably be relatively unwieldy.
>>
>> Jim
>>
>>
>>>
>>> -Robert
>>>
>>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>>> Unsubscribe:
>>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>>
>>
>>
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL:
>> http://www.antlr.org/pipermail/antlr-interest/attachments/20081120/4655e873/attachment-0001.html
>>
>> ------------------------------
>>
>> Message: 5
>> Date: Thu, 20 Nov 2008 14:50:02 -0800
>> From: Jim Idle <jimi at temporal-wave.com>
>> Subject: Re: [antlr-interest] Does it make sense to use Antlr for
>> 	interactive parsing?
>> Cc: antlr-interest at antlr.org
>> Message-ID: <1227221402.22288.56.camel at jimi.temporal-wave.com>
>> Content-Type: text/plain; charset="us-ascii"
>>
>> On Thu, 2008-11-20 at 15:13 -0600, Vishwanath Hawargi wrote:
>>
>>> Hello,
>>>  Another dumb question from me.
>>>
>>> I am looking for parsing an expression from the command line. Each of
>>> these expressions are syntactically correct.
>>> Instead of having a input file, i am having one expression at a time
>>> to  be processed.
>>> In this situation is it optimal/ ok to use antlr to validate and
>>> generate the tokens?
>>>
>>> Also, how do i process input arg instead of input file?
>>>
>>
>>
>> It makes sense if the input is relatively complicated, but if it is
>> just: command {options} something, then probably custom code is as good.
>> You run it exactly the same way as a file but use the StringStream
>> rather than the file stream. See teh api docs:
>>
>> http://www.antlr.org/api/Java/classorg_1_1antlr_1_1runtime_1_1_a_n_t_l_r_string_stream.html
>> http://www.antlr.org/api/Java
>>
>> Jim
>>
>>
>>> please let me know.
>>>
>>> thank you.
>>> vishwa
>>>
>>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>>> Unsubscribe:
>>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>>
>>
>>
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL:
>> http://www.antlr.org/pipermail/antlr-interest/attachments/20081120/721a45a1/attachment-0001.html
>>
>> ------------------------------
>>
>> Message: 6
>> Date: Fri, 21 Nov 2008 13:32:58 +0900
>> From: Davyd Madeley <davyd at fugro-fsi.com.au>
>> Subject: [antlr-interest] Updated vim syntax highlighter
>> To: antlr-interest at antlr.org
>> Message-ID: <1227241978.751.152.camel at tc35>
>> Content-Type: text/plain; charset="us-ascii"
>>
>> I found an old vim syntax highlighter on antlr-interest,  but it didn't
>> deal very nicely with some things in my grammar.
>>
>> I've updated it and thought I'd share it with anyone who might be
>> interested.
>>
>> Add it to ~/.vim/syntax/
>>
>> And add something like this to your .vimrc:
>> au BufRead,BufNewFile *.g       set syntax=antlr3
>>
>> Regards,
>> --davyd
>>
>> --
>> Davyd Madeley        Software Engineer
>> Fugro Seismic Imaging, Perth Australia
>> -------------- next part --------------
>> A non-text attachment was scrubbed...
>> Name: antlr3.vim
>> Type: application/octet-stream
>> Size: 2040 bytes
>> Desc: not available
>> Url :
>> http://www.antlr.org/pipermail/antlr-interest/attachments/20081121/0e4bcde1/attachment-0001.obj
>>
>> ------------------------------
>>
>> Message: 7
>> Date: Thu, 20 Nov 2008 22:06:36 -0800
>> From: Jean Bovet <antlr-list at arizona-software.ch>
>> Subject: Re: [antlr-interest] Maven builds, hudson continuous
>> To: Terence Parr <parrt at cs.usfca.edu>
>> Cc: antlr-interest <antlr-interest at antlr.org>
>> Message-ID: <0990F569-A597-4BC1-9A04-AA97257C1077 at arizona-software.ch>
>> Content-Type: text/plain; charset=US-ASCII; format=flowed
>>
>> Great job Jim!
>>
>> Jean
>>
>> On Nov 20, 2008, at 10:28 AM, Terence Parr wrote:
>>
>>> HI everyone,
>>>
>>> Just wanted to follow up on this note to recognize Jim Idle (or is it
>>> Idol!?) for his extraordinary efforts to get maven and the continuous
>>> build server Hudson working! It really is a huge improvement in an
>>> area that I always lag behind (build systems).
>>>
>>> I'll update the website to include all of these links for easy
>>> reference.
>>>
>>> Ter
>>>
>>> On Nov 19, 2008, at 4:39 PM, Jim Idle wrote:
>>>
>>>> As some of you may have noticed, a lot of work has been done lately
>>>> to provide the ANTLR components as Maven artifacts
>>>> (http://maven.apache.org/
>>>> ), to provide an auto-syncing repository so that new release are
>>>> available via Maven within 4 hours of release and finally to create
>>>> Maven projects so that it is easy for people other than Ter to build
>>>> ANTLR.
>>>>
>>>> If you build Java projects and have not come across Maven then I
>>>> highly recommend taking the 10 minute tour as it is pretty useful.
>>>>
>>>> As a side effect of this work, if you install the Maven plugin into
>>>> your IDE (Netbeans/IDEA/Eclipse) then you will find that you can
>>>> open the directory that contains the ANTLR source code (look for the
>>>> pom.xml file) in the IDE and it will automatically know how to build
>>>> and test the software.
>>>>
>>>> A further side effect however, should make the need for you to build
>>>> your own development snapshots. This is because we have also
>>>> implemented an instance of the Hudson continuous build server. Here
>>>> you can find the latests build status of all the ANTLR tools and you
>>>> can download the latest development snapshot, if you are not using
>>>> Maven.
>>>>
>>>> You can find the hudson reports at: http://www.antlr.org:8888/
>>>> hudson  (JIRA is still at http://www.antlr.org:8888 )
>>>>
>>>> Finally, if you are a Maven user and for some reason feel the need
>>>> to build with the latest snapshot releases (perhaps to get a bug fix
>>>> and so on), then you can connect to the ANTLR snapshot repository by
>>>> specifying it in your maven pom.xml file as follows:
>>>>
>>>> <project> ...
>>>>
>>>>    <!--
>>>>
>>>>    Inform Maven of the ANTLR snapshot repository, which it will
>>>>    need to consult to get the latest snapshot build of the runtime
>>>>    and tool directories if it was not built and installed locally.
>>>>    -->
>>>>    <repositories>
>>>>
>>>>        <!--
>>>>        This is the ANTLR repository.
>>>>        -->
>>>>        <repository>
>>>>            <id>antlr-snapshot</id>
>>>>            <name>ANTLR Testing Snapshot Repository</name>
>>>>            <url>http://antlr.org/antlr-snapshot</url>
>>>>            <snapshots>
>>>>                <enabled>true</enabled>
>>>>                <updatePolicy>always</updatePolicy>
>>>>            </snapshots>
>>>>        </repository>
>>>>
>>>>    </repositories>
>>>> ...
>>>> </project>
>>>>
>>>>
>>>> Jim
>>>>
>>>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>>>> Unsubscribe:
>>>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>>>
>>>
>>>
>>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>>> Unsubscribe:
>>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>>
>>
>>
>>
>> ------------------------------
>>
>> Message: 8
>> Date: Fri, 21 Nov 2008 21:30:57 +0800
>> From: "chain one" <chainone at gmail.com>
>> Subject: [antlr-interest] How to get the last token type just
>> 	recognized in	the lexer?
>> To: antlr-interest <antlr-interest at antlr.org>
>> Message-ID:
>> 	<5a92ffb60811210530p6f807a85mb3968c853fe9e93f at mail.gmail.com>
>> Content-Type: text/plain; charset="iso-8859-1"
>>
>> I am right now using antlr V2 to write a parser.And I meet this
>> problem,don't know how to fix it.
>> The problem is:
>>
>> Lexer rule:
>>
>>
>> INT
>> :    (DIGIT)+
>> ;
>>
>> FLOAT
>> :    '.' (DIGIT)+ (('e' | 'E') ('+' | '-')? (DIGIT)+)?
>> |    '.' ('e' | 'E') ('+' | '-')? (DIGIT)+
>>      ;
>>
>> DIGIT
>> : '0'..'9'
>> ;
>>
>> I want to match the strings like:
>>
>> 0.1E-10
>> 0.1e+1
>> 0.0
>>
>> 0.E14
>>
>> To deal with the case like:"class.e9", ".e9" here could be accepted by
>> FLOAT
>> rule and ID rule
>>
>> So it seems that the only solution is to predict the last token just
>> recognized, if the last token is a INT, then FLOAT rule should be
>> followed.
>>
>> so I need to know what the last token is.
>> calling function LA(-1) could do this, however LA(-1) is only available in
>> parser not in lexer
>>
>> So...Is there anyone could tell me how to get the last token type
>> just recognized in the lexer?
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL:
>> http://www.antlr.org/pipermail/antlr-interest/attachments/20081121/0ce5b75c/attachment-0001.html
>>
>> ------------------------------
>>
>> Message: 9
>> Date: Fri, 21 Nov 2008 09:23:05 -0800
>> From: Jim Idle <jimi at temporal-wave.com>
>> Subject: Re: [antlr-interest] Updated vim syntax highlighter
>> To: Davyd Madeley <davyd at fugro-fsi.com.au>
>> Cc: antlr-interest at antlr.org
>> Message-ID: <1227288185.22288.89.camel at jimi.temporal-wave.com>
>> Content-Type: text/plain; charset="us-ascii"
>>
>> On Fri, 2008-11-21 at 13:32 +0900, Davyd Madeley wrote:
>>
>>> I found an old vim syntax highlighter on antlr-interest,  but it didn't
>>> deal very nicely with some things in my grammar.
>>>
>>> I've updated it and thought I'd share it with anyone who might be
>>> interested.
>>>
>>> Add it to ~/.vim/syntax/
>>>
>>> And add something like this to your .vimrc:
>>> au BufRead,BufNewFile *.g       set syntax=antlr3
>>>
>>
>> Works a treat for me :-)
>>
>> We should put this up as a download.
>>
>> Jim
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL:
>> http://www.antlr.org/pipermail/antlr-interest/attachments/20081121/12af141d/attachment-0001.html
>>
>> ------------------------------
>>
>> Message: 10
>> Date: Fri, 21 Nov 2008 11:34:47 -0800
>> From: Terence Parr <parrt at cs.usfca.edu>
>> Subject: Re: [antlr-interest] Updated vim syntax highlighter
>> To: Jim Idle <jimi at temporal-wave.com>
>> Cc: antlr-interest at antlr.org
>> Message-ID: <4AA6C070-81E3-4F0E-B9C1-FA4ED4BD4C51 at cs.usfca.edu>
>> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
>>
>> It's in share now.
>> Ter
>> On Nov 21, 2008, at 9:23 AM, Jim Idle wrote:
>>
>>> On Fri, 2008-11-21 at 13:32 +0900, Davyd Madeley wrote:
>>>>
>>>> I found an old vim syntax highlighter on antlr-interest,  but it
>>>> didn't
>>>> deal very nicely with some things in my grammar.
>>>>
>>>> I've updated it and thought I'd share it with anyone who might be
>>>> interested.
>>>>
>>>> Add it to ~/.vim/syntax/
>>>>
>>>> And add something like this to your .vimrc:
>>>> au BufRead,BufNewFile *.g       set syntax=antlr3
>>>>
>>> Works a treat for me :-)
>>>
>>> We should put this up as a download.
>>>
>>> Jim
>>>
>>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>>> Unsubscribe:
>>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>>
>>
>>
>>
>> ------------------------------
>>
>> _______________________________________________
>> antlr-interest mailing list
>> antlr-interest at antlr.org
>> http://www.antlr.org/mailman/listinfo/antlr-interest
>>
>>
>> End of antlr-interest Digest, Vol 48, Issue 19
>> **********************************************
>>
>
>
> --
> Su Zhang
> Computer Information and Science
> Kansas State University
>
>
> ------------------------------
>
> Message: 10
> Date: Sat, 22 Nov 2008 20:44:17 +0300
> From: " ?????? ????????? " <gmdidro at gmail.com>
> Subject: Re: [antlr-interest] Lexer rule with alternatives (Newbie
> 	question)
> To: antlr-interest <antlr-interest at antlr.org>
> Message-ID:
> 	<1dcb5c470811220944s642bae21hd5a791396bc9c1be at mail.gmail.com>
> Content-Type: text/plain; charset=KOI8-R
>
>> but there can be problems as '+' used in to different rules will create
>> two distinct token types which will cause a MismatchedTokenTypeException
>> later.
>
> This is exactly what happens with my grammar.
> Thank you very much.
>
> 2008/11/22 Johannes Luber <jaluber at gmx.de>:
>> ?????? ????????? schrieb:
>>> Hello,
>>> why such grammar doesn't work properly:
>>> --------------------------------------------------------------------------------------
>>> expr  :
>>>         operand ((oper) operand)*
>>>               ;
>>> //Correct operands
>>> operand       :
>>>       INT
>>>       ;
>>> OPER: ('+'|'-'|'*'|'/')
>>>       ;
>>> INT   :
>>>       ('0'..'9')+
>>>       ;
>>> --------------------------------------------------------------------------------------
>>>> t+1
>>> line 0:3 mismatched input '+' expecting EOF
>>>
>>> But if I replace the Lexer rule by Parser rule:
>>>
>>> oper: ('+'|'-'|'*'|'/');
>>>
>>> All work as it should. Why I should't use Lexer rule with alternatives ?
>>
>> The problem with your example is that in the expr rule you use oper, but
>> define OPER as rule. Did you overlook this while posting or does even
>>
>> expr    :
>>         operand (OPER operand)*
>>        ;
>>
>> not work? Nonetheless, the usual way to define operands is to create a
>> single rule for each operand and reference those lexer rules in a single
>> parser rule for convenience. As "oper: ('+'|'-'|'*'|'/');" creates
>> implicit lexer rules doing it this way simulates the described approach,
>> but there can be problems as '+' used in to different rules will create
>> two distinct token types which will cause a MismatchedTokenTypeException
>> later.
>>
>> Johannes
>>>
>>> Thank you
>>>
>>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>>> Unsubscribe:
>>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>>
>>
>>
>
> ------------------------------
>
> Message: 11
> Date: Sat, 22 Nov 2008 19:39:02 +0100
> From: Chris Sekszczynska <Development at ChrisSek.de>
> Subject: [antlr-interest] Write comments to templates
> To: antlr-interest at antlr.org
> Message-ID: <3F9FA3F1-5911-40D4-B64B-FA7ED1A0378C at ChrisSek.de>
> Content-Type: text/plain; charset="us-ascii"
>
> Hi all,
>
> after a longer search, I don't found a good way  to write comments
> from the source file to template output. My workflow is the following:
>
> 	Lexer (which puts comments into the hidden channel) -> parser (which
> creates an AST) -> walker (which writes output using StringTemplate)
>
> Now I like to write all comments occurring in the source file to the
> (nearly) same position in the destination file. So I have to pass the
> comments to the walker. Of cause, I could simply put the comments into
> the default token stream and add "Comment?" to every position in every
> rule. This will make my parser and walker grammars unreadable.
>
> Isn't there a better solution? Is it, for example, possible to scan
> the token stream parallel while the AST is parsed? So it could be
> possible to write comments to the StringTemplate output just after
> they appear in the input stream at the nearly same position (using
> token.index).
>
> I know, that it is not quite clear where to put comments occurring in
> the input stream. But it's not so important to keep the context. It's
> more important to write the comments more or less to the same position.
>
> Thanks for your help in advance.
>
> Kind regards,
>
> Chris
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://www.antlr.org/pipermail/antlr-interest/attachments/20081122/49d56a56/attachment-0001.html
>
> ------------------------------
>
> _______________________________________________
> antlr-interest mailing list
> antlr-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/antlr-interest
>
>
> End of antlr-interest Digest, Vol 48, Issue 20
> **********************************************
>


-- 
Su Zhang
PHD Candidate
Computer Information and Science
Kansas State University


More information about the antlr-interest mailing list