Differences

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

Link to this comparison view

alf:teme:tema3_en_draft [2018/03/26 19:03]
alexandru.radovici
alf:teme:tema3_en_draft [2019/04/03 10:25] (current)
alexandru.radovici
Line 4: Line 4:
  
 <note important>​ <note important>​
-Deadline: **15th of April, 23:55**\\+Deadline: **7th of April, 23:55**\\
 Points: **2 points** out of the final grade\\ Points: **2 points** out of the final grade\\
 Upload the homework: [[https://​vmchecker.cs.pub.ro|vmchecker.cs.pub.ro]]\\ Upload the homework: [[https://​vmchecker.cs.pub.ro|vmchecker.cs.pub.ro]]\\
Line 26: Line 26:
   * add the parser rules for the loops   * add the parser rules for the loops
   * add the parser rules for the function definitions   * add the parser rules for the function definitions
-  * add the parser rules for the function ​run+  * add the parser rules for the function ​call
   * add the parser rules for the branches and loops   * add the parser rules for the branches and loops
   * add the parser rules for the array and struct   * add the parser rules for the array and struct
  
 Try running small scripts to test every feature. Try running small scripts to test every feature.
- 
-===== Syntax highlighting ===== 
-If you use sublime text, you may use this [[https://​github.com/​alexandruradovici/​alf2018/​blob/​master/​Devoirs/​alf/​verify/​alf.tmLanguage|syntax highlighting file]] to write Alf language. 
- 
-You may [[http://​stackoverflow.com/​questions/​12785583/​add-ts-language-files-to-sublime-text-to-support-additional-syntax-coloring|read]] here how to add the file. 
  
 ===== AST Format ===== ===== AST Format =====
Line 57: Line 52:
   * exp - any expression   * exp - any expression
   * set - setting the value of a variable   * set - setting the value of a variable
-  * message ​message ​definition +  * function ​function ​definition 
-  * class call definition+  * struct ​structure ​definition
   * property - a property of a class   * property - a property of a class
-  * list list definition+  * array array definition
   * element - an element of an array   * element - an element of an array
   * if - if statement   * if - if statement
-  * while - while statement +  * loop - while statement
-  * repeat - repeat ​statement+
   * for - for statement   * for - for statement
-  * dispatch ​send message+  * loop ... if for statement 
 +  * function_call - call (run) function
   * return - value of a function   * return - value of a function
-  * value - a value (int, real, logic, float, user_defined)+  * value - a value (integer, logic, float, user_defined)
  
 ===== Questions ===== ===== 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.+If you have any questions related to the homework, please ask them by posting an issue on the github [[https://​github.com/​upb-fils/alf|repository]] with the title format //[alf] <your question title>//​. You will need a github account for that.
  
 <note warning> <note warning>
Line 78: Line 73:
 </​note>​ </​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//.+If you want to receive an email when issues are posted or when there are new messages, got to the github [[https://​github.com/​upb-fils/alf|repository]] and click //Watch//.
   ​   ​
  
Line 85: Line 80:
  
   * variable definitions   * variable definitions
-  * message ​definitions +  * function ​definitions 
-  * class definitions (new data type) +  * struct ​definitions (new data type) 
-  * list definitions (new data type)+  * array definitions (new data type)
   * expressions   * expressions
   * values   * values
   * attributions   * attributions
-  * message sending+  * function call
   * branch (if)   * branch (if)
-  * loop (while , for or repeat)+  * loop (loop , for)
  
 <​note>​ <​note>​
-The instructions are separated by newline+The instructions are separated by ;
  
 <​code>​ <​code>​
-a:=10 +a=10; 
-b:=20l +b=20; 
-s:=55+s=55;
 </​code>​ </​code>​
 </​note>​ </​note>​
Line 111: Line 106:
 Values are Values are
   * integer number <​code>​7</​code>​   * integer number <​code>​7</​code>​
-  * real number <​code>​7.5</​code>​ +  * float number <​code>​7.5</​code>​ 
-  * character ​<​code>"​a"</​code>​+  * symbol ​<​code>"​a"</​code>​
   * string <​code>"​this is a text"</​code>​   * string <​code>"​this is a text"</​code>​
   * logic (value true or false) <​code>​false</​code>​   * logic (value true or false) <​code>​false</​code>​
Line 134: Line 129:
 <​code>​ <​code>​
 {this is a text to describe the script} {this is a text to describe the script}
-define ​v:=55+def v:integer=55;
 </​code>​ </​code>​
  
Line 178: Line 173:
 </​code>​ </​code>​
  
-[[https://​github.com/​alexandruradovici/alf2018/​tree/​master/​Devoirs/​alf/​verify/​alf/​1_value|Example]]+[[https://​github.com/​upb-fils/alf/​tree/​master/​Devoir/​alf/​verify/​alf/​1_value|Example]]
  
 ==== Variable definition ==== ==== Variable definition ====
Line 185: Line 180:
  
 <​code>​ <​code>​
-define ​variable_name [:​variable_type] [:= value or expression],​ ...+def variable_name [:​variable_type] [= value or expression],​ ...
 +def variable_name,​ variable_name,​ variable_name,​ ...  :​variable_type,​ ....;
 </​code>​ </​code>​
  
 === Examples === === Examples ===
 <​code>​ <​code>​
-define ​a:​integer ​:= 3 +def a:integer = 3; 
-define ​:= 3 +def a = 3; 
-define ​a1:integer:=3, a2:​string ​:= "​text",​ a3:int+def a1:integer = 3, a2:string = "​text",​ a3:integer; 
 +def a,b : integer;
 </​code>​ </​code>​
  
Line 198: Line 195:
  
   * integer - integer number   * integer - integer number
-  * real - floating point number +  * float - floating point number 
-  * character ​- a single character+  * symbol ​- a single character
   * string - text   * string - text
   * logic - true or false   * logic - true or false
-  * user defined (class, list)+  * user defined (struct, list)
  
 === AST === === AST ===
Line 208: Line 205:
 <code javascript>​ <code javascript>​
 { {
- id:"var",+ id:"def",
  ​ variables:​[ // array of variables  ​ variables:​[ // array of variables
   {   {
  ​ type:"​data type",  ​ type:"​data type",
-  title: "varable ​name"+  title: "variable ​name", 
 +    value: "​variable value"
   },   },
  ]  ]
Line 218: Line 216:
 </​code>​ </​code>​
  
-[[https://​github.com/​alexandruradovici/alf2018/​tree/​master/​Devoirs/​alf/​verify/​alf/​2_variable_definition|Example]]+[[https://​github.com/​upb-fils/alf/​tree/​master/​Devoir/​alf/​verify/​alf/​2_variable_definition|Example]]
  
-==== Class ====+==== Sruct ====
  
 === Language === === Language ===
 <​code>​ <​code>​
-class class_name [extends super_class] +struct struct_name ​ 
- property ​property_name:​data_type [:= initial_value]+ property_name:​data_type [= initial_value]
  ...  ...
  ...  ...
-        message message_name[:​data_type] parameter1[:​data_type][:​=default_value],​ parameter1[:​data_type][:​=default_value],​ parameter3[:​data_type][:​=default_value],​ ... 
-        begin 
-           // ... message source 
-        end 
 end; end;
 </​code>​ </​code>​
Line 238: Line 232:
 <code javascript>​ <code javascript>​
 { {
- id:"class", + id:"struct", 
- title:"​class_name",​ + title:"​struct_name",
-        parent:"​super_class_name",+
  ​ properties:​[ // array of properties  ​ properties:​[ // array of properties
   {   {
Line 247: Line 240:
  ​ value:​ "​property value" // if it exists  ​ value:​ "​property value" // if it exists
   },   },
- ]+ ]
-        messages: [ // array of messages +
-                { +
-        type:"​message return data type"​ +
-        title:"​message_name", ​      +
- parameters:​[ // array of parameters +
- ​ { +
- ​ type:"​data type",​ +
- ​ title:​ "​parameter name"​ +
- ​ },​ +
- ​ ],​ +
- statements:​[ // array of statements (even if it is only one) +
- ... +
- ​ ] +
-                }+
 } }
 </​code>​ </​code>​
  
-[[https://​github.com/​alexandruradovici/alf2018/​tree/​master/​Devoirs/​alf/​verify/​alf/​6_class|Example]]+[[https://​github.com/​upb-fils/alf/​tree/​master/​Devoir/​alf/​verify/​alf/​6_class|Example]]
  
 === Property access === === Property access ===
Line 272: Line 251:
 == Language == == Language ==
 <​code>​ <​code>​
-object_name|property+object_name.property
 </​code>​ </​code>​
  
Line 288: Line 267:
 </​code>​ </​code>​
  
-[[https://​github.com/​alexandruradovici/alf2018/​tree/​master/​Devoirs/​alf/​verify/​alf/​6_class|Example]]+[[https://​github.com/​upb-fils/alf/​tree/​master/​Devoir/​alf/​verify/​alf/​6_class|Example]]
  
  
 ==== Array ==== ==== Array ====
  
-=== List definition ===+=== Array definition ===
  
 == Language == == Language ==
Line 306: Line 285:
 <code javascript>​ <code javascript>​
 { {
- id:"list",+ id:"array",
         title: array_name,         title: array_name,
  element_type:​elements_data_type,​  element_type:​elements_data_type,​
Line 314: Line 293:
 </​code>​ </​code>​
  
-=== List access ===+=== Array access ===
  
 == Language == == Language ==
 <​code>​ <​code>​
-array_name#index+array_name[index]
 </​code>​ </​code>​
  
Line 324: Line 303:
 <code javascript>​ <code javascript>​
 { {
- id:"element_of_list", + id:"element_of_array", 
- list:{ + array:{ 
- expression for list+ expression for array
  },  },
  ​ index:​ {  ​ index:​ {
Line 334: Line 313:
 </​code>​ </​code>​
  
-[[https://​github.com/​alexandruradovici/alf2018/​tree/​master/​Devoirs/​alf/​verify/​alf/​7_array|Example]]+[[https://​github.com/​upb-fils/alf/​tree/​master/​Devoir/​alf/​verify/​alf/​7_array|Example]]
  
 ==== Expressions ==== ==== Expressions ====
Line 342: Line 321:
 ^ Operator ^ Precedence ^ ^ Operator ^ Precedence ^
 | if | Low | | if | Low |
-| = != |  |+== != |  |
 | > >= < <= | | | > >= < <= | |
 | and or xor | | | and or xor | |
Line 352: Line 331:
  
 <​code>​ <​code>​
-2+5 +2+5; 
-2*4+5 +2*4+5; 
-variable+5 +variable+5; 
-x>y +x>y; 
-x=y+x=y;
  
-2+(x+y)*(5+6)+2+(x+y)*(5+6);
 </​code>​ </​code>​
  
Line 388: Line 367:
  
 <​code>​ <​code>​
-variable ​:= expression;+variable = expression;
 </​code>​ </​code>​
  
 === Examples === === Examples ===
 <​code>​ <​code>​
-:= 1000 +x = 1000; 
-:= "​text"​ + "​s"​ +s = "​text"​ + "​s"​; 
-:[module ​f] +y = f(); 
-l#:= 900 +l[i= 900; 
-q.e := "this is a text"+q.e = "this is a text";
 </​code>​ </​code>​
  
Line 406: Line 385:
  id:"​set",​  id:"​set",​
   to: {   to: {
-  ... id, property, ​element_of_list+  ... id, property, ​element_of_array
   },   },
  ​ from:​ {  ​ from:​ {
Line 414: Line 393:
 </​code>​ </​code>​
  
-[[https://​github.com/​alexandruradovici/alf2018/​tree/​master/​Devoirs/​alf/​verify/​alf/​2_variable_definition|Example]]+[[https://​github.com/​upb-fils/alf/​tree/​master/​Devoir/​alf/​verify/​alf/​2_variable_definition|Example]]
  
  
-==== Message ​definition ====+==== Function ​definition ====
  
-Messages are functions and are usually defined in classes. If a message is defined outside a class, it belongs to the module object. 
  
 === Language === === Language ===
  
 <​code>​ <​code>​
-message message_name:​return_type parameter1:​[parameter1_type][:=value], ... = expression+fn function_name:​return_type ​(parameter1:​[parameter1_type][=value],​ ...=expression;
 </​code>​ </​code>​
  
 <​code>​ <​code>​
-message message_name:​return_type parameter1:​[parameter1_type][:​=value],​ ... +fn function_name:​return_type ​(parameter1:​[parameter1_type][:​=value],​ ...
 begin begin
    ...    ...
-end+end;
 </​code>​ </​code>​
  
Line 437: Line 415:
  
 <​code>​ <​code>​
-message ​f1+fn f1:none ()
 begin begin
 end; end;
Line 443: Line 421:
  
 <​code>​ <​code>​
-message ​sum:int a:int, b:int is a+b+fn sum:integer (a:integer, b:integer) ​=a+b;
 </​code>​ </​code>​
  
 <​code>​ <​code>​
-message ​power:int a:int, n:int +fn power:integer (a:integer, n:integer)
 begin begin
-  ​define ​p:int +  ​def p:integer; 
-  ​define ​i:int +  ​def i:integer; 
-  if n = 0 then +  if n == 0 then 
   begin   begin
-     power:=1 +     ​power=1; 
-  end +  end; 
-  for i in [1,n] p:=p * a +  for i in [1,n] p=p * a; 
-  return p +  return p; 
-end+end;
 </​code>​ </​code>​
  
Line 464: Line 442:
 <code javascript>​ <code javascript>​
 { {
- id:"message", + id:"fn", 
- title:"​message_name", ​     ​+ title:"​function_name", ​     ​
  parameters:​[ // array of parameters  parameters:​[ // array of parameters
   {   {
  ​ type:"​data type",  ​ type:"​data type",
-  id: "​parameter name"+  name: "​parameter name"
   },   },
   ],   ],
- return_type:"​type of the value that the message ​returns",​+ return_type:"​type of the value that the function ​returns",​
  statements:​[ // array of statements (even if it is only one)  statements:​[ // array of statements (even if it is only one)
  ...  ...
Line 479: Line 457:
 </​code>​ </​code>​
  
-[[https://​github.com/​alexandruradovici/alf2018/​tree/​master/​Devoirs/​alf/​verify/​alf/​4_messages|Example]]+[[https://​github.com/​upb-fils/alf/​tree/​master/​Devoir/​alf/​verify/​alf/​4_messages|Example]]
  
 === Return === === Return ===
-This is the statements ​that sets the return value of the message.+This is the statement ​that sets the return value of the function.
  
 == Example == == Example ==
 <​code>​ <​code>​
-return x+y+return x+y;
 </​code>​ </​code>​
  
Line 499: Line 477:
 </​code>​ </​code>​
  
-==== Message dispatch ​====+==== function call ====
  
 The is a call for a function The is a call for a function
Line 506: Line 484:
  
 <​code>​ <​code>​
-[object message_name ​parameter_name1:​value1,​ parameter_name2:​value,​ ...]+function_name (parameter_name1:​value1,​ parameter_name2:​value,​ ...);
 </​code>​ </​code>​
  
 <​code>​ <​code>​
-[object message_name value1value2, ...]+function_name (parameter1_valueparameter2_value, ...)
 </​code>​ </​code>​
  
Line 516: Line 494:
  
 <​code>​ <​code>​
-[module ​write text:"​Text"​] +write (text:"​Text"​); 
-:[sum n1:n2:5] +s = sum (35); 
-[module ​getdir]+getdir ​();
 </​code>​ </​code>​
  
Line 525: Line 503:
 <code javascript>​ <code javascript>​
 { {
- id:"dispatch", + id:"function_call", 
- message:"message_name",​ + function:"function_name",
- object:"​destination_object_name",+
  parameters:​{ // dictionary of parameter name or index and value  parameters:​{ // dictionary of parameter name or index and value
  ​ "​parameter1":​ parameter_value,​  ​ "​parameter1":​ parameter_value,​
Line 536: Line 513:
 </​code>​ </​code>​
  
-[[https://​github.com/​alexandruradovici/alf2018/​tree/​master/​Devoirs/​alf/​verify/​alf/​4_messages|Example]]+[[https://​github.com/​upb-fils/alf/​tree/​master/​Devoir/​alf/​verify/​alf/​4_messages|Example]]
  
 ==== Branch ==== ==== Branch ====
Line 543: Line 520:
  
 <​code>​ <​code>​
-if expression+if expression ​then
   ...    ... 
-end+end;
 </​code>​ </​code>​
  
 <​code>​ <​code>​
-if expression ​+if expression ​then
   ...    ... 
 else else
   ...   ...
-end+end;
 </​code>​ </​code>​
  
Line 577: Line 554:
 </​code>​ </​code>​
  
-[[https://​github.com/​alexandruradovici/alf2018/​tree/​master/​Devoirs/​alf/​verify/​alf/​5_branch|Example]]+[[https://​github.com/​upb-fils/alf/​tree/​master/​Devoir/​alf/​verify/​alf/​5_branch|Example]]
  
-==== Loop ====+==== Loops ====
  
 There are three types of loops: while, repeat and for. There are three types of loops: while, repeat and for.
  
-=== while ===+=== loop run ===
  
 <​code>​ <​code>​
-while expression+loop expression ​run
   ...   ...
-end+end;
 </​code>​ </​code>​
  
Line 594: Line 571:
 <code javascript>​ <code javascript>​
 { {
- id:"while",+ id:"loop_run",
  exp :​expression,​  exp :​expression,​
  statements:​ [ // array of statements  statements:​ [ // array of statements
Line 602: Line 579:
 </​code>​ </​code>​
  
-=== repeat ​===+=== loop ... when ===
  
 <​code>​ <​code>​
-repeat ​+loop 
   ...   ...
-when expression+when expression;
 </​code>​ </​code>​
  
Line 613: Line 590:
 <code javascript>​ <code javascript>​
 { {
- id:"repeat",+ id:"loop_when",
  exp :​expression,​  exp :​expression,​
  statements:​ [ // array of statements  statements:​ [ // array of statements
Line 624: Line 601:
  
 <​code>​ <​code>​
-for variable_name in expression ​+for variable_name in expression ​run
    ...    ...
-end+end;
 </​code>​ </​code>​
  
Line 632: Line 609:
  
 <​code>​ <​code>​
-for variable_name ​in (number to number)+for variable_name ​from number to number ​run
    ...    ...
-end+end;
 </​code>​ </​code>​
  
 <​code>​ <​code>​
-for variable_name ​in (number downto number)+for variable_name ​from number downto number ​run
    ...    ...
-end+end;
 </​code>​ </​code>​
  
Line 665: Line 642:
  id:"​for",​  id:"​for",​
         variable:​variable_name,​         variable:​variable_name,​
- list:{ + from: { expression }, 
- low: { expression }, +        ​to/​downto: { expression },
- high: { expression ​}, +
- direction:​ "​to"​ or "​downto"​ +
- },+
  statements:​ [ // array of statements  statements:​ [ // array of statements
  
Line 676: Line 650:
 </​code>​ </​code>​
  
-[[https://​github.com/​alexandruradovici/alf2018/​tree/​master/​Devoirs/​alf/​verify/​alf/​3_loop|Example]]+[[https://​github.com/​upb-fils/alf/​tree/​master/​Devoir/​alf/​verify/​alf/​3_loop|Example]]
  
 ===== Errors ===== ===== Errors =====
Line 747: Line 721:
 #else #else
 p := "​Linux" ​ {this source code is ignored if platform is not linux} p := "​Linux" ​ {this source code is ignored if platform is not linux}
-end+#endif
 </​code>​ </​code>​
  
Line 778: Line 752:
 ==== Public Tests ==== ==== Public Tests ====
  
-You can download the public tests from the GitHub [[https://​github.com/​alexandruradovici/alf2018/​tree/​master/​Devoirs/​alf|repository]].+You can download the public tests from the GitHub [[https://​github.com/​upb-fils/alf/​tree/​master/​Devoir/​alf|repository]].
  
 To run the tests, download the contents of the repository in the folder with the homework. Enter the //verify// folder and run ./​run_all.sh. To run the tests, download the contents of the repository in the folder with the homework. Enter the //verify// folder and run ./​run_all.sh.
Line 828: Line 802:
     * your main file (set in package.json)  ​     * your main file (set in package.json)  ​
     * your javascript files (*.js)     * your javascript files (*.js)
-    * your jison file (grammar.jison)  ​+    * your l and y file (grammar.l and grammar.y)  ​
     * the package.json file     * the package.json file
     * the Readme file     * the Readme file
Line 851: Line 825:
 echo '{ "​node":​true,​ "​loopfunc":​ true, "​esnext":​true }' > .jshintrc echo '{ "​node":​true,​ "​loopfunc":​ true, "​esnext":​true }' > .jshintrc
 jshint *.js jshint *.js
-jison grammar.jison -o grammar.js+jison grammar.y grammar.l ​-o grammar.js
 </​code>​ </​code>​
  
alf/teme/tema3_en_draft.1522080214.txt.gz · Last modified: 2018/03/26 19:03 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