User loginNavigation |
archivesa logic of precedences. SuggestionsHi, I'm new to programming language theory but like I suppose Anyways I'm asking about an idea I have for my pet programming language. It is a precedence based logic. With it the programmer can Now, suppose we have the basic infix aritmetic 'operators' +, -, *, and div + a b / a + b, +:int->int->int. We can declare their precedence with: precedences { aritmetic := {+ - * div}, + = -, * = /, * > + }or the more cute 'ladder syntax': precedences { aritmetic := (* div) (+ -) }
I have developed a 'logic of precedences' that can deal with When a program or library grows you can still declare precedences without ! n / n !.
precedences { ! > aritmetic }
I know that the emblematic languages like ocaml or haskell don't provide What do you think about this idea of declaring precedences with a 'logic system'? The language will have types like disjoint sets (a la ocaml's but with With types declared as lexems, aplication modes of functions and precedence system
% control structures for if-then-else
lexemas iftest := { iftest(bool) }
lexemas elsesol x := { thensol(x) elsesol }
% declarations (not required but useful to see ugly types)
if / if : bool -> iftest bool.
then ifcont thenexp / ifcont then thenexp, then : iftest -> x -> elsesol x.
else thencont elseexp / thencont else elseexp, else : elsesol x -> x -> x.
% this declaration puts 'if' 'then' 'else' operators to a 'ifexp' class
% (classes of precedence are useful to handle DSLs or operators related
% as a whole). It reads as: "'if' has more precedence than 'then', and 'then'
% has more precedence than 'else'; all of then put on a class 'ifexp' whose
% precedence level is greater than the rest of functions, including default
% aplication level". It also raises the invariant that no other declaration
% can mess with their relation nor merge between the 'ifexp' owned levels
% so from this point of view the DSL is unaltered.
fixed_precedences { ifexp := if then else, ifexp > all, }
% if-then-else implementation (requires lazy evaluation, naturally)
if b = iftest(b).
then ifcont exp = ifcont
con iftest(true) -> thensol(exp)
con iftest(false) -> elsesol.
else branch elseexp = branch
con thensol(x) -> x
con elsesol -> elseexp.
|
Browse archivesActive forum topics |
Recent comments
1 day 21 hours ago
2 days 18 hours ago
3 days 22 hours ago
3 days 22 hours ago
1 week 1 day ago
1 week 2 days ago
1 week 2 days ago
4 weeks 2 days ago
5 weeks 1 day ago
5 weeks 1 day ago