如何为Java/jsf代码创建自己的解析器? [英] How do I make my own parser for java/jsf code?

查看:86
本文介绍了如何为Java/jsf代码创建自己的解析器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建自己的解析器",例如:计算(4+(3-4 ^ 2))* 2或 解析java,jsf,html代码.

Hi I'd like to make my own 'parser', e.g: computing (4+(3-4^2))*2 or parsing java,jsf,html code.

事实上,我做了这样的事情,但是我感觉不好.

In fact I did something like this but I feel it's not good.

对我有什么好处吗?我试图阅读更多,但我有点困惑,LL,LR,AST,BNF,javacc yacc等:).我不确定何时要计算4 + ...

Is there anything good for me? I've tried to read more, but I'm bit confused, LL, LR, AST,BNF,javacc yacc etc :). I'm not sure which way to go, when I would like to compute 4+...

或者如果我想解析java,jsf代码并从中生成某些东西(另一个Java代码)

or if I'd like to parse java,jsf code and produce something from this(another java code)

是否有像ast这样的一般性好东西?或我可以同时使用的东西?

Is there anything generaly good enough like ast? or something which I can use for both?

感谢您的帮助.

推荐答案

在进行其他任何操作之前,您必须了解有关解析的所有内容均基于语法.

Before anything else, you have to understand that everything about parsing is based on grammars.

语法以如何以基本单位分解文本以及如何以有意义的方式堆叠这些单位来描述您要实现的语言.您可能还需要寻找令牌非终端终端概念.

Grammars describe the language you want to implement in terms of how to decompose the text in basic units and how to stack those units in some meaning ful way. You may also want to look for the token, non-terminal, terminal concepts.

LL和LR之间的差异可以是两种:实现差异和语法编写差异.如果您使用标准工具,则只需要了解第二部分.

Differences between LL and LR can be of two kinds: implementation differences, and grammar writing differences. If you use a standard tool you only need to understand the second part.

我通常使用LL(自上而下)语法.它们甚至使用自定义代码也更易于编写和实现. LR语法理论上涵盖了更多种语言,但在正常情况下,当您需要进行一些正确的错误检测时,它们只是一个障碍.

I usually use LL (top-down) grammars. They are simpler to write and to implement even using custom code. LR grammars theoretically cover more kinds of languages but in a normal situation they are just a hindrance when you need some correct error detection.

一些随机指针:

  • javacc (java,LL)
  • antlr (java,LL)
  • 是的(LL,萨米菲尔),
  • 野牛(古老的 yacc 的C,LR,GNU版本)
  • javacc (java, LL),
  • antlr (java, LL),
  • yepp (smarteiffel, LL),
  • bison (C, LR, GNU version of the venerable yacc)

这篇关于如何为Java/jsf代码创建自己的解析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆