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.
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.
Alpag input files are line-oriented text files.
Empty lines are ignored
Files can contain C/C++ like comments
Contents of file is divided into sections.
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:
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.
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:
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.