-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparser.pl
110 lines (94 loc) · 1.95 KB
/
parser.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
:- module(parser,
[program/3]).
:- use_module(library(dcg/basics)).
:- use_module(tokenize).
program(X) -->
decl_ast(Y),
{X =.. [ctrs|Y]}.
decl_ast([]) --> [].
decl_ast([H|T]) -->
decl(H),
decl_ast(T).
decl(vars(X)) -->
[punct("(")],
[word("VAR")],
id_ast(X),
[punct(")")],
{assertVars(X)}.
decl(rules(X)) -->
[punct("(")],
[word("RULES")],
rule_ast(X),
[punct(")")].
id_ast([]) --> [].
id_ast([H|T]) -->
id(H),
id_ast(T).
id(X) -->
[word(X)].
%decl --> ("VAR",id_ast); ("THEORY",thdecl_ast); ("RULES",rule);
% ("STRATEGY",strategydecl); (id,anylist_opt).
condlist([H|T]) -->
cond(H),
cond_ast(T).
cond_ast([]) --> [].
cond_ast([H|T]) -->
[punct(",")],
cond(H),
cond_ast(T).
cond(cond(X,Y)) -->
term(X),
[punct("-"),punct(">")],
term(Y).
%cond(cond(X,Y)) -->
% term(X),
% [punct("-"),punct(">"),punct("<"),punct("-")],
% term(Y).
rule_ast([]) --> [].
rule_ast([H|T]) --> rule(H),rule_ast(T).
rule(rule(beta(void),X,Y,[])) -->
term(X),
[punct("-")],
[punct(">")],
term(Y).
rule(rule(beta(void),X,Y,Z)) -->
term(X),
[punct("-")],
[punct(">")],
term(Y),
[punct("|")],
condlist(Z).
term(term(X,[])) -->
id(X).
term(term(X,[])) -->
id(X),
[punct("(")],
[punct(")")].
term(term(X,Y)) -->
id(X),
[punct("(")],
termlist(Y),
[punct(")")].
termlist([H|T]) -->
term(H),
term_ast(T).
term_ast([]) --> [].
term_ast([H|T]) -->
[punct(",")],
term(H),
term_ast(T).
%
%anylist_opt --> []; anylist.
%anylist_ast --> []; (",",anylist,anylist_ast).
%anylist --> any,anylist_ast.
%any --> id; string; ("(",anylist,")").
%thdecl --> id_ast; ("EQUATIONS",equation_ast).
%equation_ast --> []; (equation, equation_ast).
%thdecl_ast --> []; (thdecl,thdecl_ast).
%equation --> (term,"==",term).
%stratedecl --> "INNERMOST"; ("CONTEXTSENSITIVE",replacements_ast).
%replacements_ast --> []; (replacement,replacements_ast).
%replacement --> "(",id,int_ast,")".
%int_ast --> []; (int,int_ast).
%
%