Add printc and exit builtin functions

This commit is contained in:
2024-10-04 18:26:10 +02:00
parent fdf56ce9d0
commit 35742aa525
20 changed files with 139 additions and 53 deletions

View File

@@ -34,27 +34,24 @@ import Text.Megaparsec
import qualified Text.Megaparsec.Char.Lexer as Lexer
import Text.Megaparsec.Char
( alphaNumChar
-- , char
, char
, letterChar
, space1
-- , string
, string
)
import Control.Applicative (Alternative(..))
import Data.Maybe (isJust)
-- import Data.Functor (($>))
type Parser = Parsec Void Text
literalP :: Parser Literal
literalP
= {- HexadecimalLiteral <$> (string "0x" *> lexeme Lexer.hexadecimal)
<|> -} IntegerLiteral <$> Lexer.signed space integerP
{- <|> CharacterLiteral <$> lexeme charP
<|> BooleanLiteral <$> (symbol "true" $> True)
<|> BooleanLiteral <$> (symbol "false" $> False)
= HexadecimalLiteral <$> (string "0x" *> lexeme Lexer.hexadecimal)
<|> IntegerLiteral <$> Lexer.signed space integerP
<|> CharacterLiteral <$> lexeme charP
where
charP = fromIntegral . fromEnum
<$> between (char '\'') (char '\'') Lexer.charLiteral -}
<$> between (char '\'') (char '\'') Lexer.charLiteral
{-
typeDefinitionP :: Parser Declaration
typeDefinitionP = TypeDefinition
@@ -73,7 +70,7 @@ termP = choice
operatorTable :: [[Operator Parser Expression]]
operatorTable =
[ unaryOperator
-- , factorOperator
, factorOperator
, termOperator
]
where
@@ -81,10 +78,10 @@ operatorTable =
[ prefix "-" NegationExpression
, prefix "+" id
]
{- factorOperator =
factorOperator =
[ binary "*" ProductExpression
, binary "/" DivisionExpression
] -}
-- , binary "/" DivisionExpression
]
termOperator =
[ binary "+" SumExpression
, binary "-" SubtractionExpression