Trouble modeling a lisp-like language [message #1280914] |
Mon, 31 March 2014 04:48 |
Brian Findley 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.02688 seconds