Explorar el Código

Updated the syntax with for...end

Chimrod hace 5 meses
padre
commit
749c078c48
Se han modificado 3 ficheros con 21 adiciones y 0 borrados
  1. 3 0
      lib/qparser/idents.ml
  2. 17 0
      lib/qparser/parser.mly
  3. 1 0
      lib/qparser/tokens.mly

+ 3 - 0
lib/qparser/idents.ml

@@ -61,6 +61,7 @@ let _ =
       ("END", END);
       ("EXEC", KEYWORD T.Exec);
       ("EXIT", KEYWORD T.Exit);
+      ("FOR", FOR);
       ("FREELIB", KEYWORD T.FreeLib);
       ("FUNC", FUNCTION T.Func);
       ("$FUNC", FUNCTION T.Func');
@@ -141,12 +142,14 @@ let _ =
       ("SHOWSTAT", KEYWORD T.ShowStat);
       ("STATTXT", IDENT "STATTXT");
       ("$STATTXT", IDENT "$STATTXT");
+      ("STEP", STEP);
       ("STR", FUNCTION T.Str);
       ("$STR", FUNCTION T.Str');
       ("STRCOMP", FUNCTION T.Strcomp);
       ("STRFIND", FUNCTION T.Strfind);
       ("$STRFIND", FUNCTION T.Strfind');
       ("STRPOS", FUNCTION T.Strpos);
+      ("TO", TO);
       ("TRIM", FUNCTION T.Trim);
       ("$TRIM", FUNCTION T.Trim');
       ("UCASE", FUNCTION T.Ucase);

+ 17 - 0
lib/qparser/parser.mly

@@ -67,6 +67,23 @@ line_statement:
       }
     | b = inlined_block(line_sep)
       { b }
+    | FOR 
+      variable = variable
+      EQUAL
+      start = expression
+      TO 
+      to_ = expression
+      step = option(pair(STEP, expression))
+      COLUMN EOL+
+      s = line_statement*
+      END
+      {
+          let variable = Helper.variable variable in
+          let start = Analyzer.Expression.v start in
+          let to_ = Analyzer.Expression.v to_ in
+          let step = Option.map (fun v -> Analyzer.Expression.v (snd v)) step in
+          Analyzer.Instruction.for_ $loc variable ~start ~to_ ~step s
+      }
 
 (** Represent an instruction which can either be on a single line, 
     or created in a block until an END 

+ 1 - 0
lib/qparser/tokens.mly

@@ -41,6 +41,7 @@
 %token <Qsp_syntax.T.keywords>KEYWORD
 %token <Qsp_syntax.T.function_>FUNCTION
 %token <Qsp_syntax.T.function_>FUNCTION_NOARGS
+%token FOR TO STEP
 
 (* 
 (b) if the token was declared left-associative, then the conflict is resolved