Name

sglr — parses a text file and produces an parse forest conforming to a given grammar.

Synopsis

sglr [-2] [-A] [-b] [-c] [-d] [-f[adefipr]] [-i file] [-l] [-m] [-m] [-o file] [-p file] [-s symbol] [t] [-v] [-V]

Description

sglr is a scannerless, generalized LR parser. It interprets a parse table on a given textual input file. The parse table must be generated from an SDF2 grammar definition using the sdf2table tool. If the result of the parse is unambiguous, a parse tree is emitted. In the case of an ambiguity, a parse forest is emitted.

The term "scannerless" refers to the fact that the parser treats characters as tokens. There is no separate token scanner. The term "generalized" indicates that the parser finds all possible derivations for a given input string. Together, these two features allows users to construct ambiguous grammars, if they desire. sglr will not complain about conflicts in the parse table, but output the ambiguous result.

For the ambiguous cases, the user is free to construct problem-specific disambiguation tools which must be applied to the output from sglr. This is useful for dealing with various complicated programming languages that are highly ambiguous and context-sensitive.

Options

Input/Output Options

-i file

The input file is given by the file name file.

In the absence of the -i option, sglr will read from stdin.

-o file

The output will be written to the file given by the file name file.

In the absence of the -o option, sglr will write to stdout.

-p file

The parse table to use, given by the file name file.

Note: This option is always required.

Refer to the tool sdf2table for how to create parse tables.

-b

Use the binary ATerm (BAF) output format. Default is yes.

-m

Use the AsFix2ME output format. Default is yes.

-t

Use the textual AsFix output format. Default is no.

-2

Use the AsFix2 output format. Default is no.

-A

Treat ambiguities as errors. Default is no.

-c

Toggle cycle detection. Default is on.

-n

Toggle parse tree creation. Default is on.

Other Options

-f[adeipr]

Toggle filtering, or toggle specific filter. Default is to enable all filters.

a - turn on associativity filter. Default is on.

d - turn on direct eagerness filter. Default is on.

e - turn on eagerness filter. Default is on.

i - turn on injection count. Default is on.

p - turn on priority filter. Default is on.

r - turn on reject filter. Default is on.

-s symbol

Specific start symbol to use in the input grammar. Default is unspecified.

Debugging Options

-d

Turn on debugging mode.

-l

Turn on statistics logging.

-h, -?

Display usage information.

-v

Turn on verbose mode.

-V

Show tool name and version number.

--version

Displays the tool name and version.

Example

Assuming you have used sdf2table to generate a parse table for you language in the file lang.tbl, and that your input program is in the file input.lang, you can apply sglr as follows:

$ sglr -p lang.tbl -i input.lang -o lang.trm

The resulting parse tree (or possibly parse forest, if your language grammar allows ambiguities) will be in lang.trm.

Reporting Bugs

Please report bugs to

Copyright

Copyright (C) 2002-2005 Eelco Visser

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.