Next: Code Generation Compiler Back-End, Previous: Compiler, Up: Compiler
The parser is available under the (rpc compiler parser) module.
The main procedure, rpc-language->sexp, reads XDR/RPC language
descriptions and returns the abstract syntax tree (AST) in the form of
an S-expression. The AST can be shown using the --intermediate
option of the grpc-compile command-line tool (see Invoking grpc-compile). Below is an illustration of the mapping between the
XDR/RPC language and the S-exp representation.
const SIZE = 10;
struct foo
{
int x;
enum { NO = 0, YES = 1 } y;
float z[SIZE];
};
... yields:
(define-constant "SIZE" 10)
(define-type
"foo"
(struct
("x" "int")
("y" (enum ("NO" 0) ("YES" 1)))
("z" (fixed-length-array "float" "SIZE"))))
Read a specification written in the XDR Language from port and return the corresponding sexp-based representation. This procedure can raise a
&compiler-errorexception (see below).
The behavior of the parser can be controlled using the *parser-options* parameter object:
This SRFI-39 parameter object must be a list of symbols or the empty list. Each symbol describes an option. For instance,
allow-unsignedinstructs the parser to recognizeunsignedas if it wereunsigned int(see Sun XDR/RPC language extensions).
Source location information is attached to the S-expressions returned by
rpc-language->sexp. It can be queried using the procedures
below. Note that not-only top-level S-expressions (such as
define-type or define-constant expressions) can be
queried, but also sub-expressions, e.g., the enum S-expression
above.
Return the source location associated with sexp or
#fif no source location information is available.
Return the line number, column number or file name from location loc, an object returned by
sexp-location.
In case of parse errors or other compiler errors, a
&compiler-error error condition (or an instance of a sub-type
thereof) may be raise.