Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Expression Language: Using ".*" in combination with Decimal Numbers
Expression Language: Using ".*" in combination with Decimal Numbers [message #1774566] Tue, 17 October 2017 11:57 Go to next message
Lukas Schaus is currently offline Lukas SchausFriend
Messages: 25
Registered: October 2016
Junior Member

i am trying to model a portion of the MATLAB Syntax. I have problems with Expressions that contain the ".*" operator.

Here is a small portion of my Grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl ""

import "" as ecore


	{NumberLiteral} number=NUMBER


	MBinaryOperation returns MExpression:
		MUnaryOperation =>({MBinaryOperation.left=current} op=MBINARY_OPERATOR right=MUnaryOperation)*

		: '*' | '/' | '+' | '-' | '^' | './' | '.*' | '.\\' | '\\'
	MUnaryOperation returns MExpression:
		{MUnaryOperation} opUnary=MUNARY_OPERATOR? operand=MPrimaryExpression
		'-' | '+'
	MPrimaryExpression returns MExpression
		: lBrace='(' expression=MExpression rBrace=')'
		| Literal
		: NumberLiteral
		| BooleanLiteral
		{BooleanLiteral} ('true' | 'false')
terminal NUMBER returns ecore::EBigDecimal:
	('0'..'9')* ('.' ('0'..'9')+)?(('E'|'e')('-'|'+')?('0'..'9')*)?;
terminal INT returns ecore::EInt:
	'this one has been deactivated';

The workflow does not raise any errors or warnings unsing Xtext 2.8 and JDK 1.6 in eclipse Kepler.

The following input leads to a Syntax Error:

The Stacktrace indicates, that the parser tries to match the NUMBER rule after it consumed the '.' :
java.lang.AssertionError: Expected no issues, but got :ERROR (org.eclipse.xtext.diagnostics.Diagnostic.Syntax) 'required (...)+ loop did not match anything at character '*'' on MBinaryOperation, offset 0, length 2
ERROR (org.eclipse.xtext.diagnostics.Diagnostic.Syntax) 'no viable alternative at input '*'' on MBinaryOperation, offset 2, length 1
ERROR (org.eclipse.xtext.diagnostics.Diagnostic.Syntax) 'no viable alternative at input ';'' on MBinaryOperation, offset 4, length 1

	at org.eclipse.xtext.junit4.validation.ValidationTestHelper.assertNoIssues(
	at org.eclipse.xtext.junit4.validation.ValidationTestHelper.assertNoIssues(
	at org.xtext.example.mydsl.tests.ParserTests.parseInitSimpleAssignmentToSignal(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(
	at org.eclipse.xtext.junit4.XtextRunner$1.evaluate(
	at org.junit.runners.ParentRunner.runLeaf(
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(
	at org.junit.runners.ParentRunner$
	at org.junit.runners.ParentRunner$1.schedule(
	at org.junit.runners.ParentRunner.runChildren(
	at org.junit.runners.ParentRunner.access$000(
	at org.junit.runners.ParentRunner$2.evaluate(
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(

I was wondering how I could refactor my grammar and would be very grateful for any help.

P.S.: backtracking does not solve the problem


Re: Expression Language: Using ".*" in combination with Decimal Numbers [message #1774570 is a reply to message #1774566] Tue, 17 October 2017 12:21 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5978
Registered: July 2009
Senior Member

You may find that the problems get worse if you have floating point challenges such as 1.2.

You can use an alternate lexer that understands that ".*" is always better than "."; unless you also want ".<ws>*".

For OCL I still use the standard lexer but insert a RetokenizingTokenSource to join up "." "*" as ".*" between Lexer and Parser. See


and associated references.


Ed Willink
Previous Topic:Scoping with a custom VariableDeclaration in XBase
Next Topic:Linking XCastExpression to a "toX" function
Goto Forum:

Current Time: Fri Jul 20 12:51:51 GMT 2018

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

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

Back to the top