Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Trouble modeling a lisp-like language(Having DSL grammar issues in modeling a lisp-like language)
Trouble modeling a lisp-like language [message #1280914] Mon, 31 March 2014 04:48 Go to next message
Brian Findley is currently offline Brian FindleyFriend
Messages: 1
Registered: March 2014
Junior Member
Hello,

I have started work on a custom Xtext DSL for a lisp-like language. The language uses polish notation (i.e. '(function/operator arg1 arg2 arg3...)' ), and has several special forms to declare classes, methods, etc. Something is not working as expected right now, and I cannot figure it out.

Here's my DSL (most of it):


//----------------------------------------------------------------------------------

Model:
topLevelForms+=TopLevelForm*;

TopLevelForm:
DefineGlobal
// | DefineAttribute
// | DefineClass
;

DefineGlobal:
'(' 'define-global' globalName=Variable '=' value=Expression ')'
;

Expression:
FunctionCall |
SimpleLiteral
;

FunctionCall returns Expression:
'(' functionName=Name functionArgs+=Expression* ')'
;

SimpleLiteral returns Expression:
{SymbolConstant} Name |
{VariableRef} Variable |
{NumberConstant} Number |
{StringConstant} STRING
;

Number:
INT | DECIMAL | SignedInt | SignedDecimal
;

SignedInt:
('+'|'-') INT
;

SignedDecimal:
('+'|'-') DECIMAL
;

Variable:
'?' SYMBOL
;

Name:
SYMBOL
;

// Terminals

terminal SYMBOL:
(SYMBOL_START|'<')(SYMBOL_START|DIGIT|'?'|'$')*;

terminal INT: DIGIT+;

terminal DECIMAL:
(('.' INT) | (INT '.') | (INT '.' INT)) (('e'|'E') ('+'|'-')? INT)?
;

terminal fragment SYMBOL_START:
'a'..'z'|'A'..'Z'|'!'|'@'|'^'|'*'|'_'|'-'|'+'|'='|'{'|'}'|'['|':'|'>'|'.'|'/';

terminal fragment DIGIT: ('0'..'9');

terminal STRING :
'"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'"'|"'"|'\\') | !('\\'|[/code]'"') )* '"';

//----------------------------------------------------------------------------------

This DSL generates the XText artifacts w/o errors. For this DSL I'm attempting to add the capability to properly process a 'define-global' statement. For the most part, all my test cases pass, though a few do not - this is where I'm stuck.

Source code - tests that pass:


(define-global ?test1 = ?test1)
(define-global ?test2 = Test)
(define-global ?test3 = "test")
(define-global ?test4 = 1)
(define-global ?test5 = 1.0)
(define-global ?test6 = -1.0)
(define-global ?test9 = (create$ 1 (util:add 2 2 3)))
(define-global ?test10 = (< ?one 1))



Source code - tests that DO NOT pass:

(define-global ?test11 = (= 1 2 3 4)) ==> parser fails at 2nd '=', message: mismatched input '=' expecting RULE_SYMBOL
(define-global ?test12 = (+ "one" 1)) ==> parser fails at '+', message: missing RULE_SYMBOL at '+'


Something in my grammar file is not quite right - I attempted to pattern my DSL after the Clojure project DSL, though this one is somewhat different.

Any help would be greatly appreciated.

Thanks
Re: Trouble modeling a lisp-like language [message #1285402 is a reply to message #1280914] Sat, 05 April 2014 14:34 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

just from a quick glance. The failing tests both include symbols (+ and =) that are used both as keywords in the grammar (SignedInt/Decimal and DefineGlobal) well as in a terminal fragment. Try what happens, if you remove them from the fragment.

Overlapping terminals/keywords should be avoided.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Previous Topic:Xtext Embedded Editor - Null Pointer Exception
Next Topic:Cross References to "surrounding" resource
Goto Forum:
  


Current Time: Thu Apr 25 12:14:45 GMT 2024

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

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

Back to the top