~ubuntu-branches/ubuntu/vivid/menhir/vivid

« back to all changes in this revision

Viewing changes to demos/calc/lexer.mll

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2006-07-11 12:26:18 UTC
  • Revision ID: james.westby@ubuntu.com-20060711122618-dea56bmjs3qlmsd8
Tags: upstream-20060615.dfsg
Import upstream version 20060615.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(**************************************************************************)
 
2
(*                                                                        *)
 
3
(*  Menhir                                                                *)
 
4
(*                                                                        *)
 
5
(*  Fran�ois Pottier and Yann R�gis-Gianas, INRIA Rocquencourt            *)
 
6
(*                                                                        *)
 
7
(*  Copyright 2005 Institut National de Recherche en Informatique et      *)
 
8
(*  en Automatique. All rights reserved. This file is distributed         *)
 
9
(*  under the terms of the Q Public License version 1.0, with the         *)
 
10
(*  change described in file LICENSE.                                     *)
 
11
(*                                                                        *)
 
12
(**************************************************************************)
 
13
 
 
14
{
 
15
  open Parser
 
16
 
 
17
  exception Error of string
 
18
 
 
19
}
 
20
 
 
21
rule line = parse
 
22
| ([^'\n']* '\n') as line
 
23
    { line }
 
24
| eof
 
25
    { exit 0 }
 
26
 
 
27
and token = parse
 
28
| [' ' '\t']
 
29
    { token lexbuf }
 
30
| '\n'
 
31
    { EOL }
 
32
| ['0'-'9']+ as i
 
33
    { INT (int_of_string i) }
 
34
| '+'
 
35
    { PLUS }
 
36
| '-'
 
37
    { MINUS }
 
38
| '*'
 
39
    { TIMES }
 
40
| '/'
 
41
    { DIV }
 
42
| '('
 
43
    { LPAREN }
 
44
| ')'
 
45
    { RPAREN }
 
46
| eof
 
47
    { exit 0 }
 
48
| _
 
49
    { raise (Error (Printf.sprintf "At offset %d: unexpected character.\n" (Lexing.lexeme_start lexbuf))) }
 
50