Language supporting Integers, Floats, Hex Numbers and Range Expressions [message #1021370] |
Wed, 20 March 2013 00:04 |
David Pace Messages: 19 Registered: March 2013 |
Junior Member |
|
|
Hello all,
I am developing a grammar for an existing language and have ambiguity problems with integers, floats, hex numbers and range expressions.
Here is a minimal grammar to reconstruct my problem:
grammar de.davehofmann.test.TestDSL hidden (WS)
import "[url removed because of spam filter]/emf/2002/Ecore" as ecore
generate testDSL "[url removed because of spam filter]/test/TestDSL"
Model:
rangeExpression += RangeExpression*;
terminal WS : (' '|'\t'|'\r'|'\n')+;
terminal fragment DIGIT: ('0'..'9');
terminal INT returns ecore::EInt: DIGIT+;
terminal fragment HEX_DIGIT: (DIGIT|'a'..'f'|'A'..'F');
terminal HEX returns ecore::EInt: '0x' HEX_DIGIT*;
terminal IDENTIFIER : ('a'..'z') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
FLOAT returns ecore::EFloat: INT DOT INT ('e' (MINUS|PLUS)? INT)? | (INT 'e' (MINUS|PLUS)? INT);
terminal PLUS: '+';
terminal MINUS: '-';
terminal DOT: '.';
DOTDOT: DOT DOT;
RangeExpression:
'(' lowerBound=Expression DOTDOT upperBound=Expression ')';
Expression:
IntegerLiteral | FloatLiteral | Variable;
Variable:
name=IDENTIFIER;
IntegerLiteral:
value=(INT | HEX);
FloatLiteral:
value=FLOAT;
The following expressions are valid:
(1..3)
(2.2..5.1)
(2e-10..3e-8)
(0x1f..0x2d)
(e..x)
Problems:
1. Hex Numbers are not recognized at all (line 4). What's wrong here?
2. 'e' must be a valid variable name, but it clashes with the exponent 'e' in the FLOAT rule (line 5).
If FLOAT becomes a terminal rule, then
3. The expression 1..3 (line 1) is not valid because the lexer gets confused and tries to read a float.
How can I solve this?
Thanks in advance for any hints!
Dave
-
Attachment: test.tdsl
(Size: 0.05KB, Downloaded 175 times) -
Attachment: TestDSL.xtext
(Size: 0.89KB, Downloaded 167 times)
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04336 seconds