Forlan Manual


The Sym Module


Synopsis

signature SYM
structure Sym :> SYM

This module provides the abstract type of Forlan symbols. (This abstract type is actually defined by the lexical analysis module, Lex, but most Forlan users will never have to directly use Lex.)


Interface

type basic = Lex.basic
val charToBasic : char -> basic
val basicToChar : basic -> char
type sym = Lex.sym
datatype top
  = Basic of basic
  | Compound of sym option list
val fromTop : top -> sym
val toTop : sym -> top
val inputFromLabToks : (int * Lex.tok) list -> sym * (int * Lex.tok) list
val fromString : string -> sym
val input : string -> sym
val toPP : sym -> PP.pp
val toString : sym -> string
val output : string * sym -> unit
val compare : sym Sort.total_ordering
val equal : sym * sym -> bool
val size : sym -> int
val jforlanValidate : string -> unit
val jforlanPretty : string -> unit

Description

type basic = Lex.basic
The abstract type consisting of the subset of characters that are digits, lowercase letters or uppercase letters.

charToBasic c
If c is a digit, lowercase letter or uppercase letter, then charToBasic returns c. Otherwise, issues an error message.

basicToChar c
returns c.

type sym = Lex.sym
The abstract type of Forlan symbols, consisting of the least set of lists of digits, lowercase and uppercase letters, commas (,) and angle brackets (< and >) such that:

The concrete syntax for a symbol [c1, ..., cn] is c1 ... cn. E.g., [<, i, d, >] is written as <id>.

The type could be implemented using lists, but is actually implemented in a way that makes the construction and destruction of symbols more efficient. See fromTop and toTop.

datatype top
  = Basic of basic
  | Compound of sym option list
A datatype describing the top-level structure of a symbol.

fromTop top
returns the symbol whose top-level structure is described by top. If top is BasicSymTop b, then fromTop returns [b]. Otherwise, top looks like CompoundSymTop xs, in which case the symbol returned by fromTop consists of the result of appending an initial [<], followed by the lists corresponding to xs, followed by a closing [>]. Each occurrence of NONE in xs is turned into [,]. And each occurrence of the form SOME a is turned into a.

toTop a
returns the value of type sym_top describing the top-level structure of a. If the only element of a is a digit or letter, then toTop returns BasicSymTop b, where b is that digit or letter. Otherwise a is the result of appending the elements of a list of lists xs, where the first and last elements of xs are [<] and [>], respectively, and each of the remaining elements are either [,] or are single symbols. In this case, toTop returns CompoundSymTop ys, where ys is the value of type sym option list corresponding to all but the first and last elements ([<] and [>]) of xs, in the following way. [,] is turned into NONE. And a symbol x is turned into SOME x.

inputFromLabToks lts
tries to read a symbol from lts, returning the pair of that symbol with the rest of lts. Issues an error message if lts doesn't begin with a symbol.

fromString s
inputs a symbol from s.

input fil
inputs a symbol from the file named by fil.

toPP a
returns a pretty-printing expression for a.

toString a
pretty-prints a to a string.

output(fil, a)
pretty-prints a to the file fil.

compare(a, b)
compares a and b, first according to length, and then lexicographically, using the ordering in which the comma (,) comes first, followed by the digits (in ascending order), followed by the lowercase letters (in ascending order), followed by the uppercase letters (in ascending order), followed the open angle bracket (<), followed by the close angle bracket (>).

equal(a, b)
tests whether a and b are equal.

sizeSym a
returns the length of a.

jforlanValidate
is a low-level function used by JForlan. See the code for more information.

jforlanPretty
is a low-level function used by JForlan. See the code for more information.


[ Top | Parent | Root | Contents | Index ]

Forlan Version 4.12
Copyright © 2019 Alley Stoughton