User loginNavigation |
Yet another programming language with customizable syntaxI'm designing a new general-purpose programming language with entirely customizable syntax. Its "killer-feature" is naturalness in functions/macros syntax definition: other languages with customizable syntax (Nemerle, LISP, XL) requires either knowledge of compilers construction theory or reading a large amount of manuals or both (and resultant syntax definition constructs look rather cryptic), while in my language all this is done rather intuitive. Just look at examples. Example 1: `{min} < {var} < {max}` returns Boolean : min < var and var < max `{HH}:{MM}:{SS}` where HH is Natural and 0 < HH < 23; -- Here parser fails when using `{x} < {y}` MM is Natural and 0 < MM < 59; -- so it uses `{min} < {var} < {max}`. SS is Natural and 0 < SS < 59; returns Natural : HH * 3600 + MM * 60 + SS `time between {time1} and {time2}`: -- No "returns" clause, automatic type inference is used. time2 - time1 `how much {x}`: x `main`: print how much time between 23:48:12 and 08:17:00 -- Absolutely natural-language-like expression. Example 2: class Point. -- Predefined function with syntax `class {regexp(\w+)}` is used. `{p}_x` where p is Point; returns Number : field -- That's how fields and variables are declared. `{p}_y` where p is Point; returns Number : field `({x}, {y})`: p := new Point; -- Function `new Point` is declared automatically for every class. -- Function `{regexp(\w+)} := {value}` is predefined. -- Type inference is used heavily everywhere. -- Oh, and function `{f1}; {f2}` (sequential execution) is predefined too. p_x := x; -- Function `{p}_{x} := {value}` is declared automatically for every "field" function. p_y := y; return p `||{p}||`: sqrt(p_x^2 + p_y^2) `{p1} - {p2}` left-associative; priority is the same as for `{x} + {y}` -- Yes, priorities are relative. : (p1_x - p2_x, p1_y - p2_y) `D({p1}, {p2})`: ||p1 - p2|| `main` p1 := (0, 0); p2 := (3, 0); p3 := (0, 4); print D(p1, p2) + D(p2, p3) + D(p3, p1); -- We'll get 12! It is possible to create similar language with XML tags instead of "`"-s and ":"-s. For example: <func> <syntax>time between <arg>time1</arg> and <arg>time2</arg> <body>time2 - time1</body> -- Look at the body, its sytnax is still entirely customizable! </func> so in fact I'm designing a meta-language. Should I proceed or is this entirely stupid idea? By Lavir the Whiolet at 2011-05-24 07:20 | LtU Forum | previous forum topic | next forum topic | other blogs | 11878 reads
|
Browse archives
Active forum topics |
Recent comments
27 weeks 2 days ago
27 weeks 2 days ago
27 weeks 2 days ago
49 weeks 3 days ago
1 year 1 week ago
1 year 3 weeks ago
1 year 3 weeks ago
1 year 5 weeks ago
1 year 10 weeks ago
1 year 10 weeks ago