Merge lp:~oontvoo/cfg-to-pda/define-rules into lp:cfg-to-pda

Proposed by Vy Nguyen
Status: Merged
Merged at revision: 9
Proposed branch: lp:~oontvoo/cfg-to-pda/define-rules
Merge into: lp:cfg-to-pda
Diff against target: 123 lines (+51/-22)
3 files modified
pom.xml (+7/-6)
src/main/javacc/CFGGrammar.jj (+19/-11)
src/test/java/parser/ParserTest.java (+25/-5)
To merge this branch: bzr merge lp:~oontvoo/cfg-to-pda/define-rules
Reviewer Review Type Date Requested Status
Vy Thuy Nguyen Pending
Review via email: mp+130290@code.launchpad.net

Description of the change

define simple rules + test and fix pom.xml (update junit to 4.)

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pom.xml'
2--- pom.xml 2012-10-18 05:36:28 +0000
3+++ pom.xml 2012-10-18 06:50:23 +0000
4@@ -14,14 +14,15 @@
5 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
6 </properties>
7
8- <dependencies>
9+ <dependencies>
10 <dependency>
11- <groupId>junit</groupId>
12- <artifactId>junit</artifactId>
13- <version>3.8.1</version>
14- <scope>test</scope>
15+ <groupId>junit</groupId>
16+ <artifactId>junit</artifactId>
17+ <version>4.8.1</version>
18+ <scope>test</scope>
19 </dependency>
20- </dependencies>
21+</dependencies>
22+
23
24 <build>
25 <plugins>
26
27=== modified file 'src/main/javacc/CFGGrammar.jj'
28--- src/main/javacc/CFGGrammar.jj 2012-10-18 05:52:49 +0000
29+++ src/main/javacc/CFGGrammar.jj 2012-10-18 06:50:23 +0000
30@@ -23,7 +23,9 @@
31 * to a PDA
32 *
33 * All upercase letters are `variables`
34- * Anything else (lowercase and symbol) is considered `terminal`
35+ * Anything else (lowercase and symbol
36+ * (except `=` and `>` and `=>` because these two are used to make up the 'arrow')
37+ * is considered `terminal`
38 */
39
40 options
41@@ -38,11 +40,7 @@
42
43 class CFGGrammar
44 {
45- public static void main( String[] args ) throws ParseException, TokenMgrError
46- {
47- CFGGrammar parser = new CFGGrammar( System.in );
48- parser.Start();
49- }
50+ // TODO
51 }
52 PARSER_END(CFGGrammar)
53
54@@ -50,11 +48,21 @@
55 {
56 }
57 {
58- <NUMBER>
59- ( <PLUS> <NUMBER>)*
60- <EOF>
61+ <UPPER>
62+ <ARROW>
63+ (<UPPER> | <LOWER>)
64+ (<PIPE> (<UPPER> | <LOWER>))*
65+ [<EOF>]
66 }
67
68 SKIP : {" " | "\n" | "\r" | "\r\n"}
69-TOKEN : { <PLUS: "+">}
70-TOKEN : { <NUMBER: (["0"-"9"])+ >}
71+TOKEN :
72+{
73+ <ARROW: "=>" >
74+|
75+ <LOWER: (["a"-"z"])+ >
76+|
77+ <PIPE: "|">
78+|
79+ <UPPER: (["A"-"Z"])+ >
80+}
81
82=== modified file 'src/test/java/parser/ParserTest.java'
83--- src/test/java/parser/ParserTest.java 2012-10-18 05:52:49 +0000
84+++ src/test/java/parser/ParserTest.java 2012-10-18 06:50:23 +0000
85@@ -20,12 +20,32 @@
86
87 package parser;
88
89+import java.io.StringReader;
90+import java.io.BufferedReader;
91+import org.junit.Test;
92+
93+import static org.junit.Assert.*;
94 public class ParserTest
95 {
96- public static void main (String args[])
97- {
98-
99- CFGGrammar gram = new CFGGrammar(System.in);
100-
101+
102+ @Test
103+ public void testSimple() throws ParseException
104+ {
105+ doTest("A=> a");
106+
107+ }
108+
109+ @Test
110+ public void testMultipleProductions() throws ParseException
111+ {
112+ doTest("A=> a | AB | Ab");
113+
114+ }
115+
116+ private static void doTest(String in) throws ParseException
117+ {
118+ CFGGrammar parser = new CFGGrammar(new BufferedReader(new StringReader(in)));
119+
120+ parser.Start();
121 }
122 }
123\ No newline at end of file

Subscribers

People subscribed via source and target branches

to all changes: