Mercurial > ~dholland > hg > ag > index.cgi
diff tests/agcl/ffcalc/ffc-w.syn @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/agcl/ffcalc/ffc-w.syn Sat Dec 22 17:52:45 2007 -0500 @@ -0,0 +1,89 @@ +{/* + FOUR FUNCTION CALCULATOR: FFCALC.SYN +*/ +#include "Number.h" + +int Number::nCreated = 0; +char Number::buf[100]; + +} + +// -- CONFIGURATION SECTION ---------------------------- +[ + disregard white space + lexeme { real} + parser file name = "#.cpp" + wrapper {Number} + line numbers + allow macros = OFF + default token type = Number + token names +] + +// -- FOUR FUNCTION CALCULATOR ------------------------- +calculator $ + -> [calculation?, '\n']..., eof + +calculation + -> expression:x =printf("%s\n", x.asString()); + -> name:n, '=', expression:x ={ + printf("%c = %s\n",n+'A', (value[n]=x).asString());} + -> error + +(Number) expression + -> term + -> expression:x, '+', term:t = { + printf("x = %s\n", x.asString()); + printf("t = %s\n", t.asString()); + x+=t; + printf("x = %s\n", x.asString()); + return x; + } + -> expression:x, '-', term:t = x-=t; + +(Number) term + -> factor + -> term:t, '*', factor:f = t*=f; + -> term:t, '/', factor:f = t/=f; + +(Number) factor + -> name:n = value[n]; + -> real:x =Number(x); + -> '(', expression:x, ')' = x; + -> '-', factor:f = -f; + +// -- LEXICAL UNITS ------------------------------------ +digit = '0-9' +eof = -1 + +(void) white space + -> ' ' + '\t' + '\r' + '\f' + '\v' + -> "/*", ~eof?..., "*/" + +(int) name + -> 'a-z' + 'A-Z':c = c-'A'; + +(double) real + -> integer part:i, '.', fraction part:f = i+f; + -> integer part, '.'? + -> '.', fraction part:f = f; + +(double) integer part + -> digit:d = d-'0'; + -> integer part:x, digit:d = 10*x + d-'0'; + +(double) fraction part + -> digit:d =(d-'0')/10.; + -> digit:d, fraction part:f =(d-'0' + f)/10.; + +{ /* -- EMBEDDED C ---------------------------------- */ + +#define SYNTAX_ERROR printf("%s, line %d, column %d\n", \ + (PCB).error_message, (PCB).line, (PCB).column) + + Number value[64]; /* registers */ + int main(void) { + ffcalc(); + return 0; + } +} /* -- END OF EMBEDDED C ----------------------------*/