[SCM] Lisaac compiler branch, master, updated. lisaac-0.12-462-g9808145
sonntag (none)
sonntag at isaac.
Sun Sep 6 22:47:21 UTC 2009
The following commit has been merged in the master branch:
commit 980814502096153085cf57c6ca68202c99b6b95e
Author: sonntag <sonntag at isaac.(none)>
Date: Mon Sep 7 00:47:26 2009 +0200
lip stable
diff --git a/make.lip b/make.lip
index 6908b94..714f4c4 100644
--- a/make.lip
+++ b/make.lip
@@ -64,8 +64,8 @@ Section Private
- standard_path <-
// Standard library.
(
- LIP.create "lib/make.lip".init;
- // path (lisaac + "lib/*");
+ //LIP.create "lib/make.lip".init;
+ path (lisaac + "lib/*");
);
//
diff --git a/src/avoir2.txt b/src/avoir2.txt
index bd54469..8a7fcf9 100644
--- a/src/avoir2.txt
+++ b/src/avoir2.txt
@@ -1,7 +1,42 @@
-lip_integer.li: - storage:FAST_ARRAY[LIP_INTEGER] := FAST_ARRAY[LIP_INTEGER].create_with_capacity 10;
-lip_slot_code.li: + code:FAST_ARRAY[LIP_CODE];
-lip_slot_code.li: code c:FAST_ARRAY[LIP_CODE] :LIP_SLOT_CODE <-
-lip_slot_code.li: ALIAS_ARRAY[LIP_CODE].free c;
-lip_slot_code.li: code c:FAST_ARRAY[LIP_CODE] <-
-lip_slot_data.li: [
-lip_string.li: - storage:FAST_ARRAY[LIP_STRING] := FAST_ARRAY[LIP_STRING].create_with_capacity 10;
+ // You can to get current grammar with `grep "//++" parser.li'
+ //++ PROGRAM -> { "Section" (section|TYPE_LIST) { SLOT } } [CONTRACT ';']
+ //++ SLOT -> style TYPE_SLOT [':' (TYPE|'('TYPE_LIST')') ][ affect DEF_SLOT ]';'
+ //++ TYPE_SLOT -> [ LOC_ARG '.' ] identifier [ LOC_ARG { identifier LOC_ARG } ]
+ //++ | [ LOC_ARG ] '\'' operator '\'' [("Left"|"Right") [integer]] [LOC_ARG]
+ //++ DEF_SLOT -> [CONTRACT] EXPR [CONTRACT]
+ //++ LOC_ARG -> identifier ':' TYPE
+ //++ | '(' LOCAL ')'
+ //++ LOCAL -> { identifier [ ':' TYPE ] ',' } identifier ':' TYPE
+ //++ TYPE_LIST -> TYPE { ',' TYPE }
+ //++ TYPE -> '{' [ (TYPE | '(' TYPE_LIST ')') ';' ] [ TYPE_LIST ] '}'
+ //++ | [type] PROTOTYPE [ CONTRACT ]
+ //++ PROTOTYPE -> cap_identifier{('.'|'...')cap_identifier}['('PARAM_TYPE{','PARAM_TYPE}')']
+ //++ PARAM_TYPE -> TYPE
+ //++ | CONSTANT
+ //++ | identifier
+ //++ EXPR -> { ASSIGN !!AMBIGU!! affect } EXPR_OPERATOR
+ //++ ASSIGN -> '(' IDF_ASSIGN { ',' IDF_ASSIGN } ')'
+ //++ | IDF_ASSIGN
+ //++ IDF_ASSIGN -> identifier { identifier }
+ //++ EXPR_OPERATOR-> { operator } EXPR_MESSAGE { operator {operator} EXPR_MESSAGE } {operator}
+ //++ EXPR_MESSAGE -> EXPR_BASE { '.' SEND_MSG }
+ //++ EXPR_BASE -> "Old" EXPR
+ //++ | EXPR_PRIMARY
+ //++ | SEND_MSG
+ //++ EXPR_PRIMARY -> "Self"
+ //++ | result
+ //++ | PROTOTYPE
+ //++ | CONSTANT
+ //++ | '(' GROUP ')'
+ //++ | '{' [ LOC_ARG ';' !! AMBIGU!! ] GROUP '}'
+ //++ | external [ ':' ['('] TYPE ['{' TYPE_LIST '}'] [')'] ]
+ //++ CONSTANT -> integer
+ //++ | real
+ //++ | characters
+ //++ | string
+ //++ GROUP -> DEF_LOCAL {EXPR ';'} [ EXPR {',' {EXPR ';'} EXPR } ]
+ //++ CONTRACT -> '[' DEF_LOCAL { ( EXPR ';' | "..." ) } ']'
+ //++ DEF_LOCAL -> { style LOCAL ';' } !! AMBIGU !!
+ //++ SEND_MSG -> identifier [ ARGUMENT { identifier ARGUMENT } ]
+ //++ ARGUMENT -> EXPR_PRIMARY
+ //++ | identifier
diff --git a/src/lip/lip_call.li b/src/lip/lip_call.li
index 12c52a3..b1a9240 100644
--- a/src/lip/lip_call.li
+++ b/src/lip/lip_call.li
@@ -33,6 +33,8 @@ Section Inherit
Section Public
+ + receiver:LIP_CODE;
+
+ name:STRING_CONSTANT;
+ argument:LIP_CODE;
@@ -41,19 +43,20 @@ Section Public
// Creation.
//
- - create p:POSITION name n:STRING_CONSTANT with arg:LIP_CODE :SELF <-
+ - create p:POSITION receiver rec:LIP_CODE name n:STRING_CONSTANT with arg:LIP_CODE :SELF <-
( + result:SELF;
result := clone;
- result.make p name n with arg;
+ result.make p receiver rec name n with arg;
result
);
- - make p:POSITION name n:STRING_CONSTANT with arg:LIP_CODE <-
+ - make p:POSITION receiver rec:LIP_CODE name n:STRING_CONSTANT with arg:LIP_CODE <-
[
-? {p.code != 0};
]
(
position := p;
+ receiver := rec;
name := n;
argument := arg;
);
@@ -64,15 +67,26 @@ Section Public
- run <-
( + slot:LIP_SLOT_CODE;
- + val:LIP_CONSTANT;
+ + val,rec:LIP_CONSTANT;
+ str:LIP_STRING;
+ path:STRING_CONSTANT;
+ is_rec:BOOLEAN;
+ (receiver != NULL).if {
+ rec := receiver.run_expr;
+ };
(argument != NULL).if {
val := argument.run_expr;
};
- (name = ALIAS_STR.slot_exit).if {
+ (name = ALIAS_STR.slot_print).if {
+ (rec = NULL).if {
+ semantic_error (position,"Incorrect type.");
+ };
+ (val != NULL).if {
+ warning_error (position,"No argument for `print' method.");
+ };
+ rec.print;
+ }.elseif {name = ALIAS_STR.slot_exit} then {
(val != NULL).if {
warning_error (position,"No argument for `exit' method.");
};
@@ -110,6 +124,9 @@ Section Public
semantic_error (position,"Invalid argument.");
};
};
+ (rec != NULL).if {
+ rec.free;
+ };
(val != NULL).if {
val.free;
};
diff --git a/src/lip/lip_if.li b/src/lip/lip_if.li
index 533ba48..3e42fcc 100644
--- a/src/lip/lip_if.li
+++ b/src/lip/lip_if.li
@@ -58,6 +58,12 @@ Section Public
condition := rec;
then := the;
else := els;
+ (then.last != NULL).if {
+ warning_error (then.last.position,"Unreachable expression.");
+ };
+ ((else != NULL) && {else.last != NULL}).if {
+ warning_error (else.last.position,"Unreachable expression.");
+ };
);
//
@@ -72,11 +78,11 @@ Section Public
semantic_error (position,"BOOLEAN needed.");
};
(val.value).if {
- (then.lower).to (then.upper) do { i:INTEGER;
+ (then.lower).to (then.upper-1) do { i:INTEGER;
then.item i.run;
- };
+ };
}.elseif {else != NULL} then {
- (else.lower).to (else.upper) do { i:INTEGER;
+ (else.lower).to (else.upper-1) do { i:INTEGER;
else.item i.run;
};
};
diff --git a/src/lip/lip_print.li b/src/lip/lip_list.li
similarity index 74%
rename from src/lip/lip_print.li
rename to src/lip/lip_list.li
index 399e07c..8a4f5b6 100644
--- a/src/lip/lip_print.li
+++ b/src/lip/lip_list.li
@@ -20,7 +20,7 @@
///////////////////////////////////////////////////////////////////////////////
Section Header
- + name := LIP_PRINT;
+ + name := LIP_LIST;
- copyright := "2003-2008 Sonntag Benoit";
@@ -29,27 +29,27 @@ Section Header
Section Inherit
- + parent_lip_code:Expanded LIP_CODE;
+ + parent_lip_code:Expanded LIP_CODE;
Section Public
- + message:LIP_CODE;
+ + list:FAST_ARRAY(LIP_CODE);
//
// Creation.
//
- - create p:POSITION message rec:LIP_CODE :SELF <-
+ - create p:POSITION with v:FAST_ARRAY(LIP_CODE) :SELF <-
( + result:SELF;
result := clone;
- result.make p message rec;
+ result.make p with v;
result
);
- - make p:POSITION message rec:LIP_CODE <-
+ - make p:POSITION with v:FAST_ARRAY(LIP_CODE) <-
(
position := p;
- message := rec;
+ list := v;
);
//
@@ -57,12 +57,27 @@ Section Public
//
- run <-
- ( + val:LIP_CONSTANT;
-
- val := message.run_expr;
- (val = NULL).if {
- semantic_error (position,"Incorrect type.");
+ (
+ run_intern;
+ (list.last != NULL).if {
+ semantic_error (position,"Incorrect expression.");
+ };
+ );
+
+ - run_expr:LIP_CONSTANT <-
+ (
+ run_intern;
+ (list.last = NULL).if {
+ semantic_error (position,"Unreachable expression.");
+ };
+ list.last.run_expr
+ );
+
+Section Private
+
+ - run_intern <-
+ (
+ (list.lower).to (list.upper-1) do { i:INTEGER;
+ list.item i.run;
};
- val.print;
- val.free;
);
\ No newline at end of file
diff --git a/src/lip/lip_slot_code.li b/src/lip/lip_slot_code.li
index 709f447..196e61f 100644
--- a/src/lip/lip_slot_code.li
+++ b/src/lip/lip_slot_code.li
@@ -39,7 +39,7 @@ Section Public
+ argument:LIP_SLOT_DATA;
- + code:FAST_ARRAY(LIP_CODE);
+ + code:LIP_CODE;
+ comment:STRING_CONSTANT;
@@ -64,15 +64,14 @@ Section Public
- create p:POSITION section sec:STRING_CONSTANT
name n:STRING_CONSTANT
argument arg:LIP_SLOT_DATA
- code c:FAST_ARRAY(LIP_CODE) :LIP_SLOT_CODE <-
+ code c:LIP_CODE :LIP_SLOT_CODE <-
( + result:LIP_SLOT_CODE;
result := get_method n;
(result != NULL).if {
((arg = NULL) ^ (result.argument = NULL)).if {
semantic_error (result.position,"Incorrect redefinition.");
- };
- ALIAS_ARRAY(LIP_CODE).free c;
+ };
} else {
result := clone;
result.make p section sec name n argument arg code c;
@@ -83,7 +82,7 @@ Section Public
- make p:POSITION section sec:STRING_CONSTANT
name n:STRING_CONSTANT
argument arg:LIP_SLOT_DATA
- code c:FAST_ARRAY(LIP_CODE) <-
+ code c:LIP_CODE <-
(
position := p;
section := sec;
@@ -109,10 +108,8 @@ Section Public
} else {
stack.add_last NULL;
};
- (result).if {
- (code.lower).to (code.upper) do { j:INTEGER;
- code.item j.run;
- };
+ (result).if {
+ code.run;
};
stack.remove_last;
};
diff --git a/src/parser.li b/src/parser.li
index 0c2e062..ffc9b94 100644
--- a/src/parser.li
+++ b/src/parser.li
@@ -2704,17 +2704,16 @@ Section Private
- readlip_slot sec:STRING_CONSTANT :BOOLEAN <-
//// SLOT -> '+' identifier ':' TYPE [ ':=' EXPR_CONSTANT ]
- //// | '-' identifier [ identifier ':' TYPE ] '<-' '(' { EXPR ';' } ')'
+ //// | '-' identifier [ identifier ':' TYPE ] '<-' EXPR
( + result:BOOLEAN;
+ t:LIP_CONSTANT;
+ n,na:STRING_CONSTANT;
+ data:LIP_SLOT_DATA;
+ slot_code:LIP_SLOT_CODE;
- + cst:LIP_CONSTANT;
- + cod:FAST_ARRAY(LIP_CODE);
- + instr:LIP_CODE;
+ + exp:LIP_CODE;
+ pos:POSITION;
-
+ + cst:LIP_CONSTANT;
+
(read_character '+').if {
// Data.
result := TRUE;
@@ -2738,7 +2737,7 @@ Section Private
(cst = NULL).if {
syntax_error (current_position,"Incorrect expression.");
};
- data.set_value cst;
+ data.set_value cst;
cst.free;
};
}.elseif {read_character '-'} then {
@@ -2765,23 +2764,14 @@ Section Private
warning_error (current_position,"Added '<-' is needed.");
};
is_shorter2 := TRUE;
- (read_character '(').if_false {
- warning_error (current_position,"Added '(' is needed.");
- };
+ read_space;
is_shorter2 := FALSE;
- cod := ALIAS_ARRAY(LIP_CODE).new;
- {(instr := readlip_expr) != NULL}.while_do {
- cod.add_last instr;
- (read_character ';').if_false {
- warning_error (current_position,"Added ';' is needed.");
- };
- };
- (read_character ')').if_false {
- warning_error (current_position,"Added ')' is needed.");
- };
- cod := ALIAS_ARRAY(LIP_CODE).copy cod;
+ exp := readlip_expr;
+ (exp = NULL).if {
+ syntax_error (current_position,"Expression needed.");
+ };
slot_code := LIP_SLOT_CODE.create pos section sec
- name n argument data code cod;
+ name n argument data code exp;
(sec = ALIAS_STR.section_public).if {
(last_comment_slot = NULL).if {
warning_error (pos,"Comment needed.");
@@ -2794,7 +2784,7 @@ Section Private
);
- readlip_type:LIP_CONSTANT <-
- //// TYPE -> 'BOOLEAN' | 'STRING' | 'INTEGER'
+ //// TYPE -> 'BOOLEAN' | 'STRING' | 'INTEGER' | 'LIP'
( + result:LIP_CONSTANT;
(read_cap_identifier).if {
@@ -2804,6 +2794,8 @@ Section Private
result := LIP_STRING.get (ALIAS_STR.get "");
}.elseif {last_string = ALIAS_STR.prototype_boolean} then {
result := LIP_BOOLEAN.get FALSE;
+ }.elseif {last_string = ALIAS_STR.prototype_boolean} then {
+ not_yet_implemented;
} else {
syntax_error (current_position,"Incorrect type.");
};
@@ -2811,8 +2803,8 @@ Section Private
result
);
- - readlip_expr:LIP_CODE <-
- //// EXPR -> [ identifier !!AMBIGU!! ':=' ] EXPR_OPERATOR [ '.' FUNCTION ]
+ - readlip_expr_affect:LIP_CODE <-
+ //// EXPR_AFFECT -> [ identifier !!AMBIGU!! ':=' ] EXPR
( + result,val:LIP_CODE;
+ nam:STRING_CONSTANT;
@@ -2821,7 +2813,7 @@ Section Private
(read_identifier).if {
nam := last_string;
(read_symbol (ALIAS_STR.symbol_affect_immediate)).if {
- val := readlip_expr_operator;
+ val := readlip_expr;
(val = NULL).if {
syntax_error (current_position,"Incorrect expression.");
};
@@ -2831,64 +2823,13 @@ Section Private
};
};
(result = NULL).if {
- result := readlip_expr_operator;
- ((result != NULL) && {read_character '.'}).if {
- result := readlip_function result;
- (result = NULL).if {
- syntax_error (current_position,"Incorrect slot.");
- };
- };
+ result := readlip_expr;
};
result
);
- - readlip_function rec:LIP_CODE :LIP_CODE <-
- //// FUNCTION -> 'if' '{' { EXPR ';' } '}' [ 'else' '{' { EXPR ';' } '}' ]
- //// | 'print'
- ( + result:LIP_CODE;
- + the,els:FAST_ARRAY(LIP_CODE);
- + val:LIP_CODE;
-
- (read_word (ALIAS_STR.slot_if)).if {
- the := ALIAS_ARRAY(LIP_CODE).new;
- (read_character '{').if_false {
- warning_error (current_position,"Added '(' is needed.");
- };
- {(val := readlip_expr) != NULL}.while_do {
- the.add_last val;
- (read_character ';').if_false {
- warning_error (current_position,"Added ';' is needed.");
- };
- };
- (read_character '}').if_false {
- warning_error (current_position,"Added '(' is needed.");
- };
- the := ALIAS_ARRAY(LIP_CODE).copy the;
- (read_word (ALIAS_STR.slot_else)).if {
- els := ALIAS_ARRAY(LIP_CODE).new;
- (read_character '{').if_false {
- warning_error (current_position,"Added '(' is needed.");
- };
- {(val := readlip_expr) != NULL}.while_do {
- els.add_last val;
- (read_character ';').if_false {
- warning_error (current_position,"Added ';' is needed.");
- };
- };
- (read_character '}').if_false {
- warning_error (current_position,"Added '(' is needed.");
- };
- els := ALIAS_ARRAY(LIP_CODE).copy els;
- };
- result := LIP_IF.create current_position if rec then the else els;
- }.elseif {read_word (ALIAS_STR.slot_print)} then {
- result := LIP_PRINT.create current_position message rec;
- };
- result
- );
-
- - readlip_expr_operator:LIP_CODE <-
- //// EXPR_OPERATOR-> EXPR_CMP { ('|' | '&') EXPR_CMP }
+ - readlip_expr:LIP_CODE <-
+ //// EXPR -> EXPR_CMP { ('|' | '&') EXPR_CMP }
( + result,right:LIP_CODE;
+ is_or:BOOLEAN;
@@ -2967,13 +2908,10 @@ Section Private
- readlip_expr_unary:LIP_CODE <-
//// EXPR_UNARY -> ( '-' | '!' ) EXPR_UNARY
- //// | EXPR_BASE
- //// | identifier [ EXPR_ARGUMENT ]
+ //// | EXPR_BASE
( + result:LIP_CODE;
+ is_neg:BOOLEAN;
+ type:CHARACTER;
- + nam:STRING_CONSTANT;
- + arg:LIP_CODE;
((is_neg := read_character '-') || {read_character '!'}).if {
result := readlip_expr_unary;
@@ -2986,39 +2924,123 @@ Section Private
type := '!';
};
result := LIP_UNARY.create current_position operator type with result;
- }.elseif {read_identifier} then {
- nam := last_string;
- arg := readlip_expr_argument;
- result := LIP_CALL.create current_position name nam with arg;
} else {
result := readlip_expr_base;
};
result
);
+ - readlip_expr_list cod:FAST_ARRAY(LIP_CODE) <-
+ //// EXPR_LIST -> { EXPR_AFFECT ';' } [ EXPR_AFFECT ]
+ ( + instr:LIP_CODE;
+ {
+ ((instr := readlip_expr_affect) != NULL) &&
+ {read_character ';'}
+ }.while_do {
+ cod.add_last instr;
+ };
+ cod.add_last instr;
+ );
+
- readlip_expr_base:LIP_CODE <-
- //// EXPR_BASE -> '(' EXPR_OPERATOR ')'
- //// | EXPR_CONSTANT
+ //// EXPR_BASE -> EXPR_RECEIVER { '.' EXPR_MESSAGE }
( + result:LIP_CODE;
- + v:LIP_CONSTANT;
- (read_character '(').if {
- result := readlip_expr_operator;
+ result := readlip_expr_receiver;
+ {read_character '.'}.while_do {
+ result := readlip_expr_message result;
(result = NULL).if {
- syntax_error (current_position,"Incorrect expression.");
+ syntax_error (current_position,"Incorrect message.");
};
- (read_character ')').if_false {
- warning_error (current_position,"Added ')' is needed.");
+ };
+ result
+ );
+
+ - readlip_expr_receiver:LIP_CODE <-
+ //// EXPR_RECEIVER-> EXPR_PRIMARY
+ //// | EXPR_MESSAGE
+ ( + result:LIP_CODE;
+ result := readlip_expr_primary;
+ (result = NULL).if {
+ result := readlip_expr_message NULL;
+ };
+ result
+ );
+
+ - readlip_expr_message rec:LIP_CODE :LIP_CODE <-
+ //// EXPR_MESSAGE -> identifier [ EXPR_ARGUMENT ]
+ //// | 'if' '{' EXPR_LIST '}' [ 'else' '{' EXPR_LIST '}' ]
+ ( + result,arg:LIP_CODE;
+ + nam:STRING_CONSTANT;
+ + the,els:FAST_ARRAY(LIP_CODE);
+
+ (read_word (ALIAS_STR.slot_if)).if {
+ the := ALIAS_ARRAY(LIP_CODE).new;
+ (read_character '{').if_false {
+ warning_error (current_position,"Added '(' is needed.");
};
- } else {
- v := readlip_expr_constant;
- (v != NULL).if {
- result := LIP_VALUE.create current_position with v;
+ readlip_expr_list the;
+ (read_character '}').if_false {
+ warning_error (current_position,"Added '(' is needed.");
};
+ the := ALIAS_ARRAY(LIP_CODE).copy the;
+ (read_word (ALIAS_STR.slot_else)).if {
+ els := ALIAS_ARRAY(LIP_CODE).new;
+ (read_character '{').if_false {
+ warning_error (current_position,"Added '(' is needed.");
+ };
+ readlip_expr_list els;
+ (read_character '}').if_false {
+ warning_error (current_position,"Added '(' is needed.");
+ };
+ els := ALIAS_ARRAY(LIP_CODE).copy els;
+ };
+ result := LIP_IF.create current_position if rec then the else els;
+ }.elseif {read_identifier} then {
+ nam := last_string;
+ arg := readlip_expr_argument;
+ result := LIP_CALL.create current_position
+ receiver rec name nam with arg;
};
result
);
+ - readlip_expr_argument:LIP_CODE <-
+ //// EXPR_ARGUMENT-> identifier
+ //// | EXPR_PRIMARY
+ ( + result:LIP_CODE;
+
+ (read_identifier).if {
+ result := LIP_CALL.create current_position
+ receiver NULL name last_string with NULL;
+ } else {
+ result := readlip_expr_primary;
+ };
+ result
+ );
+
+ - readlip_expr_primary:LIP_CODE <-
+ //// EXPR_PRIMARY -> EXPR_CONSTANT
+ //// | '(' EXPR_LIST ')'
+ ( + result:LIP_CODE;
+ + val:LIP_CONSTANT;
+ + lst:FAST_ARRAY(LIP_CODE);
+
+ val := readlip_expr_constant;
+ (val != NULL).if {
+ result := LIP_VALUE.create current_position with val;
+ }.elseif {read_character '('} then {
+ lst := ALIAS_ARRAY(LIP_CODE).new;
+ readlip_expr_list lst;
+ (read_character ')').if_false {
+ warning_error (current_position,"Added ')'.");
+ };
+ lst := ALIAS_ARRAY(LIP_CODE).copy lst;
+ result := LIP_LIST.create current_position with lst;
+ };
+ result
+ );
+
- readlip_expr_constant:LIP_CONSTANT <-
//// EXPR_CONSTANT-> integer
//// | string
@@ -3041,20 +3063,7 @@ Section Private
};
result
);
-
- - readlip_expr_argument:LIP_CODE <-
- //// EXPR_ARGUMENT-> identifier
- //// | EXPR_BASE
- ( + result:LIP_CODE;
-
- (read_identifier).if {
- result := LIP_CALL.create current_position name last_string with NULL;
- } else {
- result := readlip_expr_base;
- };
- result
- );
-
+
//
// Parser for FORMAT.LI
//
--
Lisaac compiler
More information about the Lisaac-commits
mailing list