Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Support of semantic predicates
Support of semantic predicates [message #989180] Wed, 05 December 2012 02:22
Allan T is currently offline Allan T
Messages: 2
Registered: December 2012
Junior Member
I am trying to write a parser for C based on a ANTLR grammar (see below). For this I will have to make use of context sensitive information, i.e. semantic predicates. As far as I know, Xtext does not support that feature.

Question 1: Or does Xtext now support semantic predicates similar to how they are implemented within ANTLR?

Question 2: Assuming semantic predicates are not supported. Is there any other way to solve my problem which is making rule decisions based on the existence of user types (typedefs, structs, enums)? Could perhaps cross-references be useful in this case?

Allan

ANTLR C Grammar: http:// www. antlr.org/grammar/1153358328744/C.g

Edit:

A sample to clarify:

Entry
    : temp += (Expression | Declaration | UserType)*
;

Declaration
    : Type '*' name=ID ';'
;

Expression
    : temp1 = Primary ('*' temp2 += Primary)* ';'
;

Primary
    : temp1 = INT
    | temp2 = [Declaration]
;

Type
    : temp1 = SimpleType
    | temp2 = [UserType]
;

SimpleType
    : 'int' | 'long'
;

UserType
    : 'typedef' name=ID ';'
;


Problems occur with Declaration and Expression, because both of them are syntacticly the same. However, I would like to make a semantic distinguishment.

typedef a;
a*b;

Entity -> Declaration -> Type -> UserType -> 'a' could be resolved as a type, so take this rule and do not look in any other alternatives.

For that though, I will have to make use of some kind of semantic predicate.


Allan

[Updated on: Thu, 06 December 2012 09:52]

Report message to a moderator

Previous Topic:Error parsing model files in Linux
Next Topic:Using xtext as third party
Goto Forum:
  


Current Time: Tue Oct 21 08:52:35 GMT 2014

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

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