Skip to content
This repository has been archived by the owner on Jul 27, 2020. It is now read-only.

Commit

Permalink
Various →
Browse files Browse the repository at this point in the history
updates to extension language
started line editor
changes to comments which will become documentation
minor fixes to messy main file
starts #54
progresses #3 #19 #33 #40 #43 #46
regresses #19 #50
  • Loading branch information
GeneralGuy4872 committed Sep 26, 2019
1 parent 7b438cd commit c7bf27c
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 106 deletions.
2 changes: 2 additions & 0 deletions src/dependencies.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
;initial framework, never valid

;dependencies that are implicitly fufilled by inheritance are not shown
;cross-calling of source is marked with depends
;calling of shared libraries is marked extern
Expand Down
11 changes: 5 additions & 6 deletions src/extensionlanguage/extensionlang.lex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ LOGIFF ([Ii]("FF"|"ff")|"⇔"|"<>")
LOGXOR ([Ee]?[Xx][Oo][Rr])
EQ ([Ee][Qq]|"")
EQUALS ([=][=]|[Ee]("QUAL"|"qual"))
APPROX ("?="|[Aa]("PPROX"|"pprox")|"")
APPROX ("=~"|[Aa]("PPROX"|"pprox")|"")
BITNOR ("~|"|"¥")
NE ("!="|""|[Nn][Ee])
NPR [Nn][Pp][RrKk]
Expand Down Expand Up @@ -81,16 +81,16 @@ FI [Ff][Ii]
<COMMENT>"*/" yy_pop_state();
<COMMENT>{TEXT};

<FUNC>{WHITESPACE} return ' ';
<EXPR>{WHITESPACE} return ' ';

"(" yy_push_state(FUNC); return '(';
<FUNC>")" yy_pop_state(); return ')';
<EXPR>")" yy_pop_state(); return ')';
/*s-expressions and lists*/
"{" yy_push_state(EXPR); return '{';
<ARR>"}" yy_pop_state(); return '}';
/*infix*/
"[" yy_push_state(ARR); return '[';
<EXPR>"]" yy_pop_state(); return ']';
<FUNC>"]" yy_pop_state(); return ']';
/*c-like functions, structs, and arrays*/

{NAME} yyval.string = strdup(yytext);return(NAME);
Expand All @@ -102,7 +102,7 @@ FI [Ff][Ii]
{NANTOK} yyval.dval = atof(yytext);return(NANTOK);
{HEX} yyval.number = strtoul(yytext,NULL,16);return(RAW);
{OCTAL} yyval.number = strtoul(yytext,NULL,8);return(RAW);
{BOOLEAN} yyval.number = !(strcmp(toupper(yytext),"T") || strcmp(toupper(yytext),"TRUE"));return(BOOLEAN);
{BOOLEAN} yyval.number = !(strcmp(yytext,"T") || strcmp(toupper(yytext),"TRUE"));return(BOOLEAN);
{ERRVAL} yyval.number = -(!(strcmp(toupper(yytext),"ERR"))));return(ERRVAL);
{NULLTOK} return(NULLTOK);
"+" return '+';
Expand Down Expand Up @@ -159,5 +159,4 @@ FI [Ff][Ii]
{FI} return(FI);
{BEGIN} return(BEGIN);
{END} return(END);
{HUP} return '\003';
%%
144 changes: 70 additions & 74 deletions src/extensionlanguage/extensionlang.y
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,45 @@

%top {
#include stuff here
#include "runtime.h"
//inherits "../dummy.h"
#include "runtime.c"
%}

%union {
long number;
%union
{
intptr_t number;
char* string;
double dval;
%}
}

%%
varname
: VAR {$$ = $1}
| varname '[' NUMBER ']' {$$ = strcat($1,strcat(strcat("[",$2),"]"))}
| varname STRUCTPTR NAME {$$ = strcat($1,strcat("->",$3))}
| varname '.' NAME {$$ = strcat($1,strcat(".",$3))}
;

variable
: varname {$$ = runtime__fetchbyname($1)}
: VAR {$$ = runtime__fetch($1)}
| variable STRUCTPTR NAME {$$ = runtime__struct_pointer($1,$3)}
| variable '.' NAME {$$ = runtime__struct($1,$3)}
| variable '[' unsigned ']' {$$ = runtime__arraysub($1,$3)}
| variable '[' literalparenth ']' {$$ = runtime__arraysub($1,$3)}
| variable '[' anything ']' {$$ = runtime__arraysub_noncon($1,$3)}
;

assignment
: varname ASSIGN anything {$$ = runtime__assignbyname($1,':',$3)}
| varname ' ' ASSIGN ' ' anything {$$ = runtime__assignbyname($1,':',$5)}
| varname '+' '=' quantity {$$ = runtime__assignbyname($1,'+',$4)}
| varname ' ' '+' '=' ' ' quantity {$$ = runtime__assignbyname($1,'+',$6)}
| varname '-' '=' quantity {$$ = runtime__assignbyname($1,'-',$4)}
| varname ' ' '-' '=' ' ' quantity {$$ = runtime__assignbyname($1,'-',$6)}
| varname '*' '=' quantity {$$ = runtime__assignbyname($1,'*',$4)}
| varname ' ' '*' '=' ' ' quantity {$$ = runtime__assignbyname($1,'*',$6)}
| varname '/' '=' quantity {$$ = runtime__assignbyname($1,'/',$4)}
| varname ' ' '/' '=' ' ' quantity {$$ = runtime__assignbyname($1,'/',$6)}
| varname '%' '=' intergal {$$ = runtime__assignbyname($1,'%',$6)}
| varname ' ' '%' '=' ' ' intergal {$$ = runtime__assignbyname($1,'%',$6)}
| varname BITLEFT '=' intergal {$$ = runtime__assignbyname($1,'L',$4)}
| varname ' ' BITLEFT '=' ' ' intergal {$$ = runtime__assignbyname($1,'L',$6)}
| varname BITRIGHT '=' intergal {$$ = runtime__assignbyname($1,'R',$6)}
| varname ' ' BITRIGHT '=' ' ' intergal {$$ = runtime__assignbyname($1,'R',$6)}
| varname '&' '=' intergal {$$ = runtime__assignbyname($1,'&',$4)}
| varname ' ' '&' '=' ' ' intergal {$$ = runtime__assignbyname($1,'&',$6)}
| varname '|' '=' intergal {$$ = runtime__assignbyname($1,'|',$4)}
| varname ' ' '|' '=' ' ' intergal {$$ = runtime__assignbyname($1,'|',$6)}
| varname '~' '&' '=' intergal {$$ = runtime__assignbyname($1,'N',$5)}
| varname ' ' '~' '&' '=' ' ' intergal {$$ = runtime__assignbyname($1,'N',$7)}
| varname BITNOR '=' intergal {$$ = runtime__assignbyname($1,'Y',$4)}
| varname ' ' BITNOR '=' ' ' intergal {$$ = runtime__assignbyname($1,'N',$6)}
| varname '^' '=' intergal {$$ = runtime__assignbyname($1,'^',$4)}
| varname ' ' '^' '=' ' ' intergal {$$ = runtime__assignbyname($1,'^',$6)}
| varname EQ '=' intergal {$$ = runtime__assignbyname($1,'E',$4)}
| varname ' ' EQ '=' ' ' intergal {$$ = runtime__assignbyname($1,'E',$6)}
| varname '~' '=' intergal {$$ = runtime__assignbyname($1,'~',$4)}
| varname ' ' '~' '=' ' ' intergal {$$ = runtime__assignbyname($1,'~',$6)}
: variable optsp ASSIGN optsp anything {$$ = runtime__assign($1,0,$5)}
| variable optsp '+' '=' optsp quantity {$$ = runtime__assign($1,'+',$6)}
| variable optsp '-' '=' optsp quantity {$$ = runtime__assign($1,'-',$6)}
| variable optsp '*' '=' optsp quantity {$$ = runtime__assign($1,'*',$6)}
| variable optsp '/' '=' optsp quantity {$$ = runtime__assign($1,'/',$6)}
| variable optsp '%' '=' optsp intergal {$$ = runtime__assign($1,'%',$6)}
| variable optsp BITLEFT '=' optsp intergal {$$ = runtime__assign($1,'<',$6)}
| variable optsp BITRIGHT '=' optsp intergal {$$ = runtime__assign($1,'>',$6)}
| variable optsp '&' '=' optsp intergal {$$ = runtime__assign($1,'&',$6)}
| variable optsp '|' '=' optsp intergal {$$ = runtime__assign($1,'|',$6)}
| variable optsp '~' '&' '=' optsp intergal {$$ = runtime__assign($1,~'&',$7)}
| variable optsp '&' '~' '=' optsp intergal {$$ = runtime__assign($1,'~',$7)}
| variable optsp BITNOR '=' optsp intergal {$$ = runtime__assign($1,~'|',$6)}
| variable optsp '^' '=' optsp intergal {$$ = runtime__assign($1,'^',$6)}
| variable optsp EQ '=' optsp intergal {$$ = runtime__assign($1,~'^',$6)}
| variable optsp '~' '=' optsp intergal {$$ = runtime__assign($1,-1,$6)}
;
/*section complete!*/
/* section complete! */

anything
: quantity
Expand Down Expand Up @@ -114,11 +98,12 @@ expression
: anything
| literalexpression
| expression
/*more later*/
;
/* more later */

literalexpression
: quantityliteral
| literalparenth
| literalexpression ' ' '+' ' ' literalexpression {$$ = $2 + $5}
| literalexpression ' ' '-' ' ' literalexpression {$$ = $2 - $5}
| literalexpression ' ' '*' ' ' literalexpression {$$ = $2 * $5}
Expand All @@ -127,18 +112,14 @@ literalexpression
| literalexpression ' ' '*' '*' '*' ' ' literalexpression {$$ = pow($2,pow($2,$7))}
| '!' literalexpression {$$ = !($2)}
| literalexpression '!' {$$ = util__factorial($1)}
| literalexpression ' ' '?' ' ' literalexpression ':' literalexpression {$$ = $1 ? $5 : $7}
/*more later*/
;

commaval
: anything {$$ = $1}
| ' ' commaval {$$ = $2}
| commaval ' ' {$$ = $1}
| literalexpression optsp '?' optsp literalexpression optsp ':' optsp literalexpression {$$ = $1 ? $5 : $9}
;
/* more later
* these are the reducibles
*/

commalist
: commaval ',' commaval {
: anything ',' anything {
$$ = malloc(sizeof(struct runtime__list));
$$->next = malloc(sizeof(struct runtime__list));
$$->prev = $$->next;
Expand All @@ -151,7 +132,7 @@ commalist
$$->next->number = $3->number;
$$->next->ddval = $3->ddval;
}
| commalist ',' commaval {
| commalist ',' anything {
$$ = $1; {
foo = malloc(sizeof(struct parser__list));
$$->prev->next = foo;
Expand All @@ -167,13 +148,17 @@ commalist

spacelist
: anything ' ' anything {
$$ = malloc(sizeof(struct parser__list));
$$->next = malloc(sizeof(struct parser__list));
$$ = malloc(sizeof(struct runtime__list));
$$->next = malloc(sizeof(struct runtime__list));
$$->prev = $$->next;
$$->next->next = $$;
$$->next->prev = $$;
$$->data = $1;
$$->next->data = $3;
$$->string = $1->string;
$$->number = $1->number;
$$->ddval = $1->ddval;
$$->next->string = $3->string;
$$->next->number = $3->number;
$$->next->ddval = $3->ddval;
}
| spacelist ' ' anything {
$$ = $1; {
Expand All @@ -182,7 +167,9 @@ spacelist
foo->prev = $$->prev;
$$->prev = foo;
foo->next = $$;
foo->data = $3;
foo->string = $3->string;
foo->number = $3->number;
foo->ddval = $3->ddval;
}
}
;
Expand All @@ -192,31 +179,35 @@ array
| TEXT
;

literalparenth
: '(' optsp literalexpression optsp ')' {$$ = $3}
;

parenth
: '(' commaval ')' {$$ = $2}
| '(' assignment ')' {$$ = $2}
: '(' optsp anything optsp ')' {$$ = $3}
| '(' optsp expression optsp ')' {$$ = $3}
| '(' optsp assignment optsp ')' {$$ = $3}
| literalparenth {$$ = $1}
;

function
: NAME '(' ')' {$$ = runtime__queue_noargs($1)}
| NAME '(' anything ')' {$$ = runtime__queue($1,$3)}
| NAME '(' commalist ')' {$$ = runtime__queue_list($1,$3)}
| '(' NAME ')' {$$ = runtime__queue_noargs($2)}
| '(' NAME ' ' anything ')' {$$ = runtime__queue($2,$3)}
| '(' NAME ' ' spacelist ')' {$$ = runtime__queue_list($2,$3)}
: '`' NAME '`' {$$ = runtime__queue_noargs($2)}
| NAME '[' ']' {$$ = runtime__queue_noargs($1)}
| NAME '[' anything ']' {$$ = runtime__queue($1,$3)}
| NAME '[' commalist ']' {$$ = runtime__queue_list($1,$3)}
| '(' optsp NAME optsp ')' {$$ = runtime__queue_noargs($3)}
| '(' optsp NAME ' ' anything optsp ')' {$$ = runtime__queue($3,$5)}
| '(' optsp NAME ' ' spacelist optsp ')' {$$ = runtime__queue_list($3,$5)}
| '+' '+' variable {$$ = runtime__queue_incr_pre($3)}
| '-' '-' variable {$$ = runtime__queue_decr_pre($3)}
| variable '+' '+' {$$ = runtime__queue_incr_post($1)}
| variable '-' '-' {$$ = runtime__queue_decr_post($1)}
;

preparetodie
: HUP {return(ERR);}
;
/* section complete! */

dostuff
: function {$$ = $1}
| parenth {$$ = NULL}
| parenth {$$ = $1}
| assignment {$$ = runtime__queue_sane($1)}
| ifthen {$$ = $1}
| simpleloop {$$ = $1}
Expand Down Expand Up @@ -271,4 +262,9 @@ caseentry
caselist
: caseentry caseentry {$$ = runtime__concat_case($1,$2)}
| caselist caseentry {$$ = runtime__concat_case($1,$2)}
;
;

optsp
: /* empty */
| ' '
;
4 changes: 2 additions & 2 deletions src/extensionlanguage/runtime.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../dummy.h"
#include "../dummy.c"

struct runtime__args

Expand Down Expand Up @@ -29,4 +29,4 @@ OPCODE_POST_DECR,OPCODE_ADD,OPCODE_SUB,OPCODE_MULT,OPCODE_DIV,OPCODE_MOD,OPCODE_
OPCODE_LOGOR,OPCODE_LOGNAND,OPCODE_LOGNOR,OPCODE_LOGXOR,OPCODE_IFF,OPCODE_LOGNOT,
OPCODE_AND,OPCODE_OR,OPCODE_NAND,OPCODE_NOR,OPCODE_XOR,OPCODE_EQ,OPCODE_NOT,OPCODE_GT,
OPCODE_GE,OPCODE_EQUAL,OPCODE_NE,OPCODE_LT,OPCODE_LE,OPCODE_APPROX,OPCODE_EXP,OPCODE_TETRA,
OPCODE_RETURN,OPCODE_BREAK,OPCODE_NPR,OPCODE_NCR,OPCODE_FACT,
OPCODE_RETURN,OPCODE_BREAK,OPCODE_NPR,OPCODE_NCR,OPCODE_FACT,
Loading

0 comments on commit c7bf27c

Please sign in to comment.