Selaa lähdekoodia

Updated the syntax with for...end

Chimrod 5 kuukautta sitten
vanhempi
sitoutus
749c078c48
3 muutettua tiedostoa jossa 21 lisäystä ja 0 poistoa
  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);
       ("END", END);
       ("EXEC", KEYWORD T.Exec);
       ("EXEC", KEYWORD T.Exec);
       ("EXIT", KEYWORD T.Exit);
       ("EXIT", KEYWORD T.Exit);
+      ("FOR", FOR);
       ("FREELIB", KEYWORD T.FreeLib);
       ("FREELIB", KEYWORD T.FreeLib);
       ("FUNC", FUNCTION T.Func);
       ("FUNC", FUNCTION T.Func);
       ("$FUNC", FUNCTION T.Func');
       ("$FUNC", FUNCTION T.Func');
@@ -141,12 +142,14 @@ let _ =
       ("SHOWSTAT", KEYWORD T.ShowStat);
       ("SHOWSTAT", KEYWORD T.ShowStat);
       ("STATTXT", IDENT "STATTXT");
       ("STATTXT", IDENT "STATTXT");
       ("$STATTXT", IDENT "$STATTXT");
       ("$STATTXT", IDENT "$STATTXT");
+      ("STEP", STEP);
       ("STR", FUNCTION T.Str);
       ("STR", FUNCTION T.Str);
       ("$STR", FUNCTION T.Str');
       ("$STR", FUNCTION T.Str');
       ("STRCOMP", FUNCTION T.Strcomp);
       ("STRCOMP", FUNCTION T.Strcomp);
       ("STRFIND", FUNCTION T.Strfind);
       ("STRFIND", FUNCTION T.Strfind);
       ("$STRFIND", FUNCTION T.Strfind');
       ("$STRFIND", FUNCTION T.Strfind');
       ("STRPOS", FUNCTION T.Strpos);
       ("STRPOS", FUNCTION T.Strpos);
+      ("TO", TO);
       ("TRIM", FUNCTION T.Trim);
       ("TRIM", FUNCTION T.Trim);
       ("$TRIM", FUNCTION T.Trim');
       ("$TRIM", FUNCTION T.Trim');
       ("UCASE", FUNCTION T.Ucase);
       ("UCASE", FUNCTION T.Ucase);

+ 17 - 0
lib/qparser/parser.mly

@@ -67,6 +67,23 @@ line_statement:
       }
       }
     | b = inlined_block(line_sep)
     | b = inlined_block(line_sep)
       { b }
       { 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, 
 (** Represent an instruction which can either be on a single line, 
     or created in a block until an END 
     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.keywords>KEYWORD
 %token <Qsp_syntax.T.function_>FUNCTION
 %token <Qsp_syntax.T.function_>FUNCTION
 %token <Qsp_syntax.T.function_>FUNCTION_NOARGS
 %token <Qsp_syntax.T.function_>FUNCTION_NOARGS
+%token FOR TO STEP
 
 
 (* 
 (* 
 (b) if the token was declared left-associative, then the conflict is resolved
 (b) if the token was declared left-associative, then the conflict is resolved