Commit 19526cc2 authored by Michal Terepeta's avatar Michal Terepeta

Fix parsing of memory accesses in tests

Apparently the current parser would fail on any memory accesses, both
loads and stores. In case of the former it's enough to try parsing the
memory accesses before variables. For stores, we can use backtracking
so that we don't consume the initial "m" of memory assignemnt thinking
that it's a variable identifier.
parent cda3ec8d
......@@ -30,6 +30,7 @@ goldensTests = Framework.testGroup "Goldens tests"
, "test2"
, "test3"
, "test4"
, "test5"
, "if-test"
, "if-test2"
, "if-test3"
......
......@@ -47,6 +47,9 @@ reservedOp = P.reservedOp lexer
whitespace :: CharParser () ()
whitespace = P.whiteSpace lexer
brackets :: CharParser () a -> CharParser () a
brackets = P.brackets lexer
-- Expressions:
expr :: Parser Expr
expr = buildExpressionParser table factor
......@@ -60,8 +63,8 @@ expr = buildExpressionParser table factor
op o f assoc = Infix (do {reservedOp o; return f} <?> "operator") assoc
factor = parens expr
<|> lit
<|> fetchVar
<|> load
<|> fetchVar
<?> "simple Expression"
bool :: Parser Bool
......@@ -75,12 +78,7 @@ lit = (natural >>= (return . Lit . Int))
<?> "lit"
loc :: Char -> Parser x -> Parser x
loc s addr = try (lexeme (do { char' s
; char' '['
; a <- addr
; char' ']'
; return a
}))
loc s addr = try (lexeme (char' s >> brackets addr))
<?> "loc"
var :: Parser String
......@@ -104,7 +102,7 @@ labl = lexeme (do { id <- identifier
<?> "label"
mid :: Parser Insn
mid = asst
mid = try asst
<|> store
<?> "assignment or store"
......
-- Tests parsing of memory stores and loads.
procName(mm, aa) {
L0:
m[aa] = m[mm] + m[aa]
ret(m[aa])
}
-- Tests parsing of memory stores and loads.
procName(mm, aa) {
L0:
m[aa] = m[mm] + m[aa]
ret(m[aa])
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment