Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 96 additions & 89 deletions alex/AlexTemplate-ghc-nopred
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
{-# LINE 1 "templates/GenericTemplate.hs" #-}
{-# LINE 1 "templates/GenericTemplate.hs" #-}
{-# LINE 1 "<command-line>" #-}
{-# LINE 10 "<command-line>" #-}
# 1 "/usr/include/stdc-predef.h" 1 3 4

# 17 "/usr/include/stdc-predef.h" 3 4












-- -----------------------------------------------------------------------------
-- ALEX TEMPLATE
--
-- This code is in the PUBLIC DOMAIN; you may copy it freely and use
-- it for any purpose whatsoever.

-- -----------------------------------------------------------------------------
-- INTERNALS and main scanner engine



Expand All @@ -35,6 +24,14 @@



-- Do not remove this comment. Required to fix CPP parsing when using GCC and a clang-compiled alex.
#if __GLASGOW_HASKELL__ > 706
#define GTE(n,m) (tagToEnum# (n >=# m))
#define EQ(n,m) (tagToEnum# (n ==# m))
#else
#define GTE(n,m) (n >=# m)
#define EQ(n,m) (n ==# m)
#endif



Expand All @@ -47,34 +44,13 @@



{-# LINE 10 "<command-line>" #-}
{-# LINE 1 "templates/GenericTemplate.hs" #-}
-- -----------------------------------------------------------------------------
-- ALEX TEMPLATE
--
-- This code is in the PUBLIC DOMAIN; you may copy it freely and use
-- it for any purpose whatsoever.

-- -----------------------------------------------------------------------------
-- INTERNALS and main scanner engine

{-# LINE 21 "templates/GenericTemplate.hs" #-}





-- Do not remove this comment. Required to fix CPP parsing when using GCC and a clang-compiled alex.
#if __GLASGOW_HASKELL__ > 706
#define GTE(n,m) (tagToEnum# (n >=# m))
#define EQ(n,m) (tagToEnum# (n ==# m))
#else
#define GTE(n,m) (n >=# m)
#define EQ(n,m) (n ==# m)
#endif
{-# LINE 51 "templates/GenericTemplate.hs" #-}


data AlexAddr = AlexA# Addr#
-- Do not remove this comment. Required to fix CPP parsing when using GCC and a clang-compiled alex.
#if __GLASGOW_HASKELL__ < 503
Expand All @@ -99,13 +75,13 @@ alexIndexInt16OffAddr (AlexA# arr) off =


{-# INLINE alexIndexInt32OffAddr #-}
alexIndexInt32OffAddr (AlexA# arr) off =
alexIndexInt32OffAddr (AlexA# arr) off =
#ifdef WORDS_BIGENDIAN
narrow32Int# i
where
i = word2Int# ((b3 `uncheckedShiftL#` 24#) `or#`
(b2 `uncheckedShiftL#` 16#) `or#`
(b1 `uncheckedShiftL#` 8#) `or#` b0)
(b2 `uncheckedShiftL#` 16#) `or#`
(b1 `uncheckedShiftL#` 8#) `or#` b0)
b3 = int2Word# (ord# (indexCharOffAddr# arr (off' +# 3#)))
b2 = int2Word# (ord# (indexCharOffAddr# arr (off' +# 2#)))
b1 = int2Word# (ord# (indexCharOffAddr# arr (off' +# 1#)))
Expand Down Expand Up @@ -140,49 +116,49 @@ data AlexReturn a
| AlexToken !AlexInput !Int a

-- alexScan :: AlexInput -> StartCode -> AlexReturn a
alexScan input (I# (sc))
= alexScanUser undefined input (I# (sc))
alexScan input__ (I# (sc))
= alexScanUser undefined input__ (I# (sc))

alexScanUser user input (I# (sc))
= case alex_scan_tkn user input 0# input sc AlexNone of
(AlexNone, input') ->
case alexGetByte input of
Nothing ->
alexScanUser user__ input__ (I# (sc))
= case alex_scan_tkn user__ input__ 0# input__ sc AlexNone of
(AlexNone, input__') ->
case alexGetByte input__ of
Nothing ->



AlexEOF
Just _ ->
AlexEOF
Just _ ->



AlexError input'
AlexError input__'

(AlexLastSkip input'' len, _) ->
(AlexLastSkip input__'' len, _) ->



AlexSkip input'' len
AlexSkip input__'' len

(AlexLastAcc k input''' len, _) ->
(AlexLastAcc k input__''' len, _) ->



AlexToken input''' len k
AlexToken input__''' len (alex_actions ! k)


-- Push the input through the DFA, remembering the most recent accepting
-- state it encountered.

alex_scan_tkn user orig_input len input s last_acc =
input `seq` -- strict in the input
let
new_acc = (check_accs (alex_accept `quickIndex` (I# (s))))
alex_scan_tkn user__ orig_input len input__ s last_acc =
input__ `seq` -- strict in the input
let
new_acc = (check_accs (alex_accept `quickIndex` (I# (s))))
in
new_acc `seq`
case alexGetByte input of
Nothing -> (new_acc, input)
Just (c, new_input) ->
case alexGetByte input__ of
Nothing -> (new_acc, input__)
Just (c, new_input) ->



Expand All @@ -191,40 +167,71 @@ alex_scan_tkn user orig_input len input s last_acc =
base = alexIndexInt32OffAddr alex_base s
offset = (base +# ord_c)
check = alexIndexInt16OffAddr alex_check offset

new_s = if GTE(offset,0#) && EQ(check,ord_c)
then alexIndexInt16OffAddr alex_table offset
else alexIndexInt16OffAddr alex_deflt s
in
then alexIndexInt16OffAddr alex_table offset
else alexIndexInt16OffAddr alex_deflt s
in
case new_s of
-1# -> (new_acc, input)
-- on an error, we want to keep the input *before* the
-- character that failed, not after.
_ -> alex_scan_tkn user orig_input (if c < 0x80 || c >= 0xC0 then (len +# 1#) else len)
-1# -> (new_acc, input__)
-- on an error, we want to keep the input *before* the
-- character that failed, not after.
_ -> alex_scan_tkn user__ orig_input (if c < 0x80 || c >= 0xC0 then (len +# 1#) else len)
-- note that the length is increased ONLY if this is the 1st byte in a char encoding)
new_input new_s new_acc
new_input new_s new_acc
}
where
check_accs (AlexAccNone) = last_acc
check_accs (AlexAcc a ) = AlexLastAcc a input (I# (len))
check_accs (AlexAccSkip) = AlexLastSkip input (I# (len))
{-# LINE 198 "templates/GenericTemplate.hs" #-}
check_accs (AlexAccNone) = last_acc
check_accs (AlexAcc a ) = AlexLastAcc a input__ (I# (len))
check_accs (AlexAccSkip) = AlexLastSkip input__ (I# (len))








data AlexLastAcc a
= AlexNone
| AlexLastAcc a !AlexInput !Int
| AlexLastSkip !AlexInput !Int

instance Functor AlexLastAcc where
fmap f AlexNone = AlexNone
fmap f (AlexLastAcc x y z) = AlexLastAcc (f x) y z
fmap f (AlexLastSkip x y) = AlexLastSkip x y

data AlexAcc a user



data AlexLastAcc
= AlexNone
| AlexLastAcc !Int !AlexInput !Int
| AlexLastSkip !AlexInput !Int

data AlexAcc user
= AlexAccNone
| AlexAcc a
| AlexAcc Int
| AlexAccSkip
{-# LINE 242 "templates/GenericTemplate.hs" #-}

-- used by wrappers
iUnbox (I# (i)) = i




























File renamed without changes.
6 changes: 5 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash -eu
# build.sh -- Athena build script
# Copyright (C) 2019 Qiantan Hong <qhong@mit.edu>
# Copyright (C) 2013, 2014 Benjamin Barenblat <bbaren@mit.edu>
#
# This program is free software: you can redistribute it and/or modify it under
Expand Down Expand Up @@ -42,10 +43,13 @@ for package in alex happy; do
fi
done

mkdir -p "$TOP/.cabal-sandbox/bin"

cabal install \
--enable-library-profiling \
--enable-executable-profiling \
--alex-options="--ghc --template=\"$TOP/alex\""
--alex-options="--ghc --template=\"$TOP/alex\""\
--installdir="$TOP/.cabal-sandbox/bin"
# --happy-options="-i -a -d"
# uncomment the trailing '\' on line 42 and the entirety of line 43 to add
# debug info to happy. the '-i' flag outputs a state diagram of the compiled
Expand Down
5 changes: 3 additions & 2 deletions decafc.cabal
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- Copyright (C) 2019 Qiantan Hong <qhong@mit.edu>
-- Copyright (C) 2013, 2014 Benjamin Barenblat <bbaren@mit.edu>
--
-- This file is a part of decafc.
Expand All @@ -19,7 +20,7 @@ author: Benjamin Barenblat
maintainer: bbaren@mit.edu
license: MIT
license-file: LICENSE
extra-source-files: alex/AlexWrapper-6.035
extra-source-files: alex/AlexWrapper-basic
build-type: Simple
tested-with: GHC==7.10.3

Expand All @@ -37,7 +38,7 @@ executable decafc
, split
, transformers
, pretty-show
build-tools: alex >=3.0.2
build-tools: alex == 3.2.4
, happy


Expand Down
7 changes: 6 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ fi
mkdir .cabal-exec/
cd .cabal-exec/

wget -O - "https://downloads.haskell.org/~cabal/cabal-install-latest/cabal-install-3.0.0.0-i386-unknown-linux.tar.xz" |
if [[ $(uname) -eq "Darwin" ]]; then
arch=x86_64-apple-darwin17.7.0
else
arch=i386-unknown-linux
fi
wget -O - "https://downloads.haskell.org/~cabal/cabal-install-latest/cabal-install-3.0.0.0-${arch}.tar.xz" |
xzcat |
tar -xf -
2 changes: 1 addition & 1 deletion src/Scanner.x
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Scanner ( ScannedToken(..)
) where
}

%wrapper "6.035"
%wrapper "basic"


----------------------------------- Tokens ------------------------------------
Expand Down