Exemplo n.º 1
0
 private void initialise(GingerToken type, Variable name, ImportList il, FunctionList fl)
 {
     _type = type;
     add(name);
     add(il);
     add(fl);
 }
Exemplo n.º 2
0
        private FunctionList parseFunctionList()
        {
            FunctionList fl = new FunctionList();

            do
            {
                Function f = null;
                try
                {
                    f = parseFunction();
                }
                catch (ParseException pe)
                {
                    _errors.Add(pe);
                }

                if (f != null)
                {
                    fl.add(f);
                    //if (f.name.identifier.name.Equals("main"))
                    //{
                    //    if (_entry == null)
                    //    {
                    //        _entry = f;
                    //    }
                    //    else
                    //    {
                    //        _errors.Add(new ParseException(scanner.row, scanner.col, $"Found more than one entry point", ExceptionLevel.ERROR));
                    //    }
                    //}
                }

                nextScannerToken();
            } while (currentScannerToken != GingerToken.CloseList);

            return(fl);
        }
Exemplo n.º 3
0
        private Component parseComponent()
        {
            Component    c;
            GingerToken  type;
            Variable     name;
            FunctionList fl;
            ImportList   il;
            Identifier   extends = null;

            if (Grammar.isComponent(currentScannerToken))
            {
                type = currentScannerToken;
                nextScannerToken();

                if (currentScannerToken == GingerToken.Identifier)
                {
                    //name = new Variable(new Identifier(scanner.row, scanner.col, new string(scanner.tokenValue)));
                    name = new Variable(parseIdentifier(false));
                    nextScannerToken();

                    if (currentScannerToken == GingerToken.Extends)
                    {
                        nextScannerToken();
                        extends = parseIdentifier(false);
                        nextScannerToken();
                    }

                    if (currentScannerToken == GingerToken.OpenList)
                    {
                        nextScannerToken();
                        il = parseImportList();
                        if (currentScannerToken == GingerToken.Function)
                        {
                            fl = parseFunctionList();
                        }
                        else
                        {
                            fl = new FunctionList();
                        }

                        if (extends != null)
                        {
                            c = new Component(type, name, il, fl, extends);
                        }
                        else
                        {
                            c = new Component(type, name, il, fl);
                        }
                    }
                    else
                    {
                        throw new ParseException(scanner.row, scanner.col, $"Expected '{GingerToken.OpenList.ToString()}', found '{currentScannerToken.ToString()}'", ExceptionLevel.ERROR);
                    }
                }
                else
                {
                    throw new ParseException(scanner.row, scanner.col, $"Expected '{GingerToken.Identifier.ToString()}', found '{currentScannerToken.ToString()}'", ExceptionLevel.ERROR);
                }
            }
            else
            {
                throw new ParseException(scanner.row, scanner.col, $"Expected component type, found '{currentScannerToken.ToString()}'", ExceptionLevel.ERROR);
            }

            return(c);
        }
Exemplo n.º 4
0
 public Component(GingerToken type, Variable name, ImportList il, FunctionList fl, Identifier extends) : base()
 {
     initialise(type, name, il, fl);
     add(extends);
 }
Exemplo n.º 5
0
 public Component(GingerToken type, Variable name, ImportList il, FunctionList fl) : base()
 {
     initialise(type, name, il, fl);
 }