-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadme
145 lines (108 loc) · 5.05 KB
/
readme
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
lex
=====
PHP 5.3 or higher is required.
PHP 5.3 以上が必要です。
静的な呼び出しの継承に
遅延静的束縛 (Late Static Bindings)を使用しているためです。
http://php.net/manual/ja/language.oop5.late-static-bindings.php
PHP 5.3 未満で使用するには、
継承を止めて、「static::」を「self::」に書き直します。
amachang さん以下のものをPHPに移植したものです。
「WebKit の CSS の字句解析部分を JavaScript に移植しました」
http://d.hatena.ne.jp/amachang/20080502/1209732467
規則部の移植元 :
http://svn.webkit.org/repository/webkit/trunk/WebCore/css/tokenizer.flex
amachang さん作との違い :
1点目 :
汎用的な機能をもった Lexer クラスと
Lexer クラスに WebKit の CSS の字句解析に必要な情報を
オーバーライドした CssLexer クラスという構成になっています。
そのため、
amachang さん作では、
直接書かれていた css のコメント部分を無視している処理を一般化しています。
また、
無視をするかどうかを制御する setIgnore メソッドを追加しています。
2点目 :
Lexer クラスは、トークンの値を含んでいないため、
その結果の扱いには、注意が必要です。
なぜなら、
トークンの値は、 yacc などの構文解析器生成系による生成が必要で、
lex だけではその値を知り得ないためです。
(yacc と lex はセットで扱うので、
lex の中に含んでしまうのも可能です。
但し、その場合には、
yacc 側のトークン値が変化した場合、lex 側を書き直す処理が必要になります。)
Lexer::lex() では、以下の結果を返します。
array(
$maybe_yychar, // トークン名の文字列(string) または ASCII 値
$value, // マッチした文字列
$next // マッチした文字列を削除したソース
);
本来は、トークンの値(int)、または、ASCII 値(int)を返す必要がありますが、
トークンの値を「知らない」ことになっているため、
マッチしたトークンについては、そのトークン名を文字列(string)で返し、
そうでないものは、ASCII 値(int)を返します。
そのため、
呼び出し側で、トークンの値を適当に返す必要があります。
例)
class KMyacc
{
const INTEGER = 257;
/* 略 */
}
と定義されている中で yylex() から、Lexer クラスを呼ぶ場合
/**
* $maybe_yychar => string 'INTEGER'
* $value => string '123'
* $next => string ''
*/
list($maybe_yychar, $value, $next) = Lexer::lex('123');
$yychar = is_string($maybe_yychar) ? constant('self::' . $maybe_yychar) : $maybe_yychar;
yacc
======
kmyacc の PHPテンプレートをクラスで書き直したものです。
-kmyacc - 多言語対応LALRパーサー生成系
--http://www005.upp.so-net.ne.jp/kmori/kmyacc/
--yaccの生成を多言語できるように、テンプレート機能を持ったパーサー生成
--手を加えるのが簡単すぎる。
-PHP版のテンプレートの元を作った方
--PHPのyaccを作ったよ - ベイエリア情報局
--http://blog.bz2.jp/archives/2008/01/phpyacc.html
-上記のバグを修正した方
--ActionScriptのyaccを作ったよ - yukobaのブログ
--http://d.hatena.ne.jp/yukoba/20080220/p1
--今回は、このPHPテンプレートを元に手を加えています。
-インストール&デモ
--ハタさんのブログ(復刻版) : kmyacc-phpを触る
--http://blog.xole.net/article.php?id=653
-各種パッチを当てまくったkmyacc
--kmyacc に各種パッチを当てまくったバージョンを fork しました - muddy brown thang
--http://d.hatena.ne.jp/moriyoshi/20090824/1251119737
基本的なコマンド
====
normal mode
「calc.phpy」を使って生成します。
kmyacc calc.phpy
debug mode (通常は削除されるデバック用コードを残します)
kmyacc -t calc.phpy
custom model
(デフォルト(/usr/local/lib/kmyacc)でなく自前のテンプレートを使用します。)
kmyacc -m /<path>/kmyacc.php.parser calc.phpy
kmyacc
======
kmyacc is an LALR(1) parser generator.
HP : http://www005.upp.so-net.ne.jp/kmori/kmyacc/
kmyacc COPYRIGHT
=========
Copyright (C) 1987,1989,1992,1993,2005,2006 MORI Koichiro.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA