Alex Files

Alex User Guide
Prev |  | Next

# Chapter 3. Alex Files

In this section we describe the layout of an Alex lexical specification. We begin with the lexical syntax; elements of the lexical syntax are referred to throughout the rest of this documentation, so you may need to refer back to the following section several times.

# 3.1. Lexical syntax

Alex's lexical syntax is given below. It is written as a set of macro definitions using Alex's own syntax. These macros are used in the BNF specification of the syntax later on.

    $digit      = [0-9]
    $octdig     = [0-7]
    $hexdig     = [0-9A-Fa-f]
    $special    = [\.\;\,\$\|\*\+\?\#\~\-\{\}\(\)\[\]\^\/]
    $graphic    = $printable # $white

    @string     = \" ($graphic # \")* \"
    @id         = [A-Za-z][A-Za-z'_]*
    @smac       = '$' id
    @rmac       = '@' id
    @char       = ($graphic # $special) | @escape
    @escape     = '\\' ($printable | 'x' $hexdig+ | 'o' $octdig+ | $digit+)
    @code       = -- curly braces surrounding a Haskell code fragment

Prev | Home | Next
Introduction |  | Syntax of Alex files