Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compiler Tools JavaCC > Avoid SKIPping ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 10 Topic 469 of 540
Post > Topic >>

Avoid SKIPping while producing another terminal

by Cesare Zecca <Cesare.Zecca.prof@[EMAIL PROTECTED] > Aug 16, 2007 at 03:27 PM

Hi all

I took the NL_Xlator grammar  (see javacc-4.0\examples\SimpleExamples
\NL_Xlator.jj) as starting point for my grammar (named GpL) for a
relatively simple "arithmetic" language enriched with a limited set of
other features.
Currently the application has some entities with a string description
and its micro grammar
(identifiers, string and number literals, group names, and so on).
Current entities have their hand-coded token analyzers which have been
already unit tested.
E.g.
The Identifiers ("names" in the application jargon) do correspond to
the token

<ID : ["a"-"z", "A"-"Z","_"] ( ["a"-"z", "A"-"Z", "_", "0"-"9"] )* >

and have their domain class NameDom with its method canHadfle() that
analyzes if the provided string does respect the grammar rule quoted
just above.
The same holds for other enties (terminals).

I have the first skeleton of GpL.jj NL_XLator derived grammar.
I wrote the terminal

TOKEN :
{	<ID : ["a"-"z", "A"-"Z","_"] ( ["a"-"z", "A"-"Z", "_", "0"-"9"] )* >
|	<NUM: (["0"-"9"])+ >
|	<STRING_LITERAL
	: "\""	( ~["\"","\\","\n","\r"]
			| "\\"	( ["n","t","r","f","\\","\'","\""] )?
			| ( ["\n","\r"] | "\r\n" )
	        )* "\""
	>
}

and some non-terrminal rules (see javacc-4.0\examples\SimpleExamples
\NL_Xlator.jj)

ExpresssionList
->	Expression
	->	Term
		->	Factor()

To test a single, specific rule I isolated an Id() rule to call it
from the unit test class

String
Id() :
{
	Token lToken;
	String lResult;
}
{
	lToken = <ID>
	{
		lResult = lToken.image;
		return lResult;
	}
} // end GpL.Id()

Well, to test specifically the <ID> / Id() rule for identifiers, I
called the GpL.Id() method from the UT class and it would seem to
work.
Identifiers as

Call:   Id
  Consumed token: <<ID>: "myName_1_isOk" at line 1 column 1>
Return: Id

Call:   Id
  Consumed token: <<ID>: "_Foo2_boo2_goo2" at line 1 column 1>
Return: Id
are may others are all correctly "approved".

Instead the

"foo2 boo2"

string (that is NOT an <ID>) is wrogly approved (no ParseExpceptin is
thrown)

GpL.jj does contain the production

SKIP :
{	" "
|	"\t"
|	"\n"
|	"\r"
}

as well, but I would like that no skipping would be performed during
the <ID> / Id() rule.

Any suggestion?

Thanks in advance for any reply.

Ciao
Cesare
 




 10 Posts in Topic:
Avoid SKIPping while producing another terminal
Cesare Zecca <Cesare.Z  2007-08-16 15:27:50 
Avoid accepting prefix with (was Re: Avoid SKIPping while
AC <user@[EMAIL PROTEC  2007-08-18 07:42:40 
Re: Avoid accepting prefix with (was Re: Avoid SKIPping wh
Cesare Zecca <Cesare.Z  2007-08-20 12:35:20 
Re: Avoid accepting prefix with (was Re: Avoid SKIPping wh
Cesare Zecca <Cesare.Z  2007-08-21 17:25:51 
Re: Avoid accepting prefix with (was Re: Avoid SKIPping wh
AC <user@[EMAIL PROTEC  2007-08-24 07:44:08 
Unit tests for JavaCC tokens and productions (was: Avoid accepti
AC <user@[EMAIL PROTEC  2007-08-24 07:51:13 
Re: Unit tests for JavaCC tokens and productions (was: Avoid acc
Cesare Zecca <Cesare.Z  2007-08-28 15:03:43 
Re: Unit tests for JavaCC tokens and productions (was: Avoid acc
Cesare Zecca <Cesare.Z  2007-09-03 15:17:19 
Re: Unit tests for JavaCC tokens and productions
AC <user@[EMAIL PROTEC  2007-09-04 07:59:42 
Re: Unit tests for JavaCC tokens and productions
Cesare Zecca <Cesare.Z  2007-09-04 15:24:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Jul 6 18:58:55 CDT 2008.