[JavaCC] How to use loop in grammars?

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

[JavaCC] How to use loop in grammars?

by AlexanderPD :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi, i need to "convert" my grammar in JavaCC.. but javaCC doesn't accept loops in regular expression :(

i tried to write this:

TOKEN :
{
  < AUTOMA : "Automa" >
|   < DUEPUNTI : ":" >
| < AP2SL : < AUTOMA > <DUEPUNTI > <NOME>"\n{"<STATI>","<COPPIA>"\n"<TABTR>"." >
  | < NOME : ["A"-"Z"](["a"-"z","0"-"9"])+ >
  | < COPPIA: <STATI>","< COPPIA >"\n"<TABTR>":" | "}\n{" <LISTAALFABETO> "}\n}" <LISTASIMBOLIPILA >"}\n" >
  | < LISTASIMBOLIPILA : "$,"(<SPILA>",")+ >
  | < LISTAALFABETO : <ALFABETO>"," < LISTAALFABETO > | <ALFABETO> >
  | < TABTR : "{"<TRANSIZIONI>"}\n">
  | < TRANSIZIONI :"("(<SPILA>|"$")","(<ALFABETO>|"#")")->("<STATI>","<APILA>");"< TRANSIZIONI > | "("(<SPILA>|"$")","(<ALFABETO>|"#")")->("<STATI>","<APILA>")" >
  | < STATI : ["1"-"9"](["0"-"9"])* >
  | < ALFABETO : ["a"-"z"] >
  | < SPILA : ["A"-"Z"] >
  | < APILA : (<SPILA>)* >
}

and i get 3 looping errors :(
How to solve this? I need to write a method for each looping state?

Thank you, i'm getting mad on this :D

Re: How to use loop in grammars?

by Tom Copeland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Jun 19, 2009, at 11:38 AM, AlexanderPD wrote:

> Hi, i need to "convert" my grammar in JavaCC.. but javaCC doesn't  
> accept
> loops in regular expression :(
>
> i tried to write this:
>
> TOKEN :
> {
>  < AUTOMA : "Automa" >
> |   < DUEPUNTI : ":" >
> | < AP2SL : < AUTOMA > <DUEPUNTI >
> <NOME>"\n{"<STATI>","<COPPIA>"\n"<TABTR>"." >
>  | < NOME : ["A"-"Z"](["a"-"z","0"-"9"])+ >
>  | < COPPIA: <STATI>","< COPPIA >"\n"<TABTR>":" | "}\n{"  
> <LISTAALFABETO>
> "}\n}" <LISTASIMBOLIPILA >"}\n" >
>  | < LISTASIMBOLIPILA : "$,"(<SPILA>",")+ >
>  | < LISTAALFABETO : <ALFABETO>"," < LISTAALFABETO > | <ALFABETO> >
>  | < TABTR : "{"<TRANSIZIONI>"}\n">
>  | < TRANSIZIONI
> :"("(<SPILA>|"$")","(<ALFABETO>|"#")")->("<STATI>","<APILA>");"<  
> TRANSIZIONI
>> | "("(<SPILA>|"$")","(<ALFABETO>|"#")")->("<STATI>","<APILA>")" >
>  | < STATI : ["1"-"9"](["0"-"9"])* >
>  | < ALFABETO : ["a"-"z"] >
>  | < SPILA : ["A"-"Z"] >
>  | < APILA : (<SPILA>)* >
> }
>
> and i get 3 looping errors :(
> How to solve this? I need to write a method for each looping state?
>
> Thank you, i'm getting mad on this :D

Hi Alexander -

Perhaps you may need to use a state stack in your tokenizer to solve  
the problem.  Can you post an example of the input data which you're  
trying to parse?

Yours,

tom

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


Re: How to use loop in grammars?

by AlexanderPD :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sure, this is an example of input:

Automa : Automa_anbn
{1,2,}
{a,b}
{$,N}
{($,a)­>(1,N);(N,a)­>(1,NN);(N,b)­>(2,#)}:
{(N,b)­>(2,#)}.

i realize that i can't use a regular expression as token.. i must study more javacc :P

Tom Copeland wrote:
On Jun 19, 2009, at 11:38 AM, AlexanderPD wrote:
> Hi, i need to "convert" my grammar in JavaCC.. but javaCC doesn't  
> accept
> loops in regular expression :(
>
> i tried to write this:
>
> TOKEN :
> {
>  < AUTOMA : "Automa" >
> |   < DUEPUNTI : ":" >
> | < AP2SL : < AUTOMA > <DUEPUNTI >
> <NOME>"\n{"<STATI>","<COPPIA>"\n"<TABTR>"." >
>  | < NOME : ["A"-"Z"](["a"-"z","0"-"9"])+ >
>  | < COPPIA: <STATI>","< COPPIA >"\n"<TABTR>":" | "}\n{"  
> <LISTAALFABETO>
> "}\n}" <LISTASIMBOLIPILA >"}\n" >
>  | < LISTASIMBOLIPILA : "$,"(<SPILA>",")+ >
>  | < LISTAALFABETO : <ALFABETO>"," < LISTAALFABETO > | <ALFABETO> >
>  | < TABTR : "{"<TRANSIZIONI>"}\n">
>  | < TRANSIZIONI
> :"("(<SPILA>|"$")","(<ALFABETO>|"#")")->("<STATI>","<APILA>");"<  
> TRANSIZIONI
>> | "("(<SPILA>|"$")","(<ALFABETO>|"#")")->("<STATI>","<APILA>")" >
>  | < STATI : ["1"-"9"](["0"-"9"])* >
>  | < ALFABETO : ["a"-"z"] >
>  | < SPILA : ["A"-"Z"] >
>  | < APILA : (<SPILA>)* >
> }
>
> and i get 3 looping errors :(
> How to solve this? I need to write a method for each looping state?
>
> Thank you, i'm getting mad on this :D

Hi Alexander -

Perhaps you may need to use a state stack in your tokenizer to solve  
the problem.  Can you post an example of the input data which you're  
trying to parse?

Yours,

tom

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@javacc.dev.java.net
For additional commands, e-mail: users-help@javacc.dev.java.net

Re: How to use loop in grammars?

by Tom Copeland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Jun 20, 2009, at 9:08 AM, AlexanderPD wrote:

>
> Sure, this is an example of input:
>
> Automa : Automa_anbn
> {1,2,}
> {a,b}
> {$,N}
> {($,a) >(1,N);(N,a) >(1,NN);(N,b) >(2,#)}:
> {(N,b) >(2,#)}.
>
> i realize that i can't use a regular expression as token.. i must  
> study more
> javacc :P

Cool, yeah, you may have better results if you make your tokenizer a  
bit simpler - just separating ($,a) into  
LPAREN,DOLLAR,COMMA,ALPHA,RPAREN - and letting the parser handle the  
higher level structure.

Yours,

Tom
http://generatingparserswithjavacc.com/



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