diff tests/agcl/oldagsrc/asilbug1.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/oldagsrc/asilbug1.syn	Sat Dec 22 17:52:45 2007 -0500
@@ -0,0 +1,281 @@
+{
+/*
+ VM.SYN
+
+ Virtual Machine Compiler
+ Copyright (c) 1997 Parsifal Software, All Rights Reserved.
+
+ The expression syntax is borrowed from C but with the
+ addition of the FORTRAN exponentiation operator (**).
+
+ The cast, increment, and decrement operators are not
+ implemented, nor are operations that are defined only
+ for integers:
+   Bitwise logical operators:   &, |, ^, ~, &=, |=, ^=
+   Remainder operators:         %, %=
+   Shift operators:             <<, >>, >>=, <<=
+
+ The supported operations are:
+   Assignment operators:        =, +=, -=, *=, /=
+   Conditional expressions:     ? :
+   Logical operators:           !, &&, ||
+   Comparison operators:        ==, !=, <, <=, >, >=
+   Binary arithmetic operators: +, -, *, /
+   Exponentiation:              **
+   Unary arithmetic operators:  +, -
+   Parentheses
+   Function calls
+
+ All arithmetic is double precision floating point.
+
+ Statements may include expression statements, blocks, if/else statements
+ or while statements, following the rules of C.
+
+ The statement syntax has been written to avoid the conventional
+ if/else ambiguity.
+
+ There are no declarations. All variables are presumed to be double.
+
+ Input strings may contain any number of statements. White space may be
+ used freely, including both C and C++ style comments.
+
+ vmCompile makes the following external calls:
+   void pushChar(int character);
+     Push the specified character onto a character stack.
+
+   int locateVariable(int nameLength);
+     Pop the last nameLength characters from the character stack
+     and, treating them as the name of a variable, return an
+     index into the variable array.
+
+ Overrides for macros defined by AnaGram, such as SYNTAX_ERROR
+ are included in VMDEFS.H
+
+ VM.SYN is compiled with the AnaGram parser generator
+ yielding VM.H and VM.CPP.
+
+ To build VM, compile VM.CPP and VMDEMO.CPP and link them
+ with your C++ compiler.
+
+ For information about AnaGram, visit http://www.parsifalsoft.com.
+*/
+
+#include <math.h>
+#include "vmdefs.h"                  // defines external interface
+
+static VirtualMachine *vm;
+
+}
+// -- CONFIGURATION SECTION ----------------------------
+[
+  default token type = double
+  disregard white space
+  lexeme {real, name}
+  pointer input
+  parser name = asil
+  parser file name = "#.cpp"
+  line numbers
+]
+
+
+//parse option $
+// -> parse script, statements?, eof
+// -> skip statement, statement text?, ';'
+// -> skip statement, balanced braces
+// -> skip condition, balanced parens
+// -> eval expression, expression
+// -> exec statement, statement
+
+//parse script, skip statement, skip condition, eval expression, exec statement
+//	->                         =asil_change_reduction(PCB, syntaxSelector);
+
+(void) input string $                       // specify grammar token
+ -> statements?, eof
+
+statement text
+	-> statement char
+	-> balanced parens
+	-> statement text, statement char
+	-> statement text, balanced parens
+	-> statement text, balanced braces
+
+blank          = ' ' + '\t' + '\f' + '\v' + '\r' + '\n'
+statement char = 32..126 - blank - ';' - '(' - ')' - '{' - '}'
+
+balanced parens
+ -> '(', statement text?, ')'
+
+ balanced braces
+	-> '{', statement text?, '}'
+	-> '{', balanced braces, '}'
+
+statement
+ -> unconditional statement
+ -> conditional statement
+
+statements
+ -> statement:x                                =x;
+ -> statements:x, statement                    =x;
+
+skip statement
+ -> skip unconditional statement
+ -> skip conditional statement
+
+/*
+ An unconditional statement is any statement that does not involve
+ an if statement
+*/
+
+unconditional statement
+ -> expression:x, ';'
+ -> ';'
+ -> '{', '}'
+ -> '{', statements:s, '}'
+ -> gather unconditional while, while loop, false condition, skip statement
+
+gather unconditional while
+ -> "while", balanced parens, skip unconditional statement
+
+while loop
+ ->
+ -> while loop, true condition, statement
+
+skip unconditional statement
+ -> statement text?, ';'
+ -> balanced braces
+ -> "while", balanced parens, skip unconditional statement
+
+/*
+ Any statement with an if in it is a conditional statement
+*/
+
+conditional statement
+ -> gather conditional while, while loop, false condition, skip statement
+ -> true if clause:x, statement
+ -> false if clause:x, skip statement
+ -> true if clause:x, unconditional statement:s1, "else", skip statement:s2
+ -> false if clause:x, skip unconditional statement:s1, "else", statement:s2
+
+gather conditional while
+ -> "while", balanced parens, skip conditional statement
+
+skip conditional statement
+ -> "if", balanced parens, skip statement
+ -> "if", balanced parens, skip unconditional statement, "else", skip statement
+ -> "while", balanced parens, skip conditional statement
+
+false if clause, true if clause
+ -> "if", '(', expression:x, ')'               ={if (x) CHANGE_REDUCTION(true_if_clause);}
+
+expression
+ -> conditional expression
+ -> name:k, '=',  expression:x                 =vm->code(STORE, k), x;
+ -> name:k, "+=", expression:x                 =vm->code(ADDM,k), x;
+ -> name:k, "-=", expression:x                 =vm->code(SUBM,k), x;
+ -> name:k, "*=", expression:x                 =vm->code(MULM,k), x;
+ -> name:k, "/=", expression:x                 =vm->code(DIVM,k), x;
+
+conditional expression
+ -> logical or expression
+ -> logical or expression:c, '?',
+      expression:x, ':', conditional expression:y    =vm->codeIfElse(c,x,y);
+
+logical or expression
+ -> logical and expression
+ -> logical or expression:x, "||",
+      logical and expression:y        =vm->insertCode(OR, vm->wx - y, y), x;
+
+logical and expression
+ -> equality expression
+ -> logical and expression:x, "&&",
+      equality expression:y          =vm->insertCode(AND, vm->wx - y, y), x;
+
+equality expression
+ -> relational expression
+ -> equality expression:x, "==", relational expression:y    =vm->code(EQ), x;
+ -> equality expression:x, "!=", relational expression:y    =vm->code(NE), x;
+
+relational expression
+ -> additive expression
+ -> relational expression:x, '<',  additive expression:y    =vm->code(LT), x;
+ -> relational expression:x, "<=", additive expression:y    =vm->code(LE), x;
+ -> relational expression:x, '>',  additive expression:y    =vm->code(GT), x;
+ -> relational expression:x, ">=", additive expression:y    =vm->code(GE), x;
+
+additive expression
+ -> multiplicative expression
+ -> additive expression:x, '+',
+      multiplicative expression:y                          =vm->code(ADD), x;
+ -> additive expression:x, '-',
+      multiplicative expression:y                          =vm->code(SUB), x;
+
+multiplicative expression
+ -> factor
+ -> multiplicative expression:x, '*', factor:  y           =vm->code(MUL), x;
+ -> multiplicative expression:x, '/', factor:y             =vm->code(DIV), x;
+
+factor
+ -> primary
+ -> primary:x, "**", factor:y                              =vm->code(POW), x;
+
+primary
+ -> real:x                                               =vm->code(PUSHI, x);
+ -> name:k                                                =vm->code(PUSH, k);
+ -> "log", '(', expression:x, ')'                          =vm->code(LOG), x;
+ -> "exp", '(', expression:x, ')'                          =vm->code(EXP), x;
+ -> '(', expression:x, ')'                                                =x;
+ -> '-', primary:x                                         =vm->code(NEG), x;
+ -> '+', primary:x                                                        =x;
+ -> '!', primary:x                                         =vm->code(NOT), x;
+
+// -- LEXICAL UNITS ------------------------------------------------
+digit   = '0-9'
+eof     = 0
+letter  = 'a-z' + 'A-Z' + '_'
+
+(void) white space
+ -> blank
+ -> "/*", ~eof?..., "*/"                          // C style comment
+ -> "//", ~(eof+'\n')?..., '\n'                 // C++ style comment
+
+(double) real
+ -> simple real
+ -> simple real:x, 'e'+'E', '+'?,exponent:e            =x*pow(10,e);
+ -> simple real:x, 'e'+'E', '-',exponent:e            =x*pow(10,-e);
+
+(double) simple 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.;
+
+(int) exponent
+ -> digit:d                                                 = d-'0';
+ -> exponent:x, digit:d                              = 10*x + d-'0';
+
+(int) name
+ -> name string:k                                   =locateVariable(k);
+
+(int) name string
+ -> letter: c                                       =pushChar(c), 1;
+ -> name string:k, letter+digit: c                  =pushChar(c), k+1;
+
+{ // begin embedded C
+
+
+int compileStatements(VirtualMachine *v, char *text) {
+  vm = v;
+  resetCharStack();
+  vmCompile_pcb.pointer = (unsigned char *) text;
+  vmCompile();
+  return vmCompile_pcb.exit_flag != AG_SUCCESS_CODE;
+}
+} // end of embedded C
+/********************* End of VM.SYN ************************/