|
|
@ -520,7 +520,10 @@ class BaseParser(in: Scanner) extends Parser(in) {
|
|
|
|
val res = parseExpression
|
|
|
|
val res = parseExpression
|
|
|
|
accept('}')
|
|
|
|
accept('}')
|
|
|
|
res
|
|
|
|
res
|
|
|
|
case _ => abort(s"Illegal start of simple expression")
|
|
|
|
case _ =>
|
|
|
|
|
|
|
|
println(in.peek)
|
|
|
|
|
|
|
|
println(in.peek1)
|
|
|
|
|
|
|
|
abort(s"Illegal start of simple expression")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def parseUAtom: Exp = if (in.hasNext(isOperator)) {
|
|
|
|
def parseUAtom: Exp = if (in.hasNext(isOperator)) {
|
|
|
@ -579,7 +582,7 @@ class BaseParser(in: Scanner) extends Parser(in) {
|
|
|
|
val body = parseExpression
|
|
|
|
val body = parseExpression
|
|
|
|
VarDec(name, tp, rhs, body).withPos(pos)
|
|
|
|
VarDec(name, tp, rhs, body).withPos(pos)
|
|
|
|
case Keyword("while") =>
|
|
|
|
case Keyword("while") =>
|
|
|
|
val pos = accept("while").pos
|
|
|
|
val pos = in.next().pos
|
|
|
|
accept('(')
|
|
|
|
accept('(')
|
|
|
|
val cond = parseSimpleExpression
|
|
|
|
val cond = parseSimpleExpression
|
|
|
|
accept(')')
|
|
|
|
accept(')')
|
|
|
@ -648,7 +651,7 @@ class SyntacticSugarParser(in: Scanner) extends BaseParser(in) {
|
|
|
|
suf + "$" + next
|
|
|
|
suf + "$" + next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override def parseSimpleExpression = in.peek match { // !!!
|
|
|
|
override def parseSimpleExpression = in.peek match {
|
|
|
|
case Keyword("if") =>
|
|
|
|
case Keyword("if") =>
|
|
|
|
val pos = in.next().pos
|
|
|
|
val pos = in.next().pos
|
|
|
|
accept('(')
|
|
|
|
accept('(')
|
|
|
@ -667,17 +670,11 @@ class SyntacticSugarParser(in: Scanner) extends BaseParser(in) {
|
|
|
|
|
|
|
|
|
|
|
|
override def parseExpression = {
|
|
|
|
override def parseExpression = {
|
|
|
|
// NOTE: parse expression terminates when it parse a simples expression.
|
|
|
|
// NOTE: parse expression terminates when it parse a simples expression.
|
|
|
|
// syntax sugar allows to have an other expression after it. !!!
|
|
|
|
// syntax sugar allows to have an other expression after it.
|
|
|
|
var res = in.peek match {
|
|
|
|
var res = super.parseExpression
|
|
|
|
case Keyword("val") | Keyword("var") | Keyword("while") =>
|
|
|
|
if(in.hasNext(_ match {case Delim(';') => true; case _ => false})){
|
|
|
|
super.parseExpression
|
|
|
|
accept(';')
|
|
|
|
case _ =>
|
|
|
|
res = Let(freshName(), UnknownType, res, parseExpression).withPos(res.pos)
|
|
|
|
var simp = parseSimpleExpression
|
|
|
|
|
|
|
|
if(isNewLine(in.peek)) {
|
|
|
|
|
|
|
|
accept(';')
|
|
|
|
|
|
|
|
simp = Let(freshName(), UnknownType, simp, parseExpression).withPos(simp.pos)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
simp
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res
|
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -764,30 +761,24 @@ class FunctionParser(in: Scanner) extends SyntacticSugarParser(in) {
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* This function parse types.
|
|
|
|
* This function parse types.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* TODO !!!
|
|
|
|
* TODO
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
override def parseType = in.peek match {
|
|
|
|
override def parseType = in.peek match {
|
|
|
|
case Delim('(') =>
|
|
|
|
case Delim('(') =>
|
|
|
|
accept('(')
|
|
|
|
accept('(')
|
|
|
|
val list = parseList[Type](parseType, ',', tok => tok match {
|
|
|
|
val list = parseList[Type](parseType, ',', _ match {
|
|
|
|
case Delim(')') => false;
|
|
|
|
case Delim(')') => false; case _ => true
|
|
|
|
case _ => true
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
val argList = list map { tp => ("", tp)}
|
|
|
|
val args = list map { tp => ("", tp)}
|
|
|
|
accept("=>")
|
|
|
|
accept("=>")
|
|
|
|
val rtp = parseType
|
|
|
|
FunType(args, parseType)
|
|
|
|
FunType(argList, rtp)
|
|
|
|
|
|
|
|
case _ =>
|
|
|
|
case _ =>
|
|
|
|
val typ = super.parseType
|
|
|
|
var ty = super.parseType
|
|
|
|
if(in.peek == Delim('=') && in.peek1 == Ident(">")) {
|
|
|
|
if(in.peek == Delim('=') && in.peek1 == Ident(">")) {
|
|
|
|
accept("=>")
|
|
|
|
accept("=>")
|
|
|
|
val rtp = super.parseType
|
|
|
|
ty = FunType(List(("", ty)), super.parseType)
|
|
|
|
val typList: List[(String, Type)] = List(("", typ))
|
|
|
|
}
|
|
|
|
FunType(typList, rtp)
|
|
|
|
ty
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
typ
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|