Fixed bug in gcc invocation; added stdlib tests

This commit is contained in:
Dmitry Boulytchev 2020-01-14 17:08:35 +03:00
parent faca5c6e0e
commit 369f80f7e8
11 changed files with 515 additions and 74 deletions

View file

@ -7,7 +7,7 @@
-- name --- a string describing the meaning of the expression in free form
-- (e.g. "identifier", "string constant", etc.), used for error
-- reporting
fun createRegexp (r, name) {
public fun createRegexp (r, name) {
[regexp (r), name]
}
@ -71,20 +71,20 @@ fun matcherCreate (buf, pos, line, col) {
matchRegexp]
}
fun show (m) {
public fun show (m) {
m [0] ()
}
fun endOf (m) {
public fun endOf (m) {
m [1] ()
}
fun matchString (m, s) {
public fun matchString (m, s) {
m [2] (s)
}
-- Matches against a regexp
fun matchRegexp (m, r) {
public fun matchRegexp (m, r) {
m [3] (r)
}
@ -92,62 +92,3 @@ fun matchRegexp (m, r) {
public fun matcherInit (buf) {
matcherCreate (buf, 0, 1, 1)
}
local m = matcherInit (" -- asdasdakm ,m.,msd .,m.,asd\n \n\n abc");
local
lident = createRegexp ("[a-z][a-zA-Z_]*", "lowercase identifier"),
uident = createRegexp ("[A-Z][a-zA-Z_]*", "uppercase identifier"),
ws = createRegexp ("\\([ \t\n]\\|--[^\n]*\n\\)*", "whitespace"),
str = createRegexp ("""\([^""]\|""""\)*""", "string literal"),
decimal = createRegexp ("[0-9]+", "decimal literal"),
chr = createRegexp ("'[^']'", "character literal");
fun token (s) {
fun (m) {m.matchString (s)}
}
fun lid (m) {
matchRegexp (m, lident)
}
fun uid (m) {
matchRegexp (m, uident)
}
fun const (m) {
matchRegexp (m, decimal)
}
infixl "@" before "*" (p, f) {
fun (m) {
case p (m) of
Succ (m, x) -> Succ (m, f (x))
| err -> err
esac
}
}
infixr "|>" after "!!" (l, r) {
fun (m) {
case l (m) of
Succ (m, s) -> r (s) (m)
| err -> err
esac
}
}
infixr "||" after "|>" (l, r) {
fun (m) {
case l (m) of
s@Succ (_, _) -> s
| err -> r (m)
esac
}
}
local expr = lid @ fun (s) {Lid (s)} || const @ fun (s) {Dec (s)},
assn = lid |> fun (id) {token (":=") |> fun (s) {expr @ fun (e) {Assn (id, e)}}};
printf ("%s\n", case assn (matcherInit ("x:=3")) of Fail (err) -> err | Succ (_, s) -> s.string esac)