FuncCallee ::= "(" ")" | "(" ARGS ")"
ARGS = SINGLE "," ARGS | SINGLE
```
- - 20230928:basically fix `issue1`。其他ê物件猶著做。
\ No newline at end of file
+ - 20230928:basically fix `issue1`。其他ê物件猶著做。
+ - 20230929:add multi args parsing for `callee`.
\ No newline at end of file
let tDiv = m1TType(tk.TokenType.I_DIV);
let tLParen = m1TType(tk.TokenType.L_PAREN);
let tRParen = m1TType(tk.TokenType.R_PAREN);
+let tComma = m1TType(tk.TokenType.COMMA);
let toSome = tk.toSome;
node_process_1.argv.forEach((val, index) => {
console.log(`${index}=${val}`);
let circumfix = (f, signal) => (x) => {
var a = f(x);
if (a._tag == "Some") {
+ console.log("$$$" + repr(a.value.ast));
let inner = a.value.ast[a.value.ast.length - 2];
- let ast_middle = [inner];
+ var ast_middle;
+ if (Array.isArray(inner)) {
+ ast_middle = inner;
+ }
+ else {
+ ast_middle = [inner];
+ }
let new_ast = [ast_middle];
a.value.ast = new_ast;
}
return a;
};
/** single1 = tInt | "(" expr ")"*/
-let single1 = circumfix((x) => thenDo(thenDo(thenDo(tk.toSome(x), tLParen), expr), tRParen), "fac1");
+let single1 = circumfix((x) => thenDo(thenDo(thenDo(toSome(x), tLParen), expr), tRParen), "fac1");
let single2 = tInt;
let single = orDo(single1, single2);
-/** func = single | single "(" single ")"
- * i.e.
- *
- * func = single | func_aux ( int )
- *
-*/
+/** args = single "," args | single */
+let args1 = (x) => {
+ var ret = thenDo(thenDo(thenDo(toSome(x), single), tComma), args);
+ if (ret._tag == "Some") {
+ let retLength = ret.value.ast.length;
+ ret.value.ast = [[ret.value.ast[retLength - 3]].concat(ret.value.ast[retLength - 1])];
+ console.log("$$" + repr(ret.value.ast));
+ }
+ return ret;
+};
+let args2 = single;
+let args = orDo(args1, args2);
/** callees = "(" args ")" | "(" ")" */
-let callees1 = circumfix((x) => thenDo(thenDo(thenDo(tk.toSome(x), tLParen), tInt), tRParen), "callees1");
+let callees1 = circumfix((x) => thenDo(thenDo(thenDo(toSome(x), tLParen), args), tRParen), "callees1");
let callees2 = (x) => {
- let ret = thenDo(thenDo(tk.toSome(x), tLParen), tRParen);
+ let ret = thenDo(thenDo(toSome(x), tLParen), tRParen);
if (ret._tag == "Some") {
let new_ast = [[]];
ret.value.ast = new_ast;
};
/** facAux = callees facAux | callees */
let facAux1 = (x) => {
- var ret = thenDo(thenDo(tk.toSome(x), callees), facAux);
+ var ret = thenDo(thenDo(toSome(x), callees), facAux);
if (ret._tag == "Some") {
console.log("1232345" + repr(tkTreeToSExp(ret.value.ast[ret.value.ast.length - 1])));
let last1 = ret.value.ast[ret.value.ast.length - 1];
* Issue1 to be fixed.
*/
let fac1 = (x) => {
- var ret = thenDo(thenDo(tk.toSome(x), single), facAux);
+ var ret = thenDo(thenDo(toSome(x), single), facAux);
if (ret._tag == "Some") {
console.log("777" + repr(tkTreeToSExp(ret.value.ast)));
ret.value.ast = [applyToken, ret.value.ast[ret.value.ast.length - 2],
*
* term1 = fac (MUL | DIV) fac
*/
-let term1 = midfix((x) => thenDo(thenDo(thenDo(tk.toSome(x), fac), orDo(tMul, tDiv)), fac), "term1");
+let term1 = midfix((x) => thenDo(thenDo(thenDo(toSome(x), fac), orDo(tMul, tDiv)), fac), "term1");
/**
*
* term2 = int MUL int
*
* expr1 = term ADD term
*/
-let expr1 = midfix((x) => thenDo(thenDo(thenDo(tk.toSome(x), term), orDo(tAdd, tSub)), term), "expr1");
+let expr1 = midfix((x) => thenDo(thenDo(thenDo(toSome(x), term), orDo(tAdd, tSub)), term), "expr1");
/**
* expr2 = term
*/
let tokens = tk.tokenize("1");
let tokens2 = tk.tokenize("1(2)");
let tokens3 = tk.tokenize("1(2)(3)");
-let tokens4 = tk.tokenize("2()");
+let tokens4 = tk.tokenize("2()(4)");
//let tokens = tk.tokenize("(4-(3/4))");
//tk.tokenize(argv[2]);
let tokensFiltered = tokens4.filter((x) => {
let tDiv = m1TType(tk.TokenType.I_DIV);
let tLParen = m1TType(tk.TokenType.L_PAREN);
let tRParen = m1TType(tk.TokenType.R_PAREN);
-
+let tComma = m1TType(tk.TokenType.COMMA);
let toSome = tk.toSome;
};
-
if (counter <= 0){
return { _tag: "None"};
}
let circumfix = (f : Function, signal? : string) => (x : TokenMatcheePair)=>{
var a = f(x);
if (a._tag == "Some"){
+ console.log("$$$"+repr(a.value.ast));
let inner = a.value.ast[a.value.ast.length-2];
- let ast_middle : tkTree[] = [inner];
+ var ast_middle : tkTree[];
+ if (Array.isArray(inner)){
+ ast_middle = inner;
+ }
+ else{
+ ast_middle = [inner];
+ }
let new_ast = [ast_middle];
a.value.ast = new_ast;
}
/** single1 = tInt | "(" expr ")"*/
let single1 = circumfix((x : TokenMatcheePair) =>
- thenDo(thenDo(thenDo(tk.toSome(x), tLParen), expr), tRParen), "fac1");
+ thenDo(thenDo(thenDo(toSome(x), tLParen), expr), tRParen), "fac1");
let single2= tInt;
let single = orDo(single1, single2);
-/** func = single | single "(" single ")"
- * i.e.
- *
- * func = single | func_aux ( int )
- *
-*/
+/** args = single "," args | single */
+let args1 = (x: TokenMatcheePair)=>{
+ var ret = thenDo(thenDo(thenDo(toSome(x), single), tComma), args);
+ if (ret._tag == "Some"){
+ let retLength = ret.value.ast.length;
+ ret.value.ast = [[ret.value.ast[retLength-3]].concat(ret.value.ast[retLength-1])];
+ console.log("$$"+repr(ret.value.ast));
+ }
+ return ret;
+};
+
+let args2 = single;
+
+let args = orDo(args1, args2);
+
/** callees = "(" args ")" | "(" ")" */
let callees1 = circumfix((x : TokenMatcheePair) =>
- thenDo(thenDo(thenDo(tk.toSome(x), tLParen), tInt), tRParen), "callees1");
+ thenDo(thenDo(thenDo(toSome(x), tLParen), args), tRParen), "callees1");
let callees2 = (x: TokenMatcheePair)=>{
- let ret = thenDo(thenDo(tk.toSome(x), tLParen), tRParen);
+ let ret = thenDo(thenDo(toSome(x), tLParen), tRParen);
if (ret._tag == "Some"){
let new_ast : tkTree[] = [[]];
ret.value.ast = new_ast;
/** facAux = callees facAux | callees */
let facAux1 = (x: TokenMatcheePair)=>{
- var ret = thenDo(thenDo(tk.toSome(x), callees), facAux);
+ var ret = thenDo(thenDo(toSome(x), callees), facAux);
if (ret._tag == "Some"){
console.log("1232345"+repr(tkTreeToSExp(ret.value.ast[ret.value.ast.length-1])));
let last1 = ret.value.ast[ret.value.ast.length-1];
* Issue1 to be fixed.
*/
let fac1 = (x: TokenMatcheePair)=>{
- var ret = thenDo(thenDo(tk.toSome(x), single),facAux);
+ var ret = thenDo(thenDo(toSome(x), single),facAux);
if(ret._tag == "Some"){
console.log("777"+repr(tkTreeToSExp(ret.value.ast)));
ret.value.ast = [applyToken, ret.value.ast[ret.value.ast.length-2],
*/
let term1 = midfix((x : TokenMatcheePair)=>
- thenDo(thenDo(thenDo(tk.toSome(x), fac), orDo(tMul,tDiv)), fac), "term1");
+ thenDo(thenDo(thenDo(toSome(x), fac), orDo(tMul,tDiv)), fac), "term1");
/**
* expr1 = term ADD term
*/
let expr1 = midfix((x : TokenMatcheePair)=>
- thenDo(thenDo(thenDo(tk.toSome(x), term), orDo(tAdd,tSub)), term), "expr1");
+ thenDo(thenDo(thenDo(toSome(x), term), orDo(tAdd,tSub)), term), "expr1");
/**
* expr2 = term
*/
let tokens = tk.tokenize("1");
let tokens2 = tk.tokenize("1(2)");
let tokens3 = tk.tokenize("1(2)(3)");
-let tokens4 = tk.tokenize("2()");
+let tokens4 = tk.tokenize("2()(4)");
//let tokens = tk.tokenize("(4-(3/4))");
//tk.tokenize(argv[2]);