A good example is expression terminators (new lines in the case of Stoffle) they are considered when building the AST, but we don't need a specific node type to represent a terminator. The word abstract in AST refers to our ability to abstract away parts that, in previous steps, were explicitly present. As the name implies, we are dealing with a tree data structure, with its root representing the program itself and the children of this program node being the many expressions that make up our program. The tree created by the parser is, generally, called an abstract syntax tree (AST). When it finishes its task, we will end up with data that are finally able to express how each part of our program nests and relates to each other. Thus, the parser has the job of creating a tree from this sequence of characters. However, we are still left with data that are totally flat, something that still does not appropriately represent the nested nature of source code. Then, as shown in the previous article in this series, the lexer groups these characters into sensible data structures called tokens. We start with the source code, a raw sequence of characters. In Stoffle, we do not have such a structure, so to express the same we are forced to be more verbose: A nice example is Ruby's elsif construct. Syntactic sugar is an expression used to denote constructs that make a language easier to use, but whose removal would not cause the programming language to lose functionality. We may or may not handle some of the more interesting extras in a later article in this series. We will focus on the essentials and leave improvements as a challenge to you, my dear reader. The amount of work needed to create some extra-nice features, such as awesome error messages, is clearly greater and disproportionate to the effort required to get the basics up and running. I feel that a parser is a perfect example of the Pareto principle.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |