In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the relevant knowledge of "how to use Java LPAREN". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to use Java LPAREN" can help you solve the problem.
In order to make lexical analysis easier, we usually do not use "(", ")" and other character strings to represent terminating symbols, but instead use integer symbols such as LPAREN and RPAREN.
PARSER_BEGIN (Grammar)
Public class Grammar implements NodeType {
Public ParseTreeNode GetParseTree (InputStream in) throws ParseException
{
Grammar parser = new Grammar (in)
Return parser . _ Expression ()
}
}
PARSER_END (Grammar)
SKIP:
{
"" | ""
}
TOKEN:
{
< ID: ["a"-"z","A"-"Z","_">(["a"-"z", "A"-"Z", "_", "0"-"9" >) * >
| |
< NUM: ( ["0"-"9">) + >
| |
< PLUS: "+" >| |
< MINUS: "-" >| |
< TIMERS: "*" >| |
< OVER: "/" >| |
< LPAREN: "(" >| |
< RPAREN: ")" >}
ParseTreeNode _ Expression ():
{
ParseTreeNode ParseTree = null
ParseTreeNode node
}
{
(node=Simple__Expression ())
{
If (ParseTree = = null)
ParseTree = node
Else
{
ParseTreeNode t
T = ParseTree
While (t.next! = null)
T=t.next
T.next = node
}
}
) *
{return ParseTree;}
}
ParseTreeNode Simple__Expression ():
{
ParseTreeNode node
ParseTreeNode t
Int op
}
{
Node=Term () {}
(
Op=addop () t=Term ()
{
ParseTreeNode newNode = new ParseTreeNode ()
NewNode.nodetype = op
NewNode.child [0] = node
NewNode.child [1] = t
Switch (op)
{
Case PlusOP:
NewNode.name = "Operator: +"
Break
Case MinusOP:
NewNode.name = "Operator: -"
Break
}
Node = newNode
}
) *
{return node;}
}
Int addop (): {}
{
{return PlusOP;}
| | {return MinusOP;} |
}
ParseTreeNode Term ():
{
ParseTreeNode node
ParseTreeNode t
Int op
}
{
Node=Factor () {}
(
Op=mulop () t=Factor ()
{
ParseTreeNode newNode = new ParseTreeNode ()
NewNode.nodetype = op
NewNode.child [0] = node
NewNode.child [1] = t
Switch (op)
{
Case TimersOP:
NewNode.name = "Operator: *"
Break
Case OverOP:
NewNode.name = "Operator: /"
Break
}
Node = newNode
}
) *
{
Return node
}
}
Int mulop (): {}
{
{return TimersOP;}
| | {return OverOP;} |
}
ParseTreeNode Factor ():
{
ParseTreeNode node
Token t
}
{
T =
{
Node=new ParseTreeNode ()
Node.nodetype= IDstmt
Node.name = t.image
Return node
}
| |
T =
{
Node=new ParseTreeNode ()
Node.nodetype= NUMstmt
Node.name = t.image
Node.value= Integer.parseInt (t.image)
Return node
}
| |
Node=Simple__Expression ()
{
Return node
}
}
The definition in SKIP is the symbol that is ignored while carrying on the lexical analysis. In TOKEN, it is the lexical notation that needs to be recognized when doing lexical analysis. Of course, all of this is expressed in regular expressions.
In this example, there are multiple non-terminal symbols, and you can see that we need to write a procedure for each non-final symbol. Different non-terminating symbols can be called each other during the recognition process.
Take the Simple__Expression () process as an example, its production is Expression-> Term {addop Term}, while the input file format in javacc is node=Term () {} (op=addop () t=Term () {... }) * as mentioned earlier, the "*" symbol here is the same as a regular expression, which is repeated 0 to infinite times. Then Simple_Expression equals grammar Term Addop Term Addop Term Addop Term. And Addop is also equivalent to two operational symbols PLUS and MINUS. Here we write the grammar of Expression, but also use the assignment expression, because this is different from Yacc, Javacc grammar recognition is completely achieved in the process of function, then if we want to identify Simple_Expression grammar, it is equivalent to recognizing Term and Addop grammar in order, and identifying that grammar is equivalent to calling those two non-terminal recognition functions. Because of this, I think the grammar recognition processing of Javacc is very close to the operation process of the program. We don't need to use strict grammar format and complex system parameters like YACC. This is the end of the content about "how to use Java LPAREN". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.