|Language supporting Integers, Floats, Hex Numbers and Range Expressions [message #1021370]
||Wed, 20 March 2013 00:04
| David Hofmann
Registered: March 2013
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"
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;
'(' lowerBound=Expression DOTDOT upperBound=Expression ')';
IntegerLiteral | FloatLiteral | Variable;
value=(INT | HEX);
The following expressions are valid:
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!
(Size: 0.05KB, Downloaded 125 times)
(Size: 0.89KB, Downloaded 134 times)
Powered by FUDForum
. Page generated in 0.01965 seconds