|
@@ -50,7 +50,7 @@ export class IVProgParser {
|
|
if (token.type === this.lexerClass.RK_CONST || token.type === this.lexerClass.ID) {
|
|
if (token.type === this.lexerClass.RK_CONST || token.type === this.lexerClass.ID) {
|
|
globalVars = globalVars.concat(this.parseGlobalVariables());
|
|
globalVars = globalVars.concat(this.parseGlobalVariables());
|
|
} else if (token.type === this.lexerClass.RK_FUNCTION) {
|
|
} else if (token.type === this.lexerClass.RK_FUNCTION) {
|
|
- functions = functions.concat([]);
|
|
|
|
|
|
+ functions = functions.concat(this.parseFunctions());
|
|
} else {
|
|
} else {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -201,12 +201,16 @@ export class IVProgParser {
|
|
// ID[int/IDi][int/IDj]
|
|
// ID[int/IDi][int/IDj]
|
|
if (this.checkOpenBrace(true)) {
|
|
if (this.checkOpenBrace(true)) {
|
|
this.pos++;
|
|
this.pos++;
|
|
|
|
+ this.consumeNewLines();
|
|
dim1 = this.parseArrayDimension();
|
|
dim1 = this.parseArrayDimension();
|
|
|
|
+ this.consumeNewLines();
|
|
this.checkCloseBrace();
|
|
this.checkCloseBrace();
|
|
this.pos++;
|
|
this.pos++;
|
|
if(this.checkOpenBrace(true)) {
|
|
if(this.checkOpenBrace(true)) {
|
|
this.pos++;
|
|
this.pos++;
|
|
|
|
+ this.consumeNewLines();
|
|
dim2 = this.parseArrayDimension();
|
|
dim2 = this.parseArrayDimension();
|
|
|
|
+ this.consumeNewLines();
|
|
this.checkCloseBrace();
|
|
this.checkCloseBrace();
|
|
this.pos++;
|
|
this.pos++;
|
|
}
|
|
}
|
|
@@ -215,14 +219,14 @@ export class IVProgParser {
|
|
const equalsToken = this.getToken();
|
|
const equalsToken = this.getToken();
|
|
if(equalsToken.type === this.lexerClass.EQUAL) {
|
|
if(equalsToken.type === this.lexerClass.EQUAL) {
|
|
this.pos++;
|
|
this.pos++;
|
|
- this.consumeNewLines();
|
|
|
|
initial = this.parseExpressionOR();
|
|
initial = this.parseExpressionOR();
|
|
}
|
|
}
|
|
- this.consumeNewLines();
|
|
|
|
|
|
+
|
|
const commaToken = this.getToken();
|
|
const commaToken = this.getToken();
|
|
if(commaToken.type === this.lexerClass.COMMA) {
|
|
if(commaToken.type === this.lexerClass.COMMA) {
|
|
console.log("comma found");
|
|
console.log("comma found");
|
|
this.pos++;
|
|
this.pos++;
|
|
|
|
+ this.consumeNewLines();
|
|
return [{
|
|
return [{
|
|
isConst: isConst,
|
|
isConst: isConst,
|
|
tipo: typeString,
|
|
tipo: typeString,
|
|
@@ -233,7 +237,6 @@ export class IVProgParser {
|
|
}]
|
|
}]
|
|
.concat(this.parseDeclararion(typeString, isConst));
|
|
.concat(this.parseDeclararion(typeString, isConst));
|
|
} else {
|
|
} else {
|
|
- this.pos--;
|
|
|
|
return [{
|
|
return [{
|
|
isConst: isConst,
|
|
isConst: isConst,
|
|
tipo: typeString,
|
|
tipo: typeString,
|
|
@@ -315,6 +318,10 @@ export class IVProgParser {
|
|
return {type: 'bool', value: val};
|
|
return {type: 'bool', value: val};
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ parseArrayLiteral () {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* Returns an object {type: 'variable', value: value}.
|
|
* Returns an object {type: 'variable', value: value}.
|
|
* @returns object with fields type and value
|
|
* @returns object with fields type and value
|
|
@@ -348,11 +355,8 @@ export class IVProgParser {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
this.pos++;
|
|
this.pos++;
|
|
- this.consumeNewLines();
|
|
|
|
const returnType = this.parseType(true);
|
|
const returnType = this.parseType(true);
|
|
- this.consumeNewLines();
|
|
|
|
const functionID = this.parseID();
|
|
const functionID = this.parseID();
|
|
- this.consumeNewLines();
|
|
|
|
this.checkOpenParenthesis();
|
|
this.checkOpenParenthesis();
|
|
this.pos++;
|
|
this.pos++;
|
|
this.consumeNewLines();
|
|
this.consumeNewLines();
|
|
@@ -377,13 +381,8 @@ export class IVProgParser {
|
|
const list = [];
|
|
const list = [];
|
|
while(true) {
|
|
while(true) {
|
|
let dimensions = 0;
|
|
let dimensions = 0;
|
|
- this.consumeNewLines();
|
|
|
|
const typeString = this.parseType();
|
|
const typeString = this.parseType();
|
|
- this.pos++;
|
|
|
|
- this.consumeNewLines();
|
|
|
|
const idString = this.parseID();
|
|
const idString = this.parseID();
|
|
- this.pos++;
|
|
|
|
- this.consumeNewLines();
|
|
|
|
if (this.checkOpenBrace(true)) {
|
|
if (this.checkOpenBrace(true)) {
|
|
this.pos++;
|
|
this.pos++;
|
|
dimensions++;
|
|
dimensions++;
|
|
@@ -397,11 +396,11 @@ export class IVProgParser {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
list.push({type: typeString, id: idString, dimensions: dimensions});
|
|
list.push({type: typeString, id: idString, dimensions: dimensions});
|
|
- this.consumeNewLines();
|
|
|
|
const commaToken = this.getToken();
|
|
const commaToken = this.getToken();
|
|
if (commaToken.type !== this.lexerClass.COMMA)
|
|
if (commaToken.type !== this.lexerClass.COMMA)
|
|
break;
|
|
break;
|
|
this.pos++;
|
|
this.pos++;
|
|
|
|
+ this.consumeNewLines();
|
|
}
|
|
}
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
@@ -446,11 +445,11 @@ export class IVProgParser {
|
|
let commands = [];
|
|
let commands = [];
|
|
this.checkOpenCurly();
|
|
this.checkOpenCurly();
|
|
this.pos++;
|
|
this.pos++;
|
|
|
|
+ this.consumeNewLines();
|
|
while(true) {
|
|
while(true) {
|
|
- this.consumeNewLines();
|
|
|
|
const token = this.getToken();
|
|
const token = this.getToken();
|
|
let cmd = null;
|
|
let cmd = null;
|
|
- if (isVariableType(token)) {
|
|
|
|
|
|
+ if (this.isVariableType(token)) {
|
|
this.pos++;
|
|
this.pos++;
|
|
variablesDecl = variablesDecl.concat(this.parseDeclararion(token));
|
|
variablesDecl = variablesDecl.concat(this.parseDeclararion(token));
|
|
this.checkEOS();
|
|
this.checkEOS();
|
|
@@ -481,6 +480,8 @@ export class IVProgParser {
|
|
}
|
|
}
|
|
this.consumeNewLines();
|
|
this.consumeNewLines();
|
|
this.checkCloseCurly();
|
|
this.checkCloseCurly();
|
|
|
|
+ this.pos++;
|
|
|
|
+ this.consumeNewLines();
|
|
return {variables: variablesDecl, commands: commands};
|
|
return {variables: variablesDecl, commands: commands};
|
|
}
|
|
}
|
|
|
|
|
|
@@ -501,7 +502,6 @@ export class IVProgParser {
|
|
|
|
|
|
parseIDCommand () {
|
|
parseIDCommand () {
|
|
const id = this.parseID();
|
|
const id = this.parseID();
|
|
- this.consumeNewLines();
|
|
|
|
const equalOrParenthesis = this.getToken();
|
|
const equalOrParenthesis = this.getToken();
|
|
if (equalOrParenthesis.type === this.lexerClass.EQUAL) {
|
|
if (equalOrParenthesis.type === this.lexerClass.EQUAL) {
|
|
this.pos++
|
|
this.pos++
|
|
@@ -544,6 +544,7 @@ export class IVProgParser {
|
|
if (maybeAnd.type === this.lexerClass.OR_OPERATOR) {
|
|
if (maybeAnd.type === this.lexerClass.OR_OPERATOR) {
|
|
this.pos++;
|
|
this.pos++;
|
|
or = 'or';
|
|
or = 'or';
|
|
|
|
+ this.consumeNewLines();
|
|
exp2 = this.parseExpressionOR();
|
|
exp2 = this.parseExpressionOR();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -554,11 +555,11 @@ export class IVProgParser {
|
|
const exp1 = this.parseExpressionNot();
|
|
const exp1 = this.parseExpressionNot();
|
|
let and = null;
|
|
let and = null;
|
|
let exp2 = null;
|
|
let exp2 = null;
|
|
- this.consumeNewLines();
|
|
|
|
const andToken = this.getToken();
|
|
const andToken = this.getToken();
|
|
if (andToken.type === this.lexerClass.AND_OPERATOR) {
|
|
if (andToken.type === this.lexerClass.AND_OPERATOR) {
|
|
this.pos++;
|
|
this.pos++;
|
|
and = 'and';
|
|
and = 'and';
|
|
|
|
+ this.consumeNewLines();
|
|
exp2 = this.parseExpressionAND();
|
|
exp2 = this.parseExpressionAND();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -567,7 +568,6 @@ export class IVProgParser {
|
|
|
|
|
|
parseExpressionNot () {
|
|
parseExpressionNot () {
|
|
let not = null;
|
|
let not = null;
|
|
- this.consumeNewLines();
|
|
|
|
const maybeNotToken = this.getToken();
|
|
const maybeNotToken = this.getToken();
|
|
if (maybeNotToken.type === this.lexerClass.NOT_OPERATOR) {
|
|
if (maybeNotToken.type === this.lexerClass.NOT_OPERATOR) {
|
|
this.pos++;
|
|
this.pos++;
|
|
@@ -582,7 +582,6 @@ export class IVProgParser {
|
|
const exp1 = this.parseExpression();
|
|
const exp1 = this.parseExpression();
|
|
let rel = null;
|
|
let rel = null;
|
|
let exp2 = null;
|
|
let exp2 = null;
|
|
- this.consumeNewLines();
|
|
|
|
const relToken = this.getToken();
|
|
const relToken = this.getToken();
|
|
if(relToken.type === this.lexerClass.RELATIONAL_OPERATOR) {
|
|
if(relToken.type === this.lexerClass.RELATIONAL_OPERATOR) {
|
|
this.pos++;
|
|
this.pos++;
|
|
@@ -597,7 +596,6 @@ export class IVProgParser {
|
|
const factor = this.parseFactor();
|
|
const factor = this.parseFactor();
|
|
let op = null;
|
|
let op = null;
|
|
let exp = null;
|
|
let exp = null;
|
|
- this.consumeNewLines();
|
|
|
|
const sumOpToken = this.getToken();
|
|
const sumOpToken = this.getToken();
|
|
if(sumOpToken.type === this.lexerClass.SUM_OP) {
|
|
if(sumOpToken.type === this.lexerClass.SUM_OP) {
|
|
this.pos++;
|
|
this.pos++;
|
|
@@ -612,7 +610,6 @@ export class IVProgParser {
|
|
const term = this.parseTerm();
|
|
const term = this.parseTerm();
|
|
let op = null;
|
|
let op = null;
|
|
let factor = null;
|
|
let factor = null;
|
|
- this.consumeNewLines();
|
|
|
|
const multOpToken = this.getToken();
|
|
const multOpToken = this.getToken();
|
|
if(multOpToken.type === this.lexerClass.MULTI_OP) {
|
|
if(multOpToken.type === this.lexerClass.MULTI_OP) {
|
|
this.pos++;
|
|
this.pos++;
|
|
@@ -624,7 +621,6 @@ export class IVProgParser {
|
|
}
|
|
}
|
|
|
|
|
|
parseTerm () {
|
|
parseTerm () {
|
|
- this.consumeNewLines();
|
|
|
|
const token = this.getToken();
|
|
const token = this.getToken();
|
|
switch(token.type) {
|
|
switch(token.type) {
|
|
case this.lexerClass.INTEGER:
|
|
case this.lexerClass.INTEGER:
|
|
@@ -650,7 +646,6 @@ export class IVProgParser {
|
|
parseIDTerm () {
|
|
parseIDTerm () {
|
|
const id = this.parseID();
|
|
const id = this.parseID();
|
|
const last = this.pos;
|
|
const last = this.pos;
|
|
- this.consumeNewLines(); // DANGEROUS: exp = ID eos => results in inapropriate syntax error
|
|
|
|
if(this.checkOpenBrace(true)) {
|
|
if(this.checkOpenBrace(true)) {
|
|
this.pos++;
|
|
this.pos++;
|
|
const firstIndex = this.parseExpression();
|
|
const firstIndex = this.parseExpression();
|
|
@@ -658,7 +653,6 @@ export class IVProgParser {
|
|
this.consumeNewLines();
|
|
this.consumeNewLines();
|
|
this.checkCloseBrace();
|
|
this.checkCloseBrace();
|
|
this.pos++;
|
|
this.pos++;
|
|
- this.consumeNewLines(); // DANGEROUS: exp = v1 + v2 + v[i] eos => results in inapropriate syntax error
|
|
|
|
if(this.checkOpenBrace(true)){
|
|
if(this.checkOpenBrace(true)){
|
|
this.pos++;
|
|
this.pos++;
|
|
secondIndex = this.parseExpression();
|
|
secondIndex = this.parseExpression();
|
|
@@ -673,6 +667,7 @@ export class IVProgParser {
|
|
|
|
|
|
} else if (this.checkOpenParenthesis(true)) {
|
|
} else if (this.checkOpenParenthesis(true)) {
|
|
this.pos++;
|
|
this.pos++;
|
|
|
|
+ this.consumeNewLines();
|
|
let actualParameters = [];
|
|
let actualParameters = [];
|
|
if(!this.checkCloseParenthesis(true)) {
|
|
if(!this.checkCloseParenthesis(true)) {
|
|
actualParameters = this.parseActualParameters();
|
|
actualParameters = this.parseActualParameters();
|
|
@@ -707,13 +702,13 @@ export class IVProgParser {
|
|
while (true) {
|
|
while (true) {
|
|
this.consumeNewLines();
|
|
this.consumeNewLines();
|
|
const exp = this.parseExpressionOR();
|
|
const exp = this.parseExpressionOR();
|
|
- this.consumeNewLines();
|
|
|
|
list.push(exp);
|
|
list.push(exp);
|
|
const commaToken = this.getToken();
|
|
const commaToken = this.getToken();
|
|
if (commaToken.type !== this.lexerClass.COMMA) {
|
|
if (commaToken.type !== this.lexerClass.COMMA) {
|
|
break;
|
|
break;
|
|
} else {
|
|
} else {
|
|
this.pos++;
|
|
this.pos++;
|
|
|
|
+ this.consumeNewLines();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.consumeNewLines();
|
|
this.consumeNewLines();
|