Skip to content

Commit 119fb2b

Browse files
committed
updating langua examples
Signed-off-by: ncardozo <[email protected]>
1 parent 8d23e68 commit 119fb2b

File tree

10 files changed

+81
-69
lines changed

10 files changed

+81
-69
lines changed

.classpath

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4+
<classpathentry kind="src" path="src"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin

.project

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>parser-tester</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.release=enabled
12+
org.eclipse.jdt.core.compiler.source=1.8
File renamed without changes.
File renamed without changes.

src/lym/languages/expressions/exp.jj

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* JavaCC template file created by SF JavaCC plugin 1.5.28+ wizard for JavaCC 1.5.0+
3+
*/options{ static = true;}PARSER_BEGIN(exp)package grammar;
4+
5+
public class exp{ public static void main(String args []) throws ParseException { exp parser = new exp(System.in); while (true) { System.out.println("Reading from standard input..."); System.out.print("Enter an expression like \"1+(2+3)*4;\" :"); try { switch (exp.one_line()) { case 0 : System.out.println("OK."); break; case 1 : System.out.println("Goodbye."); break; default : break; } } catch (Exception e) { System.out.println("NOK."); System.out.println(e.getMessage()); exp.ReInit(System.in); } catch (Error e) { System.out.println("Oops."); System.out.println(e.getMessage()); break; } } }}PARSER_END(exp)SKIP :{ " "| "\r"| "\t"| "\n"}TOKEN : /* OPERATORS */{ < PLUS : "+" >| < MINUS : "-" >| < MULTIPLY : "*" >| < DIVIDE : "/" >}TOKEN :{ < CONSTANT : (< DIGIT >)+ >| < #DIGIT : [ "0"-"9" ] >}int one_line() :{int res = 0;}{ res = sum() ";" {
6+
System.out.println(res); return 0; }| ";" { return 1; }}int sum() :{
7+
int left;
8+
int right;
9+
String op;
10+
int res = 0;
11+
}{ left = term() ( ( < PLUS > | < MINUS > ) {
12+
op = token.image;
13+
} right = term()
14+
{
15+
if(op.equals("+"))
16+
left = left + right;
17+
else
18+
left = left - right;
19+
} )*
20+
{
21+
return left;
22+
} }int term() :{
23+
int left;
24+
int right = 0;
25+
String op;
26+
}{ left = unary() { } ( ( < MULTIPLY > | < DIVIDE > ) {
27+
op = token.image;
28+
} right = unary()
29+
{
30+
if(op.equals("*"))
31+
left = left * right;
32+
else
33+
left = left / right;
34+
} )*
35+
{ return left;
36+
}}int unary() :{ int res; }{ < MINUS > res = element()
37+
{ return -1*res;
38+
}| res = element()
39+
{
40+
return res;
41+
}}int element() :{int res;}{ < CONSTANT >
42+
{ int num = Integer.parseInt(token.image);
43+
return num;
44+
}| "(" res = sum() ")" { return res; }}

lym/languages/grace/Grace.jj src/lym/languages/grace/Grace.jj

+1-69
Original file line numberDiff line numberDiff line change
@@ -9,72 +9,4 @@ public class Grace{ public static void main(String args []) throws ParseExcep
99
void grace_expression() :
1010
{ }
1111
{
12-
(
13-
vars()
14-
| block ()
15-
)
16-
";"
17-
}
18-
19-
void vars() :
20-
{}
21-
{
22-
( < DEF > <WORD > <UNIFY > < CONSTANT >
23-
| < VAR > <WORD > <ASSIGNMENT > < CONSTANT >
24-
)+
25-
}
26-
27-
void block() :
28-
{ }
29-
{
30-
(
31-
"{"
32-
< WORD >
33-
( fun_call()
34-
| annonymous_function()
35-
)
36-
"}"
37-
)+
38-
}
39-
40-
void fun_call() :
41-
{}
42-
{
43-
"."< WORD >
44-
}
45-
46-
void annonymous_function() :
47-
{ }
48-
{
49-
"->" expression()
50-
}
51-
52-
void expression() :
53-
{}
54-
{
55-
< WORD >
56-
(
57-
fun_call()
58-
| arithmetic_exp()
59-
)
60-
}
61-
62-
void arithmetic_exp() :
63-
{ }
64-
{
65-
("+" | "-" | "*" | "/") var()
66-
}
67-
68-
void var() :
69-
{}
70-
{
71-
< WORD > | < CONSTANT >
72-
}
73-
74-
75-
76-
77-
78-
79-
80-
12+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)