Skip to content

Instantly share code, notes, and snippets.

@ayardley
Created February 10, 2012 03:59
Show Gist options
  • Save ayardley/1786407 to your computer and use it in GitHub Desktop.
Save ayardley/1786407 to your computer and use it in GitHub Desktop.
Winxed: Not a left-side expression near (
NotFound:
My apologies for my failure to include enough code to allow you to reproduce the error in the earlier gist. The below "should" reproduce the error for you. Please note, the "error" has mysteriously moved to the 'append()' function, and the only thing I changed was to chop out some already commented code.
Again, thank you for your help.
Alvis
P.S. The below code dies with the following error: 'lisp.i:142: Not a left-side expression near ('
##################################################################################
/* Convenience macros -- which we run through 'cpp' */
#define T(X) cpvm_T(X)
#define NIL(X) cpvm_NIL(X)
const int BUFSIZE = 1024;
/*
* Note: First, we must define four (five) types of objects:
*
* (1) ATOM - is letters, digits, symbols and anything not a list;
* (2) CONS - is a list;
* (3) CONJ - is sequence datatypes (unimplemented atm);
* (4) FUNC - holds a function; and
* (5) LAMBDA - holds a lambda expression.
*/
const int ATOM = 0;
const int CONS = 1;
const int CONJ = 2;
const int FUNC = 3;
const int LAMBDA = 4;
/* T - pseudo global variable */
function cpvm_T(v)
{
while (1) yield(v);
}
/* NIL - pseudo global variable */
function cpvm_NIL(v)
{
while (1) yield(v);
}
// Simulate '#define car(X) (((cons_object *) (X))->car)'
function car(var X)
{
return X.car;
}
// Simulate '#define cdr(X) (((cons_object *) (X))->cdr)'
function cdr(var X)
{
return X.cdr;
}
class object
{
var type;
}
class atom_object : object
{
var name;
}
class cons_object : object
{
var car;
var cdr;
}
class func_object : object
{
var fn;
}
class lambda_object : object
{
var args;
var sexp;
}
/*
=item C<main(var agrs)>
The REPL - The ClojurePVM read, eval, print loop.
=cut
*/
function main[main](var args)
{
var env = init_env();
var in;
/* getopts - read either from a file or stdin. */
if (args > 1) {
switch (args[1]) {
case '-f' :
case '--filename' :
in = new 'FileHandle';
in.open(args[2]);
break;
case '-h' :
case '--help' :
show_help();
exit(0);
break;
case '-v' :
case '--version' :
show_version();
exit(0);
break;
default :
break;
}
}
else {
in = getstdin();
}
/* The REPL */
do {
print("user> ");
print(eval(read(in), env));
print("\n");
} while (1);
if (!in.is_closed())
in.close();
return 0;
}
/*
=item C<init_env()>
....
=cut
*/
function init_env()
{
var env = cons( cons( atom('QUOTE'), cons( func(fn_quote), null)), null);
append(env, cons( atom("CAR"), cons( func(fn_car), null)));
// append(env, cons( atom("CDR"), cons( func(fn_cdr), null))); <-- #142 here
// append(env, cons( atom("CONS"), cons( func(fn_cons), null)));
// append(env, cons( atom("EQUAL"), cons( func(fn_equal), null)));
// append(env, cons( atom("ATOM"), cons( func(fn_atom), null)));
// append(env, cons( atom("COND"), cons( func(fn_cond), null)));
// append(env, cons( atom("LAMBDA"), cons( func(fn_lambda), null)));
// append(env, cons( atom("LABEL"), cons( func(fn_label), null)));
var T = atom('T');
T(T); // Initialize
var NIL = cons(null, null);
NIL(NIL); // Initialize
return env;
}
/*
=item C<append(var list, var obj)>
....
=cut
*/
function append(var list, var obj)
{
var o;
for (o = list; cdr(o) != null; o = cdr(o));
cdr(o) = cons(obj, null);
}
/*
=item C<name(var o)>
=cut
*/
function name(var o) {
if (o.type != ATOM)
exit(1);
return o.name;
}
/*
=item C<atom(string n)>
=cut
*/
function atom(string s)
{
var a = new atom_object;
a.type = ATOM;
a.name = s;
return a;
}
/*
=item C<cons(var first, var second)>
=cut
*/
function cons(var first, var second)
{
var c = new cons_object;
c.type = CONS;
c.car = first;
c.cdr = second;
return c;
}
/*
=item ....
=cut
*/
function func(var func)
{
var fn = new func_object;
fn.type = FUNC;
fn.fn = func;
return fn;
}
/*
* The seven primitives, from which we derive 'eval'.
*/
/*
=item C<fn_quote(var agrs, var env)>
....
=cut
*/
function fn_quote(var args, var env)
{
return car(args);
}
/*
=item C<fn_car(var agrs, var env)>
=cut
*/
function fn_car(var args, var env)
{
return car( car(args) );
}
/*
=item C<fn_cons(var args, var env)>
=cut
*/
function fn_cons(var args, var env)
{
var list = cons( car(args), null);
args = car( cdr(args) );
while (args != null && args.type == CONS) {
append(list, car(args));
args = cdr(args);
}
return list;
}
/*
=item C<show_help()>
Display help, depending on whether the user specifics the '--help' option
or, alternatively, specifics an incorrect option.
=cut
*/
function show_help()
{
say(<<:
Usage: clojurepvm [options] [filename]
--help Show this help
--version Show version information
:>>
); // Note: ');' must be in col. 0 to prevent 'Unterminated heredoc' error
}
/*
=item C<show_version()>
Display ClojurePVM's version and copyright information.
=cut
*/
function show_version()
{
say(<<:
This is ClojurePVM, v0.0.1
Copyright (C) 2011-2012, Alvis Yardley. All Rights Reserved.
The author hereby distributes this program under the terms of The Artistic
License 2.0, a copy of which is included in this distribution.
:>>
); // Note: See above comment
}
@ayardley
Copy link
Author

Found it in the below function:

function append(var list, var obj)
{
var o;
for (o = list; cdr(o) != null; o = cdr(o));
cdr(o) = cons(obj, null);
}

The offending line is 'cdr(o) = cons(obj, null);'. Evidently, winxed throws a syntax error; even though 'cdr(o)' is actually function call. So ... ..., can't do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment