contents index next

3. Command Interpreter

In principle there are three ways to interact with Hdrug:

The first two items are mutually exclusive: if the command interpreter is listening, then you cannot give ordinary SICStus Prolog commands and vice versa. The graphical user interface can be used in combination with both the SICStus Prolog Top-level or the command interpreter.

Prolog queries are given as ordinary Sicstus commands. This way of interacting with Hdrug can be useful for low level debugging etc. Using the command interpreter can be useful for experienced users, as it might be somewhat faster than using the graphical user interface.

The command-interpreter features a history and an alias mechanism. It includes a facility to escape to Unix, and is easily extendible by an application.

The command interpreter is started by the Prolog predicate r/0 The command interpreter command p halts the command interpreter (but Hdrug continues).

Commands for the command interpreter always constitute one line of user input. Such a line of input is tokenized into a number of *words using spaces and tabs as separation symbols. The first word is taken as the command; optional further words are taken as arguments to the command. Each command will define certain restrictions on the number and type of arguments it accepts.

Each word is treated as a Prolog atomic (either atom or integer, using name/2). In order to pass a non-atomic Prolog term as an argument to a command, you need to enclose the word in the meta-characters { and }. For example, the flag command can be used to set a global variable. For example:

16 |: flag foo bar

sets the flag foo to the value bar. As an other example,

17 |: flag foo bar(1,2,3)

sets the flag foo to the Prolog atom 'bar(1,2,3)'. Finally,

17 |: flag foo {bar(1,2,3)}

sets the flag foo to the complex Prolog term bar(1,2,3), i.e. a term with functor bar/3 and arguments 1, 2 and 3.

Also note that in case the {,} meta-characters are used, then the variables occurring in words take scope over the full command-line. For instance, the parse command normally takes a sequences of words:

18 |: parse John kisses Mary

In other to apply the parser on a sequence of three variables, where the first and third variable are identical, you give the command:

19 |: parse {A} {B} {A}

The special meaning of the {,} meta-characters can be switched off by putting a backslash in front of them. For example:

53 |: tcl set jan { piet klaas }
=> piet klaas
54 |: tcl puts jan
jan

The following meta-devices apply: All occurences of $word are replaced by the definition of the alias word. The alias command itself can be used to define aliases:

19 |: alias hallo ! cat hallo
20 |: $hallo

so command number 20 will have the same effect as typing

33 |: ! cat hallo

and if this command had been typed as command number 33 then typing

35 |: $33

gives also the same result.

Moreover, if no alias has been defined, then it will apply the last command that started with the name of the alias:

66 |: parse john kisses mary
67 |: $parse

Both commands will do the same task.

It is possible to add commands to the command interpreter. The idea is that you can define further clauses for the multifile predicate hdrug_command/3. The first argument is the first word of the command. The second argument will be the resulting Prolog goal, whereas the third argument is a list of the remaining words of the command (the arguments to the command).

:- multifile hdrug_command/3.
hdrug_command(plus,(X is A+B, format('~w~n',[X])),[A,B]).

Relevant help information for such a command should be defined using the multifile predicate hdrug_command_help/3. The first argument of this predicate should be the same as the first argument of hdrug_command. The second and third arguments are strings (list of character codes). They indicate respectively usage information, and a short explanation.

:- multifile hdrug_command_help/3.
hdrug_command_help(plus,"plus A B","Prints the sum of A and B").

For example, consider the case where we want the command rx to restart the Tcl/Tk interface. Furthermore, an optional argument of `on' or `off' indicates whether the TkConsol feature should be used. This could be defined as follows:

hdrug_command(rx,restart_x,L):-
    rxarg(L).
rxarg([on]) :- set_flag(tkconsol,on).
rxarg([off]) :- set_flag(tkconsol,off).
rxarg([]).
hdrug_command_help(rx,"rx [on,off]",
     "(re)starts graphical user interface with/without TkConsol").

3.1. flag Flag [Val]

without Val displays value of Flag; with Val sets Flag to Val

3.2. flag Flag [Val]

without Val displays value of Flag; with Val sets Flag to Val

3.3. % Words

ignores Words (comment). Note that there needs to be a space after %.

3.4. fc Files

fcompiles(Files).

3.5. um Files

use_module(Files).

3.6. el Files

ensure_loaded(Files).

3.7. c Files

compile(Files).

3.8. rc Files

reconsult(Files).

3.9. ld Files

load(Files).

3.10. libum Files

for each File, use_module(library(File)).

3.11. librc Files

for each File, reconsult(library(File)).

3.12. libc Files

for each File, compile(library(File)).

3.13. libel Files

for each File, ensure_loaded(library(File)).

3.14. libld Files

for each File, load(library(File)).

3.15. version

displays version information.

3.16. quit|exit|halt|q|stop

quits Hdrug.

3.17. b

break; enters Prolog prompt at next break level.

3.18. d

debug/0.

3.19. nd

nodebug/0.

3.20. p [Goal]

without Goal: quits command interpreter -- falls back to Prolog prompt with Goal: calls Goal. Normally you will need {} around the Goal. For example:

p { member(X,[a,b,c]), write(X), nl }

3.21. ! Command

Command is executed by the shell. Note that the space between ! and Command is required.

3.22. alias [Name [Val]]

No args: lists all aliases; one arg: displays alias Name; two args: defines an alias Name with meaning Val.

3.23. help [command|flag|pred|hook] [Arg]

displays help on command Arg or flag Arg or predicate Arg or hook Arg; without Arg prints list of available commands, flags, predicates, or hooks.

3.24. ? [command|flag|pred|hook] [Arg]

displays help on command Arg or flag Arg or predicate Arg or hook Arg; without Arg prints list of available commands, flags, predicates, or hooks.

3.25. listhelp [command|flag|pred|hook]

displays listing of all commands, flags, predicates or hooks respectively; without Class displays all help for all classes.

3.26. spy [Module] Pred

set spypoint on Module:Pred; Pred can either be Fun or Fun/Ar.

3.27. cd [Dir]

change working directory to Dir; without argument cd to home directory.

3.28. pwd

print working directory.

3.29. ls

listing of directory contents

3.30. lt [tk/clig/latex] [Type]

prints lexical hierarchy for Type; without Type, prints lexical hierarchy for top

3.31. x

(re)starts graphical user interface

3.32. nox

halts graphical user interface

3.33. tcl Cmd

calls tcl command Cmd; what is returned by the tcl command will be printed on the screen after the => arrow.

75 |: tcl expr 3 * [ expr 5 + 4 ]
=> 27

Remember that { and } need to be prefixed with backlash since otherwise the Hdrug shell treats them. For instance

63 |: tcl expr 3+4
=> 7

3.34. source File

sources Tcl source File

3.35. s [Format] [Output] Values

displays Objects with specified Format and Output; cf help on s_format, s_output and s_value respectively.

3.36. i/j/s/w/f [Path]/T

Specifies the Format of the s command.

i                write/1;

j                print/1 (default);

s                semantics (third argument of o/3 object terms)

w                words (second argument of o/3 object terms)

f Path           display as a feature structure; the optional path is a sequence of attributes separated by colons (it selects the value at that path). The prefix of the path can be a sequence of integers seperated by / in order to select a specific node in the tree: this is only possible of the category is a tree datastructure with functor tree/3 where tree labels are specified in the first argument and lists of daughters are specified in the third argument.

T                T is a tree-format, display as a tree with that format. Tree-formats are specified with the hook predicates graphic_path, graphic_label and graphic_daughter.

3.37. user/latex/tk/clig/dot

Specifies the Output of the s command.

user             as text to standard output (default);

latex            LaTeX; ghostview is used to display result;

tk               in the canvas of the graphical user interface;

dot              used DOT

clig             uses Clig

3.38. ObjSpec/DefSpec/ValSpec

Specifies the Objects to be shown form the s command.

ObjSpec will select a number objects (parser/generator results):

s 2 5 8    specifies the objects numbered 2, 5 and 8

s 4 +      specifies the objects number 4 and above

s 3 -      specifies all objects up to number 3

s 5 to 12 specifies all objects between 5 and 12

DefSpec will select a user_clause definition:

s l Fun/Ar     specifies a listing of the Fun/Ar predicate.

ValSpec will specify a goal, and select an argument of that goal:

s [Module:]Fun/Ar [Pos]

The Module prefix is optional (user module is assumed if not specified); the optional Pos argument selects a specific argument to be printed. If no Pos argument is specified then the full goal is printed. For example, if you have the following predicate defined:

x23(f(16),g(17),h).

then the following commands are possible:

|: s x23/3
x23(f(16),g(17),h)
|: s x23/3 1
h
|: s user:x23/3 2
g17

3.39. type [t/x/tk/clig/dot] [Type]

displays type t=tree x=latex tree, tk=tk tree, clig=clig tree, dot=dot tree, none=textual information. No Type implies that top is used.

3.40. ps [Keys]

compares parsers on each sentence with key in Keys; without Keys, compares parsers on all availables sentences;

3.41. psint I J

compares parsers on each sentence with key between I and J

3.42. gs [Keys]

compares generators on each lf with key in Keys; without Keys, compares generators on all available lfs;

3.43. gsint I J

compares generators on each lf with key between I and J

3.44. rt [Parser/Generator]

reset tables for parser/generator comparison for parser Parser or generator Generator; without argument reset tables for all parsers and generators

3.45. sentences

lists all sentences

3.46. lfs

lists all logical forms

3.47. pt

print parser comparison overview

3.48. ptt

print parser comparison tables in detail

3.49. pc Sentence

compares parsers on Sentences

3.50. gc LF

compares generators on LF

3.51. gco ObjNo

compares generators on LF of object ObjNo

3.52. * Sentence

parses Sentence

3.53. parse Sentence

parses Sentence

3.54. - Term

if Term is an integer ObjNo, then generate from LF of object ObjNo; otherwise Term is a semantic representation that is generated from

3.55. generate Term

if Term is an integer ObjNo, then generate from LF of object ObjNo; otherwise Term is a semantic representation that is generated from

3.56. lg [File]

with File, compile_grammar_file(File); without File, compile_grammar.

3.57. rcg [File]

with File, reconsult_grammar_file(File); without File, reconsult_grammar.

3.58. tkconsol

(re)starts graphical user interface with TkConsol feature

3.59. av

shows activity status of parsers and generator

3.60. no [gm] List

with gm, List is a list of generators which are set to inactive status; without gm, List is a list of parsers which are set to inactive status

3.61. yes [gm] List

with gm, List is a list of generators which are set to inactive status; without gm, List is a list of parsers which are set to inactive status

3.62. only [gm] List

with gm, List is a list of the only remaining active generators; without gm, List is a list of the only remaining active parsers;

3.63. sts [Parsers]

graphically displays statistics for Parsers; without Parsers displays statistics for all parsers

contents index next