Skip to content

Commit

Permalink
feat: Continue add function
Browse files Browse the repository at this point in the history
  • Loading branch information
liulinboyi committed Feb 27, 2021
1 parent 8c7b56d commit 60f7ce8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
10 changes: 10 additions & 0 deletions demo/hello-world-7.pineapple
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

func add($a,$b) {
$_a = $a + $b
print($_a)
return $_a + 1
}

$res = add(1,2)

print($res)
7 changes: 7 additions & 0 deletions dist/src/parser/Function.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports.paseReturnStatement = exports.paseBlock = exports.parseFunction = void 0
const lexer1_1 = require("../lexer1");
const parser_1 = require("../parser");
const Assignment_1 = require("./Assignment");
const Print_1 = require("./Print");
function parseFunction(lexer) {
const FunctionDeclaration = {
type: "FunctionDeclaration",
Expand Down Expand Up @@ -88,6 +89,12 @@ function paseBlock(lexer) {
});
paseBlock(lexer);
}
else if (ahead.tokenType === lexer1_1.TOKEN_PRINT) {
const print = Print_1.parsePrint(lexer);
console.log(print);
BlockStatementBody.push(print);
paseBlock(lexer);
}
return BlockStatementBody;
}
exports.paseBlock = paseBlock;
Expand Down
2 changes: 1 addition & 1 deletion dist/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const fs = require('fs');
const path = require('path');
const Execute = require('../dist/src/backend.js').Execute;
code = fs.readFileSync(path.resolve(__dirname, '../demo/hello-world-6.pineapple'), { encoding: 'utf-8' });
code = fs.readFileSync(path.resolve(__dirname, '../demo/hello-world-7.pineapple'), { encoding: 'utf-8' });
console.log(code, 'code');
if (code.length > 0) {
Execute(code);
Expand Down
8 changes: 7 additions & 1 deletion src/parser/Function.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TOKEN_IGNORED, TOKEN_LEFT_PAREN, Lexer, TOKEN_RIGHT_PAREN, TOKEN_FUNC_PARAMS_DIV, TOKEN_FUNC, BLOCK_START, TOKEN_RETURN, NUMBER, TOKEN_VAR_PREFIX, Operator, BLOCK_END } from "../lexer1";
import { TOKEN_IGNORED, TOKEN_LEFT_PAREN, Lexer, TOKEN_RIGHT_PAREN, TOKEN_FUNC_PARAMS_DIV, TOKEN_FUNC, BLOCK_START, TOKEN_RETURN, NUMBER, TOKEN_VAR_PREFIX, Operator, BLOCK_END, TOKEN_PRINT } from "../lexer1";
import { parseName, parseNumber, parseString, parseVariable } from "../parser";
import { Assignment, Identifier, Literal, parseAssignment, parseBinaryExpression } from "./Assignment";
import { parsePrint } from "./Print";

export function parseFunction(lexer: Lexer) {
const FunctionDeclaration: any = {
Expand Down Expand Up @@ -87,6 +88,11 @@ export function paseBlock(lexer: Lexer) {
kind: VariableDeclaration.kind
})
paseBlock(lexer)
} else if (ahead.tokenType === TOKEN_PRINT) {
const print = parsePrint(lexer)
console.log(print)
BlockStatementBody.push(print)
paseBlock(lexer)
}
return BlockStatementBody
}
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const fs = require('fs')
const path = require('path')
const Execute = require('../dist/src/backend.js').Execute

code = fs.readFileSync(path.resolve(__dirname, '../demo/hello-world-6.pineapple'), {encoding: 'utf-8'})
code = fs.readFileSync(path.resolve(__dirname, '../demo/hello-world-7.pineapple'), {encoding: 'utf-8'})
console.log(code, 'code')
if (code.length > 0) {
Execute(code)
Expand Down

0 comments on commit 60f7ce8

Please sign in to comment.