From 5d40ca411bed8014f9bf081436208d831ac5c972 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Thu, 17 Mar 2016 10:36:59 +0100 Subject: [PATCH] some small fixes --- deliverables/p1/p1.tex | 1 - deliverables/p1/pre.tex | 2 +- grammar/grammar.txt | 2 ++ lex.dcl | 3 --- lex.icl | 7 +++---- parse.dcl | 2 +- parse.icl | 8 ++++---- spl.icl | 2 +- 8 files changed, 12 insertions(+), 15 deletions(-) diff --git a/deliverables/p1/p1.tex b/deliverables/p1/p1.tex index 9b66b55..11b4699 100644 --- a/deliverables/p1/p1.tex +++ b/deliverables/p1/p1.tex @@ -5,7 +5,6 @@ \section{Introduction} \begin{frame} \frametitle{\textsc{SPL}} - \framesubtitle{Acronym for: \textsc{SPL}: Parser and Lexer} \begin{block}{Features} \begin{itemize} \item Implementation language: diff --git a/deliverables/p1/pre.tex b/deliverables/p1/pre.tex index c77df3b..5cc364c 100644 --- a/deliverables/p1/pre.tex +++ b/deliverables/p1/pre.tex @@ -5,7 +5,7 @@ \usepackage{clean} \title[cc1516: Lexing \& Parsing]{SPL} -\subtitle{SPL: Lexical Analysis and Parsing} +\subtitle{\texttt{ ::= 'and' }} \author[P. Jager, M. Lubbers]{Pim Jager\inst{1}\and Mart Lubbers\inst{1}} \institute[Radboud University]{% \inst{1}% diff --git a/grammar/grammar.txt b/grammar/grammar.txt index ce6732b..f78b879 100644 --- a/grammar/grammar.txt +++ b/grammar/grammar.txt @@ -1,3 +1,5 @@ + ::= * + + ::= '(' * ')' ['::' * + '}' ::= + '->' | diff --git a/lex.dcl b/lex.dcl index a6cf7c6..46c1713 100644 --- a/lex.dcl +++ b/lex.dcl @@ -2,7 +2,6 @@ definition module lex from Data.Either import :: Either from yard import :: Error - from AST import :: Pos :: Token :== (Pos, TokenValue) @@ -53,8 +52,6 @@ from AST import :: Pos | LesserToken // < | BiggerToken // > | ExclamationToken // ! - //Special tokens - | EndOfFileToken // EOF :: LexerOutput :== Either Error [Token] diff --git a/lex.icl b/lex.icl index ce642a1..aa34987 100644 --- a/lex.icl +++ b/lex.icl @@ -7,9 +7,10 @@ import StdBool import StdList import StdChar import StdString +import StdTuple import yard -from AST import :: Pos(..) +import AST :: LexItem = LexToken Int TokenValue @@ -19,9 +20,7 @@ from AST import :: Pos(..) | LexItemError String lexer :: [Char] -> LexerOutput -lexer r = case runParser (lexProgram 1 1) r of - (Right p, _) = Right p - (Left e, _) = Left e +lexer r = fst $ runParser (lexProgram 1 1) r lexProgram :: Int Int -> Parser Char [Token] lexProgram line column = lexToken >>= \t->case t of diff --git a/parse.dcl b/parse.dcl index c5d2724..111540c 100644 --- a/parse.dcl +++ b/parse.dcl @@ -4,7 +4,7 @@ from Data.Either import :: Either from Data.Maybe import :: Maybe from StdString import class toString -import lex +from lex import :: LexerOutput, :: Error, :: Token, :: TokenValue, :: Pos from AST import :: AST :: ParserOutput :== Either Error AST diff --git a/parse.icl b/parse.icl index 9aabea3..3679124 100644 --- a/parse.icl +++ b/parse.icl @@ -68,7 +68,6 @@ parseStmt = parseIfStmt <|> parseWhileStmt <|> parseBlock = parseBCBraces (many parseStmt) parseOneLine :: Parser Token [Stmt] - //first pure makes singleton list from the statement parseOneLine = pure <$> parseStmt parseFunType :: Parser Token FunType @@ -122,8 +121,8 @@ parseExpr = //Operators in order of binding strength parseOpL :: (Parser Token Op2) (Parser Token Expr) -> Parser Token Expr parseOpL ops prev = peekPos >>= \pos-> prev >>= \e1->many ( - ops >>= \op->prev >>= \e->pure (op, e) - ) >>= \moe->foldM (\e->(\(op,e2)->pure $ Op2Expr pos e op e2)) e1 moe + ops >>= \op->prev >>= \e->pure (op, e)) + >>= \moe->foldM (\e->(\(op,e2)->pure $ Op2Expr pos e op e2)) e1 moe parseBasicExpr :: Parser Token Expr parseBasicExpr = peekPos >>= \pos -> @@ -139,7 +138,8 @@ parseExpr = //Operators in order of binding strength (VarExpr pos <$> parseVarDef) parseFunCall :: Parser Token FunCall -parseFunCall = FunCall <$> parseIdent <*> (parseBBraces $ parseSepList CommaToken parseExpr) +parseFunCall = FunCall <$> parseIdent <*> + (parseBBraces $ parseSepList CommaToken parseExpr) parseVarDef :: Parser Token VarDef parseVarDef = liftM2 VarDef diff --git a/spl.icl b/spl.icl index f398f90..28b95fb 100644 --- a/spl.icl +++ b/spl.icl @@ -69,7 +69,7 @@ Start w printTokens :: [Token] -> String printTokens ts = concat $ flatten $ map pt ts where - pt ({line,col},token) = [toString line, ":", + pt ({line,col},token) = [toString line, ":", toString col, ": ", printToString token, "\n"] parseArgs :: *World -> (Opts, *World) -- 2.20.1