diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2021-05-19 16:22:10 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2021-05-19 19:14:52 +0900 |
commit | 71fb4a139179e9d27070f7f3e98971e3e029697f (patch) | |
tree | 92fbf03f1e546b3c99e6e06e98100b6ef8e4e2c6 /debian/uncrustify-trinity/uncrustify-trinity-0.73.0/tests/input/pawn/rpn_calc.pawn | |
parent | 6eae1a16a1001287ef5129db86f4ef2145ace3ca (diff) | |
download | extra-dependencies-71fb4a139179e9d27070f7f3e98971e3e029697f.tar.gz extra-dependencies-71fb4a139179e9d27070f7f3e98971e3e029697f.zip |
uncrustify: updated to version 0.73
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'debian/uncrustify-trinity/uncrustify-trinity-0.73.0/tests/input/pawn/rpn_calc.pawn')
-rw-r--r-- | debian/uncrustify-trinity/uncrustify-trinity-0.73.0/tests/input/pawn/rpn_calc.pawn | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/debian/uncrustify-trinity/uncrustify-trinity-0.73.0/tests/input/pawn/rpn_calc.pawn b/debian/uncrustify-trinity/uncrustify-trinity-0.73.0/tests/input/pawn/rpn_calc.pawn new file mode 100644 index 00000000..2965d9c7 --- /dev/null +++ b/debian/uncrustify-trinity/uncrustify-trinity-0.73.0/tests/input/pawn/rpn_calc.pawn @@ -0,0 +1,71 @@ +/* main rpn parser and lexical analysis, part of the RPN calculator */ +#include <rational> +#include <string> +enum token + { + t_type, /* operator or token type */ + Rational: t_value, /* value, if t_type is "Number" */ + t_word[20], /* raw string */ + } + +const Number = '0' +const EndOfExpr = '#' + +rpncalc(const string[]) + { + new index + new field[token] + for ( ;; ) + { + field = gettoken(string, index) + switch (field[t_type]) + { + case Number: + push field[t_value] + case '+': + push pop() + pop() + case '-': + push - pop() + pop() + case '*': + push pop() * pop() + case '/', ':': + push 1.0 / pop() * pop() + case EndOfExpr: + break /* exit "for" loop */ + default: + printf "Unknown operator '%s'\n", field[t_word] + } + } + + printf "Result = %r\n", pop() + + if (clearstack()) + print "Stack not empty\n", red + } + +gettoken(const string[], &index) + { + /* first get the next "word" from the string */ + new word[20] + word = strtok(string, index) + /* then parse it */ + new field[token] + field[t_word] = word + if (strlen(word) == 0) + { + field[t_type] = EndOfExpr /* special "stop" symbol */ + field[t_value] = 0 + } + else if ('0' <= word[0] <= '9') + { + field[t_type] = Number + field[t_value] = rationalstr(word) + } + else + { + field[t_type] = word[0] + field[t_value] = 0 + } + return field + } + |