|
Re: Validation of the Xbase Expression grammar with Xsemantics [message #1408838 is a reply to message #1407767] |
Sat, 16 August 2014 07:29 |
|
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
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Powered by
FUDForum. Page generated in 0.03422 seconds