modified: app/Lexer.hs
modified: app/Parser.hs modified: as/test.as
This commit is contained in:
parent
cda162f77d
commit
b0c91f0579
15
app/Lexer.hs
15
app/Lexer.hs
@ -5,7 +5,7 @@ import Data.Char (ord)
|
||||
|
||||
import Debug.Trace;
|
||||
|
||||
data TokenType = Quotes | Dot | Comma | Colon | EndStatement | Numeric | Literal | Assignment | OpenParen | CloseParen | OpenCurved | CloseCurved | OpenSquared | CloseSquared | Arithmetic | Comparison | Bitwise | Empty | SoftComp | CompositeAssign deriving (Show, Eq)
|
||||
data TokenType = Quotes | Dot | Comma | Colon | EndStatement | Numeric | Literal | Assignment | OpenParen | CloseParen | OpenCurved | CloseCurved | OpenSquared | CloseSquared | Arithmetic | Comparison | Bitwise | Empty | SoftComp | CompositeAssign | VarKeyword deriving (Show, Eq)
|
||||
data Token = Token {value :: [Char], token_type :: TokenType} deriving (Show)
|
||||
|
||||
-- makes token from single char
|
||||
@ -36,7 +36,18 @@ makeTokenFromEveryChar code = map (\c -> parseSingleToken c) code
|
||||
|
||||
-- entry point, which should be called to start lexer.
|
||||
tokenize :: [Char] -> [Token]
|
||||
tokenize sourceCode = excludeEmpty (checkFor (makeTokenFromEveryChar sourceCode))
|
||||
tokenize sourceCode = keyworder (excludeEmpty (checkFor (makeTokenFromEveryChar sourceCode)))
|
||||
|
||||
keyworder :: [Token] -> [Token]
|
||||
keyworder t
|
||||
| tv == "var" = (Token tv VarKeyword):(keyworderG tt)
|
||||
| otherwise = th:(keyworderG tt)
|
||||
where th = head t
|
||||
tt = tail t
|
||||
tv = value th
|
||||
|
||||
keyworderG :: [Token] -> [Token]
|
||||
keyworderG t = if length t > 0 then keyworder t else []
|
||||
|
||||
excludeEmpty :: [Token] -> [Token]
|
||||
excludeEmpty t = filter (\c -> (token_type c) /= Empty) t
|
||||
|
@ -7,13 +7,13 @@ data StmtType = Void | VariableDeclaration | AssignmentExpression | BinaryExpres
|
||||
|
||||
data TreeNode = TreeNode { stype :: StmtType, children :: [TreeNode], val :: [Char] } deriving (Show, Eq)
|
||||
|
||||
parseTokens :: [Token] -> [TreeNode]
|
||||
parseTokens :: [Token] -> TreeNode
|
||||
parseTokens tt
|
||||
| k == VariableDeclaration = parseVariableDeclaration 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 =
|
||||
parseVariableDeclaration tt = TreeNode VariableDeclaration [] []
|
@ -1 +1 @@
|
||||
var i: int = 0;
|
||||
2 + 2 * 2;
|
Loading…
x
Reference in New Issue
Block a user