Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdstorm committed Nov 13, 2018
1 parent 4acf318 commit e65d488
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 45 deletions.
6 changes: 3 additions & 3 deletions examples/cyclic.myql
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ form taxOfficeExample {

if (hasSoldHouse) {
"What was the selling price?"
sellingPrice: money = valueResidue
sellingPrice: integer = valueResidue
"Private debts for the sold house:"
privateDebt: money
privateDebt: integer
"Value residue:"
valueResidue: money =
valueResidue: integer =
((sellingPrice - privateDebt) * 2)
}

Expand Down
4 changes: 2 additions & 2 deletions examples/errors.myql
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ form taxOfficeExample {
"What was the selling price?"
sellingPrice: boolean
"Private debts for the sold house:"
privateDebt: money
privateDebt: integer
"Value residue:"
valueResidue: money =
valueResidue: integer =
((sellingPrice - privateDebt) * true)
}
}
6 changes: 3 additions & 3 deletions examples/tax.myql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ form taxOfficeExample {

if (hasSoldHouse) {
"What was the selling price?"
sellingPrice: money
sellingPrice: integer
"Private debts for the sold house:"
privateDebt: money
privateDebt: integer
"Value residue:"
valueResidue: money = sellingPrice - privateDebt
valueResidue: integer = sellingPrice - privateDebt

}
}
12 changes: 7 additions & 5 deletions src/AST.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ module AST
* - make sure there is an almost one-to-one correspondence with the grammar
*/

data AForm(loc src = |unknown://|)
data AForm(loc src = |tmp:///|)
= form(str name, list[AQuestion] questions)
;

data AQuestion(loc src = |unknown://|);

data AExpr(loc src = |unknown://|)
= ref(str name);
data AQuestion(loc src = |tmp:///|)
;

data AExpr(loc src = |tmp:///|)
= ref(str name)
;

data AType(loc src = |tmp:///|);
13 changes: 9 additions & 4 deletions src/CST2AST.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module CST2AST

import Syntax;
import AST;

import ParseTree;
import String;

Expand All @@ -16,20 +17,24 @@ import String;
*/

AForm cst2ast(start[Form] sf) {
Form f = sf.top;
return form("", []); // TODO
Form f = sf.top; // remove layout before and after form
return form("", [], src=f@\loc);
}

AQuestion cst2ast(Question q) {
// TODO
throw "Not yet implemented";
}

AExpr cst2ast(Expr e) {
switch (e) {
case (Expr)`<Id x>`: return ref("<x>", src=x@\loc);

// ...
// etc.

default: throw "Unhandled expression: <e>";
}
}

AType cst2ast(Type t) {
throw "Not yet implemented";
}
10 changes: 5 additions & 5 deletions src/Check.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ alias TEnv = rel[loc def, str name, str label, Type \type];
// To avoid recursively traversing the form, use the `visit` construct
// or deep match (e.g., `for (/question(...) := f) {...}` )
TEnv collect(AForm f) {
return {}; // TODO
return {};
}

set[Message] check(AForm f, TEnv tenv, UseDef useDef) {
return {}; // TODO
return {};
}

// - produce an error if there are declared questions with the same name but different types.
// - duplicate labels should trigger a warning
// - the declared type computed questions should match the type of the expression.
set[Message] check(AQuestion q, TEnv tenv, UseDef useDef) {
return {}; // TODO
return {};
}

// Check operand compatibility with operators.
Expand All @@ -53,9 +53,9 @@ Type typeOf(AExpr e, TEnv tenv, UseDef useDef) {
if (<u, loc d> <- useDef, <d, x, _, Type t> <- tenv) {
return t;
}

// etc.
}
return tunknown(); // TODO
return tunknown();
}

/*
Expand Down
6 changes: 2 additions & 4 deletions src/Compile.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ import lang::html5::DOM; // see standard library
*/

void compile(AForm f) {
writeFile(f.src[extension="js"], form2js(f));
writeFile(f.src[extension="html"], toString(form2html(f)));
writeFile(f.src[extension="js"].top, form2js(f));
writeFile(f.src[extension="html"].top, toString(form2html(f)));
}

HTML5Node form2html(AForm f) {
// TODO
return html();
}

str form2js(AForm f) {
// TODO
return "";
}
7 changes: 4 additions & 3 deletions src/Eval.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,20 @@ VEnv eval(AForm f, Input inp, VEnv venv) {
}

VEnv evalOnce(AForm f, Input inp, VEnv venv) {
return (); // TODO: evaluate each question
return ();
}

VEnv eval(AQuestion q, Input inp, VEnv venv) {
// evaluate conditions for branching,
// evaluate inp and computed questions to return updated VEnv
return (); // TODO
return ();
}

Value eval(AExpr e, VEnv venv) {
switch (e) {
case ref(str x): return venv[x];
// etc

// etc.

default: throw "Unsupported expression <e>";
}
Expand Down
11 changes: 6 additions & 5 deletions src/IDE.rsc
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
module IDE

import QL;
import Syntax;
import AST;
import CST2AST;
import Resolve;
import Check;
import Compile;

import util::IDE;
import Message;
import ParseTree;


private str TQL ="Tutorial QL";
private str MyQL ="MyQL";

anno rel[loc, loc] Tree@hyperlinks;

void main() {
registerLanguage(TQL, "tql", Tree(str src, loc l) {
registerLanguage(MyQL, "myql", Tree(str src, loc l) {
return parse(#start[Form], src, l);
});

Expand All @@ -28,7 +29,7 @@ void main() {
set[Message] msgs = check(ast, collect(ast), useDef);
return t[@messages=msgs][@hyperlinks=useDef];
}
return t[@message={error("Not a form", t@\loc)}];
return t[@messages={error("Not a form", t@\loc)}];
}),

builder(set[Message] (Tree t) {
Expand All @@ -45,5 +46,5 @@ void main() {
})
};

registerContributions(TQL, contribs);
registerContributions(MyQL, contribs);
}
4 changes: 2 additions & 2 deletions src/Resolve.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ alias UseDef = rel[loc use, loc def];
UseDef resolve(AForm f) = uses(f) o defs(f);

Use uses(AForm f) {
return {}; // todo
return {};
}

Def defs(AForm f) {
return {}; // todo
return {};
}
21 changes: 14 additions & 7 deletions src/Syntax.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,30 @@ extend lang::std::Id;
* Concrete syntax of QL
*/

start syntax Form = ; // TODO
start syntax Form
= "form" Id "{" Question* "}";

// TODO: question, computed question, block, if-then-else, if-then
syntax Question = ;
syntax Question
=
;

// TODO: +, -, *, /, &&, ||, !, >, <, <=, >=, ==, !=, literals (bool, int, str)
// Think about disambiguation using priorities and associativity
// and use C/Java style precedence rules (look it up on the internet)
syntax Expr
= ref: Id name
;
= Id \ "true" \ "false" // true/false are reserved keywords.
;

syntax Type
= ;

lexical Str = ; // TODO
lexical Str = ;

lexical Int = ; // TODO
lexical Int
= ;

lexical Bool = ; // TODO
lexical Bool = ;



4 changes: 2 additions & 2 deletions src/Transform.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import AST;
*/

AForm flatten(AForm f) {
return f; // TODO
return f;
}

/* Rename refactoring:
Expand All @@ -34,7 +34,7 @@ AForm flatten(AForm f) {
*/

AForm rename(AForm f, loc useOrDef, str newName, UseDef useDef) {
return f; // TODO
return f;
}


Expand Down

0 comments on commit e65d488

Please sign in to comment.