Reputation: 9
I want to write a simple compiler. in its grammer each line contains (just) a statement.
1) first the scanner does his job; so for each line we have tokens.
2) for each line we check its type(if stm, for stm, var defintion, end, ...). In this step there is lines that they types are diagnosed. for example:
func definition
var def
assignment
for stm
...
end
end
3) and now it is time to check lines order.
In other word we check:
1) each word alone (scanner)
2) each line alone (line grammer)
3) block of lines (programming language grammer)
My question: The parse step is 2? or 3? or 2 & 3? and i think it is not a standard approach for a parser. if i think right, what is wrong? and what is the solution?
Upvotes: 0
Views: 58
Reputation: 310840
No it isn't standard, and it almost certainly won't work. For one thing, lines are insignificant in most programming languages. For another, order checking isn't an explicit phase. It's all part of grammar recognition. Far too broad to cover here. I suggest you read a good book.
Upvotes: 1