alpag.net manual
Input file format / General format
< Input file format | Definition sections >

General format

Default extension of alpag file is .alp or .alpag.

If file contains only lexer or only parser definition extensions .alpl and .alpp can be used to emphasize this fact. For backward compatibility reasons extensions .lex and .yacc can also be used.

Compatibility with lex and yacc

Alpag input file format is based on file formats of lex and yacc. First versions of alpag maintained strict compatibility with these tools. However, since classical lex / yacc formats lack some tidiness and verbosity, current versions of alpag promote updated format with explicitly named file sections. Older versions of files can be easily updated to new format after some minor corrections.

This documentation is using and promoting new format. Support for old format will be gradually phased-out.

Alpag maintains compatibility with lex and yacc regarding syntax of grammar sections. That is grammar sections can be copied from lex / yacc files directly to alpag files with no corrections.

Sections

Alpag input files are line-oriented text files.

Empty lines are ignored

Files can contain C/C++ like comments

// single line comment
/*
multiline
comment
*/
/// comment lines with three slashes can copied to output code

Contents of file is divided into sections.


// head part of file

%%section1
// body of section 1
// ..

%%section2
// body of section 2
// ..

Section start is marked by placing at the beginning of line double-percent sign followed by section name. Section body extends to start of next section.

Particular section type, if not explicitly stated otherwise, can be repeated. In that case contents of all subsequent sections of the same type is combined as if it was one continuous section.

Head part of file before any explicit section contains definitions and is equivalent to %%defs section.

Below is the list of available sections:

%%defs // options and definitions
%%ldefs or %%ld // lexer-specific definitions
%%pdefs or %%pd // parser-specific definitions
%%lrules or %%lr // lexer rules
%%prules or %%pr // parser rules
%%disabled // entire section is disabled and not interpreted

Alpag file can contain lexer definition, parser definition or both.

When file contains %%ldefs or %%lrules section it is assumed that file contains lexer definition.

When file contains %%pdefs or %%prules section it is assumed that file contains parser definition.

Old file format

Older versions of Alpag used lex/yacc-like format with sections marked by anonymous %% sign. In this format a single input file can contain either lexer or parser but not both. Syntax is:

// declarations
%%
// rules
%%
// custom code

To determine contents of the file (either lexer or parser) Alpag uses file extension, respectively .lex or .yacc. Alternatively a directive explicitly specifying file contents (%lexer or %parser) can be placed in head section of the file.

Old file format is deprecated and should not be used for creating new files.

< Input file format | Definition sections >
Alpag Manual