[antlr-interest] missing tokens and strange behaviour regarding some chars
Nieves.Salor.Moral at esa.int
Nieves.Salor.Moral at esa.int
Tue Aug 3 00:37:04 PDT 2010
Hello to everyone!
I am new with ANTLR but not with compilers. Before I explain the problem
I'll try to explain a little bit the situation background.
I am trying to design for a custom language, first a syntax highlighter
and second a module that can store the information in a DB (so in essence
would be creating a compiler with its output as SQL queries).
My input language is defined in EBNF, thus it has left-recursion and
ambiguity. In order to solve it, I have changed it a little to avoid those
problems and mostly I have managed it without using predicates or
backtracking.
Working with ANTLR Works, I am debugging the grammar with different
examples (just the parser), before adding the highlighting code in the
StringTemplate. but I get these strange errors, mostly regarding
NoViableAltException.
One problem for example is trying to define negative expressions with the
simple_factor rule.
So when I debug expressions like 500 or +500 in the simple_factor, I don't
get an error. But If I try -500, I get the NoViableAltException. Also if I
change - for another symbol like @, it also work when I try @500. I have
traced all the possibilities in the different possibilities in
simple_factor, but in no one the first symbol can be a negative symbol.
And I am lost as to why this can happen. I add the whole grammar because
it is quite big to paste it.
Another problem that appears is that sometimes tokens are missed when
reading, so for example if I have an input beginning with 'initiate and
confirm', ANTLR reads 'conf' and loses the first characters. With the
same grammar that I have posted. One example of this problem goes with the
input 'initiate and confirm sys_stop of SCOE_1553 of LLCS of EGSE of
System of ODB' with the rule initiate_and_confirm_step_statement.
Thanks in advance for any input
Nieves Salor Moral
addition_operator: ADDITION_OPERATOR
;
ADDITION_OPERATOR
: '+'|'-'
;
UNSIGNED_INTEGER
: DIGIT+
;
simple_factor
: addition_operator simple_factor
| NEGATION_BOOLEAN_OPERATOR simple_factor
| constant
| '('expression ')'
| function
| object_property_request
| OBJECT_TYPE partial_path
| 'ask user' '(' expression ('default' expression)? ')'
('expect' predefined_type)?
;
constant: BOOLEAN_CONSTANT
| UNSIGNED_INTEGER ( numeric_constant|
RELATIVE_TIME_CONSTANT)
| RELATIVE_TIME_CONSTANT
| string_constant
| HEXADECIMAL_CONSTANT
;
real_constant
: ('.' UNSIGNED_INTEGER)? ('e' addition_operator?
UNSIGNED_INTEGER)?
;
numeric_constant
: real_constant engineering_units?
;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example.g
Type: application/octet-stream
Size: 11108 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20100803/50dfe6a4/attachment.obj
More information about the antlr-interest
mailing list