Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » ID looks like an expression
ID looks like an expression [message #1748524] Thu, 24 November 2016 00:00 Go to next message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 416
Registered: June 2014
Senior Member
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 #1748531 is a reply to message #1748524] Thu, 24 November 2016 03:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Context based Lexer will not work with antlr lexer
So you might replace it with a custom / external lexer.
There are some blog posts in the wild that will give some hints on that
But I don't know if they will give you enhough to do it


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: ID looks like an expression [message #1748546 is a reply to message #1748531] Thu, 24 November 2016 09:29 Go to previous message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 416
Registered: June 2014
Senior Member
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.
Previous Topic:How to override and extend the JvmModelGenerator to generate complex enumerations
Next Topic:Xcore on ANT or MWE workflow
Goto Forum:
  


Current Time: Wed Apr 24 23:56:13 GMT 2024

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

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

Back to the top