Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove languages/cola, one of the first languages to target parrot.

git-svn-id: https://svn.parrot.org/parrot/trunk@37326 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
commit 74994c1f2562b16fdd260e14be37c84adaf36349 1 parent 60103ac
@coke coke authored
Showing with 7 additions and 11,882 deletions.
  1. +1 −27 MANIFEST
  2. +1 −41 MANIFEST.SKIP
  3. +1 −1  config/gen/languages.pm
  4. +4 −14 config/gen/makefiles/languages.in
  5. +0 −4 languages/cola/MAINTAINER
  6. +0 −249 languages/cola/README
  7. +0 −59 languages/cola/System.cola
  8. +0 −20 languages/cola/TODO
  9. +0 −405 languages/cola/cola.h
  10. +0 −160 languages/cola/cola.l
  11. +0 −1,076 languages/cola/cola.y
  12. +0 −34 languages/cola/colac
  13. +0 −136 languages/cola/config/makefiles/root.in
  14. +0 −73 languages/cola/core.pir
  15. +0 −113 languages/cola/examples/calc.cola
  16. +0 −37 languages/cola/examples/expressions.cola
  17. +0 −28 languages/cola/examples/fib.cola
  18. +0 −62 languages/cola/examples/life.cola
  19. +0 −45 languages/cola/examples/mandelbrot.cola
  20. +0 −25 languages/cola/examples/oop.cola
  21. +0 −46 languages/cola/examples/reverse.cola
  22. +0 −1,391 languages/cola/gen.c
  23. +0 −2,225 languages/cola/lexer.c
  24. +0 −3,023 languages/cola/parser.c
  25. +0 −200 languages/cola/parser.h
  26. +0 −514 languages/cola/semant.c
  27. +0 −1,418 languages/cola/sym.c
  28. +0 −117 languages/cola/t/examples.t
  29. +0 −13 languages/cola/t/harness
  30. +0 −320 languages/cola/type.c
  31. +0 −1  languages/t/harness
  32. +0 −3  lib/Parrot/Distribution.pm
  33. +0 −1  lib/Parrot/Docs/File.pm
  34. +0 −1  lib/Parrot/Docs/Section/Languages.pm
View
28 MANIFEST
@@ -1,7 +1,7 @@
# ex: set ro:
# $Id$
#
-# generated by tools/dev/mk_manifest_and_skip.pl Wed Mar 11 20:08:16 2009 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Wed Mar 11 20:48:41 2009 UT
#
# See tools/dev/install_files.pl for documentation on the
# format of this file.
@@ -1178,32 +1178,6 @@ languages/chitchat/src/parser/actions.pm [chitchat]
languages/chitchat/src/parser/grammar.pg [chitchat]
languages/chitchat/t/00-sanity.t [test]
languages/chitchat/t/harness [test]
-languages/cola/MAINTAINER [cola]
-languages/cola/README []doc
-languages/cola/System.cola [cola]
-languages/cola/TODO [cola]
-languages/cola/cola.h [cola]
-languages/cola/cola.l [cola]
-languages/cola/cola.y [cola]
-languages/cola/colac [cola]
-languages/cola/config/makefiles/root.in [cola]
-languages/cola/core.pir [cola]
-languages/cola/examples/calc.cola [cola]
-languages/cola/examples/expressions.cola [cola]
-languages/cola/examples/fib.cola [cola]
-languages/cola/examples/life.cola [cola]
-languages/cola/examples/mandelbrot.cola [cola]
-languages/cola/examples/oop.cola [cola]
-languages/cola/examples/reverse.cola [cola]
-languages/cola/gen.c [cola]
-languages/cola/lexer.c [cola]
-languages/cola/parser.c [cola]
-languages/cola/parser.h [cola]
-languages/cola/semant.c [cola]
-languages/cola/sym.c [cola]
-languages/cola/t/examples.t [test]
-languages/cola/t/harness [test]
-languages/cola/type.c [cola]
languages/forth/MAINTAINER [forth]
languages/forth/config/makefiles/root.in [forth]
languages/forth/forth.pir [forth]
View
42 MANIFEST.SKIP
@@ -1,6 +1,6 @@
# ex: set ro:
# $Id$
-# generated by tools/dev/mk_manifest_and_skip.pl Wed Mar 11 06:24:56 2009 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Wed Mar 11 20:48:41 2009 UT
#
# This file should contain a transcript of the svn:ignore properties
# of the directories in the Parrot subversion repository. (Needed for
@@ -511,46 +511,6 @@
^languages/chitchat/src/gen_builtins\.pir/
^languages/chitchat/src/gen_grammar\.pir$
^languages/chitchat/src/gen_grammar\.pir/
-# generated from svn:ignore of 'languages/cola/'
-^languages/cola/.*\.def$
-^languages/cola/.*\.def/
-^languages/cola/.*\.dll$
-^languages/cola/.*\.dll/
-^languages/cola/.*\.exe$
-^languages/cola/.*\.exe/
-^languages/cola/.*\.exp$
-^languages/cola/.*\.exp/
-^languages/cola/.*\.ilk$
-^languages/cola/.*\.ilk/
-^languages/cola/.*\.lib$
-^languages/cola/.*\.lib/
-^languages/cola/.*\.o$
-^languages/cola/.*\.o/
-^languages/cola/.*\.obj$
-^languages/cola/.*\.obj/
-^languages/cola/.*\.pdb$
-^languages/cola/.*\.pdb/
-^languages/cola/Makefile$
-^languages/cola/Makefile/
-^languages/cola/a\.pasm$
-^languages/cola/a\.pasm/
-^languages/cola/a\.pbc$
-^languages/cola/a\.pbc/
-^languages/cola/a\.pir$
-^languages/cola/a\.pir/
-^languages/cola/colacc$
-^languages/cola/colacc/
-^languages/cola/imcc$
-^languages/cola/imcc/
-^languages/cola/lexer\.c$
-^languages/cola/lexer\.c/
-^languages/cola/parser\.[ch]$
-^languages/cola/parser\.[ch]/
-^languages/cola/parser\.output$
-^languages/cola/parser\.output/
-# generated from svn:ignore of 'languages/cola/examples/'
-^languages/cola/examples/.*\.colacctmp$
-^languages/cola/examples/.*\.colacctmp/
# generated from svn:ignore of 'languages/forth/'
^languages/forth/Makefile$
^languages/forth/Makefile/
View
2  config/gen/languages.pm
@@ -35,7 +35,7 @@ sub _init {
$data{result} = q{};
$data{default_languages} = qq{
bf
- cardinal chitchat cola
+ cardinal chitchat
forth
jako
lisp
View
18 config/gen/makefiles/languages.in
@@ -16,7 +16,7 @@ SVN := svn
# When adding or removing languages, please update the list
LANGUAGES := \
BASIC bf \
- cardinal chitchat cola \
+ cardinal chitchat \
forth \
jako \
lisp \
@@ -196,7 +196,7 @@ test-unified: all
test-separate: all \
bf.test \
- cardinal.test chitchat.test cola.test \
+ cardinal.test chitchat.test \
forth.test \
jako.test \
lisp.test \
@@ -208,7 +208,7 @@ test-separate: all \
clean: \
BASIC.clean bf.clean \
- cardinal.clean chitchat.clean cola.clean \
+ cardinal.clean chitchat.clean \
forth.clean \
jako.clean \
lisp.clean \
@@ -220,7 +220,7 @@ clean: \
realclean: \
bf.realclean \
- cardinal.realclean chitchat.realclean cola.realclean \
+ cardinal.realclean chitchat.realclean \
forth.realclean \
jako.realclean \
lisp.realclean \
@@ -275,16 +275,6 @@ chitchat.clean:
chitchat.realclean:
- $(MAKE) chitchat realclean
-cola : cola.dummy
-cola.dummy:
- - $(MAKE) cola
-cola.test:
- - $(MAKE) cola test
-cola.clean:
- - $(MAKE) cola clean
-cola.realclean:
- - $(MAKE) cola realclean
-
forth : forth.dummy
forth.dummy:
- $(MAKE) forth
View
4 languages/cola/MAINTAINER
@@ -1,4 +0,0 @@
-# $Id$
-
-N: Melvin Smith
-E: melvin.smith@mindspring.com
View
249 languages/cola/README
@@ -1,249 +0,0 @@
-"Cola" - A compiler for the Parrot/Perl6 VM
-
- V0.1.2
-
- I've started this compiler (I call it Cola) to simultaneously
- teach myself how to write a compiler (ok I admit I squeaked
- through Compiler Design in school because I was too busy
- playing online MUD and basketball), as well as help
- out a project that I love, Perl6/Parrot!
-
- To really start having fun with the Parrot runtime I wanted
- a language similar to C/C++/C#/Java.
-
- The Cola parser is LALR, developed with flex/bison. It targets
- an intermediate language (PIR) which can be found in
- parrot/imcc or alongside Cola on CPAN.
- IMCC does the register allocation/spill control, optimization
- and various other dirty things, before generating machine
- instructions. Currently the only target is Parrot.
-
-Where to Get the Latest Compiler
-
- This was a quick 2-week project in 2002 to show how to compile
- to Parrot. Sometime in 2005 I plan to release a full implementation
- of Cola to CPAN and will update the README accordingly.
- http://cpan.org/authors/id/M/ME/MELVIN
-
-The Syntax
-
- Who knows? C# and Perl mix.
-
- The easiest way to see what it currently looks like is
- to read the examples.
-
-Supported Constructs
-
- For some quick samples, see the cola/examples/ subdirectory.
-
- Statements: FOR, WHILE, IF, ELSE, BREAK, CONTINUE, RETURN.
-
- All of these are limited in their current version but follow
- typical C-ish rules (break breaks out of current loop, continue
- shortcuts to the next iteration). return may return a value
- from anywhere inside a method.
-
- 0.0.4 adds logical operators.
- Conditional expressions may now be compound and use logical
- operators (&& and ||).
- CAUTION: Assignments inside conditionals such as...
-
- if((i = 15) == 15)
-
- are still not supported. This sort of expression will be fixed
- in the next update.
-
- Types: int, float, string (classes and arrays coming soon)
- Currently these map directly to the Parrot primitive types.
- Very simple type coercement and checking is supported.
-
- Variable Declarations:
- For now declare all your variables at the top of each method.
- Block scoping will be done soon.
- You may initialize your variables in the declaration.
-
- Expressions: Parens, +, -, *, /, %, ++ and -- are supported in
- any combination or complexity. Post and pre-increment are also
- supported. You may use the + operator on strings for concatenation.
-
- The following works:
-
- Console.WriteLine("Hello Mr " + name + "\n");
-
- There is no support for concatenation with non-strings yet.
- I need to whip up a few conversion routines.
-
- Comparisons: <, >, <=, >=, !=, ==
-
- Bitwise operators: <<, >>, |, &, ^, and ~ are now supported in 0.0.4
-
- Conditional expressions: Commonly known as the ternary conditional...
- As I understand the Java and C# language spec,
- conditional expressions must be on the right hand side of an
- assignment or anywhere that uses the return value, however you
- cannot use ternaries standalone as a statement. So in Cola you can
- say:
- max = i > j ? i : j;
- or:
- max = i > j ? foo() : bar();
-
- But it is not proper (although C allows you) to say:
-
- i > j ? printf("max=i\n") : printf("max=j\n");
-
- If you think I have misread the C# grammar spec, please email me.
-
- Boolean: The boolean ! operator isn't yet supported.
-
- Objects and Methods:
- Classic C++/Java style, recursion supported. Return types supported.
- Will be adding variable argument support per the C# spec.
-
- Member variables or "fields" aren't yet supported. You
- can use const definitions, but member variables
- are incomplete pending a little more work on Parrot.
- Its possible to do them now with PerlHash or PerlArray,
- but I'm working on something faster for strictly typed,
- non-dynamic languages.
-
- Currently instance methods are the same as class methods. So
- you could do:
-
- Console.WriteLine("");
-
- or Console c = new Console();
- c.WriteLine("");
-
- The compiler doesn't yet differentiate between static or class
- methods and instance methods, and whether you are calling them
- as such.
-
- OOP is really just faked for now, enough for people to write
- in a high level language for Parrot. As everything, it is a work
- in progress. All objects are simply PerlString references for now.
-
- Current Builtin Subroutines
-
- Since I have yet to implement class importing, the system routines
- are just plain wrappers around the Parrot ops. Currently they are:
-
- strlen, substr, strchop, ord, puts, puti, putf, gets, sleep
-
- See gen.c and main() for the current kludgy way to patch in more wrappers.
-
- In calc.cola I also did a sample implementation of a string to int
- conversion called StrToInt().
-
-
- Arrays:
- Parrot now has a substr with replace op so we can emulate arrays
- on top of it. It is a hack but it works.
-
-What you currently CANNOT do even though the Parser may eat it...
- Statement lists: i = j, j = k;
- Nested assigns: i = (j = 0);
- Fancy For loops: for(i = 0; j++, j < 4; i++)
- Empty For headers: for(;;) // use while(1)
-
-Using the Compiler
-
- You will need Flex and Bison installed to build the compiler.
- These are the GNU versions of the classic lex and yacc, but
- are more modern. The grammars should work with standard lex/yacc
- but I've not tested this lately. parser.c is provided pre-generated
- so you do not actually need lex/yacc.
-
- Build Cola from the languages directory above this by typing:
-
- make languages
-
- Usage:
-
- colacc examples/mandelbrot.cola
-
- NOTE: colacc will expect you to have core.pir in the current directory
- when you execute it as it autoincludes it in generated code.
-
- This will call Parrot (and imcc) to generate 2 types of output. a.pasm
- and a.pbc. You can run the .pbc (bytecode) immediately with Parrot:
-
- parrot a.pbc
-
- You can also see the Parrot assembly in "a.pasm".
-
- Currently colac is a short Perl pre-processor that includes
- classes for any import statements (using System;)
- If you have trouble with colac you can just use colacc which
- is the raw compiler which ignores 'using' directives.
-
- Also, if you look in "a.pir" you will see an intermediate
- language. Debugging the compiler is easier by looking at the
- intermediate code. This language can be piped through imcc to
- re-generate the .pasm file, however this is done by default.
-
- Currently the compiler is very limited with a few warnings and
- a few simple type coercions.
-
- If you try to do something fancy, the grammar might accept
- it but the code will probably come out wrong or simply crash the
- compiler. Read all the samples before trying anything.
-
-Intermediate Code
-
-
- Please see the README in the parrot/imcc directory.
-
- For a nice sample of intermediate code, compile mandelbrot.cola or
- calc.cola which actually does a limited form of parsing with Parrot.
-
-
-Register Allocation
-
- Done via graph-coloring. Cola emits intermediate code that uses
- named locals/globals and symbolic temporary registers. IMCC
- handles the allocation and spilling.
-
- See parrot/imcc/README
-
-Optimization
-
- Very limited. No explicit optimization phase yet.
-
- You might see dumb code generated in the form of:
-
- set I1, I0
- set I2, I1
-
- or..
-
- branch LABEL34
- LABEL34: ...
-
- generated between basic blocks or in situations where
- the generator is currently dumb.
-
- The plan is to convert intermediate code to SSA (Static
- Single Assignment) form before doing various optimization
- passes.
-
-Coming Soon
- Some form of a printf()
- Full array support
-
-
-Gaping Holes
-
- Arrays
- Strings can be treated as arrays, thats it for now.
- Will be adding full array support soon.
-
- Class/Struct instantiation
- Lotta work involved here, I won't go there for now.
- Parrot currently does not have an adequate bytecode "class format"
- in which to write symbol table information. This will change soon.
-
- Object Methods and Field references
- Again, a lot of work, but on the list. I'm sort of faking
- method calls for now, no instance calls.
-
-
View
59 languages/cola/System.cola
@@ -1,59 +0,0 @@
-//
-// My naive beginnings of the C# System namespace
-
-//namespace System {
-
-public class Object {
-}
-
-public class Boolean {
-}
-
-public class Sbyte {
-}
-
-public class Byte {
-}
-
-public class Char {
-}
-
-public class Int16 {
-}
-
-public class Int32 {
-}
-
-public class Int64 {
-}
-
-public class UInt16 {
-}
-
-public class UInt32 {
-}
-
-public class UInt64 {
-}
-
-public class Single {
-}
-
-public class Double {
-}
-
-public class Decimal {
-}
-
-public class String {
-}
-
-class Console {
- public void WriteLine(string s) {
- puts(s);
- }
-}
-
-
-//}
-
View
20 languages/cola/TODO
@@ -1,20 +0,0 @@
-The following tickets were stored in parrot's RT system.
-
-They have now been marked as rejected in that system, but are listed
-here for posterity, so they can easily be migrated into cola's new
-ticketing system, whatever that may be.
-
-#48198: [TODO] [cola] Add support for member resolution in lookup_type()
- http://rt.perl.org/rt3/Ticket/Display.html?id=48198
-
-#48200: [TODO] [cola] Add documentation to files and functions
- http://rt.perl.org/rt3/Ticket/Display.html?id=48200
-
-#48202: [TODO] [cola] Rewrite push_sym() to call generic Node versions of calls
- http://rt.perl.org/rt3/Ticket/Display.html?id=48202
-
-#48204: [TODO] [cola] Check method signature in gen_arg_list_expr() and find out what type is expected
- http://rt.perl.org/rt3/Ticket/Display.html?id=48204
-
-#48206: [TODO] [cola] Check that expression evaluates to a method in gen_method_call()
- http://rt.perl.org/rt3/Ticket/Display.html?id=48206
View
405 languages/cola/cola.h
@@ -1,405 +0,0 @@
-/*
- * cola.h
- *
- * $Id$
- *
- * Cola compiler for Parrot
- *
- * Copyright (C) 2002 Melvin Smith <melvin.smith@mindspring.com>
- *
- * The giant, hulking header file.
- */
-
-#ifndef PARROT_LANGUAGES_COLA_H_GUARD
-#define PARROT_LANGUAGES_COLA_H_GUARD
-
-# define COLA_VERSION "0.0.11.1"
-
-# define DEBUG 0
-
-void abort(void);
-void exit(int status);
-
-
-enum ASTKIND {
- KIND_DECL,
- KIND_STATEMENT,
- KIND_BLOCK,
- KIND_EXPR,
- KIND_PARAM
-};
-
-enum ASTTYPE {
- ASTT_LITERAL,
- ASTT_IDENTIFIER,
- ASTT_NAMESPACE_DECL,
- ASTT_CLASS_DECL,
- ASTT_CONSTANT_DECL,
- ASTT_FIELD_DECL,
- ASTT_METHOD_DECL,
- ASTT_FIXED_PARAM,
- ASTT_PARAM_ARRAY,
- ASTT_ASSIGN,
- ASTT_OP,
- ASTT_LOGICAL,
- ASTT_INDEX,
- ASTT_IF,
- ASTT_WHILE,
- ASTT_FOR,
- ASTT_BREAK,
- ASTT_CONTINUE,
- ASTT_RETURN,
- ASTT_GOTO,
- ASTT_METHOD_CALL,
- ASTT_BOOLEAN,
- ASTT_COMPARISON,
- ASTT_CONDITIONAL_EXPR,
- ASTT_PREINC,
- ASTT_POSTINC,
- ASTT_NEW_OBJECT
-};
-
-enum TYPES {
- TYPE_SCALAR,
- TYPE_REFERENCE,
- TYPE_ARRAY,
- TYPE_METHOD,
- TYPE_CLASS
-};
-
-# define MOD_PUBLIC (1)
-# define MOD_PRIVATE (1<<1)
-# define MOD_PROTECTED (1<<2)
-# define MOD_STATIC (1<<3)
-# define MOD_VIRTUAL (1<<4)
-
-
-
-/* Identifiers, etc. */
-typedef struct _SymbolTable SymbolTable;
-typedef struct _AST AST;
-typedef struct _Type Type;
-
-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.
- * NOTE: next and tnext must be the first 2 members of the struct
- */
- struct _Symbol *next,
- *tnext;
-
- char *name;
- int scope;
- 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;
- struct _Symbol *typename;
- Type *type;
- int is_lval;
- struct _Symbol *namespace; /* What namespace or class owns me */
- SymbolTable *table; /* If I'm a namespace/class, this is my symbol table */
- struct _Symbol *literal;
- int line;
-} Symbol;
-
-/* Node for Abstract Syntax Tree */
-struct _AST {
- /* next and tnext must be the first 2 members of the struct */
- struct _AST *next,
- *tnext;
- struct _AST *up,
- *arg1,
- *arg2;
- /* start_label is 1st statement in construct
- * end_label is _after_ last statement so it can
- * be used to jump out, break, etc. from loops, switches.
- */
- char *start_label,
- *end_label;
- enum ASTKIND kind; /* General node class (STATEMENT) */
- enum ASTTYPE asttype; /* Specific node type (IF|ASSIGN|...)*/
- int op; /* Operation */
- Type *type; /* Unresolved until type-check pass */
- Symbol *typename;
- Symbol *sym;
- /* Expression generic nodes */
- Symbol *targ;
- Symbol *vars;
- /* Conditional specific nodes
- * Reuse above nodes for if_then_else
- * arg1 = _then_ branch
- * arg2 = _else_ branch
- */
- union {
- /*
- struct _EXPR {
- struct _AST *arg1;
- struct _AST *arg2;
- } Expr;
- */
- struct _CLASS {
- struct _AST *body;
- } Class;
- struct _CONDITIONAL {
- struct _AST *condition, *end;
- } Conditional;
- struct _METHOD {
- struct _Symbol *params;
- struct _AST *body;
- } Method;
- struct _LOOP {
- struct _AST *init;
- struct _AST *iteration;
- struct _AST *condition;
- struct _AST *body;
- } Loop;
- } Attr;
-};
-
-# define HASH_SIZE 109
-
-struct _SymbolTable {
- long count;
- int scope;
- Symbol *table[HASH_SIZE];
-};
-
-/* Array stuff */
-typedef struct _Rank {
- Node *next,
- *tnext;
- int dim;
-} Rank;
-
-struct _Type {
- Node *next,
- *tnext;
- unsigned long flags;
- enum TYPES kind; /* class, array, pointer/reference */
- int size;
-/*
- int typeid;
- int parentid;
-*/
- Symbol *sym; /* symbol representing name of type */
- Type *type; /* Element or referenced type */
-};
-
-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
- * classes, namespaces, etc.
- */
-
-/* This will be some static method, Main from a
- * single class in the assembly, if it is executable.
- */
-extern Symbol *main_method;
-
-/* The static, global symbol table */
-extern Symbol *global_namespace;
-extern SymbolTable *global_symbol_table;
-/* The current working symbol table */
-extern SymbolTable *current_symbol_table;
-/*
- * The stack of symbols representing the current
- * nested scope (namespaces, classes, etc.)
- * Namespaces and classes are represented by a Symbol
- * and each hold a SymbolTable which holds any nested
- * types and members for the particular object.
- */
-extern Symbol *namespace_stack;
-/* The current working namespace or class.
- * current_namespace->table == current_symbol_table
- */
-extern Symbol *current_namespace;
-extern int scope;
-/* Pointers to the builtin type entries in the symbol table */
-extern Type *t_object,
- *t_void,
- *t_string,
- *t_bool,
- *t_sbyte,
- *t_byte,
- *t_char,
- *t_int32,
- *t_uint32,
- *t_int64,
- *t_uint64,
- *t_short,
- *t_ushort,
- *t_float,
- *t_double,
- *t_decimal;
-
-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(const char * name);
-Symbol *new_identifier_symbol(const char * name);
-Symbol *new_literal_symbol(const char * name);
-Symbol *new_type_symbol(const char * name);
-Symbol *mk_namespace_symbol(Symbol *);
-Symbol *mk_class_symbol(Symbol *);
-Symbol *mk_method_symbol(Symbol *, const char *, const char *);
-Symbol *symbol_concat(Symbol *, Symbol *);
-Symbol *symbol_join3(Symbol *, Symbol *, Symbol *);
-Symbol *symbol_join4(Symbol *, Symbol *, Symbol *, Symbol *);
-SymbolTable *new_symbol_table();
-void push_sym(Symbol ** list, Symbol * p);
-void tpush_sym(Symbol ** list, Symbol * p);
-void tunshift_sym(Symbol ** list, Symbol * p);
-Symbol *pop_sym(Symbol ** list);
-Symbol *tpop_sym(Symbol ** list);
-void push_namespace(Symbol * ns);
-Symbol *pop_namespace();
-void init_symbol_tables();
-void init_builtin_types();
-Symbol *split(const char *, const char *);
-unsigned int hash_str(const char * str);
-Symbol *lookup_symbol(const char *);
-Symbol *lookup_symbol_in_tab(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);
-Symbol *store_symbol(SymbolTable *, Symbol *);
-Symbol *store_identifier(SymbolTable *, Symbol *);
-Symbol *store_method(SymbolTable *, const char * name, Type *);
-int push_scope();
-Symbol *pop_scope();
-void discard_scope();
-void declare_local(Symbol * id);
-
-/*
- * Type related utilities
- */
-
-extern Type **type_table;
-extern int type_table_size;
-
-Type *store_type(const char * name, int size);
-Type *lookup_type(const char * name);
-Type *lookup_type_symbol(Symbol * id);
-const char *type_name(Type *);
-void coerce_operands(Type ** t1, Type ** t2);
-Type *new_array(Symbol * typename, Rank * rank);
-Rank *new_rank(int dim);
-Symbol *array_signature(Type * t);
-
-/* Type checking and semantic phase */
-void build_ast(AST *);
-void build_class_decl(AST *);
-void build_class_body(AST *);
-void build_method_decl(AST *);
-void build_field_decl(AST *);
-void build_statement_list(AST *);
-void build_expr_list(AST *);
-void build_expr(AST *);
-void build_if(AST *);
-void build_conditional(AST *);
-void build_method_call(AST *);
-void build_new_expr(AST *);
-void build_loop(AST *);
-void build_return(AST *);
-void resolve_identifier(Symbol **);
-
-
-char *str_dup(const char *);
-char *str_cat(const char *, const char *);
-void dump_namespace(Symbol *);
-void dump_symbol_table(SymbolTable *);
-Symbol *check_id_redecl(SymbolTable * table, const char * name);
-Symbol *check_id_decl(SymbolTable * table, const char * name);
-void unshift_ast(AST ** list, AST * p);
-AST *new_ast(enum ASTKIND kind, int type, AST * left, AST * right);
-AST *new_statement(int type, AST * left, AST * right);
-AST *new_expr(int type, AST * left, AST * right);
-AST *new_op_expr(AST * left, int op, AST * right);
-AST *new_logical_expr(AST * left, int op, AST * right);
-AST *new_if(AST * condition, AST *, AST *);
-AST *new_conditional(AST * condition, AST *, AST *);
-AST *new_while(AST * condition, AST * block);
-AST *new_for(AST * init, AST * condition, AST * increment, AST * block);
-extern int primary_block;
-extern AST *primary_block_stack[];
-void push_primary_block(AST *p);
-AST *pop_primary_block();
-AST *get_cur_primary_block();
-AST *cur_method;
-
-/* Code generation phase */
-void gen_ast(AST * ast);
-void gen_namespace_decl(AST *);
-void gen_class_decl(AST *);
-void gen_class_body(AST * ast);
-void gen_field_decl(AST * ast);
-void gen_constant_decl(AST * ast);
-void gen_method_decl(AST * ast);
-void gen_block(AST * ast);
-void gen_statement(AST * ast);
-void gen_var_decl(AST * ast);
-void gen_assign(AST * ast);
-void gen_expr(AST * ast, Symbol * lval, Type * t);
-void gen_method_call(AST *);
-void gen_if(AST *);
-void gen_while(AST *);
-void gen_for(AST *);
-void gen_boolean(AST *, const char * true_label, const char * false_label,
- int invert);
-
-void emit_op_expr(Symbol * res, Symbol * arg1, char * op, Symbol * arg2);
-void emit_unary_expr(Symbol * res, Symbol * arg1, char * op);
-
-char *new_itemp();
-char *new_ntemp();
-char *new_stemp();
-char *new_ptemp();
-Symbol *new_temp(Type * t);
-
-void reset_temps();
-char *get_label();
-char *make_label();
-char *op_name(int);
-int op_inverse(int);
-
-# define NAME(x) ((x)->literal == NULL ? (x)->name : (x)->literal->name)
-# define IS_LVAL(x) ((x)->is_lval)
-# define IS_RVAL(x) (!(x)->is_lval)
-# define SWITCH_OR_LOOP() (primary_block > 0 ? 1 : 0)
-# define eval_expr(x) (((x)->asttype == ASTT_LITERAL || (x)->asttype == ASTT_IDENTIFIER) ? ((x)->targ = (x)->sym, 1) : 0)
-
-extern long line;
-
-#endif /* PARROT_LANGUAGES_COLA_H_GUARD */
-
-/*
- * Local variables:
- * c-file-style: "parrot"
- * End:
- * vim: expandtab shiftwidth=4:
- */
View
160 languages/cola/cola.l
@@ -1,160 +0,0 @@
-%{
-/*
- * cola.l
- *
- * $Id$
- *
- * Cola compiler for Parrot
- *
- * Copyright (C) 2002 Melvin Smith
- *
- * The lexer. Grammar for Flex.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "cola.h"
-#include "parser.h"
-
-extern long line;
-int yyerror(char *);
-%}
-
-%option outfile="lexer.c"
-
-LETTER [a-zA-Z_]
-DIGIT [0-9]
-LETTERDIGIT [a-zA-Z0-9_]
-SIGN [-+]
-STRINGCONSTANT \"[^"\n]*["\n]
-CHARCONSTANT \'[^'\n]*\'
-RANKSPEC \[[,]*\]
-
-%%
-
-[\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;
-"this" return THIS;
-"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}* {
- Symbol * s;
- s = new_identifier_symbol(yytext);
- s->line = line;
- yylval.sym = s;
- return IDENTIFIER;
- }
-
-{SIGN}?{DIGIT}+"."{DIGIT}+ {
- Symbol * s = new_literal_symbol(yytext);
- s->type = t_float;
- s->typename = t_float->sym;
- yylval.sym = s;
- return LITERAL;
- }
-
-{SIGN}?{DIGIT}+ {
- Symbol * s = new_literal_symbol(yytext);
- s->type = t_int32;
- s->typename = t_int32->sym;
- yylval.sym = s;
- return LITERAL;
- }
-
-{STRINGCONSTANT} {
- Symbol * s = new_literal_symbol(yytext);
- s->type = t_string;
- s->typename = t_string->sym;
- yylval.sym = s;
- return LITERAL;
- }
-
-{RANKSPEC} {
- /*
- * This might bite me in the butt later, but its easier to offload
- * this to the lexer. [], [,], etc.
- */
- Symbol * s = new_literal_symbol(yytext);
- fprintf(stderr, "Rank spec /%s/\n", s->name);
- yylval.sym = s;
- return RANKSPEC;
- }
-
-"++" 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 ]+ ;
-. return yytext[0];
-%%
-
-#ifdef yywrap
-# undef yywrap
-#endif
-
-int yywrap() {
- /* Add code here to open next source file and start scanning
- yywrap returns 0 if scanning is to continue
- */
- return 1;
-}
-
-
-/*
- * Local variables:
- * c-file-style: "parrot"
- * End:
- * vim: expandtab shiftwidth=4:
- */
View
1,076 languages/cola/cola.y
@@ -1,1076 +0,0 @@
-%{
-/*
- * cola.y
- *
- * $Id$
- *
- * Cola compiler for Parrot
- *
- * Copyright (C) 2002 Melvin Smith <melvin.smith@mindspring.com>
- *
- * Borrows heavily from Java and C#
- * Java is a registered trademark of Sun Microsystems
- * C# is a registered trademark of Microsoft Corporation
- *
- * The parser. Grammar for Bison.
- */
-
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "cola.h"
-
-int yyerror(char *);
-int yylex();
-extern char yytext[];
-long line;
-int indent;
-
-AST *ast_start = NULL;
-
-/* Pointers to the builtin type entries in the symbol table */
-
-%}
-
-%union {
- int ival;
- Symbol * sym;
- Type * type;
- AST * ast;
- void * p;
-}
-
-%token ASM
-
-%token ABSTRACT BOOL BREAK BYTE CHAR CLASS CONST
-%token CONTINUE
-%token DOUBLE DECIMAL ELSE EXTERN
-%token FALSE FLOAT FOR
-%token GET GOTO
-%token IF INT INTERNAL
-%token LONG METHOD MODIFIER NEW NAMESPACE NULLVAL
-%token OUT OVERRIDE OBJECT PRIVATE PROTECTED PUBLIC
-%token REF READONLY RETURN
-%token SBYTE SET SHORT STRING STATIC
-%token THIS TRUE TYPE
-%token UINT USHORT ULONG USING VIRTUAL VOID WHILE
-%token <sym> IDENTIFIER LITERAL RANKSPEC
-%token <ival> INC DEC LOGICAL_AND LOGICAL_OR LOGICAL_EQ LOGICAL_NE
-%token <ival> LOGICAL_LTE LOGICAL_GTE
-%token <ival> LEFT_SHIFT RIGHT_SHIFT INDEX
-
-%token TYPE METHOD
-
-%type <sym> type array_type
-%type <sym> predefined_type integral_type
-%type <sym> qualified_name member_access
-%type <sym> namespace_scope_start class_scope_start
-%type <sym> formal_param_list fixed_params fixed_param
-%type <ast> var_declarator var_declarators
-%type <ast> using_directives using_directive attribute_list
-%type <ast> namespace_member_decls namespace_member_decl
-%type <ast> namespace_decl class_decl namespace_body
-%type <ast> return_statement jump_statement asm_block
-%type <ast> statement statement_list
-%type <ast> decl_statement method_decl field_decl
-%type <ast> class_body class_member_decl_list class_member_decl
-%type <ast> local_var_decl
-%type <ast> method_header method_body
-%type <ast> block labeled_statement embedded_statement
-%type <ast> expr_statement selection_statement if_statement
-%type <ast> iteration_statement while_statement for_statement
-%type <ast> expr_list expr statement_expr assignment
-%type <ast> primary_expr boolean_expr equality_expr element_access
-%type <ast> post_inc_expr post_dec_expr pre_inc_expr pre_dec_expr
-%type <ast> new_expr new_object_expr
-%type <ast> conditional_expr conditional_or_expr
-%type <ast> conditional_and_expr inclusive_or_expr and_expr
-%type <ast> shift_expr exclusive_or_expr relational_expr
-%type <ast> unary_expr add_expr mult_expr
-%type <ast> method_call arg arg_list
-%type <ival> modifier modifiers opt_modifiers
-%type <ival> relational_op
-%type <sym> rank_specifiers
-
-%left '-' '+'
-%left '*' '/'
-%nonassoc IF
-%nonassoc ELSE
-%right '='
-%nonassoc UMINUS INC DEC
-%left '('
-%left '[' '{'
-%left '.'
-
-%start compilation_unit
-
-%%
-
-optional_semi :
- | ';'
- ;
-
-compilation_unit:
- using_directives attribute_list namespace_member_decls
- {
- unshift_ast(&ast_start, $1);
- unshift_ast(&ast_start, $2);
- unshift_ast(&ast_start, $3);
- printf("DONE: compilation_unit.\n");
- }
- ;
-
-using_directives: /*NULL*/
- { $$ = NULL; }
- | using_directives using_directive
- {
- unshift_ast(&($$), $1);
- }
- ;
-
-using_directive:
- USING IDENTIFIER '=' IDENTIFIER ';'
- { printf("using_alias_directive\n"); }
- | USING IDENTIFIER ';'
- {
- printf("using_directive\n");
- /*load_module($2->name);*/
- }
- ;
-
-attribute_list : /*NULL*/
- { $$ = NULL; }
- ;
-
-namespace_decl:
- namespace_scope_start namespace_body
- {
- pop_namespace();
- $$ = new_ast(KIND_DECL, ASTT_NAMESPACE_DECL, $2, NULL);
- $$->sym = $1;
- }
- ;
-
-namespace_scope_start:
- NAMESPACE qualified_name
- {
- Symbol *n, *t, *last = current_namespace;
- if (lookup_type_symbol($2)) {
- printf("Error, redefinition of [%s]\n", $2->name);
- exit(0);
- }
- for (n = split(".", $2->name); n; n = n->tnext) {
- n->kind = $2->kind;
- t = mk_namespace_symbol(n);
- store_symbol(last->table, t);
- last = n;
- }
- push_namespace(t);
- $$ = t;
- }
- ;
-
-qualified_name:
- IDENTIFIER
- { $$ = $1; fprintf(stderr, "qualified_name <- IDENTIFIER\n"); }
- | qualified_name '.' IDENTIFIER
- {
- $$ = symbol_join3($1, new_symbol("."), $3);
- fprintf(stderr, "qualified_name <- qualified_name . IDENTIFIER\n");
- }
- ;
-
-namespace_body:
- '{' using_directives namespace_member_decls '}'
- {
- $$ = $2;
- if ($3)
- unshift_ast(&($$), $3);
- }
- ;
-
-namespace_member_decls: /*NULL*/
- { $$ = NULL; }
- |
- namespace_member_decls namespace_member_decl
- {
- $$ = $1;
- if ($2)
- unshift_ast(&($$), $2);
- }
- ;
-
-namespace_member_decl:
- namespace_decl
- | class_decl
- ;
-
-class_decl:
- opt_modifiers class_scope_start class_body optional_semi
- {
- pop_namespace();
- $$ = new_ast(KIND_DECL, ASTT_CLASS_DECL, NULL, NULL);
- $$->Attr.Class.body = $3;
- $$->sym = $2;
- $$->sym->flags = $1;
- }
- ;
-
-opt_modifiers:
- { $$ = 0; }
- | modifiers
- ;
-
-modifiers:
- modifiers modifier
- { $$ = $1 | $2; }
- | modifier
- ;
-
-modifier:
- PUBLIC
- { $$ = MOD_PUBLIC; }
- | PRIVATE
- { $$ = MOD_PRIVATE; }
- | PROTECTED
- { $$ = MOD_PROTECTED; }
- | STATIC
- { $$ = MOD_STATIC; }
- | VIRTUAL
- { $$ = MOD_VIRTUAL; }
- ;
-
-class_body:
- '{' class_member_decl_list '}'
- { $$ = $2; }
- ;
-
-class_scope_start:
- CLASS IDENTIFIER
- {
- /* Create a new namespace for class and put it in effect */
- Symbol * c;
-#if DEBUG
- fprintf(stderr, "\nclass_scope_start <- CLASS IDENTIFIER (%s)\n", $2->name);
-#endif
- c = mk_class_symbol($2);
- push_namespace(c);
-/*
- push_scope();
-*/
- $$ = c;
- }
- ;
-
-class_member_decl_list:
- { $$ = NULL; }
- | class_member_decl_list class_member_decl
- {
- $$ = $1;
- unshift_ast(&($$), $2);
- }
- ;
-
-class_member_decl:
- field_decl
- | method_decl
-/*
- | property_decl
- | event_decl
- | indexer_decl
- | operator_decl
- | constructor_decl
- | destructor_decl
- | static_constructor_decl
- | type_decl
-*/
- ;
-
-
-decl_statement:
- local_var_decl ';'
- { $$ = $1; }
- | CONST type IDENTIFIER '=' LITERAL ';'
- {
- $3->typename = $2;
- $3->literal = $5;
- check_id_redecl(current_symbol_table, $3->name);
- store_symbol(current_symbol_table, $3);
- $$ = new_statement(ASTT_CONSTANT_DECL, NULL, NULL);
- $$->typename = $2;
- if (lookup_symbol_in_tab(current_symbol_table, $$->sym->name)) {
- printf("Warning: declaration of '%s' shadows previous instance.\n",
- $$->sym->name);
- }
- }
- ;
-
-local_var_decl:
- type var_declarators
- {
- AST * decl;
- if ($1 == NULL) {
- printf("Internal compiler error: local_var_decl: type is NULL\n");
- abort();
- }
- for (decl=$2; decl; decl = decl->next) {
-#if DEBUG
- fprintf(stderr, "local_var: [%s] typename [%s]\n",
- decl->arg1->sym->name, $1->name);
-#endif
- decl->arg1->sym->typename = $1;
- }
- $$ = $2;
- }
- ;
-
-field_decl:
- opt_modifiers type var_declarators ';'
- {
- AST * decl;
- if ($2 == NULL) {
- printf("Internal compiler error: field_decl: type is NULL\n");
- abort();
- }
- for (decl=$3; decl; decl = decl->next) {
-#if DEBUG
- fprintf(stderr, "field: [%s] typename [%s]\n",
- decl->arg1->sym->name, $2->name);
-#endif
- decl->arg1->sym->typename = $2;
- }
- $$ = $3;
- }
- ;
-
-var_declarators:
- var_declarator
- | var_declarators ',' var_declarator
- {
- $$ = $1;
- unshift_ast(&($$), $3);
- }
- ;
-
-var_declarator:
- IDENTIFIER '=' expr
- {
- AST * decl, * init;
- decl = new_expr(ASTT_IDENTIFIER, NULL, NULL);
- decl->sym = $1;
- init = new_expr(ASTT_ASSIGN, decl, $3);
- $$ = new_statement(ASTT_FIELD_DECL, decl, init);
-#if DEBUG
- fprintf(stderr, " var_declarator <- IDENTIFER(%s)=init_expr\n", $1->name);
-#endif
- }
- | IDENTIFIER
- {
- AST * decl = new_expr(ASTT_IDENTIFIER, NULL, NULL);
- decl->sym = $1;
- $$ = new_statement(ASTT_FIELD_DECL, decl, NULL);
-#if DEBUG
- fprintf(stderr, " var_declarator <- IDENTIFIER(%s)\n", $1->name);
-#endif
- }
- ;
-
-method_decl:
- method_header method_body
- {
- $$ = $1;
- $$->Attr.Method.body = $2;
- }
- ;
-
-method_header:
- opt_modifiers type IDENTIFIER '(' formal_param_list ')'
- {
- Symbol * param;
- $$ = new_statement(ASTT_METHOD_DECL, NULL, NULL);
- $3->kind = METHOD;
- $3->typename = $2;
- $3->flags = $1;
- $$->sym = $3;
- $$->Attr.Method.params = $5;
- /* Methods/Fields stored at scope 0 of class namespace.
- * We can store these at parse time.
- */
- store_symbol(current_symbol_table, $$->sym);
- if ($1 & MOD_STATIC) {
- if (!strcmp($3->name, "Main")) {
- if (main_method)
- fprintf(stderr,
- "Warning: multiple definitions of a static Main()\n");
- main_method = $3;
- }
- }
- }
- | opt_modifiers VOID IDENTIFIER '(' formal_param_list ')'
- {
- Symbol * param;
- $$ = new_statement(ASTT_METHOD_DECL, NULL, NULL);
- $3->kind = METHOD;
- $3->typename = new_type_symbol("void");
- $3->flags = $1;
- $$->sym = $3;
- $$->Attr.Method.params = $5;
- /* Methods/Fields stored at scope 0 of class namespace.
- * We can store these at parse time.
- */
- store_symbol(current_symbol_table, $$->sym);
- if ($1 & MOD_STATIC) {
- if (!strcmp($3->name, "Main")) {
- if (main_method)
- fprintf(stderr,
- "Warning: multiple definitions of a static Main()\n");
- main_method = $3;
- }
- }
- }
-
- ;
-
-
-formal_param_list: /*NULL*/
- { $$ = NULL; }
- | fixed_params
- { $$ = $1; }
-/*
- | fixed_params ',' param_array
- | param_array
-*/
- ;
-
-fixed_params:
- fixed_param
- | fixed_params ',' fixed_param
- {
- $$ = $1;
- tunshift_sym(&($$), $3);
- }
- ;
-
-fixed_param:
- type IDENTIFIER
- {
-#if DEBUG
- fprintf(stderr, " fixed_param <- type IDENTIFIER(%s)\n", $2->name);
-#endif
- $2->typename = $1;
- $$ = $2;
- }
- ;
-
-/*
-param_modifier:
- REF
- | OUT
- ;
-
-param_array:
- attributes PARAMS array_type IDENTIFIER
- ;
-*/
-
-method_body:
- block
- { $$ = $1; }
- ;
-
-block:
- '{' block_scope statement_list '}'
- {
- $$ = $3;
- if ($$) {
- $$->vars = pop_scope();
- }
- else {
- discard_scope();
- }
- }
- ;
-
-block_scope:
- { push_scope(); }
- ;
-
-embedded_statement:
- block
- {$$ = $1;}
- | expr_statement
- { fprintf(stderr, "##End of expr_statement\n\n"); $$ = $1; }
- | selection_statement
- { fprintf(stderr, "##End of selection_statement\n\n"); $$ = $1; }
- | iteration_statement
- { fprintf(stderr, "##End of iteration_statement\n\n"); $$ = $1; }
- | jump_statement
- { fprintf(stderr, "##End of jump_statement\n\n"); $$ = $1; }
- | return_statement
- { fprintf(stderr, "##End of return_statement\n\n"); $$ = $1; }
- | asm_block
- { $$ = $1; }
- ;
-
-statement:
- embedded_statement
- | decl_statement
- { fprintf(stderr, "##End of decl_statement\n\n"); $$ = $1; }
- | labeled_statement
- { fprintf(stderr, "##End of labeled_statement\n\n"); $$ = $1; }
- ;
-
-statement_list:
- /* NULL */
- { $$ = NULL; }
- | statement
- { $$ = $1; }
- | statement_list statement
- {
- $$ = $1;
- unshift_ast(&($$), $2);
- }
- ;
-
-labeled_statement:
- IDENTIFIER ':' statement
- { $$ = $3; $$->sym = $1; }
- ;
-
-expr_statement:
- statement_expr ';'
- { $$ = $1; }
- ;
-
-jump_statement:
- BREAK ';'
- { $$ = new_statement(ASTT_BREAK, NULL, NULL); }
- | CONTINUE ';'
- { $$ = new_statement(ASTT_CONTINUE, NULL, NULL); }
- | GOTO IDENTIFIER ';'
- {
- $$ = NULL;
- printf("GOTO not supported yet.\n");
- exit(0);
- }
- ;
-
-return_statement:
- RETURN expr ';'
- { $$ = new_statement(ASTT_RETURN, $2, NULL); }
- | RETURN ';'
- { $$ = new_statement(ASTT_RETURN, NULL, NULL); }
- ;
-
-asm_block:
- ASM '(' LITERAL ')' ';'
- { $$ = NULL; }
- ;
-
-arg_list:
- arg
- | arg_list ',' arg
- {
- $$ = $1;
- unshift_ast(&($$), $3);
- }
- ;
-
-arg:
- { $$ = NULL; }
- | expr
- { $$ = $1; }
- | REF
- { $$ = NULL; }
- | OUT
- { $$ = NULL; }
- ;
-
-selection_statement:
- if_statement
- ;
-
-if_statement:
- IF '(' boolean_expr ')' embedded_statement
- ELSE embedded_statement
- {
- $$ = new_if($3, $5, $7);
- }
- | IF '(' boolean_expr ')' embedded_statement
- {
- $$ = new_if($3, $5, NULL);
- }
- ;
-
-iteration_statement:
- while_statement
- | for_statement
- ;
-
-while_statement:
- WHILE '(' boolean_expr ')' embedded_statement
- {
- $$ = new_while($3, $5);
- }
- ;
-
-for_statement:
- FOR '(' statement_expr ';' boolean_expr ';' statement_expr ')'
- embedded_statement
- {
- if ($3 == NULL) {
- printf("for_statement: NULL init statement\n");
- exit(0);
- }
- $$ = new_for($3, $5, $7, $9);
- }
- ;
-
-type:
- qualified_name
- {
- fprintf(stderr, "!TYPE[%s]\n", $1->name);
- $$ = $1;
- }
- | predefined_type
- | array_type
- ;
-
-predefined_type:
- BOOL
- { $$ = new_type_symbol("bool"); }
- | STRING
- { $$ = new_type_symbol("string"); }
- | FLOAT
- { $$ = new_type_symbol("num"); }
- | integral_type
- ;
-
-integral_type:
- INT
- { $$ = new_type_symbol("int"); }
- | BYTE
- { $$ = new_type_symbol("byte"); }
- ;
-
-array_type:
- type rank_specifiers
- {
- $$ = symbol_concat($1, $2);
-#if DEBUG
- fprintf(stderr, " array_type: %s\n", $1->name);
-#endif
- }
- ;
-
-rank_specifiers:
- RANKSPEC
- {
- /* $1 is the dimension of the current rank */
- $$ = $1;
-#if DEBUG
- fprintf(stderr, " rank_spec /%s/\n", $1->name);
-#endif
- }
- | rank_specifiers RANKSPEC
- {
- $$ = symbol_concat($1, $2);
- }
- ;
-
-/*
- * Expressions
- */
-statement_expr:
- method_call
- | assignment
- | post_inc_expr
- | post_dec_expr
- | pre_inc_expr
- | pre_dec_expr
- ;
-
-assignment:
- unary_expr '=' expr
- { $$ = new_expr(ASTT_ASSIGN, $1, $3); }
- /*
- | unary_expr compound_assign_op expr
- {
- $$ = new_expr(ASTT_ASSIGN, $1, new_op_expr($1, $2, $3));
- }
- */
- ;
-
-/*
- * Expressions
- */
-pre_inc_expr:
- INC unary_expr
- {
- $$ = new_expr(ASTT_PREINC, $2, NULL);
- $$->op = INC;
- }
- ;
-
-pre_dec_expr:
- DEC unary_expr
- {
- $$ = new_expr(ASTT_PREINC, $2, NULL);
- $$->op = DEC;
- }
- ;
-
-post_inc_expr:
- primary_expr INC
- {
- $$ = new_expr(ASTT_POSTINC, $1, NULL);
- $$->op = INC;
- }
- ;
-
-post_dec_expr:
- primary_expr DEC
- {
- $$ = new_expr(ASTT_POSTINC, $1, NULL);
- $$->op = DEC;
- }
- ;
-
-expr:
- conditional_expr
- {
- $$ = $1;
-#if DEBUG
- fprintf(stderr, " expr <- conditional_expr\n");
-#endif
- }
- | assignment
- ;
-
-expr_list:
- expr
- | expr_list ',' expr
- ;
-
-boolean_expr:
- expr
- ;
-
-primary_expr:
- LITERAL
- {
- $$ = new_expr(ASTT_LITERAL, NULL, NULL); $$->sym = $1;
-#if DEBUG
- fprintf(stderr, " primary_expr <- LITERAL(%s)\n", $1->name);
-#endif
- }
- | IDENTIFIER
- {
- Symbol * orig;
- $$ = new_expr(ASTT_IDENTIFIER, NULL, NULL);
- $$->sym = $1;
-#if DEBUG
- fprintf(stderr, " primary_expr <- IDENTIFIER(%s)\n", $1->name);
-#endif
- }
- | '(' expr ')'
- {
- $$ = $2;
- }
- | element_access
- | method_call
- | post_inc_expr
- | post_dec_expr
- | new_expr
- | member_access
- { $$ = new_expr(ASTT_IDENTIFIER, NULL, NULL); $$->sym = $1; }
- ;
-
-unary_expr:
- primary_expr
- { $$ = $1; }
- | '+' unary_expr
- { $$ = $2; $$->op = '+'; }
- | '-' unary_expr
- { $$ = $2; $$->op = '-'; }
- | '!' unary_expr
- { $$ = $2; $$->op = '!'; }
- | '~' unary_expr
- { $$ = $2; $$->op = '~'; }
- | pre_inc_expr
- | pre_dec_expr
- ;
-
-method_call:
- primary_expr '(' arg_list ')'
- {
- if ($1->asttype != ASTT_IDENTIFIER) {
- fprintf(stderr, "Error (line %d), method call must be a simple name or member access.\n", line);
- exit(0);
- }
- $$ = new_expr(ASTT_METHOD_CALL, $1, $3);
-#if DEBUG
- fprintf(stderr, " method_call <- primary_expr ( arg_list )\n");
-#endif
- }
- ;
-
-member_access:
- qualified_name
- { $$ = $1;
-#if DEBUG
- fprintf(stderr, " member_access <- qualified_name\n");
-#endif
- }
- ;
-
-element_access:
- primary_expr '[' expr ']'
- {
- $$ = new_expr(ASTT_INDEX, $1, $3);
- $$->op = INDEX;
-#if DEBUG
- fprintf(stderr, " element_access <- primary-expr(pex[ex])\n");
-#endif
- }
- ;
-
-new_expr:
- new_object_expr
-/*
- | new_array_expr
- | new_delegate_expr
-*/
- ;
-
-new_object_expr:
- NEW type '(' arg_list ')'
- {
- $$ = new_expr(ASTT_NEW_OBJECT, $4, NULL);
- /* $2 is a Symbol of a typename, will resolve to a real type
- * in semantic pass.
- */
- $$->typename = $2;
- }
- ;
-
-mult_expr:
- unary_expr
- | mult_expr '*' unary_expr
- {
- $$ = new_op_expr($1, '*', $3);
- }
- | mult_expr '/' unary_expr
- {
- $$ = new_op_expr($1, '/', $3);
- }
- | mult_expr '%' unary_expr
- {
- $$ = new_op_expr($1, '%', $3);
- }
- ;
-
-add_expr:
- mult_expr
- | add_expr '+' mult_expr
- {
- $$ = new_op_expr($1, '+', $3);
- }
- | add_expr '-' mult_expr
- {
- $$ = new_op_expr($1, '-', $3);
- }
- ;
-
-conditional_expr:
- conditional_or_expr
- | conditional_or_expr '?' expr ':' expr
- {
- /* Ternary is just a if/then/else statement which can return a value */
- $$ = new_conditional($1, $3, $5);
- }
- ;
-
-conditional_and_expr:
- inclusive_or_expr
- | conditional_and_expr LOGICAL_AND inclusive_or_expr
- {
- $$ = new_logical_expr($1, LOGICAL_AND, $3);
- }
- ;
-
-conditional_or_expr:
- conditional_and_expr
- | conditional_or_expr LOGICAL_OR conditional_and_expr
- {
- $$ = new_logical_expr($1, LOGICAL_OR, $3);
- }
- ;
-
-and_expr:
- equality_expr
- | and_expr '&' equality_expr
- {
- $$ = new_op_expr($1, '&', $3);
- }
- ;
-
-exclusive_or_expr:
- and_expr
- | exclusive_or_expr '^' and_expr
- {
- $$ = new_op_expr($1, '~', $3);
- }
- ;
-
-inclusive_or_expr:
- exclusive_or_expr
- | inclusive_or_expr '|' exclusive_or_expr
- {
- $$ = new_op_expr($1, '|', $3);
- }
- ;
-
-relational_op:
- '<'
- {$$ = '<';}
- | '>'
- {$$ = '>';}
- | LOGICAL_LTE
- {$$ = LOGICAL_LTE;}
- | LOGICAL_GTE
- {$$ = LOGICAL_GTE;}
- ;
-
-relational_expr:
- shift_expr
- | relational_expr relational_op shift_expr
- {
- $$ = new_expr(ASTT_COMPARISON, $1, $3);
- $$->op = $2;
- }
- ;
-
-equality_expr:
- relational_expr
- | equality_expr LOGICAL_EQ relational_expr
- {
- $$ = new_expr(ASTT_COMPARISON, $1, $3);
- $$->op = LOGICAL_EQ;
- }
- | equality_expr LOGICAL_NE relational_expr
- {
- $$ = new_expr(ASTT_COMPARISON, $1, $3);
- $$->op = LOGICAL_NE;
- }
- ;
-
-shift_expr:
- add_expr
- | shift_expr LEFT_SHIFT add_expr
- {
- $$ = new_op_expr($1, LEFT_SHIFT, $3);
- }
- | shift_expr RIGHT_SHIFT add_expr
- {
- $$ = new_op_expr($1, RIGHT_SHIFT, $3);
- }
- ;
-
-
-%%
-
-
-
-extern FILE *yyin;
-
-
-int main(int argc, char * argv[])
-{
- fprintf(stderr, "Cola - Copyright (C) 2002 Melvin Smith <melvins@us.ibm.com>\n");
- fprintf(stderr, "colac version %s\n\n", COLA_VERSION);
- if (argc > 1) {
- if (!(yyin = fopen(argv[1], "r"))) {
- printf("Error reading source file %s.\n", argv[1]);
- exit(0);
- }
- }
- else {
- printf("No source file specified.\n");
- exit(0);
- }
-
- line = 1;
- init_symbol_tables();
- init_builtin_types();
- /* Kludge - fake routines by adding them to symbol table
- * and emitting them.
- */
- {
- store_method(current_symbol_table, "puts", t_void);
- store_method(current_symbol_table, "puti", t_void);
- store_method(current_symbol_table, "putf", t_void);
- store_method(current_symbol_table, "gets", t_string);
- store_method(current_symbol_table, "substr", t_string);
- store_method(current_symbol_table, "strlen", t_int32);
- store_method(current_symbol_table, "strchop", t_string);
- store_method(current_symbol_table, "strrep", t_string);
- store_method(current_symbol_table, "ord", t_int32);
- store_method(current_symbol_table, "sleep", t_void);
- }
-
- fprintf(stderr, "Pass 1: Starting parse...\n");
- yyparse();
- fclose(yyin);
-
- fprintf(stderr, "Pass 2: Type checking...\n");
- fprintf(stderr, "Pass 2: Start scope is [%d]\n", scope);
- build_ast(ast_start);
-
- fprintf(stderr, "Pass 3: Semantic checking...\n");
- /*semant_ast(ast_start); */
-
- freopen("a.pir", "w", stdout);
- fprintf(stderr, "Compiling intermediate code to a.pir\n");
-/*
- printf("#Dump of global namespace:\n");
- indent = 0;
- dump_namespace(current_namespace);
-*/
- printf("# Cola (%s) generated\n#\n", COLA_VERSION);
-
- fprintf(stderr, "Pass 4: Code generation...\n");
-
- if (ast_start) {
- gen_ast(ast_start);
- }
-
- printf("# Include standard API stuff\n");
- printf(".include \"core.pir\"\n\n");
- fflush(stdout);
- fprintf(stderr, "%ld lines compiled to PIR.\n", line);
- fprintf(stderr, "Generating PASM\n");
- system("../../parrot -o a.pasm a.pir");
- fprintf(stderr, "Generating PBC (Bytecode)\n");
- system("../../parrot -o a.pbc a.pir");
- return 0;
-}
-
-int yyerror(char * s)
-{
-/*
- fprintf(stderr, "last token = [%s]\n", yylval.sym->name);
-*/
- fprintf(stderr, "(error) line %ld: %s\n", line, s);
- fprintf(stderr, "Didn't create output asm.\n");
- exit(0);
-}
-
-
-/*
- * Local variables:
- * c-file-style: "parrot"
- * End:
- * vim: expandtab shiftwidth=4:
- */
View
34 languages/cola/colac
@@ -1,34 +0,0 @@
-#! perl -w
-
-# Cola preprocessor
-# Kludge to preload classes until the parser
-# can do it.
-
-print "colac preprocessor\n\n";
-
-my $file = $ARGV[0];
-
-open(IN, "<$file") or die("No source file: $file\n");
-
-my @file = <IN>;
-my $using;
-my $class;
-
-open(OUT, ">$file.colacctmp");
-
-foreach my $line (@file) {
- if(($using, $class) = $line =~ m/^(using\s+(\w+);)/) {
- open(USE, "<$class.cola") or die("Error: can't include $class.cola\n");
- {
- local $/;
- my $class = <USE>;
- print OUT $class;
- }
- $line =~ s/$using//;
- }
- print OUT $line;
-}
-
-close(OUT);
-
-system("./colacc $file.colacctmp");
View
136 languages/cola/config/makefiles/root.in
@@ -1,136 +0,0 @@
-# Copyright (C) 2004-2009, Parrot Foundation.
-# $Id$
-
-# Makefile for languages/cola
-
-# Set up commands
-PERL = @perl@
-RM_F = @rm_f@
-CHMOD = @chmod@
-CC = @cc@
-DEBUG = @cc_debug@
-YACC = @yacc@
-LEX = @lex@
-RECONFIGURE = $(PERL) @build_dir@/tools/dev/reconfigure.pl
-#CONDITIONED_LINE(darwin):
-#CONDITIONED_LINE(darwin):# MACOSX_DEPLOYMENT_TARGET must be defined for OS X compilation/linking
-#CONDITIONED_LINE(darwin):export MACOSX_DEPLOYMENT_TARGET := @osx_version@
-
-# Set up extensions
-O = @o@
-EXE = @exe@
-
-# Set up directories
-BUILD_DIR = @build_dir@
-
-# Libraries: Ordinarily, no special libraries are needed
-# for cola, but one of the following settings might be helpful
-# in some cases.
-# Use the same libraries as Parrot:
-# LIBS = @libs@
-# You might need these for some versions of flex and/or yacc:
-# LIBS = -ll -ly
-# Ordinarily, no special libraries are needed for cola.
-LIBS =
-
-# These manual settings might be helpful in some situations.
-# Visual C++
-# CC = cl
-#
-# GCC
-# CC = gcc -Wall -pedantic
-#
-# GCC with Electric Fence
-# CC = gcc -efence -Wall -pedantic
-# LIBS = -lefence
-
-HEADERS = cola.h parser.h
-
-default :
- $(MAKE) colacc$(EXE)
- -$(CHMOD) 775 colacc$(EXE)
-
-help :
- @echo ""
- @echo "Following targets are available for the user:"
- @echo ""
- @echo " default : build 'colacc'"
- @echo " This is the default."
- @echo ""
- @echo " test: run the test suite"
- @echo ""
- @echo " clean: clean up temporary files"
- @echo ""
- @echo " realclean: clean up generated files"
- @echo ""
- @echo " superclean: clean up generated files, also the flex/bison files"
- @echo ""
- @echo " help: print this help message"
-
-# regenerate the Makefile
-Makefile: config/makefiles/root.in
- cd $(BUILD_DIR) && $(RECONFIGURE) --step=gen::languages --languages=cola
-
-nogen : gen$(O) semant$(O) sym$(O) type$(O)
- $(CC) $(DEBUG) -c parser.c
- $(CC) $(DEBUG) -c lexer.c
- $(CC) $(DEBUG) -o colacc$(EXE) parser$(O) lexer$(O) gen$(O) semant$(O) sym$(O) type$(O) $(LIBS)
-
-clean :
- $(RM_F) \
- core \
- "*.obj" "*.pdb" "*.ilk" \
- "*$(O)" \
- parser.output \
- colacc$(EXE) \
- a.pir a.pbc a.pasm
-
-realclean: clean
- $(RM_F) Makefile
-
-# Don't run this target unless you have bison and flex installed.
-# These programs are needed for regenerating the removed files.
-superclean: realclean
- $(RM_F) parser.h
- $(RM_F) lexer.c parser.c
-
-publish :
- $(PERL) publish.pl < MANIFEST
-
-dist :
- $(PERL) distribution.pl < MANIFEST
-
-parser.c : cola.y
- $(YACC) -d -o parser.c cola.y
-
-lexer.c : cola.l $(HEADERS)
- $(LEX) cola.l
-
-lexer$(O) : lexer.c $(HEADERS)
- $(CC) $(DEBUG) -c lexer.c
-
-parser$(O) : parser.c $(HEADERS)
- $(CC) $(DEBUG) -c parser.c
-
-semant$(O) : semant.c $(HEADERS)
- $(CC) $(DEBUG) -c semant.c
-
-sym$(O) : sym.c $(HEADERS)
- $(CC) $(DEBUG) -c sym.c
-
-type$(O) : type.c $(HEADERS)
- $(CC) $(DEBUG) -c type.c
-
-gen$(O) : gen.c $(HEADERS)
- $(CC) $(DEBUG) -c gen.c
-
-colacc$(EXE) : parser$(O) lexer$(O) gen$(O) semant$(O) sym$(O) type$(O)
- $(CC) $(DEBUG) -o colacc$(EXE) parser$(O) lexer$(O) gen$(O) semant$(O) sym$(O) type$(O) $(LIBS)
-
-test: default
- cd .. && $(PERL) t/harness --languages=cola
-
-# Local variables:
-# mode: makefile
-# End:
-# vim: ft=make:
View
73 languages/cola/core.pir
@@ -1,73 +0,0 @@
-# Some basic routines for Cola programs
-# Autoincluded in generated PIR code
-
-.sub __puts
- .param string s
- print s
-.end
-
-.sub __puti
- .param int i
- print i
-.end
-
-.sub __putf
- .param num n
- print n
-.end
-
-.sub __substr
- .param int i2
- .param int i1
- .param string s
- .local string sret
- substr sret, s, i1, i2
- .return(sret)
-.end
-
-.sub __strlen
- .param string s
- .local int len
- length len, s
- .return(len)
-.end
-
-.sub __strchop
- .param string s
- chopn s, 1
- .return(s)
-.end
-
-.sub __strrep
- .param string s0
- .param int i1
- .param int i0
- .param string s1
- substr s1, i0, i1, s0
- .return (s1)
-.end
-
-.sub __ord
- .param string s
- .local int i
- ord i, s
- .return (i)
-.end
-
-.sub __gets
- .local string s
- read s, 512
- .return(s)
-.end
-
-.sub __sleep
- .param int sec
- sleep sec
-.end
-
-
-# Local Variables:
-# mode: pir
-# fill-column: 100
-# End:
-# vim: expandtab shiftwidth=4 ft=pir:
View
113 languages/cola/examples/calc.cola
@@ -1,113 +0,0 @@
-// calc.cola
-//
-// Toy calculator (simple 2 argument expressions: 1 + 2, 1 * 2, 2 / 1, 2 - 1)
-// Demonstrates subroutines, strings, string indexed access with [], etc.
-// REVISION: Support assignment to array indirections.
-//
-// Copyright (C) 2002 Melvin Smith
-
-using System;
-
-public class Calc {
-
- // Get a numbered item out of a string
- public string GetArgN(string s, int n) {
- int i = 0, start = 0, len = 0, count=1;
-
- // Skip leading space
- while(s[i] == " ")
- i++;
-
- if(s[i] == "")
- return "";
-
- start = i;
- while(s[i] != "") {
- if(s[i] == " ") {
- if(count == n)
- return substr(s, start, len);
- else {
- i++;
- // Skip more space
- while(s[i] == " ")
- i++;
- start = i;
- len = 0;
- count++;
- }
- }
- else {
- len++;
- i++;
- }
- }
-
- if(count < n)
- return "";
- return substr(s, start, len);
- }
-
- // Implement string to int conversion in Parrot
- // just for fun.
- public int StrToInt(string str) {
- int i, len, val = 0;
- int base = ord("0");
- len = strlen(str);
- if(str[0] == "")
- return 0;
- i = 0;
- while(str[i] != "") {
- val = val * 10 + ord(str[i++]) - base;
- }
- return val;
- }
-
- // Main program
- static void Main() {
- string s, arg1, arg2, op;
- int i1, i2;
- while(1) {
- puts("Parrot Calculator (type 'quit' to exit)>\n");
- s = gets();
- if(s == "")
- break;
- if(s == "\n")
- continue;
- s = strchop(s);
-
- puts("You typed: " + s + "\n");
- if(s == "quit")
- break;
-
- arg1 = GetArgN(s, 1);
- op = GetArgN(s, 2);
- arg2 = GetArgN(s, 3);
-
- if(arg1 == "" || op == "" || arg2 == "") {
- puts("Not enough arguments.\n");
- continue;
- }
- i1 = StrToInt(arg1);
- i2 = StrToInt(arg2);
- if(op == "+") {
- puts("Adding...\n= ");
- puti(i1 + i2);
- } else if(op == "-") {
- puts("Subtracting...\n= ");
- puti(i1 - i2);
- } else if(op == "*") {
- puts("Multiplying...\n= ");
- puti(i1 * i2);
- } else if(op == "/") {
- puts("Dividing...\n= ");
- if(i2 == 0) {
- puts("Divide by zero illegal.\n");
- continue;
- }
- puti(i1 / i2);
- }
-
- puts("\n");
- }
- }
-}
View
37 languages/cola/examples/expressions.cola
@@ -1,37 +0,0 @@
-// expressions.cola
-//
-// Samples of legal Cola expressions and syntaxes
-//
-// Copyright (C) 2002 Melvin Smith
-
-using System;
-
-class Expressions {
- public int foo() {
- puts("foo\n");
- return 1;
- }
-
- public int bar() {
- puts("bar\n");
- return 2;
- }
-
- public static void Main() {
- // Declaration with initialization
- int i = 10, j = 7;
-
- // Declaration with conditional expression initialization
- int min = i < j ? i : j;
- puti(min);
-
- // Conditional expression as argument
- puti( i > j ? i : j );
-
- // Methods as conditional expression arguments
- min = foo() < bar() ? foo() : bar();
- puti(min);
- }
-}
-
-
View
28 languages/cola/examples/fib.cola
@@ -1,28 +0,0 @@
-//
-// fib.cola
-//
-
-public class Fib {
- static void Main() {
- int n = 24, a = 1, b = 1, f = 1, i = 3;
-
- puts("Algorithm F2 (Fibonacci's function)\n");
- puts(" Calculating fib(");
- puti(n);
- puts(") = ...\n");
-
- while(i <= n) {
- puti(i);
- puts("\n");
- f = a + b;
- a = b;
- b = f;
- i++;
- }
-
- puts(" ... = ");
- puti(f);
- puts("\n");
- }
-}
-
View
62 languages/cola/examples/life.cola
@@ -1,62 +0,0 @@
-// life.cola
-//
-// Game of life
-//
-// Copyright (C) 2002 Melvin Smith
-//
-public class Life {
- public string Generate(string input) {
- int cell, neighbours, i;
- int len = strlen(input);
- int pos, offset;
- string birth = " * ";
- string death = " ** ";
- string output = input;
- for(cell=0; cell < len; cell++) {
- neighbours = 0;
- i = cell + len;
- if(input[(i - 1) % len] == "*") neighbours++;
- if(input[(i + 1) % len] == "*") neighbours++;
- if(input[(i - 17) % len] == "*") neighbours++;
- if(input[(i + 17) % len] == "*") neighbours++;
- if(input[(i - 16) % len] == "*") neighbours++;
- if(input[(i + 16) % len] == "*") neighbours++;
- if(input[(i - 15) % len] == "*") neighbours++;
- if(input[(i + 15) % len] == "*") neighbours++;
- if (input[cell] == "*")
- output[cell] = death[neighbours];
- else if(neighbours == 3) {
- output[cell] = "*";
- }
- }
- return output;
- }
-
- static void Main() {
- string world = " ** * * * " +
- " ** * * " +
- " * " +
- " * ** " +
- " * * " +
- " **** " +
- " **** " +
- " * " +
- " * ** " +
- " * * " +
- " * * " +
- " * " +
- " " +
- " * " +
- " * " +
- " * *"
- ;
- int i, j;
- for(i = 0; i < 500; i++) {
- // Print World
- for(j = 0; j < 16; j++)
- puts(substr(world, j * 16, 16) + "\n");
- puts("----------------\n");
- world = Generate(world);
- }
- }
-}
View
45 languages/cola/examples/mandelbrot.cola
@@ -1,45 +0,0 @@
-// mandelbrot.cola
-//
-using System;
-
-// The Reference C version snagged from Jako sample
-// main(){
-// int x, y, k;
-// char *b = " .:,;!/>)|&IH%*#";
-// float r, i, z, Z, t, c, C;
-//
-// for (y=30; puts(""), C = y*0.1 - 1.5, y--;){
-// for (x=0; c = x*0.04 - 2, z=0, Z=0, x++ < 75;){
-// for (r=c, i=C, k=0; t = z*z - Z*Z + r, Z = 2*z*Z + i, z=t, k<112; k++)
-// if (z*z + Z*Z > 10) break;
-// printf ("%c", b[k%16]);
-// }
-// }
-// }
-
-public class Mandelbrot {
- public static void Main() {
- string b = " .:,;!/>)|&IH%*#";
- int x, y, k;
- float r, i, z, Z, t, c, C;
-
- for(y=30; y>0; y--) {
-