Code Monkey home page Code Monkey logo

jlexphp's Introduction

JLexPHP: a Lexical Analyzer Generator for PHP, based on JLex.
For copyright and licensing information, see the COPYING file.

This is an adaptation of some Java code that generates lexers from lex style
input files.

The porting effort was pretty trivial, with the hardest part being the buffer management.

Usage is fairly typical of lexers; you'll want to create a lexer file like this:

----8<------
<?php
include 'jlex.php';

%%

D = [0-9]

%%

D+ { echo "The number ", $this->yytext(), "\n"; }
.  { echo "Something else ", $this->yytext(), "\n"; }

----8<------

Then run process this file:

  java -cp JLexPHP.jar JLexPHP.Main your.lex

(the supplied makefile will create the jar file for you, or you
can build it with:

  javac JLexPHP/Main.java
  jar cvf JLexPHP.jar JLexPHP/*.class
)

JLexPHP will output your.lex.php.  It will contain a class that will recognize
the input stream described in your .lex file.

Usage of that class is along the lines of:

$scanner = new Yylex(fopen("file", "r"));
while ($scanner->yylex())
	;

A more complicated scanner will use the createToken() method to create a token
object that can then be fed into a parser, such as a lemon based parser.  You
can see an example of that in the c.lex source file.  It is designed to work in
conjunction with it's corresponding c.y file in my lemon port for php.


You can find more information on the lexer syntax in the JLex manual:
http://www.cs.princeton.edu/~appel/modern/java/JLex/current/manual.html


Enjoy!

--Wez.

jlexphp's People

Contributors

wez avatar dhobsd avatar vonloxley avatar

Watchers

Roy Merkel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.