

But how do they get that meaning? Its through the interaction of the symbol and the environment.

It is at this point that we arrive at the Syntax Directed Definition (also known as Attribute Grammar). What does the + operator represent? What does a represent? What does = represent (as an action)? Is the operation semantically valid (i.e you are not adding a character and a number)?įor this reason, you need to also specify the semantic rules for a language.

Which are then passed on to the parser, who creates the following syntax tree: =īy now though, you have recognized that this language construct is valid and well formed, but you have done nothing to derive its meaning. Then by the end of the lexical analysis, you have the following tokens (let's assume there are actual token definitions that look like them in your language's spec, but let's keep it simple for now): INT(int) You already know, that in order to specify a language, at the lexical and at the syntactic level, you have to different constructs, and those are tokens (implemented mostly by regular expressions), which specify the lexical structure of some code, and the (context free) grammar, which specifies the structure of some code at the syntactic level (providing later phases of the compiler with a easier to handle representation - the abstract syntax tree - while doing syntactic sanity checkings itself, i.e making sure that the input is valid and not syntactically malformed).įor instance, assuming you have the following small code snippet: int c = a + 5 Well, in order for you not to be confused, you have to take things from the start.
