Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Unavoidable space issue(The OneWhitespaceFormatter.java strikes again)
Unavoidable space issue [message #990384] Wed, 12 December 2012 04:10 Go to next message
Thomas Haarhoff is currently offline Thomas Haarhoff
Messages: 8
Registered: December 2012
Location: Germany
Junior Member
Hello.
I'm developing a parser for a low level language.
I want to parse a bigger size the generated code and dont want to adjust this code.

My Problem is now the following (simplified):

Function:
'define' Return_Attributes? returnType=Type name=VAR_TYPE pl=ParameterList 'unnamed_addr'? Function_Attributes* ('section ' STRING)? body=FunctionBody;


If you see, this should parse a function with its header and body. For example:

define void @_ZN5StackC2Ev(@class.Stack* %this) unnamed_addr nounwind align 2 { ... }


The goal is, the resulting AST contains:
FunctionHeader:
-> returnType: void
-> name: @_ZN5StackC2Ev
-> ParameterList pl:
->-> params: List of TypeAndValue
-> FunctionBody body:
->-> InstructionList (not part of problem - this part is fine Smile )


But between the name and the parameterlist the parser wants to have a space.
The funny thing is, the parser does not want this space before the closing bracket.

Here the other rules of interest.

ParameterList:
'(' (params+=TypeAndValue (',' params+=TypeAndValue)*)? ')';

TypeAndValue:
(VAR_TYPE | Basic_Type )Type;

So the should be possible:
( )
( type value )
( type value, type value, type value )
but also:
(type value )
(type value, type value, type value )
but this is not possible, cause the parser wants the space after the bracket.

VAR_TYPE is the only a terminal rule. (Basic_Type and Type may have a structual content so they can't be terminal rules...)

Has now someone perhaps an idea how i can fix this issue?

-Thomas
Re: Unavoidable space issue [message #990506 is a reply to message #990384] Wed, 12 December 2012 14:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6143
Registered: July 2009
Senior Member
HI,

how does VAR_TYPE look like?

~Christian
Re: Unavoidable space issue [message #990766 is a reply to message #990506] Fri, 14 December 2012 03:07 Go to previous messageGo to next message
Thomas Haarhoff is currently offline Thomas Haarhoff
Messages: 8
Registered: December 2012
Location: Germany
Junior Member
Hello Christian,

The Code for VAR_TYPE and the related rules

terminal VAR_TYPE:
(PREFIX_CHAR (VAR_ID|INT) | ('(' VAR_TYPE ')' '*'*)) ('.' (BRACKETS | VAR_ID))*;

terminal BRACKETS:
'(' VAR_ID ')' '*'*;

terminal VAR_ID:
('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '_' | '0'..'9')* '*'*;

terminal PREFIX_CHAR:
('%' | '@') '.'?;


I put some examples here

%foo
(%Stack.Node).Node.a.very.long.identifier 
@_44bar.your.choice
%._
@_ZN5StackC2Ev


The opening bracket of the function header is not parsed via this rule. One of my thoughts also.

-Thomas
Re: Unavoidable space issue [message #990768 is a reply to message #990766] Fri, 14 December 2012 03:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6143
Registered: July 2009
Senior Member
Hi,

remember: first lexer (handles the terminals) then parser
the lexer is context free => the name=VAR_TYPE will eat up the bracket

~Christian
Re: Unavoidable space issue [message #990770 is a reply to message #990768] Fri, 14 December 2012 03:37 Go to previous messageGo to next message
Thomas Haarhoff is currently offline Thomas Haarhoff
Messages: 8
Registered: December 2012
Location: Germany
Junior Member
Ok. This now helps me in understanding. Thanks.
But I dont know what to do now. I even dont know what to google or searh in the to find help.
My I trouble you for some advice?
Re: Unavoidable space issue [message #990772 is a reply to message #990770] Fri, 14 December 2012 03:45 Go to previous message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6143
Registered: July 2009
Senior Member
Hi,

you can try to switch from a terminal rule to a data type rule.
btw are you sure it is a good idea if your ids contain ()

~Christian
Previous Topic:Syntax Highlight of disconnected rules
Next Topic:Getting EReference from Node
Goto Forum:
  


Current Time: Wed Jul 30 21:25:37 EDT 2014

Powered by FUDForum. Page generated in 0.02302 seconds