Differences

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

Link to this comparison view

alf:teme:tema_en_3 [2018/04/22 15:56]
alexandru.radovici
alf:teme:tema_en_3 [2018/04/24 23:59] (current)
alexandru.radovici
Line 35: Line 35:
 You may use your grammar file or the [[https://​github.com/​alexandruradovici/​alf-alfy-language-public/​blob/​master/​alfy.jison|reference file]] You may use your grammar file or the [[https://​github.com/​alexandruradovici/​alf-alfy-language-public/​blob/​master/​alfy.jison|reference file]]
  
-<​hidden>​ 
-<​note>​ 
-If you want to use your grammar file, please make the following modifications:​ 
-  - write real instead of float 
-  - the for grammar is //for variable from expression to (or downto) expression step expressison run// 
-  - add the line number (yylineno+1) to all the AST nodes 
-  - the operator precedence is different, please look in the reference jison file 
-  - at the //empty// value, modify attribute op: '​empty'​ to t:'​empty'​ 
-  - the structure elements must be reversed 
-</​note>​ 
-</​hidden>​ 
  
 ===== Hints for solving the homework ===== ===== Hints for solving the homework =====
Line 52: Line 41:
   * Determine all the variable types in the symbol table   * Determine all the variable types in the symbol table
   * Determine the types for all the instructions that return a result   * Determine the types for all the instructions that return a result
-  * While determinig ​the types, write the errors ​+  * While determining ​the types, write the errors ​
   ​   ​
 ===== Output file ===== ===== Output file =====
Line 88: Line 77:
 The context object stores The context object stores
   * the variable declared in that context   * the variable declared in that context
-  * the functions ​declared in that context +  * the message ​declared in that context 
-  * the clases ​declared in that context+  * the classes ​declared in that context
   * the parent context id (position in the symbol_table array)   * the parent context id (position in the symbol_table array)
-  * the type of the context (script ​or message) +  * the type of the context (module ​or message) 
-  * the name of the message which context it is (unless this is not the script+  * the name of the message which context it is (unless this is not the module) 
-  * the type of the return value of the message which context it is (unless this is not the script)+  * the name of the class which context it is (unless this is not the module
 +  * the type of the return value of the message which context it is (unless this is not the module)
  
 <​note>​ <​note>​
 Context objects are generated by Context objects are generated by
-  * the main script ​+  * the main module ​
   * a message definition   * a message definition
 +  * a class
 </​note>​ </​note>​
  
Line 128: Line 119:
                "​from": ​ // the first index                "​from": ​ // the first index
                "​to":​ // the last index                "​to":​ // the last index
-               // for struct+               // for class
                "​elements":​ [ // a list of array elements (the node form the AST)                "​elements":​ [ // a list of array elements (the node form the AST)
                   {                   {
Line 141: Line 132:
    "​parent":​ 0, // the parent context position in the symbol_table (except of the main script that has no parent), usually 0,     "​parent":​ 0, // the parent context position in the symbol_table (except of the main script that has no parent), usually 0, 
    "​type":​ // the type of the     "​type":​ // the type of the 
-   "​message":​ // the function ​name if this is a function context+   "​message":​ // the message ​name if this is a function context 
 +   "​class":​ // the class name if the context is in a message that is in a class
    "​return_value":​ // the return type of the function if this is a function context    "​return_value":​ // the return type of the function if this is a function context
 } }
Line 154: Line 146:
       }       }
    },    },
-   "​functions": {},+   "​messages": {},
    "​types":​ {    "​types":​ {
       "​school":​ {       "​school":​ {
-         "​type":​ "struct",+         "​type":​ "class",
          "​line":​ 6,          "​line":​ 6,
          "​elements":​ [          "​elements":​ [
Line 185: Line 177:
 ==== Expression return type ==== ==== Expression return type ====
 For each of the following nodes, determine the return type For each of the following nodes, determine the return type
-  * expression+  * exp
   * value   * value
-  * id +  * identifier 
-  * value_of_function +  * return 
-  * element_of_array +  * element 
-  * element_of_struct+  * property 
 +  * dispatch
  
-Set type the by adding a parameter ​in the node.+Set type the by adding a parameter ​type in the node.
  
 <​note>​ <​note>​
 When searching for a variable, the algorithm is: When searching for a variable, the algorithm is:
-  * if it is a function ​context, search the local variables+  * if it is a message ​context, search the local variables
   * if not found, search the parameters   * if not found, search the parameters
-  * if not found, search the script ​context local variables+  * if not found, search the class context local variables
  
-  * if it is the script ​context, search the local variables+  * if it is the module ​context, search the global ​variables
 </​note>​ </​note>​
  
Line 206: Line 199:
 <code javascript>​ <code javascript>​
 {    {   
-   "​type": "expression",+   "​id": "exp",
    "​op":​ "​=",​    "​op":​ "​=",​
    "​left":​ {    "​left":​ {
-      "type": "expression",+      "id": "exp",
       "​op":​ "​mod",​       "​op":​ "​mod",​
       "​left":​ {       "​left":​ {
-         "​type": "​id",​+         "​id": "​id",​
          "​value":​ "​n",​          "​value":​ "​n",​
          "​line":​ 8,          "​line":​ 8,
          "​symbol":​ 1,          "​symbol":​ 1,
-         "​t": "​int"​+         "​type": "​int"​
       },       },
       "​right":​ {       "​right":​ {
-         "​type": "​id",​+         "​id": "​id",​
          "​value":​ "​i",​          "​value":​ "​i",​
          "​line":​ 8,          "​line":​ 8,
          "​symbol":​ 1,          "​symbol":​ 1,
-         "​t": "​int"​+         "​type": "​int"​
       },       },
       "​line":​ 8,       "​line":​ 8,
Line 230: Line 223:
    },    },
    "​right":​ {    "​right":​ {
-      "type": "​value",​ +      "id": "​value",​ 
-      "t": "​int",​+      "type": "​int",​
       "​value":​ 0,       "​value":​ 0,
       "​line":​ 8,       "​line":​ 8,
Line 238: Line 231:
    "​line":​ 8,    "​line":​ 8,
    "​symbol":​ 1,    "​symbol":​ 1,
-   "​t": "​logic"​+   "​type": "​logic"​
 } }
 </​code>​ </​code>​
Line 251: Line 244:
   * functions are defined before being used   * functions are defined before being used
   * array indexes are numbers   * array indexes are numbers
-  * struct elements ​exist+  * class properties ​exist
   * the variable for element_of_array is an array   * the variable for element_of_array is an array
-  * the variable for element_of_struct ​is a struct+  * the variable for a property ​is a class
   * variables are not redefined ​   * variables are not redefined ​
   * functions are not redefined ​   * functions are not redefined ​
Line 349: Line 342:
 </​code>​ </​code>​
  
-=== UNDEFINED_FUNCTION ​===+=== UNDEFINED_MESSAGE ​===
 The error occurs when a function call is made to a function that is not defned. The error occurs when a function call is made to a function that is not defned.
  
Line 355: Line 348:
 <code javascript>​ <code javascript>​
 { {
-   id: // function ​name+   id: // message ​name
 } }
 </​code>​ </​code>​
Line 378: Line 371:
 } }
  
-=== NOT_STRUCT_ELEMENT ​===+=== NOT_CLASS_PROPERTY ​===
 The error occurs when an element is not part of that struct. The error occurs when an element is not part of that struct.
  
Line 384: Line 377:
 <code javascript>​ <code javascript>​
 { {
-   struct: // struct name +   class: // struct name 
-   element: // element name+   property: // element name
 } }
 </​code>​ </​code>​
  
-=== NOT_STRUCT ​=== +=== NOT_CLASS ​=== 
-The error occurs when an element ​is requested for a variable that is not a struct ​type+The error occurs when a property ​is requested for a variable that is not a class type
  
 == Elements == == Elements ==
Line 419: Line 412:
 </​code>​ </​code>​
  
-=== VALUE_OUTSIDE_FUNCTION ​=== +=== RETURN_OUTSIDE_MESSAGE ​=== 
-The error occurs when a value statement (value_of_function ​node) is used outside a function+The error occurs when a value statement (return ​node) is used outside a message
  
 == Elements == == Elements ==
Line 511: Line 504:
 Bonus will be awarded only if all other tests pass. Bonus will be awarded only if all other tests pass.
 </​note> ​ </​note> ​
 +
 +===== Copying =====
 +
 +The homework is individual. Any attempt of copying will result in **0p** for the homework. Automated anti copying system will be used.
 +
 +
 +===== Questions =====
 +
 +If you have any questions related to the homework, please ask them by posting an issue on the github [[https://​github.com/​alexandruradovici/​alf2018.git|repository]] with the title format //​[calculator] <your question title>//​. You will need a github account for that.
 +
 +<note warning>
 +**DO NO POST ANY CODE**. This is considered copying and will result in a 0p homework for you.
 +</​note>​
 +
 +If you want to receive an email when issues are posted or when there are new messages, got to the github [[https://​github.com/​alexandruradovici/​alf2018|repository]] and click //Watch//.
   ​   ​
 ===== Testing ===== ===== Testing =====
Line 533: Line 541:
  
 <code bash> <code bash>
-wget https://​nodejs.org/​dist/​v6.10.0/node-v6.10.0-linux-x64.tar.xz +wget https://​nodejs.org/​dist/​v8.9.4/node-v8.9.4-linux-x64.tar.xz 
-tar xvfJ node-v6.10.0-linux-x64.tar.xz +tar xvfJ node-v8.9.4-linux-x64.tar.xz 
-cd node-v6.10.0-linux-x64+cd node-v8.9.4-linux-x64
 sudo cp -R * /usr sudo cp -R * /usr
 </​code>​ </​code>​
Line 566: Line 574:
  
   - Create a zip (not rar, ace, 7zip or anything else) archive containing:   - Create a zip (not rar, ace, 7zip or anything else) archive containing:
-    * your main file (main.js)  ​ +    * your main file   ​ 
-    * your alfy.jison file +    * your grammar.jison file 
     * your javascript files (*.js)     * your javascript files (*.js)
-    * yarn.lock (if you are using yarn) 
     * the package.json file     * the package.json file
     * the Readme file     * the Readme file
   - sign in with [[https://​vmchecker.cs.pub.ro|vmchecker]]   - sign in with [[https://​vmchecker.cs.pub.ro|vmchecker]]
   - select the //Automates et Langages Formelles (FILS)// course   - select the //Automates et Langages Formelles (FILS)// course
-  - select //3. Semantic//+  - select //4. Semantic//
   - upload the archive   - upload the archive
  
Line 589: Line 596:
 unzip archive.zip homework unzip archive.zip homework
 cd homework cd homework
-# if the file yarn.lock exists 
-yarn 
-# else 
 npm install npm install
 echo '{ "​node":​true,​ "​esnext":​true }' > .jshintrc echo '{ "​node":​true,​ "​esnext":​true }' > .jshintrc
alf/teme/tema_en_3.1524401772.txt.gz · Last modified: 2018/04/22 15:56 by alexandru.radovici
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0