Porcelain/app/Parser.hs
alterdekim b0c91f0579 modified: app/Lexer.hs
modified:   app/Parser.hs
	modified:   as/test.as
2024-11-07 02:45:38 +03:00

19 lines
681 B
Haskell

module Parser where
import Control.Exception
import Lexer (Token (..), TokenType (..) )
data StmtType = Void | VariableDeclaration | AssignmentExpression | BinaryExpression deriving (Show, Eq)
data TreeNode = TreeNode { stype :: StmtType, children :: [TreeNode], val :: [Char] } deriving (Show, Eq)
parseTokens :: [Token] -> TreeNode
parseTokens tt
| k == VarKeyword = parseVariableDeclaration tt
| otherwise = TreeNode Void [] ""
where t = head tt
k = token_type t
-- Keyword(var) Literal Colon Literal Assignment (Expression) EndStatement
parseVariableDeclaration :: [Token] -> TreeNode
parseVariableDeclaration tt = TreeNode VariableDeclaration [] []