[cig-commits] r6052 - in cs/babel/trunk/spike: Demos Spike/Compiler
bin
leif at geodynamics.org
leif at geodynamics.org
Mon Feb 19 19:15:26 PST 2007
Author: leif
Date: 2007-02-19 19:15:25 -0800 (Mon, 19 Feb 2007)
New Revision: 6052
Added:
cs/babel/trunk/spike/Demos/primes.spk
cs/babel/trunk/spike/Spike/Compiler/Makefile
cs/babel/trunk/spike/Spike/Compiler/main.c
cs/babel/trunk/spike/Spike/Compiler/parser.pyx
Removed:
cs/babel/trunk/spike/Demos/primes.pyx
Modified:
cs/babel/trunk/spike/Spike/Compiler/CmdLine.py
cs/babel/trunk/spike/Spike/Compiler/ExprNodes.py
cs/babel/trunk/spike/Spike/Compiler/Main.py
cs/babel/trunk/spike/Spike/Compiler/Nodes.py
cs/babel/trunk/spike/Spike/Compiler/SpikeTypes.py
cs/babel/trunk/spike/Spike/Compiler/gram.y
cs/babel/trunk/spike/Spike/Compiler/scan.l
cs/babel/trunk/spike/bin/spikec
Log:
Embryonic implementation of Spike.
The Pyrex 'primes' example (featured on the home page of the Pyrex web
site) has been re-written in Spike:
primes.pyx -> primes.spk
(Notice that "primes.spk" is almost valid C code. It will be trivial
to port C projects to Spike.)
The Spike implementation is just barely complete enough to translate
the "primes.spk" example into C source for a working Python extension
module.
~~~ How to play with Spike. ~~~
This is somewhat silly, but you need Pyrex installed in order to build
Spike.
cd Spike/Compiler
# You may have to tweak 'Makefile'.
# (Note that Spike currently embeds Python.)
make
cd ../../bin
export PATH=`pwd`:$PATH
cd ..
export PYTHONPATH=`pwd`:$PYTHONPATH
cd Demos
spikec primes.spk
# The output file is "primes.c".
# (Currently, Spike also echoes the input file to stdout.)
gcc -g -shared -o primesmodule.so primes.c -I/usr/include/python2.4
python -c "from primes import primes; print primes(10)"
Deleted: cs/babel/trunk/spike/Demos/primes.pyx
===================================================================
--- cs/babel/trunk/spike/Demos/primes.pyx 2007-02-20 01:28:30 UTC (rev 6051)
+++ cs/babel/trunk/spike/Demos/primes.pyx 2007-02-20 03:15:25 UTC (rev 6052)
@@ -1,18 +0,0 @@
-def primes(int kmax):
- cdef int n, k, i
- cdef int p[1000]
- result = []
- if kmax > 1000:
- kmax = 1000
- k = 0
- n = 2
- while k < kmax:
- i = 0
- while i < k and n % p[i] <> 0:
- i = i + 1
- if i == k:
- p[k] = n
- k = k + 1
- result.append(n)
- n = n + 1
- return result
Copied: cs/babel/trunk/spike/Demos/primes.spk (from rev 5996, cs/babel/trunk/spike/Demos/primes.pyx)
===================================================================
--- cs/babel/trunk/spike/Demos/primes.pyx 2007-02-10 04:30:11 UTC (rev 5996)
+++ cs/babel/trunk/spike/Demos/primes.spk 2007-02-20 03:15:25 UTC (rev 6052)
@@ -0,0 +1,24 @@
+
+obj primes(int kmax) {
+ int n, k, i;
+ int p[1000];
+ obj result;
+
+ result = list();
+ if (kmax > 1000)
+ kmax = 1000;
+ k = 0;
+ n = 2;
+ while (k < kmax) {
+ i = 0;
+ while (i < k && n % p[i] != 0)
+ i = i + 1;
+ if (i == k) {
+ p[k] = n;
+ k = k + 1;
+ result->append(n);
+ }
+ n = n + 1;
+ }
+ return result;
+}
Modified: cs/babel/trunk/spike/Spike/Compiler/CmdLine.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/CmdLine.py 2007-02-20 01:28:30 UTC (rev 6051)
+++ cs/babel/trunk/spike/Spike/Compiler/CmdLine.py 2007-02-20 03:15:25 UTC (rev 6052)
@@ -64,7 +64,7 @@
bad_usage()
else:
arg = pop_arg()
- if arg.endswith(".pyx"):
+ if arg.endswith(".spk"):
sources.append(arg)
elif arg.endswith(".o"):
options.objects.append(arg)
Modified: cs/babel/trunk/spike/Spike/Compiler/ExprNodes.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/ExprNodes.py 2007-02-20 01:28:30 UTC (rev 6051)
+++ cs/babel/trunk/spike/Spike/Compiler/ExprNodes.py 2007-02-20 03:15:25 UTC (rev 6052)
@@ -693,7 +693,12 @@
if not self.entry:
#print "NameNode.analyse_target_declaration:", self.name ###
#print "...declaring as py_object_type" ###
- self.entry = env.declare_var(self.name, py_object_type, self.pos)
+ if False:
+ # Death to Pythonic behavior...
+ self.entry = env.declare_var(self.name, py_object_type, self.pos)
+ else:
+ error(self.pos, "'%s' undeclared" % self.name)
+ self.entry = env.declare_var(self.name, SpikeTypes.error_type, self.pos)
def analyse_types(self, env):
self.entry = env.lookup(self.name)
@@ -2098,6 +2103,70 @@
return "(~%s)" % self.operand.result_code
+class PrefixIncNode(UnopNode):
+ # prefix '++' operator
+
+ def analyse_c_operation(self, env):
+ if self.operand.type.is_int or self.base.type.is_ptr:
+ self.type = self.operand.type
+ else:
+ self.type_error()
+
+ def py_operation_function(self):
+ return "Spike_NYI_PreIncrement"
+
+ def calculate_result_code(self):
+ return "(++%s)" % self.operand.result_code
+
+
+class PrefixDecNode(UnopNode):
+ # prefix '--' operator
+
+ def analyse_c_operation(self, env):
+ if self.operand.type.is_int or self.base.type.is_ptr:
+ self.type = self.operand.type
+ else:
+ self.type_error()
+
+ def py_operation_function(self):
+ return "Spike_NYI_PreDecrement"
+
+ def calculate_result_code(self):
+ return "(--%s)" % self.operand.result_code
+
+
+class PostfixIncNode(UnopNode):
+ # postfix '++' operator
+
+ def analyse_c_operation(self, env):
+ if self.operand.type.is_int or self.base.type.is_ptr:
+ self.type = self.operand.type
+ else:
+ self.type_error()
+
+ def py_operation_function(self):
+ return "Spike_NYI_PostIncrement"
+
+ def calculate_result_code(self):
+ return "(%s++)" % self.operand.result_code
+
+
+class PostfixDecNode(UnopNode):
+ # postfix '--' operator
+
+ def analyse_c_operation(self, env):
+ if self.operand.type.is_int or self.base.type.is_ptr:
+ self.type = self.operand.type
+ else:
+ self.type_error()
+
+ def py_operation_function(self):
+ return "Spike_NYI_PostDecrement"
+
+ def calculate_result_code(self):
+ return "(%s--)" % self.operand.result_code
+
+
class AmpersandNode(ExprNode):
# The C address-of operator.
#
@@ -2131,6 +2200,22 @@
pass
+class IndirectionNode(UnopNode):
+ # '*' indirection operator
+
+ def analyse_c_operation(self, env):
+ if self.base.type.is_ptr:
+ self.type = self.operand.type.base_type
+ else:
+ self.type_error()
+
+ def py_operation_function(self):
+ return "Spike_NYI_Indirect"
+
+ def calculate_result_code(self):
+ return "(*%s)" % self.operand.result_code
+
+
unop_node_classes = {
"+": UnaryPlusNode,
"-": UnaryMinusNode,
@@ -2506,12 +2591,12 @@
self.py_to_c_op[self.operator],
self.operand2.result_code)
- py_to_c_op = {'and': "&&", 'or': "||"}
+ py_to_c_op = {'and': "&&", 'or': "||", '&&': "&&", '||': "||"}
def generate_evaluation_code(self, code):
self.operand1.generate_evaluation_code(code)
test_result = self.generate_operand1_test(code)
- if self.operator == 'and':
+ if self.operator == 'and' or self.operator == '&&':
sense = ""
else:
sense = "!"
Modified: cs/babel/trunk/spike/Spike/Compiler/Main.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/Main.py 2007-02-20 01:28:30 UTC (rev 6051)
+++ cs/babel/trunk/spike/Spike/Compiler/Main.py 2007-02-20 03:15:25 UTC (rev 6052)
@@ -130,7 +130,7 @@
self.modules[name] = scope
return scope
- def parse(self, source_filename, type_names, pxd):
+ def xxxparse(self, source_filename, type_names, pxd):
# Parse the given source file and return a parse tree.
f = open(source_filename, "rU")
s = SpikeScanner(f, source_filename,
@@ -143,6 +143,16 @@
raise CompileError
return tree
+ def parse(self, source_filename, type_names, pxd):
+ import parser
+ import Nodes
+ stats = parser.parse(source_filename)
+ initial_pos = (source_filename, 1, 0)
+ pos = initial_pos
+ body = Nodes.StatListNode(pos, stats = stats)
+ tree = Nodes.ModuleNode(initial_pos, doc = None, body = body)
+ return tree
+
def extract_module_name(self, path):
# Get the module name out of a source file pathname.
_, tail = os.path.split(path)
Added: cs/babel/trunk/spike/Spike/Compiler/Makefile
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/Makefile 2007-02-20 01:28:30 UTC (rev 6051)
+++ cs/babel/trunk/spike/Spike/Compiler/Makefile 2007-02-20 03:15:25 UTC (rev 6052)
@@ -0,0 +1,30 @@
+
+CFLAGS = -g -I/usr/include/python2.4
+BIN = ../../bin
+
+SRC = gram.y scan.l main.c parser.pyx
+OBJ = gram.o scan.o main.o parser.o
+
+$(BIN)/pyspike: $(OBJ)
+ gcc $(CFLAGS) $(OBJ) -o $(BIN)/pyspike -lpython2.4
+
+scan.o: gram.h
+
+gram.h: gram.o
+
+gram.c: gram.y parser.h
+ bison -dv $< -o $@
+
+scan.c: scan.l gram.c
+ flex -o$@ $<
+
+parser.h: parser.o
+
+parser.o: parser.pyx
+ pyrexc $<
+ gcc $(CFLAGS) -c -o $@ parser.c
+
+clean:
+ rm -f gram.h gram.c scan.c parser.c y.output *.o
+
+#.PRECIOUS: gram.c scan.c
Modified: cs/babel/trunk/spike/Spike/Compiler/Nodes.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/Nodes.py 2007-02-20 01:28:30 UTC (rev 6051)
+++ cs/babel/trunk/spike/Spike/Compiler/Nodes.py 2007-02-20 03:15:25 UTC (rev 6052)
@@ -2293,8 +2293,101 @@
def caller_will_check_exceptions(self):
return 1
-
+
+class SpikeFuncDefNode(DefNode):
+ # A Spike function definition.
+
+ def __init__(self, pos, visibility, base_type, declarator, body):
+ import ExprNodes
+ args = []
+ call_args = []
+ for arg_decl in declarator.args:
+ arg = CArgDeclNode(arg_decl.pos,
+ base_type = arg_decl.base_type,
+ declarator = arg_decl.declarator,
+ not_none = 0,
+ default = None)
+ args.append(arg)
+ call_arg = ExprNodes.NameNode(arg_decl.pos, name = arg_decl.declarator.name)
+ call_args.append(call_arg)
+ DefNode.__init__(self,
+ pos,
+ name = declarator.base.name,
+ args = args,
+ star_arg = None,
+ starstar_arg = None,
+ doc = None,
+ body = None)
+ declarator.base.name = "__spike_cf_" + declarator.base.name
+ self.cfunc = CFuncDefNode(pos,
+ visibility = visibility,
+ base_type = base_type,
+ declarator = declarator,
+ body = body)
+ self.construct_body(call_args, base_type)
+
+ def construct_body(self, call_args, base_type):
+ import ExprNodes
+ # NYI: 'base_type' is not correct for the return type.
+ ret_decl = CVarDefNode(self.pos, visibility = 'private', base_type = base_type,
+ declarators = [CNameDeclaratorNode(self.pos, name = "ret", cname = None)])
+ name = self.cfunc.declarator.base.name
+ function = ExprNodes.NameNode(self.pos, name = name)
+ expr = ExprNodes.SimpleCallNode(self.pos,
+ function = function,
+ args = call_args)
+ ret = ExprNodes.NameNode(self.pos, name = "ret")
+ stmt1 = SingleAssignmentNode(self.pos, lhs = ret, rhs = expr)
+ ret = ExprNodes.NameNode(self.pos, name = "ret")
+ stmt2 = ReturnStatNode(self.pos, value = ret)
+ self.body = StatListNode(self.pos, stats = [ret_decl, stmt1, stmt2])
+ return
+
+ #
+ # BlockNode protocol
+ #
+
+ def generate_const_definitions(self, env, code):
+ self.cfunc.generate_const_definitions(env, code)
+ DefNode.generate_const_definitions(self, env, code)
+
+ def generate_interned_name_decls(self, env, code):
+ self.cfunc.generate_interned_name_decls(env, code)
+ DefNode.generate_interned_name_decls(self, env, code)
+
+ def generate_py_string_decls(self, env, code):
+ self.cfunc.generate_py_string_decls(env, code)
+ DefNode.generate_py_string_decls(self, env, code)
+
+ #
+ # StatNode protocol
+
+ def generate_function_definitions(self, env, code):
+ self.cfunc.generate_function_definitions(env, code)
+ DefNode.generate_function_definitions(self, env, code)
+
+ def generate_execution_code(self, code):
+ self.cfunc.generate_execution_code(code)
+ DefNode.generate_execution_code(self, code)
+
+ #
+ # Node protocol
+ #
+
+ def analyse_declarations(self, env):
+ self.cfunc.analyse_declarations(env)
+ DefNode.analyse_declarations(self, env)
+
+ def analyse_expressions(self, env):
+ self.cfunc.analyse_expressions(env)
+ DefNode.analyse_expressions(self, env)
+
+ def generate_code(self, code):
+ self.cfunc.generate_code(code)
+ DefNode.generate_code(self, code)
+
+
class PyClassDefNode(StatNode, BlockNode):
# A Python class definition.
#
Modified: cs/babel/trunk/spike/Spike/Compiler/SpikeTypes.py
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/SpikeTypes.py 2007-02-20 01:28:30 UTC (rev 6051)
+++ cs/babel/trunk/spike/Spike/Compiler/SpikeTypes.py 2007-02-20 03:15:25 UTC (rev 6052)
@@ -766,7 +766,7 @@
(1, 0, "float"): c_float_type,
(1, 0, "double"): c_double_type,
(1, 1, "double"): c_longdouble_type,
- (1, 0, "object"): py_object_type,
+ (1, 0, "obj"): py_object_type,
}
def widest_numeric_type(type1, type2):
Modified: cs/babel/trunk/spike/Spike/Compiler/gram.y
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/gram.y 2007-02-20 01:28:30 UTC (rev 6051)
+++ cs/babel/trunk/spike/Spike/Compiler/gram.y 2007-02-20 03:15:25 UTC (rev 6052)
@@ -1,4 +1,17 @@
-%token IDENTIFIER CONSTANT STRING_LITERAL SIZEOF
+%{
+
+#include <Python.h>
+#include "parser.h"
+
+#define YYSTYPE PyObject *
+
+#define CHECK(x) if (!(x)) { PyErr_Print(); Py_Exit(1); }
+
+%}
+
+%token IDENTIFIER
+%token LITERAL_INT LITERAL_FLOAT LITERAL_CHAR LITERAL_STRING
+%token SIZEOF
%token PTR_OP INC_OP DEC_OP LEFT_OP RIGHT_OP LE_OP GE_OP EQ_OP NE_OP
%token AND_OP OR_OP MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN
%token SUB_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN
@@ -7,6 +20,7 @@
%token TYPEDEF EXTERN STATIC AUTO REGISTER
%token CHAR SHORT INT LONG SIGNED UNSIGNED FLOAT DOUBLE CONST VOLATILE VOID
%token STRUCT UNION ENUM ELIPSIS RANGE
+%token OBJ
%token CASE DEFAULT IF ELSE SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN
@@ -14,107 +28,109 @@
%%
primary_expr
- : identifier
- | CONSTANT
- | STRING_LITERAL
- | '(' expr ')'
+ : identifier { CHECK($$ = name_expr($1)); }
+ | LITERAL_INT { CHECK($$ = literal_int_expr($1)); }
+ | LITERAL_FLOAT { CHECK($$ = literal_float_expr($1)); }
+ | LITERAL_CHAR { CHECK($$ = literal_char_expr($1)); }
+ | LITERAL_STRING { CHECK($$ = literal_string_expr($1)); }
+ | '(' expr ')' { $$ = $2; }
;
postfix_expr
: primary_expr
- | postfix_expr '[' expr ']'
- | postfix_expr '(' ')'
- | postfix_expr '(' argument_expr_list ')'
- | postfix_expr '.' identifier
- | postfix_expr PTR_OP identifier
- | postfix_expr INC_OP
- | postfix_expr DEC_OP
+ | postfix_expr '[' expr ']' { CHECK($$ = index_expr($1, $3)); }
+ | postfix_expr '(' ')' { CHECK($$ = call_expr($1, empty_list())); }
+ | postfix_expr '(' argument_expr_list ')' { CHECK($$ = call_expr($1, $3)); }
+ | postfix_expr '.' identifier { CHECK($$ = attr_expr($1, $3)); }
+ | postfix_expr PTR_OP identifier { CHECK($$ = attr_expr($1, $3)); }
+ | postfix_expr INC_OP { CHECK($$ = postfix_inc_expr($1)); }
+ | postfix_expr DEC_OP { CHECK($$ = postfix_dec_expr($1)); }
;
argument_expr_list
- : assignment_expr
- | argument_expr_list ',' assignment_expr
+ : assignment_expr { CHECK($$ = argument_expr_list(Py_None, $1)); }
+ | argument_expr_list ',' assignment_expr { CHECK($$ = argument_expr_list($1, $3)); }
;
unary_expr
: postfix_expr
- | INC_OP unary_expr
- | DEC_OP unary_expr
- | unary_operator cast_expr
- | SIZEOF unary_expr
- | SIZEOF '(' type_name ')'
+ | unary_operator cast_expr { CHECK($$ = unary_op_expr($1, $2)); }
+ | SIZEOF unary_expr { CHECK($$ = sizeof_var_expr($2)); }
+ | SIZEOF '(' type_name ')' { CHECK($$ = sizeof_type_expr($3)); }
;
unary_operator
- : '&'
- | '*'
- | '+'
- | '-'
- | '~'
- | '!'
+ : '&' { CHECK($$ = unary_address_of()) }
+ | '*' { CHECK($$ = unary_indirection()) }
+ | '+' { CHECK($$ = unary_plus()) }
+ | '-' { CHECK($$ = unary_minus()) }
+ | '~' { CHECK($$ = unary_bitwise_negation()) }
+ | '!' { CHECK($$ = unary_not()) }
+ | INC_OP { CHECK($$ = unary_prefix_inc()) }
+ | DEC_OP { CHECK($$ = unary_prefix_dec()) }
;
cast_expr
: unary_expr
- | '(' type_name ')' cast_expr
+ | '(' type_name ')' cast_expr { CHECK($$ = cast_expr($2, $4)); }
;
multiplicative_expr
: cast_expr
- | multiplicative_expr '*' cast_expr
- | multiplicative_expr '/' cast_expr
- | multiplicative_expr '%' cast_expr
+ | multiplicative_expr '*' cast_expr { CHECK($$ = mul_expr($1, $3)); }
+ | multiplicative_expr '/' cast_expr { CHECK($$ = div_expr($1, $3)); }
+ | multiplicative_expr '%' cast_expr { CHECK($$ = mod_expr($1, $3)); }
;
additive_expr
: multiplicative_expr
- | additive_expr '+' multiplicative_expr
- | additive_expr '-' multiplicative_expr
+ | additive_expr '+' multiplicative_expr { CHECK($$ = add_expr($1, $3)); }
+ | additive_expr '-' multiplicative_expr { CHECK($$ = sub_expr($1, $3)); }
;
shift_expr
: additive_expr
- | shift_expr LEFT_OP additive_expr
- | shift_expr RIGHT_OP additive_expr
+ | shift_expr LEFT_OP additive_expr { CHECK($$ = shift_left_expr($1, $3)); }
+ | shift_expr RIGHT_OP additive_expr { CHECK($$ = shift_right_expr($1, $3)); }
;
relational_expr
: shift_expr
- | relational_expr '<' shift_expr
- | relational_expr '>' shift_expr
- | relational_expr LE_OP shift_expr
- | relational_expr GE_OP shift_expr
+ | relational_expr '<' shift_expr { CHECK($$ = l_expr($1, $3)); }
+ | relational_expr '>' shift_expr { CHECK($$ = g_expr($1, $3)); }
+ | relational_expr LE_OP shift_expr { CHECK($$ = le_expr($1, $3)); }
+ | relational_expr GE_OP shift_expr { CHECK($$ = ge_expr($1, $3)); }
;
equality_expr
: relational_expr
- | equality_expr EQ_OP relational_expr
- | equality_expr NE_OP relational_expr
+ | equality_expr EQ_OP relational_expr { CHECK($$ = eq_expr($1, $3)); }
+ | equality_expr NE_OP relational_expr { CHECK($$ = ne_expr($1, $3)); }
;
and_expr
: equality_expr
- | and_expr '&' equality_expr
+ | and_expr '&' equality_expr { CHECK($$ = and_expr($1, $3)); }
;
exclusive_or_expr
: and_expr
- | exclusive_or_expr '^' and_expr
+ | exclusive_or_expr '^' and_expr { CHECK($$ = xor_expr($1, $3)); }
;
inclusive_or_expr
: exclusive_or_expr
- | inclusive_or_expr '|' exclusive_or_expr
+ | inclusive_or_expr '|' exclusive_or_expr { CHECK($$ = or_expr($1, $3)); }
;
logical_and_expr
: inclusive_or_expr
- | logical_and_expr AND_OP inclusive_or_expr
+ | logical_and_expr AND_OP inclusive_or_expr { CHECK($$ = logical_and_expr($1, $3)); }
;
logical_or_expr
: logical_and_expr
- | logical_or_expr OR_OP logical_and_expr
+ | logical_or_expr OR_OP logical_and_expr { CHECK($$ = logical_or_expr($1, $3)); }
;
conditional_expr
@@ -124,7 +140,7 @@
assignment_expr
: conditional_expr
- | unary_expr assignment_operator assignment_expr
+ | unary_expr assignment_operator assignment_expr { CHECK($$ = assignment_expr(Py_None, $1, $3)); }
;
assignment_operator
@@ -151,8 +167,8 @@
;
declaration
- : declaration_specifiers ';'
- | declaration_specifiers init_declarator_list ';'
+ : declaration_specifiers ';' { CHECK($$ = declaration($1, empty_list())); }
+ | declaration_specifiers init_declarator_list ';' { CHECK($$ = declaration($1, $2)); }
;
declaration_specifiers
@@ -163,8 +179,8 @@
;
init_declarator_list
- : init_declarator
- | init_declarator_list ',' init_declarator
+ : init_declarator { CHECK($$ = init_declarator_list(Py_None, $1)); }
+ | init_declarator_list ',' init_declarator { CHECK($$ = init_declarator_list($1, $3)); }
;
init_declarator
@@ -181,17 +197,18 @@
;
type_specifier
- : CHAR
+ : CHAR { CHECK($$ = char_type()); }
| SHORT
- | INT
- | LONG
- | SIGNED
- | UNSIGNED
- | FLOAT
- | DOUBLE
+ | INT { CHECK($$ = int_type()); }
+ | LONG { CHECK($$ = long_type()); }
+ | SIGNED { CHECK($$ = signed_type()); }
+ | UNSIGNED { CHECK($$ = unsigned_type()); }
+ | FLOAT { CHECK($$ = float_type()); }
+ | DOUBLE { CHECK($$ = double_type()); }
| CONST
| VOLATILE
- | VOID
+ | VOID { CHECK($$ = void_type()); }
+ | OBJ { CHECK($$ = obj_type()); }
| struct_or_union_specifier
| enum_specifier
| TYPE_NAME
@@ -246,29 +263,29 @@
declarator
: declarator2
- | pointer declarator2
+ | pointer declarator2 { CHECK($$ = pointer_declarator($1, $2)); }
;
declarator2
- : identifier
- | '(' declarator ')'
- | declarator2 '[' ']'
- | declarator2 '[' constant_expr ']'
- | declarator2 '(' ')'
- | declarator2 '(' parameter_type_list ')'
- | declarator2 '(' parameter_identifier_list ')'
+ : identifier { CHECK($$ = name_declarator($1)); }
+ | '(' declarator ')' { CHECK($$ = $2); }
+ | declarator2 '[' ']' { CHECK($$ = array_declarator($1, Py_None)); }
+ | declarator2 '[' constant_expr ']' { CHECK($$ = array_declarator($1, $3)); }
+ | declarator2 '(' ')' { CHECK($$ = function_declarator($1, empty_list())); }
+ | declarator2 '(' parameter_type_list ')' { CHECK($$ = function_declarator($1, $3)); }
+ | declarator2 '(' parameter_identifier_list ')' { CHECK($$ = function_declarator($1, $3)); }
;
pointer
- : '*'
- | '*' type_specifier_list
- | '*' pointer
- | '*' type_specifier_list pointer
+ : '*' { CHECK($$ = pointer(Py_None)); }
+ | '*' type_specifier_list { CHECK($$ = pointer($2)); }
+ | '*' pointer { CHECK($$ = pointer($2)); }
+ | '*' type_specifier_list pointer { CHECK($$ = pointer($3)); /*???*/ }
;
type_specifier_list
- : type_specifier
- | type_specifier_list type_specifier
+ : type_specifier { CHECK($$ = type_specifier_list(Py_None, $1)); }
+ | type_specifier_list type_specifier { CHECK($$ = type_specifier_list($1, $2)); }
;
parameter_identifier_list
@@ -287,36 +304,36 @@
;
parameter_list
- : parameter_declaration
- | parameter_list ',' parameter_declaration
+ : parameter_declaration { CHECK($$ = parameter_list(Py_None, $1)); }
+ | parameter_list ',' parameter_declaration { CHECK($$ = parameter_list($1, $3)); }
;
parameter_declaration
- : type_specifier_list declarator
+ : type_specifier_list declarator { CHECK($$ = pair($1, $2)); }
| type_name
;
type_name
- : type_specifier_list
- | type_specifier_list abstract_declarator
+ : type_specifier_list { CHECK($$ = pair($1, empty_declarator())); }
+ | type_specifier_list abstract_declarator { CHECK($$ = pair($1, $2)); }
;
abstract_declarator
- : pointer
+ : pointer { CHECK($$ = pointer_declarator($1, empty_declarator())); }
| abstract_declarator2
- | pointer abstract_declarator2
+ | pointer abstract_declarator2 { CHECK($$ = pointer_declarator($1, $2)); }
;
abstract_declarator2
- : '(' abstract_declarator ')'
- | '[' ']'
- | '[' constant_expr ']'
- | abstract_declarator2 '[' ']'
- | abstract_declarator2 '[' constant_expr ']'
- | '(' ')'
- | '(' parameter_type_list ')'
- | abstract_declarator2 '(' ')'
- | abstract_declarator2 '(' parameter_type_list ')'
+ : '(' abstract_declarator ')' { CHECK($$ = $2); }
+ | '[' ']' { CHECK($$ = array_declarator(empty_declarator(), Py_None)); }
+ | '[' constant_expr ']' { CHECK($$ = array_declarator(empty_declarator(), $2)); }
+ | abstract_declarator2 '[' ']' { CHECK($$ = array_declarator($1, Py_None)); }
+ | abstract_declarator2 '[' constant_expr ']' { CHECK($$ = array_declarator($1, $3)); }
+ | '(' ')' { CHECK($$ = function_declarator(empty_declarator(), empty_list())); }
+ | '(' parameter_type_list ')' { CHECK($$ = function_declarator(empty_declarator(), $2)); }
+ | abstract_declarator2 '(' ')' { CHECK($$ = function_declarator($1, empty_list())); }
+ | abstract_declarator2 '(' parameter_type_list ')' { CHECK($$ = function_declarator($1, $3)); }
;
initializer
@@ -346,35 +363,35 @@
;
compound_statement
- : '{' '}'
- | '{' statement_list '}'
- | '{' declaration_list '}'
- | '{' declaration_list statement_list '}'
+ : '{' '}' { CHECK($$ = compound_statement(Py_None, Py_None)); }
+ | '{' statement_list '}' { CHECK($$ = compound_statement(Py_None, $2)); }
+ | '{' declaration_list '}' { CHECK($$ = compound_statement($2, Py_None)); }
+ | '{' declaration_list statement_list '}' { CHECK($$ = compound_statement($2, $3)); }
;
declaration_list
- : declaration
- | declaration_list declaration
+ : declaration { CHECK($$ = declaration_list(Py_None, $1)); }
+ | declaration_list declaration { CHECK($$ = declaration_list($1, $2)); }
;
statement_list
- : statement
- | statement_list statement
+ : statement { CHECK($$ = statement_list(Py_None, $1)); }
+ | statement_list statement { CHECK($$ = statement_list($1, $2)); }
;
expression_statement
- : ';'
- | expr ';'
+ : ';' { CHECK($$ = pass_statement()); }
+ | expr ';' { CHECK($$ = expression_statement($1)); }
;
selection_statement
- : IF '(' expr ')' statement
- | IF '(' expr ')' statement ELSE statement
+ : IF '(' expr ')' statement { CHECK($$ = if_statement($3, $5, Py_None)); }
+ | IF '(' expr ')' statement ELSE statement { CHECK($$ = if_statement($3, $5, $7)); }
| SWITCH '(' expr ')' statement
;
iteration_statement
- : WHILE '(' expr ')' statement
+ : WHILE '(' expr ')' statement { CHECK($$ = while_statement($3, $5)); }
| DO statement WHILE '(' expr ')' ';'
| FOR '(' ';' ';' ')' statement
| FOR '(' ';' ';' expr ')' statement
@@ -390,23 +407,23 @@
: GOTO identifier ';'
| CONTINUE ';'
| BREAK ';'
- | RETURN ';'
- | RETURN expr ';'
+ | RETURN ';' { CHECK($$ = return_statement(Py_None)); }
+ | RETURN expr ';' { CHECK($$ = return_statement($2)); }
;
file
- : external_definition
- | file external_definition
+ : external_definition { external_definition($1); }
+ | file external_definition { external_definition($2); }
;
external_definition
: function_definition
- | declaration
+ | declaration { $$ = Py_None; }
;
function_definition
- : declarator function_body
- | declaration_specifiers declarator function_body
+ : declarator function_body { CHECK($$ = function_definition(Py_None, $1, $2)); }
+ | declaration_specifiers declarator function_body { CHECK($$ = function_definition($1, $2, $3)); }
;
function_body
@@ -415,7 +432,7 @@
;
identifier
- : IDENTIFIER
+ : IDENTIFIER { CHECK($$ = $1); }
;
%%
Added: cs/babel/trunk/spike/Spike/Compiler/main.c
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/main.c 2007-02-20 01:28:30 UTC (rev 6051)
+++ cs/babel/trunk/spike/Spike/Compiler/main.c 2007-02-20 03:15:25 UTC (rev 6052)
@@ -0,0 +1,25 @@
+
+#include <stdio.h>
+#include <Python.h>
+
+PyMODINIT_FUNC initparser(void);
+
+struct _inittab inittab[] = {
+ { "parser", initparser },
+ { 0, 0 }
+};
+
+
+int yyparse();
+
+int main(int argc, char **argv)
+{
+ /* add our extension modules */
+ if (PyImport_ExtendInittab(inittab) == -1) {
+ fprintf(stderr, "%s: PyImport_ExtendInittab failed! Exiting...\n", argv[0]);
+ return 1;
+ }
+ return Py_Main(argc, argv);
+}
+
+/* end of file */
Added: cs/babel/trunk/spike/Spike/Compiler/parser.pyx
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/parser.pyx 2007-02-20 01:28:30 UTC (rev 6051)
+++ cs/babel/trunk/spike/Spike/Compiler/parser.pyx 2007-02-20 03:15:25 UTC (rev 6052)
@@ -0,0 +1,402 @@
+
+cdef extern from "stdio.h":
+ struct FILE
+ FILE *fopen(char *filename, char *mode)
+cdef extern from "yy.h":
+ FILE *yyin
+ int yyparse()
+
+theDefList = list()
+
+def parse(char *filename):
+ cdef int status
+
+ global yyin
+ yyin = fopen(filename, "r")
+ status = yyparse()
+ if (status != 0):
+ raise RuntimeError("parse error")
+ return theDefList
+
+#------------------------------------------------------------------------
+#
+# grammar actions
+#
+#------------------------------------------------------------------------
+
+from Spike.Compiler.Nodes import \
+ CSimpleBaseTypeNode, \
+ SpikeFuncDefNode
+
+from Spike.Compiler.ExprNodes import \
+ AttributeNode, \
+ CharNode, \
+ FloatNode, \
+ IndexNode, \
+ IntNode, \
+ NameNode, \
+ PostfixDecNode, \
+ PostfixIncNode, \
+ SimpleCallNode, \
+ SizeofTypeNode, \
+ SizeofVarNode, \
+ StringNode
+
+pos = ("nowhere.pyx", 1, 0) # NYI
+
+
+# expressions -- primary
+
+cdef public object name_expr(object name):
+ return NameNode(pos, name = name)
+
+cdef public object literal_int_expr(object value):
+ return IntNode(pos, value = value)
+
+cdef public object literal_float_expr(object value):
+ return FloatNode(pos, value = value)
+
+cdef public object literal_char_expr(object value):
+ return CharNode(pos, value = value)
+
+cdef public object literal_string_expr(object value):
+ return StringNode(pos, value = value)
+
+
+# expressions -- postfix
+
+cdef public object index_expr(object base, object index):
+ return IndexNode(pos, base = base, index = index)
+
+cdef public object call_expr(object function, object args):
+ return SimpleCallNode(pos, function = function, args = args)
+
+cdef public object attr_expr(object obj, object attribute):
+ return AttributeNode(pos, obj = obj, attribute = attribute)
+
+cdef public object postfix_inc_expr(object operand):
+ return PostfixIncNode(pos, operator = '++', operand = operand)
+
+cdef public object postfix_dec_expr(object operand):
+ return PostfixDecNode(pos, operator = '--', operand = operand)
+
+cdef public object argument_expr_list(object argument_expr_list, object assignment_expr):
+ if argument_expr_list is None:
+ argument_expr_list = []
+ argument_expr_list.append(assignment_expr)
+ return argument_expr_list
+
+
+# expressions -- unary
+
+cdef public object unary_op_expr(object operator, object operand):
+ cls, operator = operator
+ return cls(pos, operator = operator, operand = operand)
+
+cdef public object sizeof_var_expr(object operand):
+ return SizeofVarNode(pos, operand = operand)
+
+cdef public object sizeof_type_expr(object type_name):
+ base_type, declarator = type_name
+ return SizeofTypeNode(pos, base_type = base_type, declarator = declarator)
+
+cdef public object cast_expr(object type_name, object operand):
+ base_type, declarator = type_name
+ return TypecastNode(base_type = base_type, declarator = declarator, operand = operand)
+
+
+# expressions -- binary
+
+from Spike.Compiler.ExprNodes import \
+ MulNode, \
+ ModNode, \
+ AddNode, \
+ SubNode, \
+ NumBinopNode, \
+ IntBinopNode, \
+ BoolBinopNode, \
+ PrimaryCmpNode
+
+from Spike.Compiler.Nodes import \
+ SingleAssignmentNode
+
+cdef public object mul_expr(operand1, operand2):
+ return MulNode(pos, operator = "*", operand1 = operand1, operand2 = operand2)
+
+cdef public object div_expr(operand1, operand2):
+ return NumBinopNode(pos, operator = "/", operand1 = operand1, operand2 = operand2)
+
+cdef public object mod_expr(operand1, operand2):
+ return ModNode(pos, operator = "%", operand1 = operand1, operand2 = operand2)
+
+cdef public object add_expr(operand1, operand2):
+ return AddNode(pos, operator = "+", operand1 = operand1, operand2 = operand2)
+
+cdef public object sub_expr(operand1, operand2):
+ return SubNode(pos, operator = "-", operand1 = operand1, operand2 = operand2)
+
+cdef public object shift_left_expr(operand1, operand2):
+ return IntBinopNode(pos, operator = "<<", operand1 = operand1, operand2 = operand2)
+
+cdef public object shift_right_expr(operand1, operand2):
+ return IntBinopNode(pos, operator = ">>", operand1 = operand1, operand2 = operand2)
+
+cdef public object l_expr(operand1, operand2):
+ return PrimaryCmpNode(pos, operator = "<", operand1 = operand1, operand2 = operand2)
+
+cdef public object g_expr(operand1, operand2):
+ return PrimaryCmpNode(pos, operator = ">", operand1 = operand1, operand2 = operand2)
+
+cdef public object le_expr(operand1, operand2):
+ return PrimaryCmpNode(pos, operator = "<=", operand1 = operand1, operand2 = operand2)
+
+cdef public object ge_expr(operand1, operand2):
+ return PrimaryCmpNode(pos, operator = ">=", operand1 = operand1, operand2 = operand2)
+
+cdef public object eq_expr(operand1, operand2):
+ return PrimaryCmpNode(pos, operator = "==", operand1 = operand1, operand2 = operand2)
+
+cdef public object ne_expr(operand1, operand2):
+ return PrimaryCmpNode(pos, operator = "!=", operand1 = operand1, operand2 = operand2)
+
+cdef public object and_expr(operand1, operand2):
+ return IntBinopNode(pos, operator = "&", operand1 = operand1, operand2 = operand2)
+
+cdef public object xor_expr(operand1, operand2):
+ return IntBinopNode(pos, operator = "^", operand1 = operand1, operand2 = operand2)
+
+cdef public object or_expr(operand1, operand2):
+ return IntBinopNode(pos, operator = "|", operand1 = operand1, operand2 = operand2)
+
+cdef public object logical_and_expr(operand1, operand2):
+ return BoolBinopNode(pos, operator = "&&", operand1 = operand1, operand2 = operand2)
+
+cdef public object logical_or_expr(operand1, operand2):
+ return BoolBinopNode(pos, operator = "||", operand1 = operand1, operand2 = operand2)
+
+cdef public object assignment_expr(operator, lhs, rhs):
+ # NYI
+ return SingleAssignmentNode(pos, lhs = lhs, rhs = rhs)
+
+
+# expressions -- unary operators
+
+from Spike.Compiler.ExprNodes import \
+ AmpersandNode, \
+ IndirectionNode, \
+ UnaryPlusNode, \
+ UnaryMinusNode, \
+ TildeNode, \
+ NotNode, \
+ PrefixIncNode, \
+ PrefixDecNode
+
+cdef public object unary_address_of(): return AmpersandNode, '&'
+cdef public object unary_indirection(): return IndirectionNode, '*'
+cdef public object unary_plus(): return UnaryPlusNode, '+'
+cdef public object unary_minus(): return UnaryMinusNode, '-'
+cdef public object unary_bitwise_negation(): return TildeNode, '~'
+cdef public object unary_not(): return NotNode, '!'
+cdef public object unary_prefix_inc(): return PrefixIncNode, '++'
+cdef public object unary_prefix_dec(): return PrefixDecNode, '--'
+
+
+# declarations
+
+from Spike.Compiler.Nodes import \
+ CVarDefNode
+
+cdef public object declaration(object declaration_specifiers, object init_declarator_list):
+ # NYI: do some error checking on 'declaration_specifiers'.
+ kwds = dict(
+ name = 'int', module_path = [],
+ is_basic_c_type = 1, signed = 1,
+ longness = 0, is_self_arg = 0
+ )
+ kwds.update(declaration_specifiers)
+ base_type = CSimpleBaseTypeNode(pos, **kwds)
+ return CVarDefNode(pos, visibility = 'private', base_type = base_type, declarators = init_declarator_list)
+
+cdef public object declaration_specifiers(object specifier, object declaration_specifiers):
+ declaration_specifiers.update(specifier)
+ return declaration_specifiers
+
+cdef public object init_declarator_list(object init_declarator_list, object init_declarator):
+ if init_declarator_list is None:
+ init_declarator_list = []
+ init_declarator_list.append(init_declarator)
+ return init_declarator_list
+
+
+# declarations -- type specifiers
+
+cdef public object char_type(): return dict(name = 'char')
+cdef public object int_type(): return dict(name = 'int')
+cdef public object float_type(): return dict(name = 'float')
+cdef public object double_type(): return dict(name = 'double')
+cdef public object void_type(): return dict(name = 'void')
+cdef public object obj_type(): return dict(name = 'obj')
+
+cdef public object long_type(): return dict(longness = 1)
+cdef public object signed_type(): return dict(signed = 1)
+cdef public object unsigned_type(): return dict(signed = 0)
+
+
+# declarators
+
+from Spike.Compiler.Nodes import \
+ CNameDeclaratorNode, \
+ CArrayDeclaratorNode, \
+ CFuncDeclaratorNode, \
+ CPtrDeclaratorNode, \
+ CArgDeclNode
+
+cdef public object pointer_declarator(object pointer, object declarator):
+ last = pointer
+ while pointer.base is not None:
+ last = pointer.base
+ last.base = declarator
+ return pointer
+
+cdef public object name_declarator(object name):
+ return CNameDeclaratorNode(pos, name = name, cname = None)
+
+cdef public object array_declarator(object base, object dimension):
+ return CArrayDeclaratorNode(pos, base = base, dimension = dimension)
+
+cdef public object function_declarator(object declarator, object parameter_list):
+ return CFuncDeclaratorNode(pos,
+ base = declarator,
+ args = parameter_list,
+ has_varargs = 0, #ellipsis,
+ exception_value = None,
+ exception_check = 0,
+ )
+
+cdef public object pointer(object base):
+ return CPtrDeclaratorNode(pos, base)
+
+cdef public object type_specifier_list(object type_specifier_list, object type_specifier):
+ if type_specifier_list is None:
+ type_specifier_list = CSimpleBaseTypeNode(
+ pos,
+ name = 'int', module_path = [],
+ is_basic_c_type = 1, signed = 1,
+ longness = 0, is_self_arg = 0
+ )
+ # NYI: do some error checking.
+ type_specifier_list.__dict__.update(type_specifier)
+ return type_specifier_list
+
+cdef public object parameter_list(object parameter_list, object parameter_declaration):
+ if parameter_list is None:
+ parameter_list = []
+ base_type, declarator = parameter_declaration
+ node = CArgDeclNode(pos,
+ base_type = base_type,
+ declarator = declarator,
+ not_none = 0,
+ default = None)
+ parameter_list.append(node)
+ return parameter_list
+
+
+# abstract declarators
+
+cdef public object empty_declarator():
+ return CNameDeclaratorNode(pos, name = "", cname = None)
+
+
+# statements
+
+from Spike.Compiler.Nodes import \
+ StatListNode, \
+ PassStatNode, \
+ ExprStatNode, \
+ IfClauseNode, \
+ IfStatNode, \
+ WhileStatNode, \
+ ReturnStatNode
+
+cdef public object compound_statement(object declaration_list, object statement_list):
+ stats = []
+ if declaration_list is not None:
+ stats.extend(declaration_list.stats)
+ if statement_list is not None:
+ stats.extend(statement_list.stats)
+ ret = StatListNode(pos, stats = stats)
+ return ret
+
+cdef public object declaration_list(object declaration_list, object declaration):
+ if declaration_list is None:
+ declaration_list = StatListNode(pos, stats = [])
+ declaration_list.stats.append(declaration)
+ return declaration_list
+
+cdef public object statement_list(object statement_list, object statement):
+ if statement_list is None:
+ statement_list = StatListNode(pos, stats = [])
+ statement_list.stats.append(statement)
+ return statement_list
+
+cdef public object pass_statement():
+ return PassStatNode(pos)
+
+cdef public object expression_statement(object expr):
+ from Spike.Compiler.Nodes import StatNode
+ if isinstance(expr, StatNode):
+ # NYI -- AssignmentNodes currently go though here
+ return expr
+ return ExprStatNode(pos, expr = expr)
+
+cdef public object if_statement(object condition, object if_clause, object else_clause):
+ if_clauses = [IfClauseNode(pos, condition = condition, body = if_clause)]
+ return IfStatNode(pos, if_clauses = if_clauses, else_clause = else_clause)
+
+cdef public object while_statement(object expr, object statement):
+ return WhileStatNode(pos, condition = expr, body = statement, else_clause = None)
+
+cdef public object return_statement(object value):
+ return ReturnStatNode(pos, value = value)
+
+
+# external definitions
+
+cdef public void external_definition(object definition):
+ theDefList.append(definition)
+
+cdef public object function_definition(object declaration_specifiers,
+ object declarator,
+ object function_body):
+ # NYI: do some error checking on 'declaration_specifiers'.
+ kwds = dict(
+ name = 'int', module_path = [],
+ is_basic_c_type = 1, signed = 1,
+ longness = 0, is_self_arg = 0
+ )
+ kwds.update(declaration_specifiers)
+ base_type = CSimpleBaseTypeNode(pos, **kwds)
+ func = SpikeFuncDefNode(pos,
+ visibility = 'public',
+ base_type = base_type,
+ declarator = declarator,
+ body = function_body)
+ return func
+
+
+# utils
+
+cdef public object empty_list():
+ return list()
+
+cdef public object pair(object a, object b):
+ return a, b
+
+cdef public object name(char *text):
+ return str(text)
+
+cdef public object yystr(char *text):
+ return str(text)
+
+
+# end of file
Modified: cs/babel/trunk/spike/Spike/Compiler/scan.l
===================================================================
--- cs/babel/trunk/spike/Spike/Compiler/scan.l 2007-02-20 01:28:30 UTC (rev 6051)
+++ cs/babel/trunk/spike/Spike/Compiler/scan.l 2007-02-20 03:15:25 UTC (rev 6052)
@@ -6,8 +6,13 @@
IS (u|U|l|L)*
%{
+
+#define YYSTYPE PyObject *
+
#include <stdio.h>
-#include "y.tab.h"
+#include <Python.h>
+#include "gram.h"
+#include "parser.h"
void count();
%}
@@ -33,6 +38,7 @@
"if" { count(); return(IF); }
"int" { count(); return(INT); }
"long" { count(); return(LONG); }
+"obj" { count(); return(OBJ); }
"register" { count(); return(REGISTER); }
"return" { count(); return(RETURN); }
"short" { count(); return(SHORT); }
@@ -50,19 +56,16 @@
{L}({L}|{D})* { count(); return(check_type()); }
-0[xX]{H}+{IS}? { count(); return(CONSTANT); }
-0[xX]{H}+{IS}? { count(); return(CONSTANT); }
-0{D}+{IS}? { count(); return(CONSTANT); }
-0{D}+{IS}? { count(); return(CONSTANT); }
-{D}+{IS}? { count(); return(CONSTANT); }
-{D}+{IS}? { count(); return(CONSTANT); }
-'(\\.|[^\\'])+' { count(); return(CONSTANT); }
+0[xX]{H}+{IS}? { count(); yylval = yystr(yytext); return(LITERAL_INT); }
+0{D}+{IS}? { count(); yylval = yystr(yytext); return(LITERAL_INT); }
+{D}+{IS}? { count(); yylval = yystr(yytext); return(LITERAL_INT); }
+'(\\.|[^\\'])+' { count(); yylval = yystr(yytext); return(LITERAL_CHAR); }
-{D}+{E}{FS}? { count(); return(CONSTANT); }
-{D}*"."{D}+({E})?{FS}? { count(); return(CONSTANT); }
-{D}+"."{D}*({E})?{FS}? { count(); return(CONSTANT); }
+{D}+{E}{FS}? { count(); yylval = yystr(yytext); return(LITERAL_FLOAT); }
+{D}*"."{D}+({E})?{FS}? { count(); yylval = yystr(yytext); return(LITERAL_FLOAT); }
+{D}+"."{D}*({E})?{FS}? { count(); yylval = yystr(yytext); return(LITERAL_FLOAT); }
-\"(\\.|[^\\"])*\" { count(); return(STRING_LITERAL); }
+\"(\\.|[^\\"])*\" { count(); yylval = yystr(yytext); return(LITERAL_STRING); }
">>=" { count(); return(RIGHT_ASSIGN); }
"<<=" { count(); return(LEFT_ASSIGN); }
@@ -130,7 +133,7 @@
if ((c1 = input()) != '/' && c != 0)
{
- unput(c1);
+ /*unput(c1);*/
goto loop;
}
@@ -169,6 +172,6 @@
/*
* it actually will only return IDENTIFIER
*/
-
+ yylval = name(yytext);
return(IDENTIFIER);
}
Modified: cs/babel/trunk/spike/bin/spikec
===================================================================
--- cs/babel/trunk/spike/bin/spikec 2007-02-20 01:28:30 UTC (rev 6051)
+++ cs/babel/trunk/spike/bin/spikec 2007-02-20 03:15:25 UTC (rev 6052)
@@ -1,4 +1,5 @@
-#!/usr/bin/env python
+#!/usr/bin/env pyspike
+# -*- Python -*-
#
# Spike -- Main Program, Unix
More information about the cig-commits
mailing list