GithubHelp home page GithubHelp logo

lexer's Introduction

Lexer

简单词法分析器,由Jflex生成。

包含以下编程语言的词法分析器:

  • C
  • C++
  • Java
  • JavaScript

xxLexer.java是词法分析器类。假如使用C语言词法分析器,调用方法如下:

FileReader fileReader=new FileReader("jflexTest.c");
CLexer cLexer=new CLexer(fileReader);
int idx=0;
while (true) {
	try
	{
		CType cType=cLexer.yylex();
		if(cType==CType.EOF)
		{
			break;
		}
		//这里输出三个数据
		//1.状态的位置
		//2.状态的名称
		//3.状态的内容
		//4.内容的长度
		int len=cLexer.yytext().length();
		String target=String.format("(%d,%s,\"%s\",%d)", idx,cType.name(),cLexer.yytext(),len);
		System.out.println(target);
		idx+=len;
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
}

xxLexer成员解释:

  • xxLexer(Reader reader) 从Reader构造一个词法分析器对象
  • yylex() 得到下一个词法分析器状态
  • yytext() 返回当前状态所匹配的文本

lexer's People

Contributors

luoyesiqiu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lexer's Issues

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.