安卓ANTLR使工作不正常 [英] android ANTLR make not working properly
问题描述
我想用ANTLR在Android上,我发现这一点: ANTLR和Android
I am trying to use ANTLR on Android, and I found this: ANTLR and Android
下载AntlrJavaRuntime后,我不知道该怎么做,我应该做出这样的:
After downloading the AntlrJavaRuntime I am not sure of what to do, I am supposed to make this:
1. lunch the appropriate target
2. make AntlrJavaRuntime
3. verify that AntlrJavaRuntime.xml was placed in /system/etc/permissions and
4. AntlrJavaRuntime.jar was placed in /system/framework
5. after this, you can run a normal make
首先,什么是第1步,即使手段?
First of all, what does step 1 even means?
其次,当我尝试这样做:让AntlrJavaRuntime我收到以下错误:
Secondly, when I try doing: make AntlrJavaRuntime I get the following error:
~/AntlrJavaRuntime$ make AntlrJavaRuntime
make: Nothing to be done for `AntlrJavaRuntime'.
这是很难找到这个文件,所以任何帮助,真是AP preciated(或如何获得ANTLR准备的Android项目一个明显的例子)。
It's very hard to find documentation about this, so any help is really appreciated (or a clear example of how to get ANTLR ready for an Android project).
推荐答案
嗯,我只是做了一个小测试与普通ANTLR版本,一切都很好。
Well, I just did a little test with a "plain" ANTLR version, and everything went just fine.
下面是我所做的:
创建一个 bk.andabac
的活动命名为一个包,名为 AndAbac
(Android的算盘)的新项目名为 AndAbac
。
Create a new project called AndAbac
(Android-Abacus) with a package named bk.andabac
and an activity called AndAbac
.
中创建一个语法文件 Exp.g
(说明的这里)系统上的任意位置,并粘贴在它下面的:
Create a grammar file called Exp.g
(explanation here) anywhere on your system and paste the following in it:
grammar Exp;
@parser::header {
package bk.andabac;
}
@lexer::header {
package bk.andabac;
}
eval returns [double value]
: exp=additionExp {$value = $exp.value;}
;
additionExp returns [double value]
: m1=multiplyExp {$value = $m1.value;}
( '+' m2=multiplyExp {$value += $m2.value;}
| '-' m2=multiplyExp {$value -= $m2.value;}
)*
;
multiplyExp returns [double value]
: a1=atomExp {$value = $a1.value;}
( '*' a2=atomExp {$value *= $a2.value;}
| '/' a2=atomExp {$value /= $a2.value;}
)*
;
atomExp returns [double value]
: n=Number {$value = Double.parseDouble($n.text);}
| '(' exp=additionExp ')' {$value = $exp.value;}
;
Number
: ('0'..'9')+ ('.' ('0'..'9')+)?
;
WS
: (' ' | '\t' | '\r'| '\n') {$channel=HIDDEN;}
;
3下载ANTLR和放大器;生成词法/语法分析器
下载ANTLR这里:<一href="http://www.antlr3.org/download/antlr-3.3-complete.jar">http://www.antlr3.org/download/antlr-3.3-complete.jar并把它放在同一目录下 Exp.g
文件。 (此处解释)生成词法和语法分析器,并复制生成的的.java
文件到以下文件夹在你的Android项目:的src / BK / andabac
。同时把这个ANTLR罐子到你的Android项目的类路径。
3 download ANTLR & generate lexer/parser
Download ANTLR here: http://www.antlr3.org/download/antlr-3.3-complete.jar and put it in the same directory as your Exp.g
file. Generate a lexer and parser (explanation here) and copy the generated .java
files to the following folder in your Android project: src/bk/andabac
. Also put this ANTLR jar to the classpath of your Android project.
粘贴 RES /布局/ main.xml中
如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:id="@+id/input_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="5 * (8 + 2)"
/>
<Button
android:id="@+id/parse_button"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="eval" />
<TextView
android:id="@+id/output_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
</LinearLayout>
和的src / BK / andabac / AndAbac.java
如下:
package bk.andabac;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
public class AndAbac extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button button = (Button)findViewById(R.id.parse_button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
EditText in = (EditText)findViewById(R.id.input_text);
TextView out = (TextView)findViewById(R.id.output_text);
String source = in.getText().toString();
ExpLexer lexer = new ExpLexer(new ANTLRStringStream(source));
ExpParser parser = new ExpParser(new CommonTokenStream(lexer));
try {
out.setText(source + " = " + parser.eval());
}
catch (RecognitionException e) {
out.setText("Oops: " + e.getMessage());
}
}
});
}
}
5的测试应用程序
无论是运行在模拟器的项目,或创建一个APK文件和Android设备(我测试了,都工作)上安装此。你会看到$ P $经过以下pssing的<大骨节病>评估键:
这篇关于安卓ANTLR使工作不正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!