|
@@ -1,7 +1,7 @@
|
|
import { CommonTokenStream, InputStream } from 'antlr4/index';
|
|
import { CommonTokenStream, InputStream } from 'antlr4/index';
|
|
import * as Expressions from './expressions/';
|
|
import * as Expressions from './expressions/';
|
|
import * as Commands from './commands/';
|
|
import * as Commands from './commands/';
|
|
-import { recover } from "./ivprogLexer";
|
|
|
|
|
|
+import * as AstHelpers from "./ast_helpers";
|
|
import { toInt, toString, toBool, toReal } from './../typeSystem/parsers';
|
|
import { toInt, toString, toBool, toReal } from './../typeSystem/parsers';
|
|
import { Types } from "./../typeSystem/types";
|
|
import { Types } from "./../typeSystem/types";
|
|
import { CompoundType } from "./../typeSystem/compoundType";
|
|
import { CompoundType } from "./../typeSystem/compoundType";
|
|
@@ -36,7 +36,7 @@ export class IVProgParser {
|
|
constructor (input, lexerClass) {
|
|
constructor (input, lexerClass) {
|
|
this.lexerClass = lexerClass;
|
|
this.lexerClass = lexerClass;
|
|
this.lexer = new lexerClass(new InputStream(input));
|
|
this.lexer = new lexerClass(new InputStream(input));
|
|
- this.lexer.recover = recover.bind(this.lexer);
|
|
|
|
|
|
+ this.lexer.recover = AstHelpers.recover.bind(this.lexer);
|
|
this.tokenStream = new CommonTokenStream(this.lexer);
|
|
this.tokenStream = new CommonTokenStream(this.lexer);
|
|
this.tokenStream.fill();
|
|
this.tokenStream.fill();
|
|
this.pos = 1;
|
|
this.pos = 1;
|
|
@@ -608,6 +608,7 @@ export class IVProgParser {
|
|
hasOpen = true;
|
|
hasOpen = true;
|
|
}
|
|
}
|
|
this.consumeNewLines();
|
|
this.consumeNewLines();
|
|
|
|
+ let parsedCommand = false;
|
|
while(true) {
|
|
while(true) {
|
|
|
|
|
|
const cmd = this.parseCommand();
|
|
const cmd = this.parseCommand();
|
|
@@ -615,8 +616,13 @@ export class IVProgParser {
|
|
break;
|
|
break;
|
|
if(cmd !== -1) {
|
|
if(cmd !== -1) {
|
|
if (cmd instanceof Array) {
|
|
if (cmd instanceof Array) {
|
|
|
|
+ if(parsedCommand) {
|
|
|
|
+ const lastToken = this.getToken(this.pos - 1);
|
|
|
|
+ throw SyntaxErrorFactory.invalid_var_declaration(lastToken);
|
|
|
|
+ }
|
|
variablesDecl = variablesDecl.concat(cmd);
|
|
variablesDecl = variablesDecl.concat(cmd);
|
|
} else {
|
|
} else {
|
|
|
|
+ parsedCommand = true;
|
|
commands.push(cmd);
|
|
commands.push(cmd);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -634,7 +640,7 @@ export class IVProgParser {
|
|
const token = this.getToken();
|
|
const token = this.getToken();
|
|
if (this.isVariableType(token)) {
|
|
if (this.isVariableType(token)) {
|
|
if(!this.insideScope(IVProgParser.FUNCTION)) {
|
|
if(!this.insideScope(IVProgParser.FUNCTION)) {
|
|
- throw SyntaxErrorFactory.invalid_var_declaration(token.line);
|
|
|
|
|
|
+ throw SyntaxErrorFactory.invalid_var_declaration(token);
|
|
}
|
|
}
|
|
this.pushScope(IVProgParser.BASE);
|
|
this.pushScope(IVProgParser.BASE);
|
|
const varType = this.parseType();
|
|
const varType = this.parseType();
|