User Tools

Site Tools


semantic_tutorial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
semantic_tutorial [2016/12/01 17:07]
deva
semantic_tutorial [2016/12/08 13:25] (current)
deva [Step 5: Type checking]
Line 115: Line 115:
   * For each //​expression rule//, do the necessary type checking and set the semantic value of the left-hand side of the rule. The semantic value of the left-hand side can be referenced by the ''​$$''​ symbol.   * For each //​expression rule//, do the necessary type checking and set the semantic value of the left-hand side of the rule. The semantic value of the left-hand side can be referenced by the ''​$$''​ symbol.
     * For example, the rule of number literals will have the following code: ''​$$ = new type(integer);''​     * For example, the rule of number literals will have the following code: ''​$$ = new type(integer);''​
-    * In case of the rule of a single variable name, we have to ask the type of the variable from the symbol table. (Note, that we have earlier checked in this rule whether the variable was in the symbol table, so after this check we are safe to retrieve the variable data.) ''​$$ = new type(symboltable[*$1].var_type);''​+    * In case of the rule of a single variable name, we have to ask the type of the variable from the symbol table. (Note, that we have earlier checked in this rule whether the variable was in the symbol table, so after this check we are safe to retrieve the variable data.) ''​$$ = new type(symbol_table[*$1].var_type);''​
     * In case of expressions build using operators, there is need for type checking the arguments. For example, the rule for addition will have this C++ code:     * In case of expressions build using operators, there is need for type checking the arguments. For example, the rule for addition will have this C++ code:
 <​code>​ <​code>​
semantic_tutorial.1480608479.txt.gz · Last modified: 2016/12/01 17:07 by deva