예제 #1
0
            public VarDefStatement Parse()
            {
                List <string> res = new List <string>();

                PeekToken();
                if (Test(Token.Type.Var, VarDefState.Pre))
                {
                    while (true)
                    {
                        Expect(Token.Type.Name, VarDefState.Post);
                        if (ProgramParser.IsKeyword(lastToken.str))
                        {
                            throw Error(
                                      (at, message) =>
                                      new UnsupportedIdentifierException(at, message, "matches keyword"),
                                      lastToken.str
                                      );
                        }
                        if (vars.ContainsKey(lastToken.str))
                        {
                            throw Error(
                                      (at, message) =>
                                      new UnsupportedIdentifierException(at, message,
                                                                         "matches argument name"),
                                      lastToken.str
                                      );
                        }
                        if (!res.Contains(lastToken.str))
                        {
                            res.Add(lastToken.str);
                        }
                        else
                        {
                            throw Error(
                                      (at, message) =>
                                      new UnsupportedIdentifierException(at, message,
                                                                         "redefinition"),
                                      lastToken.str
                                      );
                        }
                        if (Test(Token.Type.Semicolon, VarDefState.End))
                        {
                            break;
                        }
                        Expect(Token.Type.Comma, VarDefState.Pre);
                    }
                    return(new VarDefStatement(res));
                }
                return(null);
            }
예제 #2
0
 protected Variable GetVar(string name)
 {
     if (!vars.ContainsKey(name))
     {
         if (ProgramParser.IsKeyword(name))
         {
             throw Error(
                       (at, message) => new UnexpectedTokenException(at, message),
                       "keyword '" + name + "', expected variable name"
                       );
         }
         throw Error(
                   (at, message) => new UnrecognizedTokenException(at, message),
                   "cannot find variable '" + name
                   );
     }
     return(vars[name]);
 }
예제 #3
0
 protected MethodOperation.Factory GetFunc(string name)
 {
     if (!funcs.ContainsKey(name))
     {
         if (ProgramParser.IsKeyword(name))
         {
             throw Error(
                       (at, message) => new UnexpectedTokenException(at, message),
                       "keyword '" + name + "', expected function name"
                       );
         }
         throw Error(
                   (at, message) => new UnrecognizedTokenException(at, message),
                   "cannot find function '" + name + "' to call"
                   );
     }
     return(funcs[name]);
 }
예제 #4
0
 CompileResult Compile(string expression)
 {
     return(ProgramParser.Parse <CompileResult>(expression, typeof(Context)));
 }