Differences

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

Link to this comparison view

alf:teme:tema3_en_draft [2019/03/14 23:55]
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 66: Line 61:
   * for - for statement   * for - for statement
   * loop ... if - for statement   * loop ... if - for statement
-  * function_run ​- run a function+  * function_call ​call (runa function
   * return - value of a function   * return - value of a function
   * value - a value (integer, logic, float, user_defined)   * value - a value (integer, logic, float, user_defined)
Line 72: Line 67:
 ===== 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 91: Line 86:
   * values   * values
   * attributions   * attributions
-  * function ​run+  * function ​call
   * branch (if)   * branch (if)
   * loop (loop , for)   * 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 134: Line 129:
 <​code>​ <​code>​
 {this is a text to describe the script} {this is a text to describe the script}
-def 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 193: Line 188:
 def a:integer = 3; def a:integer = 3;
 def a = 3; def a = 3;
-def a1:integer = 3, a2:string = "​text",​ a3:int;+def a1:integer = 3, a2:string = "​text",​ a3:integer;
 def a,b : integer; def a,b : integer;
 </​code>​ </​code>​
Line 214: Line 209:
   {   {
  ​ type:"​data type",  ​ type:"​data type",
-  title: "varable ​name",​ +  title: "variable ​name",​ 
-    value: "varable ​value"+    value: "variable ​value"
   },   },
  ]  ]
Line 221: 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]]
  
 ==== Sruct ==== ==== Sruct ====
Line 249: Line 244:
 </​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 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]]
  
  
Line 309: Line 304:
 { {
  id:"​element_of_array",​  id:"​element_of_array",​
- list:{+ array:{
  expression for array  expression for array
  },  },
Line 318: 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 336: 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 377: Line 372:
 === Examples === === Examples ===
 <​code>​ <​code>​
-x = 1000 +x = 1000; 
-s = "​text"​ + "​s"​ +s = "​text"​ + "​s"​; 
-y = f() +y = f(); 
-l[i] = 900 +l[i] = 900; 
-q.e = "this is a text"+q.e = "this is a text";
 </​code>​ </​code>​
  
Line 398: 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]]
  
  
Line 407: Line 402:
  
 <​code>​ <​code>​
-fn function_name:​return_type (parameter1:​[parameter1_type][=value],​ ...) => expression+fn function_name:​return_type (parameter1:​[parameter1_type][=value],​ ...) => expression;
 </​code>​ </​code>​
  
Line 426: 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 447: 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 462: 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 482: Line 477:
 </​code>​ </​code>​
  
-==== Message dispatch ​====+==== function call ====
  
 The is a call for a function The is a call for a function
Line 489: 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 499: Line 494:
  
 <​code>​ <​code>​
-[module ​write text:"​Text"​] +write (text:"​Text"​); 
-:[sum n1:n2:5] +s = sum (35); 
-[module ​getdir]+getdir ​();
 </​code>​ </​code>​
  
Line 508: 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 519: 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 526: 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 560: 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 577: Line 571:
 <code javascript>​ <code javascript>​
 { {
- id:"while",+ id:"loop_run",
  exp :​expression,​  exp :​expression,​
  statements:​ [ // array of statements  statements:​ [ // array of statements
Line 585: Line 579:
 </​code>​ </​code>​
  
-=== repeat ​===+=== loop ... when ===
  
 <​code>​ <​code>​
-repeat ​+loop 
   ...   ...
-when expression+when expression;
 </​code>​ </​code>​
  
Line 596: Line 590:
 <code javascript>​ <code javascript>​
 { {
- id:"repeat",+ id:"loop_when",
  exp :​expression,​  exp :​expression,​
  statements:​ [ // array of statements  statements:​ [ // array of statements
Line 607: Line 601:
  
 <​code>​ <​code>​
-for variable_name in expression ​+for variable_name in expression ​run
    ...    ...
-end+end;
 </​code>​ </​code>​
  
Line 615: 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 648: 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 659: 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 730: 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 761: 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 811: 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 834: 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.1552600548.txt.gz · Last modified: 2019/03/14 23:55 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