ID looks like an expression [message #1748524] |
Wed, 23 November 2016 19:00  |
Eclipse User |
|
|
|
I am working on creating an XText grammar and the supporting infrastructure for GNU Linker Scripts. This is for the Eclipse CDT project.
In the grammar 2+3, for example, depending on context, can either be an identifier or an expression:
For example, this is a valid file:
SECTIONS {
.out_name : {
file*.o(.text.*)
2+3(*)
symbol = 2+3;
}
}
The first 2+3 is a filename, so almost anything that can be a filename is allowed there. The second 2+3 is an expression to be assigned to symbol.
This is part of my xtext file. I am using ValidID for the places that an ID is needed (like symbol in example) and FilenameID for the file*.o, .text.* and * parts.
ValidID hidden():
ID | "MEMORY" | "o" | "org" | "l" | "len";
FilenameID hidden():
(ID | '*' | '?' | '^' | '!')+;
terminal ID:
('a'..'z' | 'A'..'Z' | '.' | '/' | '\\' | '$' | '_' | '~')
('a'..'z' | 'A'..'Z' | '.' | '/' | '\\' | '$' | '_' | '~' | '0'..'9' | '-' | '+' | ':' | '[' | ']')*;
This appears to work, but with warning from ANTLR on the FilenameID rule like this one:
Decision can match input such as "'^'" using multiple alternatives: 4, 6 As a result, alternative(s) 6 were disabled for that input
However, if I expand FilenameID to include all the symbols I need, which includes leading 0-9 + - then I get more warnings like the above from ANTLR, and I start getting parsing errors.
GNU ld solves this by using context lexing rules, but AFAIU for XText I should be doing this with datatype rules.
Any ideas? Thanks,
Jonah
|
|
|
|
Re: ID looks like an expression [message #1748546 is a reply to message #1748531] |
Thu, 24 November 2016 04:29  |
Eclipse User |
|
|
|
Thanks Christian for the tips. I was afraid of that.
I may try to approach the problem from a different direction in that case. Fortunately, I don't need to have an exact object representation of the linker script, including the expressions, so I may re-write my grammar completely and see if I can parse to a higher level.
|
|
|
Powered by
FUDForum. Page generated in 0.06251 seconds