Regarding VB.Net Grammar

View: New views
19 Messages — Rating Filter:   Alert me  

Regarding VB.Net Grammar

by Kishore1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All;

I am new to Javacc therefore my post is a question for everyone who knows Javacc better than me.

I am in search of a Java based parser + AST for VB.Net. I tried/read few tools for this task like Gold Parser. But this tool grammar is incomplete/incorrect and not provide the AST as well.

Now I have started reading about Javacc grammar and going to write new grammar file for VB.Net.
Please tell me, what time will it take to complete the grammar/ Or Am I going in a wrong direction due to presence of a grammar anywhere??



Please don't ignore my post, Ans me immediately.

Thanks In Advance
Kishore1

RE: Re[JavaCC] garding VB.Net Grammar

by Laughing Man :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
The only list of grammars that I know of is at https://javacc.dev.java.net/servlets/ProjectDocumentList?folderID=110

I'm not at all familiar with .NET, so I don't know if it's especially different than regular visual basic which is on the list.

If not, you could make one. Though that can be a bit tricky.

> Date: Thu, 17 Jul 2008 06:19:36 -0700
> From: kishore_74_lko@...
> To: users@...
> Subject: [JavaCC] Re[JavaCC] garding VB.Net Grammar
>
>
> Hi All;
>
> I am new to Javacc therefore my post is a question for everyone who knows
> Javacc better than me.
>
> I am in search of a Java based parser + AST for VB.Net. I tried/read few
> tools for this task like Gold Parser. But this tool grammar is
> incomplete/incorrect and not provide the AST as well.
>
> Now I have started reading about Javacc grammar and going to write new
> grammar file for VB.Net.
> Please tell me, what time will it take to complete the grammar/ Or Am I
> going in a wrong direction due to presence of a grammar anywhere??
>
>
> Please don't ignore my post, Ans me immediately.
>
> Thanks In Advance
> Kishore1
> --
> View this message in context: http://www.nabble.com/Regarding-VB.Net-Grammar-tp18507856p18507856.html
> Sent from the java.net - javacc users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>


Discover the new Windows Vista Learn more!

Re: Regarding VB.Net Grammar

by Kishore1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for giving reply.

Yes the above mentioned link contains VB grammar but that jj file (grammar) is verbose due to contains code & less grammar, I can not understand to much of that file.

Pls tell me any other link or Tell me what time is required to craete a new grammar file for VB.net??

Thanks again
Kishore1

RE: Re: Re[JavaCC] garding VB.Net Grammar

by Laughing Man :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
The amount of time it would take would vary considerably depending on the individual.

You'll have to learn JavaCC. The Tutorials that come with JavaCC aren't that great, so I would recommend getting Tom Copeland's book (Generating Parsers with JavaCC. You'll almost certainly have to order this online because JavaCC is very obscure.) It'll cost you some money, but you'd figure the stuff out a bit faster... Probably.

If I had to give a number, (and I don't want to) I would guess one to three months to figure out the basics. I wouldn't be able to tell you how long it to rewrite the grammar. It would probably be more time efficient to spend a few hours trying to learn what's in the VB grammar itself, but by rewriting it you would probably understand JavaCC better.

What is it that you're trying to do anyways? You might have a "weird" situation, in which case everything is harder and more interesting :P

> Date: Thu, 17 Jul 2008 06:57:01 -0700
> From: kishore_74_lko@...
> To: users@...
> Subject: [JavaCC] Re: Re[JavaCC] garding VB.Net Grammar
>
>
> Thanks for giving reply.
>
> Yes the above mentioned link contains VB grammar but that jj file (grammar)
> is verbose due to contains code & less grammar, I can not understand to much
> of that file.
>
> Pls tell me any other link or Tell me what time is required to craete a new
> grammar file for VB.net??
>
> Thanks again
> Kishore1
> --
> View this message in context: http://www.nabble.com/Regarding-VB.Net-Grammar-tp18507856p18509031.html
> Sent from the java.net - javacc users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>


Get news, entertainment and everything you care about at Live.com. Check it out!

RE: Re: Re[JavaCC] garding VB.Net Grammar

by Kishore1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Laughing Man;

Thanks for giving such a valuable comments on my post.

Currently I have a little problem while parsing a VB.Net source file by using a small grammar written by me. I have declared the following portion in grammar:

----------------------------------------------------------------------------------
SPECIAL_TOKEN : /* WHITE SPACE */
{
    <SPACE: ( " " | "\t" | "\r" | "\f" | " _\r\n" )+ >
}

<START_OF_LINE> SPECIAL_TOKEN :
{
   <LEADING_SPACE: ( " " | "\t" | "\r" | "\f" | " _\r\n" )+ >
}

SKIP :
{
  <(<SPACE>)*("\r\n" | "\n" | "\r")>
}

TOKEN :
{
   < LineTerminator :  ("\r\n"| "\n" | "\r") >  
}



void CompilationUnit() :
{}
{
   [ (ImportsStatement())+ ]
   <EOF>
}


void ImportsStatement():
{}
{
  <IMPORTS> <IDENTIFIER> <LineTerminator>
}

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

The <IMPORTS> and <IDENTIFIER> are well defined sets in the same grammar. But when I parse
the following VB.Net code file having only these 2 lines:

Imports Microsoft.VisualBasic
Imports System.Data


The paresr generates the following error:

------------------------------------------------
Encountered "Imports" at line 2, column 1.
Was expecting:
    <LineTerminator> ...
------------------------------------------------


Please tell me what is the problem in my grammar??

Thanks in advance
kishore1

Re: RE: Re: Re[JavaCC] garding VB.Net Grammar

by Stuart A. Yeates :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The problem is that SKIP and LineTerminator both contain "\r\n", "\n"
and "\r" and SKIP is first.

cheers
stuart

On Fri, Jul 18, 2008 at 8:03 PM, Kishore1 <kishore_74_lko@...> wrote:

>
> Hi Laughing Man;
>
> Thanks for giving such a valuable comments on my post.
>
> Currently I have a little problem while parsing a VB.Net source file by
> using a small grammar written by me. I have declared the following portion
> in grammar:
>
> ----------------------------------------------------------------------------------
> SPECIAL_TOKEN : /* WHITE SPACE */
> {
>    <SPACE: ( " " | "\t" | "\r" | "\f" | " _\r\n" )+ >
> }
>
> <START_OF_LINE> SPECIAL_TOKEN :
> {
>   <LEADING_SPACE: ( " " | "\t" | "\r" | "\f" | " _\r\n" )+ >
> }
>
> SKIP :
> {
>  <(<SPACE>)*("\r\n" | "\n" | "\r")>
> }
>
> TOKEN :
> {
>   < LineTerminator :  ("\r\n"| "\n" | "\r") >
> }
>
>
>
> void CompilationUnit() :
> {}
> {
>   [ (ImportsStatement())+ ]
>   <EOF>
> }
>
>
> void ImportsStatement():
> {}
> {
>  <IMPORTS> <IDENTIFIER> <LineTerminator>
> }
>
> -------------------------------------------------------------------------------------
> The <IMPORTS> and <IDENTIFIER> are well defined sets in the same grammar.
> But when I parse
> the following VB.Net code file having only these 2 lines:
>
> Imports Microsoft.VisualBasic
> Imports System.Data
>
> The paresr generates the following error:
>
> ------------------------------------------------
> Encountered "Imports" at line 2, column 1.
> Was expecting:
>    <LineTerminator> ...
> ------------------------------------------------
>
> Please tell me what is the problem in my grammar??
>
> Thanks in advance
> kishore1
>
> --
> View this message in context: http://www.nabble.com/Regarding-VB.Net-Grammar-tp18507856p18524409.html
> Sent from the java.net - javacc users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: RE: Re: Re[JavaCC] garding VB.Net Grammar

by Kishore1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Stuart for valuable reply.

According to your suggestion I have removed the SKIP token from the grammar and rest is same but now the newline problem is still there with another source code file like:

---------------------------------------------------------------------------------
Imports System.Data
Imports System.Data.Common

Public Class AfeDataHandler
    Const DBNAME_AFE As String = "ParkerIntAppAfe"
    Const DBNAME_AFE_CACHED As String = "ParkerIntAppAfe"
    Const DBNAME_COMMON As String = "ParkerIntCommon"

    Function GetExchangeRate(ByVal Currency As String) As Decimal
    Return GetExchangeRate
    End Function
   
End Class
---------------------------------------------------------------------------------


On parsing above code the parser generates this error:

==============================
Encountered "Const" at line 6, column 5.
Was expecting one of:
    <LineTerminator> ...
    <IDENTIFIER> ...
==============================

What is the problem in my grammar now? please explain me.
Thanks in advance
Kishore

Re: Re: RE: Re: Re[JavaCC] garding VB.Net Grammar

by Sreenivasa Viswanadha :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You should really use the DEBUG_PARSER and DEBUG_TOKEN_MANAGER options.
That prints out how the lexer and parser are processing your input. That
should help you debug the issues.

> Thanks Stuart for valuable reply.
>
> According to your suggestion I have removed the SKIP token from the grammar
> and rest is same but now the newline problem is still there with another
> source code file like:
>
> ---------------------------------------------------------------------------------
> Imports System.Data
> Imports System.Data.Common
>
> Public Class AfeDataHandler
>     Const DBNAME_AFE As String = "ParkerIntAppAfe"
>     Const DBNAME_AFE_CACHED As String = "ParkerIntAppAfe"
>     Const DBNAME_COMMON As String = "ParkerIntCommon"
>
>     Function GetExchangeRate(ByVal Currency As String) As Decimal
>     Return GetExchangeRate
>     End Function
>    
> End Class
> ---------------------------------------------------------------------------------
>
> On parsing above code the parser generates this error:
>
> ==============================
> Encountered "Const" at line 6, column 5.
> Was expecting one of:
>     <LineTerminator> ...
>     <IDENTIFIER> ...
> ==============================
>
> What is the problem in my grammar now? please explain me.
> Thanks in advance
> Kishore
>
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Re: RE: Re: Re[JavaCC] garding VB.Net Grammar

by Kishore1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Since in VB.Net line terminator is a part of syntax hence I have defined it as:

<LineTerminator :  ("\r\n"| "\n" | "\r") >


This token is referred in most part of grammar to define any complete production lets say:

void ImportsStatement():
{}
{
  <IMPORTS> <IDENTIFIER> <LineTerminator>
}


Also there can be many blank lines in source code of VB.Net to be parsed, How these blank lines can be distinguish from   <LineTerminator>.

-------------------------------------------------------------
When these code lines are parsed :

Imports System.Data
Imports System.Data.Common


No error comes but with a blank line in between above 2 lines like:

Imports System.Data

Imports System.Data.Common


the parser generates this error:

Encountered "Imports" at line 3, column 1.
Was expecting one of:
    <EOF>
    "#" ...
    <WhiteSpace> ...

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

Pls see my problem & give a complete suggestion/solution.

Thanks In Advance
Kishore1

Re: Re: Re: RE: Re: Re[JavaCC] garding VB.Net Grammar

by J.Chris Findlay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Try using (<LineTerminator>)+ instead as this will allow blank lines anywhere.

On Mon, Jul 21, 2008 at 6:52 PM, Kishore1 <kishore_74_lko@...> wrote:

Since in VB.Net line terminator is a part of syntax hence I have defined it
as:

<LineTerminator :  ("\r\n"| "\n" | "\r") >

This token is referred in most part of grammar to define any complete
production lets say:

void ImportsStatement():
{}
{
 <IMPORTS> <IDENTIFIER> <LineTerminator>
}

Also there can be many blank lines in source code of VB.Net to be parsed,
How these blank lines can be distinguish from   <LineTerminator>.

-------------------------------------------------------------
When these code lines are parsed :

Imports System.Data
Imports System.Data.Common


No error comes but with a blank line in between above 2 lines like:

Imports System.Data

Imports System.Data.Common


the parser generates this error:

Encountered "Imports" at line 3, column 1.
Was expecting one of:
   <EOF>
   "#" ...
   <WhiteSpace> ...
--------------------------------------------------------------

Pls see my problem & give a complete suggestion/solution.

Thanks In Advance
Kishore1
--
View this message in context: http://www.nabble.com/Regarding-VB.Net-Grammar-tp18507856p18563094.html
Sent from the java.net - javacc users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...




--
- J.Chris Findlay
(c:

Re: Re: Re: RE: Re: Re[JavaCC] garding VB.Net Grammar

by Kishore1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi J.Chris Findlay

Thanks for a suggestion. I replaces all LineTerminator with (<LineTerminator>)+ as you told. That problem is solved but again same type of problem is coming in next code given here:

--------------------------------------------------------------------------------
Imports System.Data

Imports System.Data.Common

Public Class AfeDataHandler

    Const DBNAME_AFE As String = "ParkerIntAppAfe"
   
    Const DBNAME_AFE_CACHED As String = "ParkerIntAppAfe"
   
    Const DBNAME_COMMON As String = "ParkerIntCommon"
   
End Class

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


the parser generates this error on above code:

Encountered "Const" at line 9, column 5.
Was expecting:
    <LineTerminator> ...



In grammar file I have defined the following well defined productions:

---------------------------------------------------------------------
void ConstantMemberDeclaration() :
{}
{
   [ Attributes() ] [ (ConstantModifier())+ ] <CONST> ConstantDeclarators() (<LineTerminator>)+
}
void ConstantModifier() :
{}
{
   AccessModifier() | <SHADOWS>
}  
void ConstantDeclarators() :
{}
{
   ConstantDeclarator()
}
void ConstantDeclarator() :
{}
{
   <IDENTIFIER> [ <AS> TypeName() ] <ASSIGN> ConstantExpression() (<LineTerminator>)+
}

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

Please tell, what is the problem in my grammar????

Thanks
Kishore1

Re: Re: Re: Re: RE: Re: Re[JavaCC] garding VB.Net Grammar

by Dale Anson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Try removing

(<LineTerminator>)+

from

void ConstantDeclarator()

This production is consuming the line terminators, but ConstantMemberDeclaration() is still expecting one.


Dale



Kishore1 wrote:

> Hi J.Chris Findlay
>
> Thanks for a suggestion. I replaces all LineTerminator with
> (<LineTerminator>)+ as you told. That problem is solved but again same type
> of problem is coming in next code given here:
>
> --------------------------------------------------------------------------------
> Imports System.Data
>
> Imports System.Data.Common
>
> Public Class AfeDataHandler
>
>     Const DBNAME_AFE As String = "ParkerIntAppAfe"
>    
>     Const DBNAME_AFE_CACHED As String = "ParkerIntAppAfe"
>    
>     Const DBNAME_COMMON As String = "ParkerIntCommon"
>    
> End Class
>
> --------------------------------------------------------------------------------
>
>
> the parser generates this error on above code:
>
> Encountered "Const" at line 9, column 5.
> Was expecting:
>     <LineTerminator> ...
>
>
> In grammar file I have defined the following well defined productions:
>
> ---------------------------------------------------------------------
> void ConstantMemberDeclaration() :
> {}
> {
>    [ Attributes() ] [ (ConstantModifier())+ ] <CONST> ConstantDeclarators()
> (<LineTerminator>)+
> }
> void ConstantModifier() :
> {}
> {
>    AccessModifier() | <SHADOWS>
> }  
> void ConstantDeclarators() :
> {}
> {
>    ConstantDeclarator()
> }
> void ConstantDeclarator() :
> {}
> {
>    <IDENTIFIER> [ <AS> TypeName() ] <ASSIGN> ConstantExpression()
> (<LineTerminator>)+
> }
> ---------------------------------------------------------------------
>
> Please tell, what is the problem in my grammar????
>
> Thanks
> Kishore1
>
>  

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Re: Re: Re: RE: Re: Re[JavaCC] garding VB.Net Grammar

by Kishore1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Dale for a suggestion.

I want to ask a another question. If this is given language specification :

InvocationExpression ::= Expression [ ( [ ArgumentList ] ) ]
ArgumentList ::=
   PositionalArgumentList , NamedArgumentList |
   PositionalArgumentList |
   NamedArgumentList
PositionalArgumentList ::=
   Expression |
   PositionalArgumentList , [ Expression ]
NamedArgumentList ::=
   IdentifierOrKeyword : = Expression |
   NamedArgumentList , IdentifierOrKeyword : = Expression


Then I have written the following productions in grammar :

void InvocationExpression() :
{}
{
   Expression() [ <LPAREN> [ ArgumentList() ] <RPAREN> ]
}
void ArgumentList() :
{}
{
   PositionalArgumentList() <COMMA> NamedArgumentList()| PositionalArgumentList() | NamedArgumentList()
}  
void PositionalArgumentList():
{}
{
  Expression() (<COMMA> [Expression()])*
}  
void NamedArgumentList() :
{}
{
   ((<IDENTIFIER> | Literal()) <COLON> <ASSIGN> Expression()) (<COMMA> (<IDENTIFIER> | Literal()) <COLON> <ASSIGN> Expression())*
}


Pls tell me whether my understanding is correct or not? Is there any bugs in my implementation??

Thanks
Kishore1

Re: Re: Re: Re: RE: Re: Re[JavaCC] garding VB.Net Grammar

by Kishore1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All;

Why No one is answering my question? Is it tough?

After all you all are genius person in JavaCC field.

If you all do not help me, then how will I complete my Grammar.


Pls say something.......


Thanks ALL

Kishore1  

Re: Re: Re: Re: Re: RE: Re: Re[JavaCC] garding VB.Net Grammar

by Stuart A. Yeates :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Jul 25, 2008 at 7:06 PM, Kishore1 <kishore_74_lko@...> wrote:
>
> Hi All;
>
> Why No one is answering my question? Is it tough?

It may be related to the way you are asking your questions.

There is a really good document on getting answers to questions in
open source projects at
http://www.catb.org/~esr/faqs/smart-questions.html

cheers
stuart

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Re: Re: Re: Re: RE: Re: Re[JavaCC] garding VB.Net Grammar

by Kishore1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Stuart for telling guidelines about how to post a question.

I am again asking my question. If this part is VB.Net language specification :

InvocationExpression ::= Expression [ ( [ ArgumentList ] ) ]
ArgumentList ::=
   PositionalArgumentList , NamedArgumentList |
   PositionalArgumentList |
   NamedArgumentList
PositionalArgumentList ::=
   Expression |
   PositionalArgumentList , [ Expression ]
NamedArgumentList ::=
   IdentifierOrKeyword : = Expression |
   NamedArgumentList , IdentifierOrKeyword : = Expression


Then will the following productions in grammar is correct:

void InvocationExpression() :
{}
{
   Expression() [ <LPAREN> [ ArgumentList() ] <RPAREN> ]
}
void ArgumentList() :
{}
{
   PositionalArgumentList() <COMMA> NamedArgumentList()| PositionalArgumentList() | NamedArgumentList()
}  
void PositionalArgumentList():
{}
{
  Expression() (<COMMA> [Expression()])*
}  
void NamedArgumentList() :
{}
{
   ((<IDENTIFIER> | Literal()) <COLON> <ASSIGN> Expression()) (<COMMA> (<IDENTIFIER> | Literal()) <COLON> <ASSIGN> Expression())*
}


Tell if there is any bugs in my approach.

Thanks
Kishore1

Re: Re: Re: Re: Re: Re: RE: Re: Re[JavaCC] garding VB.Net Grammar

by Paul Cager-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, July 25, 2008 11:24, Kishore1 wrote:

>
> Thanks Stuart for telling guidelines about how to post a question.
>
> I am again asking my question. If this part is VB.Net language
> specification
> :
>
> InvocationExpression ::= Expression [ ( [ ArgumentList ] ) ]
> ArgumentList ::=
>    PositionalArgumentList , NamedArgumentList |
>    PositionalArgumentList |
>    NamedArgumentList
> PositionalArgumentList ::=
>    Expression |
>    PositionalArgumentList , [ Expression ]
> NamedArgumentList ::=
>    IdentifierOrKeyword : = Expression |
>    NamedArgumentList , IdentifierOrKeyword : = Expression
>
>
> Then will the following productions in grammar is correct:
>
> void InvocationExpression() :
> {}
> {
>    Expression() [ <LPAREN> [ ArgumentList() ] <RPAREN> ]
> }
> void ArgumentList() :
> {}
> {
>    PositionalArgumentList() <COMMA> NamedArgumentList()|
> PositionalArgumentList() | NamedArgumentList()
> }
> void PositionalArgumentList():
> {}
> {
>   Expression() (<COMMA> [Expression()])*
> }
> void NamedArgumentList() :
> {}
> {
>    ((<IDENTIFIER> | Literal()) <COLON> <ASSIGN> Expression()) (<COMMA>
> (<IDENTIFIER> | Literal()) <COLON> <ASSIGN> Expression())*
> }
>
> Tell if there is any bugs in my approach.
>
> Thanks
> Kishore1

I think that representation will generate lots of choice conflicts, for
example both PositionalArgumentList and NamedArgumentList can start with
an identifier (or literal). You could solve that problem by using
lookahead (see http://www.engr.mun.ca/~theo/JavaCC-FAQ) but I think you
probably need to refactor the grammar into a form that is more friendly to
recursive descent compilation. Again the FAQ should help you get started
with this.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Re: Re: Re: Re: RE: Re: Re[JavaCC] garding VB.Net Grammar

by Theodore Norvell :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Kishore1 wrote:
> Hi All;
>
> Why No one is answering my question? Is it tough?
Actually I did reply, although my reply doesn't seem to have reached the
list.  It is not tough.  You just n