Skip to content

Commit d422cb7

Browse files
committed
add copying and readme information
--HG-- branch : JLexPHP extra : convert_revision : svn%3A6e7b9e80-5218-0410-8339-b7667638d355/wez/php/JLexPHP%40148
1 parent a739949 commit d422cb7

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

COPYING

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright 2006 Wez Furlong, OmniTI Computer Consulting, Inc.
2+
Based on JLex which is:
3+
4+
JLEX COPYRIGHT NOTICE, LICENSE, AND DISCLAIMER
5+
Copyright 1996-2000 by Elliot Joel Berk and C. Scott Ananian
6+
7+
Permission to use, copy, modify, and distribute this software and its
8+
documentation for any purpose and without fee is hereby granted,
9+
provided that the above copyright notice appear in all copies and that
10+
both the copyright notice and this permission notice and warranty
11+
disclaimer appear in supporting documentation, and that the name of
12+
the authors or their employers not be used in advertising or publicity
13+
pertaining to distribution of the software without specific, written
14+
prior permission.
15+
16+
The authors and their employers disclaim all warranties with regard to
17+
this software, including all implied warranties of merchantability and
18+
fitness. In no event shall the authors or their employers be liable
19+
for any special, indirect or consequential damages or any damages
20+
whatsoever resulting from loss of use, data or profits, whether in an
21+
action of contract, negligence or other tortious action, arising out
22+
of or in connection with the use or performance of this software.
23+
**************************************************************/
24+
25+

README

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
JLexPHP: a Lexical Analyzer Generator for PHP, based on JLex.
2+
For copyright and licensing information, see the COPYING file.
3+
4+
This is an adaptation of some Java code that generates lexers from lex style
5+
input files.
6+
7+
The porting effort was pretty trivial, with the hardest part being the buffer management.
8+
9+
Usage is fairly typical of lexers; you'll want to create a lexer file like this:
10+
11+
----8<------
12+
<?php
13+
include 'jlex.php';
14+
15+
%%
16+
17+
D = [0-9]
18+
19+
%%
20+
21+
D+ { echo "The number ", $this->yytext(), "\n"; }
22+
. { echo "Something else ", $this->yytext(), "\n"; }
23+
24+
----8<------
25+
26+
Then run process this file:
27+
28+
java -cp JLexPHP.jar JLexPHP.Main your.lex
29+
30+
(the supplied makefile will create the jar file for you, or you
31+
can build it with:
32+
33+
javac JLexPHP/Main.java
34+
jar cvf JLexPHP.jar JLexPHP/*.class
35+
)
36+
37+
JLexPHP will output your.lex.php. It will contain a class that will recognize
38+
the input stream described in your .lex file.
39+
40+
Usage of that class is along the lines of:
41+
42+
$scanner = new Yylex(fopen("file", "r"));
43+
while ($scanner->yylex())
44+
;
45+
46+
A more complicated scanner will use the createToken() method to create a token
47+
object that can then be fed into a parser, such as a lemon based parser. You
48+
can see an example of that in the c.lex source file. It is designed to work in
49+
conjunction with it's corresponding c.y file in my lemon port for php.
50+
51+
52+
You can find more information on the lexer syntax in the JLex manual:
53+
http://www.cs.princeton.edu/~appel/modern/java/JLex/current/manual.html
54+
55+
56+
Enjoy!
57+
58+
--Wez.
59+
60+

jlex.php

+25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
11
<?php # vim:ts=2:sw=2:et:
2+
/*
3+
Copyright 2006 Wez Furlong, OmniTI Computer Consulting, Inc.
4+
Based on JLex which is:
5+
6+
JLEX COPYRIGHT NOTICE, LICENSE, AND DISCLAIMER
7+
Copyright 1996-2000 by Elliot Joel Berk and C. Scott Ananian
8+
9+
Permission to use, copy, modify, and distribute this software and its
10+
documentation for any purpose and without fee is hereby granted,
11+
provided that the above copyright notice appear in all copies and that
12+
both the copyright notice and this permission notice and warranty
13+
disclaimer appear in supporting documentation, and that the name of
14+
the authors or their employers not be used in advertising or publicity
15+
pertaining to distribution of the software without specific, written
16+
prior permission.
17+
18+
The authors and their employers disclaim all warranties with regard to
19+
this software, including all implied warranties of merchantability and
20+
fitness. In no event shall the authors or their employers be liable
21+
for any special, indirect or consequential damages or any damages
22+
whatsoever resulting from loss of use, data or profits, whether in an
23+
action of contract, negligence or other tortious action, arising out
24+
of or in connection with the use or performance of this software.
25+
**************************************************************
26+
*/
227

328
class JLexToken {
429
public $line;

0 commit comments

Comments
 (0)