|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
term_expansion masks static predicate when file is loaded with "yap -l"Howdy all,
I'm trying to write a lexer generator for Yap. I have a special term type of the form @rule := <stuff>, and I am currently expanding this (via `term_expansion`) into a clause of the predicate `match` for each rule. I also have a few static `match` clauses in the same file. I have a "Client" file that uses the lexer and loads it via `consult`. The problem comes when loading the Client file. If I load it via `consult` after starting the interpreter, everything works fine. If I pre-load it from the command-line via `yap -l`, then the static `match` clauses are no longer present. This behavior doesn't make sense to me, so I'm thinking it's a bug, or a misunderstanding of some nuance between command-line loading and `consult`. Here's a stripped down example that demonstrates the behavior): File: lexrule_simple.pl =========================================== :- source. % Define the operators :- op(100, fx, '@'). % Indicates a lexer rule. :- op(1200, xfx, ':='). % Lexer rule neck user:term_expansion( (@H := B), Expanded) :- NewPred = ( match(H, H - L) --> (B, {format('Calling expanded rule: ~w~n', [H])}) ), expand_term(NewPred, Expanded). match(_, _ - C) --> [C]. =========================================== File: use_lexrule_simple.pl =========================================== :- source. :- consult(disappearing_match). @p := bar. bar --> [a]. =========================================== If the file is loaded via =========================================== ?- consult(use_lexrule_simple). ?- listing(match). match(_,_-C,A,B) :- 'C'(A,C,B). match(p,p-_,A,B) :- bar(A,B), format('Calling expanded rule: ~w~n',user:[p]). yes ?- match(X, X - T, [a], []). T = a ? ; Calling expanded rule: p X = p ? ; no =========================================== If it is loaded via yap -l use_lexrule_simple.pl: =========================================== ?- listing(match). match(p,p-_,A,B) :- bar(A,B), format('Calling expanded rule: ~w~n',user:[p]). yes ?- match(X, X - T, [a], []). Calling expanded rule: p X = p ? ; no =========================================== Any ideas, suggestions? I could well be missing something, but the documentation doesn't indicate that `yap -l` is any different from consulting the file after the interpreter has been started, so I can't see why Yap would behave in this way. As a side question: I'm writing this lexer generator because searches for such a system have turned up nothing and I'd like to wrap all of the lexing logic (reading the file, tokenizing, etc.) into one package. Is there a better approach, or is there an existing system that I'm not aware of? Thanks! ~Brian W. DeVries ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Yap-users mailing list Yap-users@... https://lists.sourceforge.net/lists/listinfo/yap-users |
| Free embeddable forum powered by Nabble | Forum Help |