Code Monkey home page Code Monkey logo

pseudoparser's Introduction

PseudoP

Intérprete de Pseudocódigo: JFlex y CUP

  • Implementa patrón de diseño Interpreter.

Traductor a Código Go y Python

VSCode Theme

Pantalla

GitHub Theme

Pantalla

Eclipse Theme

Pantalla

Gramática Libre del Contexto

<INIT> ::=
    'inicio' TK_id <INSTSGLOBAL> 'fin' |
    'inicio' TK_id 'fin'

<INSTSGLOBAL> ::=
    <INSTSGLOBAL>  <INSTGLOBAL> |
    <INSTGLOBAL>

<INSTGLOBAL> ::=
    <CALLMAINFUNC> |
    <DECLID>       |
    <DECLFUNC>

<INSTRUCTIONS> ::=
    <INSTRUCTIONS> <INSTRUCTION> |
    <INSTRUCTION>

<INSTRUCTION> ::=
    <DECLID>         |
    <ID_ASIGN>       |
    <IFSTRUCT>       |
    <SWITCHSTRUCT>   |
    <LOOPFOR>        |
    <LOOPWHILE>      |
    <LOOPDOWHILE>    |
    <CALLFUNC>       |
    <PRINT>          |
    'retornar' <EXP> |
    'regresar'       |
    'continuar'      |
    'detener'

<CALLMAINFUNC> ::=
    'inicia' <CALLFUNC>

<DECLID> ::=
    'ingresar' <LISTID> 'como' <TYPE> 'con valor' <EXP>

<ID_ASIGN> ::=
    <LISTID> '<-' <EXP>

<LISTID> ::=
    <LISTID> ',' TK_id |
    TK_id

<IFSTRUCT> ::=
    'si' <EXP> 'entonces' <ELSEIFSTRUCT> |
    'si' <EXP> 'entonces' <ELSESTRUCT>   |
    'si' <EXP> 'entonces' <INSTIF>

<ELSEIFSTRUCT> ::=
    <INSTRUCTIONS> 'o si' <EXP> 'entonces' <ELSEIFSTRUCT> |
    <INSTRUCTIONS> 'o si' <EXP> 'entonces' <ELSESTRUCT>   |
    <INSTRUCTIONS> 'o si' <EXP> 'entonces' <INSTIF>       |
    'o si' <EXP> 'entonces' <ELSEIFSTRUCT>                |
    'o si' <EXP> 'entonces' <ELSESTRUCT>                  |
    'o si' <EXP> 'entonces' <INSTIF>

<ELSESTRUCT> ::=
    <INSTRUCTIONS> 'de lo contrario' <INSTIF> |
    'de lo contrario' <INSTIF>

<INSTIF> ::=
    <INSTRUCTIONS> 'fin si' |
    'fin si'

<SWITCHSTRUCT> ::=
    'segun' <EXP> 'hacer' <CASESDEFAULT> 'fin segun' |
    'segun' <EXP> 'hacer' 'fin segun'

<CASESDEFAULT> ::=
    <CASES> <DEFAULT> |
    <CASES>           |
    <DEFAULT>

<CASES> ::=
    <CASES> <CASE> |
    <CASE>

<CASE> ::=
    'en caso de ser' <EXP> 'entonces' <INSTRUCTIONS> |
    'en caso de ser' <EXP> 'entonces'

<DEFAULT> ::=
    'de lo contrario' 'entonces' <INSTRUCTIONS> |
    'de lo contrario' 'entonces'

<LOOPFOR> ::=
    'para' TK_id '<-' <EXP> 'hasta' <EXP> 'con incremento' <EXP> 'hacer' <INST_FOR> |
    'para' TK_id '<-' <EXP> 'hasta' <EXP> 'hacer' <INST_FOR>

<INST_FOR> ::=
    <INSTRUCTIONS> 'fin para' |
    'fin para'

<LOOPWHILE> ::=
    'mientras' <EXP>  'hacer' <INST_WHILE>

<LOOPDOWHILE> ::=
    <INST_REPEAT> 'cuando' <EXP>

<INST_WHILE> ::=
    <INSTRUCTIONS> 'fin mientras' |
    'fin mientras'

<INST_REPEAT> ::=
    'repetir' <INSTRUCTIONS> |
    'repetir'

<DECLFUNC> ::=
    'funcion' TK_id <TYPE> 'con parametros' '(' <LISTPARAMS> ')' <INST_FUNC> |
    'funcion' TK_id <TYPE> <INST_FUNC>                                       |
    'metodo'  TK_id 'con parametros' '(' <LISTPARAMS> ')' <INST_METH>        |
    'metodo'  TK_id <INST_METH>

<INST_FUNC> ::=
    <INSTRUCTIONS> 'fin funcion' |
    'fin funcion'

<INST_METH> ::=
    <INSTRUCTIONS> 'fin metodo' |
    'fin metodo'

<LISTPARAMS> ::=
    <LISTPARAMS> ',' TK_id <TYPE> |
    TK_id <TYPE>

<CALLFUNC> ::=
    'ejecutar' TK_id '(' <LISTARGS> ')' |
    'ejecutar' TK_id '(' ')'

<LISTARGS> ::=
    <LISTARGS> ',' <EXP> |
    <EXP>

<PRINT> ::=
    'imprimir nl' <EXP> |
    'imprimir'    <EXP>

<TYPE> ::=
    'Cadena'   |
    'Entero'   |
    'Caracter' |
    'Booleano' |
    'Decimal'

<EXP> ::=
    <ARITHMETICS> |
    <RELATIONALS> |
    <LOGICS>      |
    <CALLFUNC>    |
    TK_id         |
    TK_str        |
    TK_char       |
    TK_num        |
    'Verdadero'   |
    'Falso'       |
    '(' <EXP> ')'

<ARITHMETICS> ::=
    <EXP> '+'        <EXP> |
    <EXP> '-'        <EXP> |
    <EXP> '*'        <EXP> |
    <EXP> '/'        <EXP> |
    <EXP> 'potencia' <EXP> |
    <EXP> 'modulo'   <EXP> |
    '-'   <EXP> 

<RELATIONALS> ::=
    <EXP> 'igual a'         <EXP> |
    <EXP> 'diferente de'    <EXP> |
    <EXP> 'menor igual que' <EXP> |
    <EXP> 'mayor igual que' <EXP> |
    <EXP> 'menor que'       <EXP> |
    <EXP> 'mayor que'       <EXP>

<LOGICS> ::=
    <EXP> 'y' <EXP> |
    <EXP> 'o' <EXP> |
    'no'  <EXP>

Precedencia de Operadores

Nivel Asociatividad Token
8 Izquierda RW_or
7 Izquierda RW_and
6 Derecha RW_not
5 Izquierda RW_equequ, RW_notequ
4 Izquierda RW_less, RW_lessequ, RW_more, RW_moreequ
3 Izquierda TK_plus, TK_minus
2 Izquierda TK_mult, TK_div, RW_mod
1 No Asociativa RW_pow
0 Derecha TK_uminus

Instalación JFlex y CUP

  • Descargar la JFlex: JFlex
  • Descargar la CUP: CUP
  • Incluir las librerías en el proyecto java.

Generación de Scanner

import java.io.File;
public class GScanner {
    public static void main(String[] args) {
        jflex.Main.generate(
            new File(
                "src/Language/Scanner.jflex"
            )
        );
    }
}

Generación de Parser

public class GParser {
    public static void main(String[] args) {
        generate();
    }
    public static void generate() {
        try {
            java_cup.Main.main(
                new String[] {
                    "-destdir",
                    "src/Language",
                    "-symbols",
                    "TOK",
                    "-parser",
                    "Parser",
                    "src/Language/Parser.cup"
                }
            );
        }
        catch(Exception e) {
            System.out.println(e);
        }
    }
}

Intérprete con JFlex y CUP

Usuario: brandonT2002
Repositorio: MiniJ

Intérprete con JavaCC

Usuario: bryan967132
Repositorio: MiniJInterpreter

Traductor a C3D con JFlex y CUP

Usuario: bryan967132
Repositorio: MiniJCompiler

pseudoparser's People

Contributors

bryan967132 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.