Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def vardecl: Parser[List[Decl]] = (identifiers <~ ":") ~ types <~ ";" ^^
- {
- case il ~ typ => il.map((x) => VarDecl(x, typ))
- }
- def constdecl: Parser[List[Decl]] = ("final" ~> types) ~ (ident <~ "=") ~ (literal <~ ";") ^^
- {
- case typ ~ id ~ value => List(ConstDecl(Id(id), typ, value))
- }
- def abstractmethoddecl: Parser[List[Decl]] = ("abstract" ~> returnType) ~ ident ~ ("(" ~> paramslist <~ ")" ~ ";") ^^
- {
- case a ~ b ~ c => List(MethodAbstractDecl(a, Id(b), c))
- }
- def classdecl: Parser[ClassDecl] = "class" ~> ident ~ opt("extends" ~> ident) ~ ("{" ~> rep(listAttribute) <~ "}") ^^
- {
- case id ~ Some(sup) ~ d => d match {
- case Nil => ClassDecl(Id(id), Id(sup), List[ClassDecl]())
- case head :: tail => ClassDecl(Id(id), Id(sup), tail.foldRight(head)((b, x) => b ::: x))
- }
- case id ~ None ~ d => d match {
- case Nil => ClassDecl(Id(id), null, List[ClassDecl]())
- case head :: tail => ClassDecl(Id(id), null, tail.foldRight(head)((b, x) => b ::: x))
- }
- }
- def listAttribute:Parser[List[Decl]] = constdecl | vardecl | abstractmethoddecl | method
- def method: Parser[List[Decl]] = methoddecl | constructordecl
- def methoddecl: Parser[List[Decl]] = (returnType) ~ ident ~ ("(" ~> paramslist <~ ")") ~ blockstmt ^^
- {
- case typ ~ id ~ pramlist ~ stm => List(MethodImpDecl(typ, Id(id), pramlist, stm))
- }
- def constructordecl: Parser[List[Decl]] = ident ~ ("(" ~> paramslist <~ ")") ~ blockstmt ^^
- {
- case id ~ pramlist ~ stm => List(MethodImpDecl(null, Id(id), pramlist, stm))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement