Skip to content

Commit

Permalink
Flush out Cola updates, cyaz in 2 weeks. :)
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.parrot.org/parrot/trunk@1329 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
Melvin Smith committed Apr 13, 2002
1 parent 6ff5ed1 commit d2fd487
Show file tree
Hide file tree
Showing 8 changed files with 571 additions and 249 deletions.
57 changes: 32 additions & 25 deletions languages/cola/Makefile
@@ -1,51 +1,58 @@
# Manually generated by programmer

CC=gcc -Wall
YACC=bison -v -y
LEX=flex
LIBS=
#LIBS=-ll -ly
#LIBS=-lfl
# Visual C++
#CC = cl
DEBUG = -g
# GCC
CC = gcc -Wall
YACC = bison -v -y
LEX = flex
LIBS =
#LIBS = -ll -ly
#LIBS = -lfl

HEADERS = cola.h parser.h

default:
default :
$(MAKE) x
cp x colac

clean:
nogen : sym.o type.o gen.o
$(CC) $(DEBUG) -c parser.c
$(CC) $(DEBUG) -c lexer.c
$(CC) $(DEBUG) -o x parser.o lexer.o sym.o type.o gen.o $(LIBS)

clean :
rm -f core
rm -f *.o *.imc
rm -f parser.h parser.output
rm -f lexer.c parser.c
rm -f x

publish:
publish :
perl publish.pl < MANIFEST

parser.c: cola.y
parser.c : cola.y
$(YACC) -d -o parser.c cola.y

lexer.c: cola.l $(HEADERS)
lexer.c : cola.l $(HEADERS)
$(LEX) cola.l

lexer.o: lexer.c $(HEADERS)
$(CC) -g -c lexer.c
lexer.o : lexer.c $(HEADERS)
$(CC) $(DEBUG) -c lexer.c

parser.o: parser.c $(HEADERS)
$(CC) -g -c parser.c
parser.o : parser.c $(HEADERS)
$(CC) $(DEBUG) -c parser.c

sym.o: sym.c $(HEADERS)
$(CC) -g -c sym.c
sym.o : sym.c $(HEADERS)
$(CC) $(DEBUG) -c sym.c

type.o: type.c $(HEADERS)
$(CC) -g -c type.c
type.o : type.c $(HEADERS)
$(CC) $(DEBUG) -c type.c

gen.o: gen.c $(HEADERS)
$(CC) -g -c gen.c
gen.o : gen.c $(HEADERS)
$(CC) $(DEBUG) -c gen.c

tree.o: tree.c $(HEADERS)
$(CC) -g -c tree.c
x : parser.o lexer.o sym.o type.o gen.o
$(CC) $(DEBUG) -o x parser.o lexer.o sym.o type.o gen.o $(LIBS)

x: parser.o lexer.o sym.o type.o gen.o
$(CC) -g -o x parser.o lexer.o sym.o type.o gen.o $(LIBS)
65 changes: 54 additions & 11 deletions languages/cola/cola.h
Expand Up @@ -11,7 +11,7 @@
#ifndef _COLA_H
#define _COLA_H

#define COLA_VERSION "0.0.4"
#define COLA_VERSION "0.0.4.4"


void abort(void);
Expand Down Expand Up @@ -56,36 +56,45 @@ enum ASTTYPE {
ASTT_NEW_OBJECT
};

enum TYPES {
TYPE_SCALAR,
TYPE_REFERENCE,
TYPE_ARRAY,
TYPE_METHOD,
TYPE_CLASS
};

/* Identifiers, etc. */
typedef struct _SymbolTable SymbolTable;
typedef struct _AST AST;
typedef struct _Type Type;

/* Symbol structure */
typedef struct _Node {
struct _Node *next,
*tnext;
} Node;

/* Symbol structure */
typedef struct _Symbol {
/* ->tnext is for manipulation of Symbols outside
* Symbol tables, etc. such as temporary lists.
* ->next is used by the symbol table methods.
* next and tnext must be the first 2 members of the struct
* NOTE: next and tnext must be the first 2 members of the struct
*/
struct _Symbol *next,
*tnext;

char *name;
int scope;
unsigned int flags;
/* Symbol.class is initially IDENTIFIER if it is not resolved to
* a type, variable, function, etc. Upon resolution it will be
* one of TYPE, LITERAL, VARIABLE, METHOD, NAMESPACE
*/
int kind;
Type *type;
int size;
AST * init_expr;
int is_lval;
SymbolTable *table; /* For functions/procs */
struct _Symbol *members; /* Classes/Namespaces */
struct _Symbol *literal;
int line;
} Symbol;
Expand Down Expand Up @@ -139,17 +148,42 @@ struct _AST {
struct _SymbolTable {
long count;
int scope;
Symbol *table[ HASH_SIZE ];
Symbol *table[HASH_SIZE];
};

/* Array stuff */
typedef struct _Rank {
Node *next,
*tnext;
int dim;
} Rank;

struct _Type {
int kind; /* scalar, array, class, pointer/reference */
Node *next,
*tnext;
unsigned long flags;
enum TYPES kind; /* scalar, array, class, pointer/reference */
int typeid;
int parentid;
int size;
Symbol *sym; /* Pointer to symbol table representing name of type */
Symbol *sym; /* Pointer to symbol table representing name of type */
/* Array or reference specific infu */
Type *type; /* Element or referenced type */
/* Array specific info */
Rank *rank;
int dim; /* Total dim, can be derived from evaluating rank list */
int **bounds; /* N x 2 dimensional array of bounds where N = dimensions */
};

typedef struct _Array {
Node *next,
*tnext;
Type *type; /* The type of element */
Rank *rank;
int dim; /* Total dim, can be derived from evaluating rank list */
int **bounds; /* N x 2 dimensional array of bounds where N = dimensions */
} __Array;


/*
* Symbol tables, scope stacks, for handling
Expand Down Expand Up @@ -183,6 +217,13 @@ extern Type *t_void,

void assert(void * p);

void push(Node ** list, Node * p);
void tpush(Node ** list, Node * p);
void tunshift(Node ** list, Node * p);
Node *pop(Node ** list);
Node *tpop(Node ** list);


Symbol *new_symbol(int kind, const char * name);
void push_sym(Symbol ** list, Symbol * p);
void tpush_sym(Symbol ** list, Symbol * p);
Expand All @@ -200,7 +241,7 @@ Symbol *lookup_symbol(SymbolTable *, const char *);
Symbol *lookup_symbol_scope(SymbolTable *, const char *, int);
Symbol *lookup_namespace(SymbolTable * tab, const char * name);
Symbol *lookup_class(SymbolTable * tab, const char * name);
void store_symbol(SymbolTable *, Symbol *);
Symbol *store_symbol(SymbolTable *, Symbol *);
Symbol *store_identifier(SymbolTable *, const char * name, int kind, Type * t);
int push_scope();
Symbol *pop_scope(SymbolTable *);
Expand All @@ -217,6 +258,9 @@ Type *lookup_type(const char * name);
Symbol *lookup_type_symbol(Symbol * id);
const char *type_name(Type *);
void coerce_operands(Type ** t1, Type ** t2);
Type *new_array(Type * type, Rank * rank);
Rank *new_rank(int dim);
Symbol *array_signature(Type * t);


char *str_dup(const char *);
Expand All @@ -241,7 +285,6 @@ AST *pop_primary_block();
AST *get_cur_primary_block();
AST *cur_method;


void gen_bootstrap();
void gen_ast(AST * ast);
void gen_namespace_decl(AST *);
Expand Down
145 changes: 60 additions & 85 deletions languages/cola/cola.l
Expand Up @@ -16,7 +16,7 @@
#include "parser.h"

extern long line;
int yyerror( char * );
int yyerror(char *);
%}

%option outfile="lexer.c"
Expand All @@ -30,54 +30,53 @@ CHARCONSTANT \'[^'\n]*\'

%%

[\n] { line++; }
\/\/.*\n { line++; /* COMMENT */}


"__asm" { return(ASM); }
"bool" { return(BOOL); }
"break" { return(BREAK); }
"byte" { return(BYTE); }
"const" { return(CONST); }
"continue" { return(CONTINUE); }
"char" { return(CHAR); }
"class" { return(CLASS); }
"decimal" { return(DECIMAL); }
"double" { return(DOUBLE); }
"else" { return(ELSE); }
"false" { return(FALSE); }
"float" { return(FLOAT); }
"get" { return(GET); }
"goto" { return(GOTO); }
"for" { return(FOR); }
"if" { return(IF); }
"int" { return(INT); }
"long" { return(LONG); }
"namespace" { return(NAMESPACE); }
"new" { return(NEW); }
"null" { return(NULLVAL); }
"out" { return(OUT); }
"object" { return(OBJECT); }
"override" { return(OVERRIDE); }
"public" { return(PUBLIC); }
"private" { return(PRIVATE); }
"protected" { return(PROTECTED); }
"readonly" { return(READONLY); }
"ref" { return(REF); }
"return" { return(RETURN); }
"set" { return(SET); }
"sbyte" { return(SBYTE); }
"short" { return(SHORT); }
"static" { return(STATIC); }
"string" { return(STRING); }
"true" { return(TRUE); }
"uint" { return(UINT); }
"ulong" { return(ULONG); }
"ushort" { return(USHORT); }
"using" { return(USING); }
"virtual" { return(VIRTUAL); }
"void" { return(VOID); }
"while" { return(WHILE); }
[\n] line++;
\/\/.*\n line++; /* COMMENT */

"__asm" return(ASM);
"bool" return(BOOL);
"break" return(BREAK);
"byte" return(BYTE);
"const" return(CONST);
"continue" return(CONTINUE);
"char" return(CHAR);
"class" return(CLASS);
"decimal" return(DECIMAL);
"double" return(DOUBLE);
"else" return(ELSE);
"false" return(FALSE);
"float" return(FLOAT);
"get" return(GET);
"goto" return(GOTO);
"for" return(FOR);
"if" return(IF);
"int" return(INT);
"long" return(LONG);
"namespace" return(NAMESPACE);
"new" return(NEW);
"null" return(NULLVAL);
"out" return(OUT);
"object" return(OBJECT);
"override" return(OVERRIDE);
"public" return(PUBLIC);
"private" return(PRIVATE);
"protected" return(PROTECTED);
"readonly" return(READONLY);
"ref" return(REF);
"return" return(RETURN);
"set" return(SET);
"sbyte" return(SBYTE);
"short" return(SHORT);
"static" return(STATIC);
"string" return(STRING);
"true" return(TRUE);
"uint" return(UINT);
"ulong" return(ULONG);
"ushort" return(USHORT);
"using" return(USING);
"virtual" return(VIRTUAL);
"void" return(VOID);
"while" return(WHILE);


{LETTER}{LETTERDIGIT}* {
Expand Down Expand Up @@ -109,42 +108,18 @@ CHARCONSTANT \'[^'\n]*\'
return(LITERAL);
}

"++" { return(INC); }
"--" { return(DEC); }
"||" { return(LOGICAL_OR);}
"&&" { return(LOGICAL_AND);}
"==" { return(LOGICAL_EQ);}
"!=" { return(LOGICAL_NE);}
"<<" { return(LEFT_SHIFT);}
">>" { return(RIGHT_SHIFT);}
"." { return('.'); }
"[" { return('['); }
"]" { return(']'); }
"," { return(','); }
":" { return(':'); }
";" { return(';'); }
"<=" { return(LOGICAL_LTE);}
">=" { return(LOGICAL_GTE);}
"<" { return(LOGICAL_LT);}
">" { return(LOGICAL_GT);}
"(" { return('('); }
")" { return(')'); }
"{" { return('{'); }
"}" { return('}'); }
"=" { return('='); }
"+" { return('+'); }
"-" { return('-'); }
"/" { return('/'); }
"*" { return('*'); }
"!" { return('!'); }
"?" { return('?'); }
"%" { return('%'); }
"|" { return('|'); }
"&" { return('&'); }
"^" { return('^'); }
"~" { return('~'); }
[\t\f ]+ ;
. { /* ignore */ }
"++" return(INC);
"--" return(DEC);
"||" return(LOGICAL_OR);
"&&" return(LOGICAL_AND);
"==" return(LOGICAL_EQ);
"!=" return(LOGICAL_NE);
"<<" return(LEFT_SHIFT);
">>" return(RIGHT_SHIFT);
"<=" return(LOGICAL_LTE);
">=" return(LOGICAL_GTE);
[\t\f\r ]+ ;
. { fprintf(stderr, "TOK[%c]\n", yytext[0]); return yytext[0]; }
%%

#ifdef yywrap
Expand Down

0 comments on commit d2fd487

Please sign in to comment.