Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Validation of the Xbase Expression grammar with Xsemantics
Validation of the Xbase Expression grammar with Xsemantics [message #1407767] Wed, 13 August 2014 12:09 Go to next message
Günther Fiedler is currently offline Günther FiedlerFriend
Messages: 21
Registered: February 2013
Junior Member
Hello,

I´m currently working on the validation of a Expression grammar. I integrated the complete Xbase Expression grammar in my own Xtext language.

Following link shows the Xbase grammar: https://github.com/eclipse/xtext/blob/master/plugins/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/Xbase.xtext

I think that Xsemantics is perfect for my validation, although this language is new for me. Below is shown my first try to implement a validation according to the example project.

Maybe there is someone who can correct me, or give me a first introduction example for the Xbase grammar.

Kind regards,
Günther


judgments {
type |- Expression Expression : output Object
error "cannot type " + stringRep(CmfExpression)
source Expression

}
rule ExpressionBin
G |- ExpressionBinaryOperation binop : Object type

from {
G |- binop.leftOperand : var Object leftType
G |- binop.rightOperand : var Object rightType

if (binop.^feature == "=")
{
(leftType instanceof ExpressionVariableDeclaration && rightType instanceof PrimitiveDataType)
type = DslFactory::eINSTANCE.createPrimitiveDataType
}
else if (binop.^feature == "+=" )
{
(leftType instanceof CmfExpressionVariableDeclaration && rightType instanceof PrimitiveDataType)
type = CmfDslFactory::eINSTANCE.createPrimitiveDataType
}
else if (cmfbinop.^feature == "-=" )
{
(leftType instanceof ExpressionVariableDeclaration && rightType instanceof PrimitiveDataType)
type = DslFactory::eINSTANCE.createPrimitiveDataType
}
else if (binop.^feature == "*=" )
{
(leftType instanceof ExpressionVariableDeclaration && rightType instanceof PrimitiveDataType)
type = DslFactory::eINSTANCE.createPrimitiveDataType
}
else if (binop.^feature == "/=" )
{
(leftType instanceof ExpressionVariableDeclaration && rightType instanceof PrimitiveDataType)
type = DslFactory::eINSTANCE.createPrimitiveDataType
}
else if (binop.^feature == "||")
{
(leftType instanceof BoolPrimitiveType && rightType instanceof BoolPrimitiveType)
type = DslFactory::eINSTANCE.createBoolPrimitiveType
}
else if (binop.^feature == "&&")
{
(leftType instanceof BoolPrimitiveType && rightType instanceof BoolPrimitiveType)
type = DslFactory::eINSTANCE.createBoolPrimitiveType
}
else if (binop.^feature == ">=")
{
(leftType instanceof PrimitiveDataType && rightType instanceof PrimitiveDataType)
type = DslFactory::eINSTANCE.createBoolPrimitiveType
}
else if (binop.^feature == "+")
{
(leftType instanceof PrimitiveDataType && rightType instanceof PrimitiveDataType)
if (leftType instanceof IntPrimitiveType){
rightType = leftType
type = leftType
}
type = DslFactory::eINSTANCE.createBoolPrimitiveType
}

}



Re: Validation of the Xbase Expression grammar with Xsemantics [message #1408838 is a reply to message #1407767] Sat, 16 August 2014 07:29 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 13/08/2014 14:09, Günther Fiedler wrote:
> Hello,
>
> I´m currently working on the validation of a Expression grammar. I
> integrated the complete Xbase Expression grammar in my own Xtext language.
> Following link shows the Xbase grammar:
> https://github.com/eclipse/xtext/blob/master/plugins/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/Xbase.xtext
>
>
> I think that Xsemantics is perfect for my validation, although this
> language is new for me. Below is shown my first try to implement a
> validation according to the example project.
> Maybe there is someone who can correct me, or give me a first
> introduction example for the Xbase grammar.
>
> Kind regards,
> Günther
>
>
> judgments {
> type |- Expression Expression : output Object
> error "cannot type " + stringRep(CmfExpression)
> source Expression
>
> }
> rule ExpressionBin
> G |- ExpressionBinaryOperation binop : Object type
>
> from {
> G |- binop.leftOperand : var Object leftType
> G |- binop.rightOperand : var Object rightType
>
> if (binop.^feature == "=")
> {
> (leftType instanceof ExpressionVariableDeclaration && rightType
> instanceof PrimitiveDataType)
> type = DslFactory::eINSTANCE.createPrimitiveDataType
> }
> else if (binop.^feature == "+=" )
> {
> (leftType instanceof CmfExpressionVariableDeclaration && rightType
> instanceof PrimitiveDataType)
> type = CmfDslFactory::eINSTANCE.createPrimitiveDataType
> }
> else if (cmfbinop.^feature == "-=" )
> {
> (leftType instanceof ExpressionVariableDeclaration && rightType
> instanceof PrimitiveDataType)
> type = DslFactory::eINSTANCE.createPrimitiveDataType
> }
> else if (binop.^feature == "*=" )
> {
> (leftType instanceof ExpressionVariableDeclaration && rightType
> instanceof PrimitiveDataType)
> type = DslFactory::eINSTANCE.createPrimitiveDataType
> }
> else if (binop.^feature == "/=" )
> {
> (leftType instanceof ExpressionVariableDeclaration && rightType
> instanceof PrimitiveDataType)
> type = DslFactory::eINSTANCE.createPrimitiveDataType
> }
> else if (binop.^feature == "||")
> {
> (leftType instanceof BoolPrimitiveType && rightType instanceof
> BoolPrimitiveType)
> type = DslFactory::eINSTANCE.createBoolPrimitiveType
> }
> else if (binop.^feature == "&&")
> {
> (leftType instanceof BoolPrimitiveType && rightType instanceof
> BoolPrimitiveType)
> type = DslFactory::eINSTANCE.createBoolPrimitiveType
> }
> else if (binop.^feature == ">=")
> {
> (leftType instanceof PrimitiveDataType && rightType instanceof
> PrimitiveDataType)
> type = DslFactory::eINSTANCE.createBoolPrimitiveType
> }
> else if (binop.^feature == "+")
> {
> (leftType instanceof PrimitiveDataType && rightType instanceof
> PrimitiveDataType)
> if (leftType instanceof IntPrimitiveType){
> rightType = leftType
> type = leftType }
> type = DslFactory::eINSTANCE.createBoolPrimitiveType
> }
> }
>

Hi

I'm the author of Xsemantics; I'm not sure I understand what you want to
achieve. If you are using Xbase in your DSL, then you should rely on
Xbase validation and typing: by implementing your JvmModelInferrer you
will have standard Java-like type inference and type checking (i.e.,
validation) for free. If you want to customize Xbase type system, then
you should customize Xbase type computer.

Xsemantics is meant for DSLs that do not use Xbase.

Or do you want to achieve something else?

(By the way, the way you implemented the type rule in Xsemantics looks
correct to me, but please consider that this is only a typing rule, you
won't get any validation unless you implement 'checkrule's).

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Previous Topic:Why Xtext is better than ANTLR
Next Topic:Suppressing Xtext Debug messages when using log4j API
Goto Forum:
  


Current Time: Thu Apr 25 04:12:55 GMT 2024

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

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

Back to the top