Code Examples
A repository of 155 code examples for BeepBeep
ParserExample.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2018 Sylvain HallĂ©
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published
7  by the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package dsl;
19 
20 import java.io.FileNotFoundException;
21 import java.io.InputStream;
22 
23 import ca.uqac.lif.bullwinkle.BnfParser;
24 import ca.uqac.lif.bullwinkle.BnfParser.InvalidGrammarException;
25 import ca.uqac.lif.bullwinkle.BnfParser.ParseException;
26 import ca.uqac.lif.bullwinkle.ParseNode;
27 import ca.uqac.lif.bullwinkle.ParseNodeVisitor.VisitException;
28 
29 /**
30  * Use the Bullwinkle parser to parse simple arithmetic expressions.
31  * <p>
32  * <img src="./doc-files/dsl/tree.png" alt="Parse tree">
33  * @author Sylvain HallĂ©
34  */
35 public class ParserExample
36 {
37  @SuppressWarnings("unused")
38  public static void main(String[] args) throws FileNotFoundException, InvalidGrammarException, ParseException, VisitException
39  {
40  ///
41  InputStream is = ParserExample.class
42  .getResourceAsStream("arithmetic.bnf");
43  BnfParser parser = new BnfParser(is);
44  ParseNode root = parser.parse("3 + (4 - 5)");
45  ///
46  }
47 
48 }
Use the Bullwinkle parser to parse simple arithmetic expressions.