Skip to content

Commit

Permalink
feat: fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
liulinboyi committed Jul 27, 2021
1 parent 2f2c41d commit 4bd68cd
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
6 changes: 5 additions & 1 deletion demo/hello-world-15.pineapple
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
$a = 10 # 10
$p_a = "a: " + $a
$b = 30 # 30
$p_a = "a: " + $a + $b # a: 1030
$c = 50 # 50
$d = $a + $b + $c # 90
print($p_a)
print($c)
11 changes: 11 additions & 0 deletions dist/src/parser/Assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ function parseBinaryExpression(lexer, idAndinit, assignment, leftType) {
else if (leftType === 'Literal') {
BinaryExpression.left = new Literal(idAndinit.init.value);
}
else if (leftType === "BinaryExpression") {
BinaryExpression.left = idAndinit.init;
}
if (ahead.tokenType === lexer1_1.NUMBER) {
const literial = new Literal(parser_1.parseNumber(lexer));
BinaryExpression.right = literial;
Expand All @@ -245,6 +248,14 @@ function parseBinaryExpression(lexer, idAndinit, assignment, leftType) {
VariableDeclarator.id.name = idAndinit.id.name;
VariableDeclarator.init = BinaryExpression;
assignment.declarations.push(VariableDeclarator);
let oahead = lexer.LookAhead();
if (oahead.tokenType === lexer1_1.Operator) {
lexer.NextTokenIs(lexer1_1.Operator); // +-*/
// lexer.LookAheadAndSkip(TOKEN_IGNORED); // 空格
lexer.isIgnored();
const idAndinits = assignment.declarations.pop();
parseBinaryExpression(lexer, idAndinits, assignment, "BinaryExpression");
}
return assignment;
}
exports.parseBinaryExpression = parseBinaryExpression;
5 changes: 3 additions & 2 deletions dist/test/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require('fs');
const path = require('path');
const Execute = require('../src/backend.ts').Execute;
const backend_1 = require("../src/backend");
let code = fs.readFileSync(path.resolve(__dirname, '../demo/hello-world-15.pineapple'), { encoding: 'utf-8' });
console.log(code, 'code');
if (code.length > 0) {
Execute(code);
backend_1.Execute(code);
}
14 changes: 14 additions & 0 deletions src/parser/Assignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ export function parseBinaryExpression(lexer: Lexer, idAndinit: { init: Literal |
BinaryExpression.left = new Identifier((idAndinit.init as Identifier).name)
} else if (leftType === 'Literal') {
BinaryExpression.left = new Literal((idAndinit.init as Literal).value)
} else if (leftType === "BinaryExpression") {
BinaryExpression.left = idAndinit.init
}
if (ahead.tokenType === NUMBER) {
const literial = new Literal(parseNumber(lexer))
Expand All @@ -286,5 +288,17 @@ export function parseBinaryExpression(lexer: Lexer, idAndinit: { init: Literal |
VariableDeclarator.id.name = idAndinit.id.name;
VariableDeclarator.init = BinaryExpression;
(assignment as any).declarations.push(VariableDeclarator)

let oahead = lexer.LookAhead()

if (oahead.tokenType === Operator) {
lexer.NextTokenIs(Operator); // +-*/
// lexer.LookAheadAndSkip(TOKEN_IGNORED); // 空格
lexer.isIgnored()
const idAndinits = (assignment as any).declarations.pop();
parseBinaryExpression(lexer, idAndinits, assignment, "BinaryExpression");
}


return assignment
}
4 changes: 2 additions & 2 deletions test/test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const fs = require('fs')
const path = require('path')
const Execute = require('../src/backend.ts').Execute
import { Execute } from '../src/backend'

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

0 comments on commit 4bd68cd

Please sign in to comment.