root/lang/python/dfareg/branches/PLY200811/dfareg/lexer.py @ 24197

Revision 24197, 0.6 kB (checked in by hiratara, 5 years ago)

PLY使ってみる
PLYを使うコンパイラに変更
「RA layer request failed: COPY of」が発生のため、いったん削除
PLYブランチを作成(再)
やっぱエラー出るので、もう一回削除
PLYを利用するコンパイラに変更(再)

Line 
1# -*- coding: utf-8 -*-
2"""
3regular expression lexical analyzer
4----------------------------------------
5Author: hiratara <hira.tara@gmail.com>
6"""
7from ply import lex
8
9tokens = (
10    'OPE_UNION',
11    'OPE_STAR',
12    'LPAREN',
13    'RPAREN',
14    'VALUE',
15)
16
17def t_OPE_UNION(t):
18    ur'\|'
19    return t
20
21def t_OPE_STAR(t):
22    ur'\*'
23    return t
24
25def t_LPAREN(t):
26    ur'\('
27    return t
28
29def t_RPAREN(t):
30    ur'\)'
31    return t
32
33def t_VALUE(t):
34    ur'\\?(.)'
35    t.value = t.value[-1:]
36    return t
37
38def t_error(t):
39    print "Illegal character '%s'" % t.value[0]
40    raise t
41
42lex.lex()
Note: See TracBrowser for help on using the browser.