diff options
author | Ben Gruver <bgruv@google.com> | 2011-11-15 16:02:09 -0800 |
---|---|---|
committer | Ben Gruver <bgruv@google.com> | 2011-11-16 11:07:51 -0800 |
commit | 324c4644fee44b9898524c09511bd33c3f12e2df (patch) | |
tree | 1e3285425b3b39500a7ec82b47535e354587d67b /antlr-3.4/runtime/Python/tests/t015calc.g | |
parent | 939f4a47010d361698e8f81a67e2337e180fc086 (diff) | |
download | antlr-jb-mr1-dev-plus-aosp.tar.gz |
Add full source for antlr project (version 3.4)android-sdk-support_r11android-cts-4.2_r2android-cts-4.2_r1android-cts-4.1_r4android-cts-4.1_r2android-cts-4.1_r1android-4.3_r3.1android-4.3_r3android-4.3_r2.3android-4.3_r2.2android-4.3_r2.1android-4.3_r2android-4.3_r1.1android-4.3_r1android-4.3_r0.9.1android-4.3_r0.9android-4.3.1_r1android-4.2_r1android-4.2.2_r1.2android-4.2.2_r1.1android-4.2.2_r1android-4.2.1_r1.2android-4.2.1_r1.1android-4.2.1_r1android-4.1.2_r2.1android-4.1.2_r2android-4.1.2_r1android-4.1.1_r6.1android-4.1.1_r6android-4.1.1_r5android-4.1.1_r4android-4.1.1_r3android-4.1.1_r2android-4.1.1_r1.1android-4.1.1_r1tools_r22.2tools_r22tools_r21jb-releasejb-mr2.0.0-releasejb-mr2.0-releasejb-mr2-releasejb-mr2-devjb-mr1.1-releasejb-mr1.1-dev-plus-aospjb-mr1.1-devjb-mr1-releasejb-mr1-dev-plus-aospjb-mr1-devjb-mr0-releasejb-dev
This replaces the existing source for an unknown version of the antlr-runtime
with the full source for the antlr tool. However, we are still building
just the runtime jar, not the full tool.
The full tool will be included as a prebuilt jar, due to the complexities
of building this tool.
Since we will have both the full tool and the runtime jar in the Android tree,
the module name for the runtime jar has been changed from "antlr" to
"antlr-runtime"
Change-Id: I38d5f3e5e82392dc122f46bf7961aab5b42e40c5
Signed-off-by: Ben Gruver <bgruv@google.com>
Diffstat (limited to 'antlr-3.4/runtime/Python/tests/t015calc.g')
-rw-r--r-- | antlr-3.4/runtime/Python/tests/t015calc.g | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/antlr-3.4/runtime/Python/tests/t015calc.g b/antlr-3.4/runtime/Python/tests/t015calc.g new file mode 100644 index 0000000..f08e3ce --- /dev/null +++ b/antlr-3.4/runtime/Python/tests/t015calc.g @@ -0,0 +1,54 @@ +grammar t015calc; +options { + language = Python; +} + +@header { +import math +} + +@parser::init { +self.reportedErrors = [] +} + +@parser::members { +def emitErrorMessage(self, msg): + self.reportedErrors.append(msg) +} + +evaluate returns [result]: r=expression {result = r}; + +expression returns [result]: r=mult ( + '+' r2=mult {r += r2} + | '-' r2=mult {r -= r2} + )* {result = r}; + +mult returns [result]: r=log ( + '*' r2=log {r *= r2} + | '/' r2=log {r /= r2} +// | '%' r2=log {r %= r2} + )* {result = r}; + +log returns [result]: 'ln' r=exp {result = math.log(r)} + | r=exp {result = r} + ; + +exp returns [result]: r=atom ('^' r2=atom {r = math.pow(r,r2)} )? {result = r} + ; + +atom returns [result]: + n=INTEGER {result = int($n.text)} + | n=DECIMAL {result = float($n.text)} + | '(' r=expression {result = r} ')' + | 'PI' {result = math.pi} + | 'E' {result = math.e} + ; + +INTEGER: DIGIT+; + +DECIMAL: DIGIT+ '.' DIGIT+; + +fragment +DIGIT: '0'..'9'; + +WS: (' ' | '\n' | '\t')+ {$channel = HIDDEN}; |