Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Cannot seem to properly reference (Having trouble using the referencing syntax. Getting rule and reference errors)
Cannot seem to properly reference [message #1034594] Fri, 05 April 2013 12:28 Go to next message
Eclipse UserFriend
Greetings:

I am attempting to do references in the language I am developing. The language I am developing has a syntax for representing latitudes and longitudes. This syntax is:

Boston: 42 N 21, 71 W 5
NewYork: 40 N 47, 73 W 58
Roanoke: 37 N 17, 79 W 57

What I would like to do is to be able to declare cities and later in my program refer back to them, like so:
if [Lat(Boston) is N] then write("Boston is in the Northern Hemisphere")

I have a set of rules that I am attempting to use to be able to construct such a syntax:

City:
Name=ID':' ladeg=INT LADir lamin=INT', 'lodeg=INT LODir lomin=INT
;

LODir: ('W' | 'E');

LADir: ('N' | 'S');

Function:
name=ID'('[City]')';

IfStat:
'if' '[' [Function] 'is' [LADir] 'then' Output
;

Output:
'write''('writing=STRING')'
;

I am getting all kinds of bizarre errors, some of them sayig that my "rules have to be unique" whenever I attempt to put in my references. I have read the section on references, and I do understand that the reference syntax '[]' refers to what is returned from the rule, but I am not actually changing what is supposed to be returned. Also: I do not see any reason why XTexy should say that my LADir and Output rules are not unique (My Output rule error goes away when M eliminate it in my IfStat rule!). I am slso getting errors with the [City] references.

I have read the section in the docuentation on References, and based on what little it actually says about them it looks like I am properly utilizing them.

I know something is not right here, I just don't know what that is. Could soeone please enlighten me???
Re: Cannot seem to properly reference [message #1034610 is a reply to message #1034594] Fri, 05 April 2013 12:59 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

looks like you have some missunderstandings regarding the syntax.

first you should assign things (if you call a rule)

'then' output=Output

then you should use cross refs only at places where you want to cross ref

Function:
name=ID'('[City]')';

is ok

[Function] not,

you should replace it with

function=Function
Re: Cannot seem to properly reference [message #1036751 is a reply to message #1034610] Mon, 08 April 2013 15:15 Go to previous messageGo to next message
Eclipse UserFriend
Thanks, Christian:

The corrections I made based on your suggestions enabled me to create the grammar successfully.

Unfortunately, I think that I am still not getting references.

In my test file I have the following:

Boston: 42 N 21, 71 W 5


Lat(Boston)

if[Lat(Boston) is N] then write("Boston is in Northern Hemisphere")

I am getting grammatical errors saying that it cannot find the reference to the city "Boston".

I *think* I understand the problem: I am referencing the City object for Boston (which I sort of want to do because ultimately I want to look at the Latitude value), but what I am actually using is the Name ID of the City (the "Name" which is "Boston").

In other words, I still don't think I understand references.

How can I get my grammar to properly refer to the City that has the name "Boston"?


Re: Cannot seem to properly reference [message #1036754 is a reply to message #1036751] Mon, 08 April 2013 15:17 Go to previous messageGo to next message
Eclipse UserFriend
HI,

can you share a complete grammar and test file
Re: Cannot seem to properly reference [message #1036766 is a reply to message #1036754] Mon, 08 April 2013 15:40 Go to previous messageGo to next message
Eclipse UserFriend
Btw it should be name=ID and not Name=ID (if you use the Upper Case variant you have to adopt IQualifiedNameProvider)
Re: Cannot seem to properly reference [message #1037408 is a reply to message #1036766] Tue, 09 April 2013 10:17 Go to previous messageGo to next message
Eclipse UserFriend
No problem.

The grammar is below:

grammar net.factor3.example.Discuss with org.eclipse.xtext.common.Terminals

generate discuss "http://www.factor3.net/example/Discuss"

Model:
greetings+=Line*;

Line:
(City | Function | IfStat)
;

City:
name=ID':' ladeg=INT LADir lamin=INT', 'lodeg=INT LODir lomin=INT
;

LODir: 'W' | 'E';

LADir: 'N' | 'S';

Function:
name=ID '(' city=[City] ')';

Output:
'write''('writing=STRING')'
;

IfStat:
'if' '[' func=Function 'is' lat=LADir ']' 'then' out=Output
;


The contents of th test file is below:

Boston: 42 N 21, 71 W 5


Lat(Boston)

if[Lat(Boston) is N] then write("Boston is in Northern Hemisphere")

Note that the errors occur wherever Lat(Boston) is, so the last two lines cause errors...
Re: Cannot seem to properly reference [message #1037538 is a reply to message #1037408] Tue, 09 April 2013 13:24 Go to previous messageGo to next message
Eclipse UserFriend
Sorry,

i cannot reproduce this. sure you regenerated the language and did not any other changes?
Re: Cannot seem to properly reference [message #1038962 is a reply to message #1037538] Thu, 11 April 2013 10:56 Go to previous message
Eclipse UserFriend
Actually:

I did give you an accurate copy of the language, but as it turns out I forgot to make a change to the language file after generating the artifacts.

Apparently, when you make changes to the grammar and regenerate the artifacts, your changes aren't reflected in the resulting language editor until you make a change to the file.

I had probably gotten this right days ago, but kept seeing errors until I added a change after seeing your last post. The grammar works without problems.

Sorry for the annoyance...
Previous Topic:Get position of a keyword/ rule, formatter
Next Topic:Validation adding to results each time
Goto Forum:
  


Current Time: Sun Jul 13 11:55:46 EDT 2025

Powered by FUDForum. Page generated in 0.05250 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top