Ejemplo n.º 1
0
        //SourceCode ::= Statement+
        static public (SourceCode, string) parseSourceCode(ref lexer.Lexer Lexer)
        {
            SourceCode sourceCode = new SourceCode();
            string     error;

            sourceCode.LineNum             = Lexer.GetLineNum();
            (sourceCode.Statements, error) = parseStatements(ref Lexer);
            if (error != null)
            {
                return(sourceCode, error);
            }
            return(sourceCode, null);
        }
Ejemplo n.º 2
0
        //Variable ::= "$" Name Ignored
        static public (Variable, string) parseVariable(ref lexer.Lexer Lexer)
        {
            Variable variable = new Variable();
            string   error;

            variable.LineNum = Lexer.GetLineNum();
            Lexer.NextTokenIs(lexer.TOKEN_VAR_PREFIX);
            (variable.Name, error) = parseName(ref Lexer);
            if (error != null)
            {
                return(variable, error);
            }
            Lexer.LookAheadAndSkip(lexer.TOKEN_IGNORED);
            return(variable, null);
        }
Ejemplo n.º 3
0
        //Print ::= "print" "(" Ignored Variable Ignored ")" Ignored
        static public (Print, string) parsePrint(ref lexer.Lexer Lexer)
        {
            Print  print = new Print();
            string error;

            print.LineNum = Lexer.GetLineNum();
            Lexer.NextTokenIs(lexer.TOKEN_PRINT);
            Lexer.NextTokenIs(lexer.TOKEN_LEFT_PAREN);
            Lexer.LookAheadAndSkip(lexer.TOKEN_IGNORED);
            (print.Variable, error) = parseVariable(ref Lexer);
            if (error != null)
            {
                return(print, error);
            }
            Lexer.LookAheadAndSkip(lexer.TOKEN_IGNORED);
            Lexer.NextTokenIs(lexer.TOKEN_RIGHT_PAREN);
            Lexer.LookAheadAndSkip(lexer.TOKEN_IGNORED);
            return(print, null);
        }
Ejemplo n.º 4
0
        //Assignment  ::= Variable Ignored "=" Ignored String Ignored
        static public (Assignment, string) parseAssignment(ref lexer.Lexer Lexer)
        {
            Assignment assignment = new Assignment();
            string     error;

            assignment.LineNum           = Lexer.GetLineNum();
            (assignment.Variable, error) = parseVariable(ref Lexer);
            if (error != null)
            {
                return(assignment, error);
            }
            Lexer.LookAheadAndSkip(lexer.TOKEN_IGNORED);
            Lexer.NextTokenIs(lexer.TOKEN_EQUAL);
            Lexer.LookAheadAndSkip(lexer.TOKEN_IGNORED);
            (assignment.String, error) = parseString(ref Lexer);
            if (error != null)
            {
                return(assignment, error);
            }
            Lexer.LookAheadAndSkip(lexer.TOKEN_IGNORED);
            return(assignment, null);
        }