Need help getting started on a grammar [message #1219861] |
Fri, 06 December 2013 10:20 |
Jordan Wallet Messages: 16 Registered: December 2013 |
Junior Member |
|
|
I've been going at the documentation for a good 4 hours now and I'm just about at the end of my rope. I'm trying to write a simple grammar that resembles a programming language and I can't get all the warnings/errors To go away.
The problem is that I can get any specific one to go away, so I don't know what's wrong with my approach. I feel like I lack some fundamental concept in A few examples of the problems I've run into:
The documentation never explicitly states what a "feature" (assigned value) is. What are they?
The documentation does not properly explain the difference between terminal rules and data type rules. No, really! For example, search the page for "above mentioned reasons", and then try to find reasons above it; you won't find any.
I'm not sure why I would want to, because the tutorials were written from a Java perspective and glossed over data types entirely, but I cannot set return types on terminals:
terminal NUMBER returns ecore::EInt: Quote:- Couldn't resolve reference to AbstractMetamodelDeclaration 'ecore'
- Cannot create datatype EInt
This makes me suspect that my project setup is broken, but I just went with the default, so I don't know what gives.
And then this gives me a 'Cannot change type twice within a rule' error:
ArithmeticExpression:
Variable'++' |
Variable'--' |
((Variable | ParensExpression | NUMBER) ARITHMETIC_OPERATOR ArithmeticExpression)
; But I'm not explicitly declaring any types (the return type above was just illustrative, it's usually not there), so shouldn't everything just be EStrings or inferred?
If anyone can shed any light on any if these issues, it would be greatly appreciated. (Incidentally, since these sorts of topics usually elicit "what are you trying to do?" types of responses: ultimately my goal, if I can get XText working at all, is an editor with a syntax highlighter and error checker.)
|
|
|
|
|
|
|
Re: Need help getting started on a grammar [message #1219927 is a reply to message #1219926] |
Fri, 06 December 2013 20:06 |
|
Hi,
the uri is just a name(space) not an url you can open with your browser
your grammar should look like
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Model:
greetings+=Greeting*;
Greeting:
'Hello' name=STRING count=MyInt 'times' '!';
MyInt returns ecore::EInt:
INT
;
and it should work out of the box
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Re: Need help getting started on a grammar [message #1219931 is a reply to message #1219928] |
Fri, 06 December 2013 21:09 |
|
Hi,
sorry without any reproducable grammar it is hard to say anything.
Feature is a term of ecore
(E) Classes consist of (EStrutural)Features. These features can be (E)Attributes (that have a simple type like EString or EInt or MyEnum) and (E)References. References can be contained (Children) or not contained (Cross References)
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Need help getting started on a grammar [message #1219938 is a reply to message #1219931] |
Fri, 06 December 2013 22:57 |
Jordan Wallet Messages: 16 Registered: December 2013 |
Junior Member |
|
|
To what end do I assign features in my rules? It's fine to say that it's a thing in another thing, but I can't find any explanation of how they are used in parsing or anything.
My errors all seem to arise when things can branch to a terminal or another rule. For example as I posted before
ArithmeticExpression:
Variable'++' |
Variable'--' |
((Variable | ParensExpression | NUMBER) ARITHMETIC_OPERATOR ArithmeticExpression)
;
Or something of the form
RuleOne:
RuleTwo | RuleThree | TERMINAL
;
Which gives a non-assignment warning, but then gives a "cannot find Type" error if I do something like
RuleOne:
result=(RuleTwo | RuleThree | TERMINAL)
;
Again, these all eventually reach endpoints with implicit return types, so I don't see why there's any problem with types.
EDIT: Here's a more concrete example:
StringClause:
clause=(LocalVariable | STRING_TERMINAL)
;
LocalVariable:
'#'symbol=SIMPLE_NAME
;
terminal fragment ALPHANUM:
('a'..'z'|'A'..'Z'|'0'..'9'|'_')
;
terminal SIMPLE_NAME:
('a'..'z')(ALPHANUM)*
;
terminal fragment ESCAPED_CHAR:
'\\'('n'|'t'|'\\'|'\"'|'\'')
;
terminal STRING_TERMINAL:
'"'(ESCAPED_CHAR | !('\''|'"'))*'"' |
'\''(ESCAPED_CHAR | !('\''|'"'))*'\''
;
The first rule gives a "cannot find type" error.
[Updated on: Fri, 06 December 2013 23:21] Report message to a moderator
|
|
|
Re: Need help getting started on a grammar [message #1219949 is a reply to message #1219938] |
Sat, 07 December 2013 08:57 |
|
Hi,
you mix up terminals and non terminals
StringClause:
clause=(LocalVariable | STRING_TERMINAL)
;
LocalVariable:
'#' value=SIMPLE_NAME
;
terminal fragment ALPHANUM:
('a'..'z'|'A'..'Z'|'0'..'9'|'_')
;
terminal SIMPLE_NAME:
('a'..'z')(ALPHANUM)*
;
terminal fragment ESCAPED_CHAR:
'\\'('n'|'t'|'\\'|'\"'|'\'')
;
terminal STRING_TERMINAL:
'"'(ESCAPED_CHAR | !('\''|'"'))*'"' |
'\''(ESCAPED_CHAR | !('\''|'"'))*'\''
;
or
StringClause:
child=LocalVariable | value=STRING_TERMINAL
;
LocalVariable:
'#' SIMPLE_NAME
;
terminal fragment ALPHANUM:
('a'..'z'|'A'..'Z'|'0'..'9'|'_')
;
terminal SIMPLE_NAME:
('a'..'z')(ALPHANUM)*
;
terminal fragment ESCAPED_CHAR:
'\\'('n'|'t'|'\\'|'\"'|'\'')
;
terminal STRING_TERMINAL:
'"'(ESCAPED_CHAR | !('\''|'"'))*'"' |
'\''(ESCAPED_CHAR | !('\''|'"'))*'\''
;
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Sat, 07 December 2013 09:18] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
Re: Need help getting started on a grammar [message #1227849 is a reply to message #1221165] |
Sun, 05 January 2014 20:22 |
Jordan Wallet Messages: 16 Registered: December 2013 |
Junior Member |
|
|
I'm still trying to find a solution for my DSL and I was wondering if Xtext is appropriate. I don't need something that compiles in Java, I just want something that can e.g. give me warnings about undeclared variables. Would another tool (e.g. LiClipse) be simpler to get up and running for such a purpose? I haven't made any headway at all with Xtext so far.
[Updated on: Sun, 05 January 2014 20:22] Report message to a moderator
|
|
|
|
|
|
Re: Need help getting started on a grammar [message #1254757 is a reply to message #1229546] |
Sun, 23 February 2014 19:42 |
Jordan Wallet Messages: 16 Registered: December 2013 |
Junior Member |
|
|
I'm back! Sorry to necro a thread after such a long absence, but I ate up my window of free time just trying to get this one issue resolved.
So if terminals cannot be derived from non-terminals, why are character ranges disabled in non-terminals? It seems really odd to need to define every single letter and numeral seperately.
EDIT: Now the issues are coming back to me. I just eliminated terminal rules and I still get "cannot find type" errors. Mixing the rules doesn't seem to be the issue.
On a related note, if anyone knows of any documentation on XText other than the official documentation, I'd be very grateful to know about it.
[Updated on: Sun, 23 February 2014 19:52] Report message to a moderator
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06425 seconds