• Welcome to TUKE FÓRUM - Fórum pre študentov Technickej Univerzity v Košiciach.
 

Modelovanie a Generovanie Softverovych Architektur

Started by jaros51, 03.03.2009, 21:21:35

« predchdzajce - alie »

MKI

no kto tu hodi nejaky tutorial na to dvanste cviko bo skacem z okna asi :D
www.mki.sk Kvalitne a lacne TONERY :)

Ing. nemtom

brix will be shat

mrtvyhubar

Viditeľné škody na nábytku sú ťažko opraviteľné a kazia celkový vzhľad
bytu. Myslite na to pred tým než začnete búchať pesťou po stole kôli nefunkčnému zadaniu.
"Making new tables in real life is not as simple as CREATE TABLE in sql"

Ing. nemtom

kto mi vysvetli ako spravit 10. cviko? ale ziadne omacky ale priamo step by step, nemam cas lustit hadanky :D
brix will be shat

paly-sk

Quote from: Bc. nemtom on  10.05.2009, 16:53:36
kto mi vysvetli ako spravit 10. cviko? ale ziadne omacky ale priamo step by step, nemam cas lustit hadanky :D

snad ti napomoze cast mojej komunikaci so spoluziakom, ktory tomu tiez nie velmi rozumel:

startovaci symbol je Model
cize pojdes to triedy model a do konstruktora das @Range(minOccurs =1), kedze v ebnf je zapisane entity+ a to vyjadruje, ze model musi obsahovat aspon jednu entitu
tzn. ze konstruktor Model musi mat pred Entity[] entities anotaciu @Range(minOccurs = 1)
model by bol vyrieseny a ides hlbsie, kedze parametrom modelu je objekt typu Entity, tak ides do tej triedy
a teraz vidis, ze v ebnf je Entity rozpisana ako ako 'entity' <NAME> ...
to znamena ze pred konstruktor das anotaciu before a ako parameter je das ENTITY (ked si blizsie pozries ten subor package-info.java, tak tam su definovane lexikalne jednotky a pod tokenom ENTITY sa skryva entity)
a teraz v konstruktori prvy parameter je name, cize to uz bude @Token("NAME")
a potom ide 1 a viac properties
cize ked pozries ebnf, tak tam najprv vidis {
cize pred Property[] properties das @Before("LBR") a zaroven aj @After("RBR"), lebo zatvrokami koncia aj definovanie entity v ebnf
a este tam das @Range(minOccurs = 1), lebo entita musi mat aspon jednu property podla ebnf

Snad by ti to uz malo byt jasne. Teraz uvidis vyhodu vyuzitia tohto generatora oproti vlastnemu krkolomnemu parseru, ktory sme robili na zaciatku ;-)

Ked to budes mat cele, tak pozri subor grammar.ebnf a mal byt taky isty ako je v tom 10. cviku (niektore zatvorky si mozes odmysliet v tej vygenerovanej gramatike) a este to co je na stranke ako Entity+ budes mat vo svojej gramatike ako (Entity (Entity)*). Potom uz len staci 2-krat skompilovat a nasledne spustit a nezabudni pridat do konstruktora vytvorenie toho parsera ako je v 5. tej ulohe.

Ing. nemtom

thx, kuknem na to a ked to pojde podakujem zas :P zatial mozes hladat komunikaciu ohladom dalsieho cvika :D
brix will be shat

Ing. nemtom

brix will be shat

Raleon

Quote from: paly-sk on  10.05.2009, 18:09:32
startovaci symbol je Model
cize pojdes to triedy model a do konstruktora das @Range(minOccurs =1), kedze v ebnf je zapisane entity+ a to vyjadruje, ze model musi obsahovat aspon jednu entitu
tzn. ze konstruktor Model musi mat pred Entity[] entities anotaciu @Range(minOccurs = 1)
model by bol vyrieseny a ides hlbsie, kedze parametrom modelu je objekt typu Entity, tak ides do tej triedy
a teraz vidis, ze v ebnf je Entity rozpisana ako ako 'entity' <NAME> ...
to znamena ze pred konstruktor das anotaciu before a ako parameter je das ENTITY (ked si blizsie pozries ten subor package-info.java, tak tam su definovane lexikalne jednotky a pod tokenom ENTITY sa skryva entity)
a teraz v konstruktori prvy parameter je name, cize to uz bude @Token("NAME")
a potom ide 1 a viac properties
cize ked pozries ebnf, tak tam najprv vidis {
cize pred Property[] properties das @Before("LBR") a zaroven aj @After("RBR"), lebo zatvrokami koncia aj definovanie entity v ebnf
a este tam das @Range(minOccurs = 1), lebo entita musi mat aspon jednu property podla ebnf

Snad by ti to uz malo byt jasne. Teraz uvidis vyhodu vyuzitia tohto generatora oproti vlastnemu krkolomnemu parseru, ktory sme robili na zaciatku ;-)

Ked to budes mat cele, tak pozri subor grammar.ebnf a mal byt taky isty ako je v tom 10. cviku (niektore zatvorky si mozes odmysliet v tej vygenerovanej gramatike) a este to co je na stranke ako Entity+ budes mat vo svojej gramatike ako (Entity (Entity)*). Potom uz len staci 2-krat skompilovat a nasledne spustit a nezabudni pridat do konstruktora vytvorenie toho parsera ako je v 5. tej ulohe.

Hmm. diky, Tebou popisana cast aj ide.
Ale ako dalej annotovat property, atd.? bo uz tam mi netbeans neakceptuje tie tokeny, before alebo after, ...


There is no such bad temper that can not be fixed with some good wine.

paly-sk

    public Property(
            @Token("NAME") String name,
            @Before("COLON") Type type,
            @Separator("COMMA") Constraint[] constraints) {
        ...
    }

a zaroven treba anotavat aj enumeracny typ:

    public enum Type {
        @Token("INTEGER") INTEGER,
        @Token("REAL") REAL,
        @Token("STRING") STRING;
    }

Ing. nemtom

brix will be shat

Ing. nemtom

sk.tuke.magsa.parserext.javacc.Parser mate tam ten parser? lebo ja ne
brix will be shat

Raleon

Quote from: paly-sk on  10.05.2009, 22:02:13
    public Property(
            @Token("NAME") String name,
            @Before("COLON") Type type,
            @Separator("COMMA") Constraint[] constraints) {
        ...
    }

a zaroven treba anotavat aj enumeracny typ:

    public enum Type {
        @Token("INTEGER") INTEGER,
        @Token("REAL") REAL,
        @Token("STRING") STRING;
    }

Na token name pri property mi hodi netbeans chybu:
Incompatible types
found: org.javacc.parser.Token
required: java.lang.annotation.Annotation
a tak isto pri enumeracii :(


There is no such bad temper that can not be fixed with some good wine.

paly-sk

Quote from: Bc. nemtom on  10.05.2009, 22:10:25
ako zistim ze to mam dobre?
pozries si subor grammar.ebnf a porovnas ho s tym, co je v 10. cviku

Quote from: Bc. nemtom on  10.05.2009, 22:15:40
sk.tuke.magsa.parserext.javacc.Parser mate tam ten parser? lebo ja ne
ten parser ti nevygenerovalo, lebo mas nejaku chybu. ked si pozries ten stack trace pri exception, tak tam zistis, ze kde je chyba

paly-sk

Quote from: Raleon on  10.05.2009, 22:22:17
Na token name pri property mi hodi netbeans chybu:
Incompatible types
found: org.javacc.parser.Token
required: java.lang.annotation.Annotation
a tak isto pri enumeracii :(
oznacil si druhy konstruktor anotaciou @Exclude?

Raleon

Quote from: paly-sk on  10.05.2009, 22:31:39
Quote from: Raleon on  10.05.2009, 22:22:17
Na token name pri property mi hodi netbeans chybu:
Incompatible types
found: org.javacc.parser.Token
required: java.lang.annotation.Annotation
a tak isto pri enumeracii :(
oznacil si druhy konstruktor anotaciou @Exclude?

ano. Inak i to da do ebnf s |...

zaujimave, ze co vypluje ten onen, tak to vyzera takto ::
Entity ::= (<ENTITY> <NAME> (<LBR> (Property (Property)*) <RBR>))
Length ::= (<MIN_LENGTH> <MAX_LENGTH>)
Model ::= (Entity (Entity)*)
Property ::= (<NAME> (<COLON> Type) ((Constraint ((<COMMA> Constraint))*))?)

(to je len cast z toho / nemm tam normalne dvojbodku, ale tak blbo ze colon, atd)


Tu je kod property:
public class Property {

    private final String name;
    private Constraint[] constraints;

    public Property(@Token("NAME") String name ,@Before("COLON") Type type,  @Separator("COMMA") Constraint[] constraints)
    {
      this.name=name;
      this.type=type;
      this.constraints=constraints;
    }

    @Exclude
    public Property(String name, Type type) {
        this.name = name;
        this.type = type;
    }

    public Constraint[] getConstraints() {
        return constraints;
    }

    public void setConstraints(Constraint[] constraints) {
        this.constraints = constraints;
    }

    public enum Type {
        @Token("INTEGER") INTEGER, @Token("REAL") REAL, @Token("STRING") STRING;
    }
    private final Type type;



    public String getName() {
        return name;
    }

    public Type getType() {
        return type;
    }

    public <T extends Constraint> T getConstraint(Class<T> clazz) {
        if (constraints==null) return null;
        for (Constraint c : constraints) {
            if (c.getClass().getSimpleName().compareTo(clazz.getSimpleName()) == 0) {
                return (T) c;
            }
        }
        return null;
    }

    public boolean hasConstraint(Class<? extends Constraint> clazz) {
        if (constraints==null) return false;
        for (Constraint c : constraints) {
            if (c.getClass().getSimpleName().compareTo(clazz.getSimpleName()) == 0) {
                return true;
            }
        }
        return false;
    }

    @Override
    public String toString() {
        if (constraints != null) {
            return name + Arrays.asList(constraints);
        } else {
            return name;
        }
    }
}


Pri Clean and build  vypise toto:
init:
deps-clean:
Deleting directory E:\Thomass\Programming\Java\mags\build
clean:
init:
deps-jar:
Created dir: E:\Thomass\Programming\Java\mags\build\classes
Compiling 40 source files to E:\Thomass\Programming\Java\mags\build\classes
E:\Thomass\Programming\Java\mags\src\sk\tuke\magsa\parserext\Parser.java:4: package sk.tuke.magsa.parserext.javacc does not exist
  private static sk.tuke.magsa.parserext.javacc.Parser parser;
YAJCo parser generator 0.1
YAJCo: Generating output to 'file:/E:/Thomass/Programming/Java/mags/src/sk/tuke/magsa/parserext/javacc/grammar.jj'
Java Compiler Compiler Version 4.0 (Parser Generator)
(type "javacc" with no arguments for help)
Reading from file E:\Thomass\Programming\Java\mags\src\sk\tuke\magsa\parserext\javacc\grammar.jj . . .
org.javacc.parser.ParseException: Encountered ")" at line 70, column 3.
Was expecting one of:
    "LOOKAHEAD" ...
    "try" ...
    "(" ...
    "{" ...
    "[" ...
    "boolean" ...
    "char" ...
    "byte" ...
    "short" ...
    "int" ...
    "long" ...
    "float" ...
    "double" ...
    <IDENTIFIER> ...
    "+" ...
    "-" ...
    "++" ...
    "--" ...
    "~" ...
    "!" ...
    <INTEGER_LITERAL> ...
    <FLOATING_POINT_LITERAL> ...
    <CHARACTER_LITERAL> ...
    <STRING_LITERAL> ...
    "true" ...
    "false" ...
    "null" ...
    "this" ...
    "super" ...
    "new" ...
    "void" ...
    "options" ...
    "IGNORE_CASE" ...
    "PARSER_BEGIN" ...
    "PARSER_END" ...
    "JAVACODE" ...
    "TOKEN" ...
    "SPECIAL_TOKEN" ...
    "MORE" ...
    "SKIP" ...
    "TOKEN_MGR_DECLS" ...
    "EOF" ...
    "<" ...
   
Detected 1 errors and 0 warnings.
E:\Thomass\Programming\Java\mags\src\sk\tuke\magsa\parserext\Parser.java:4: package sk.tuke.magsa.parserext.javacc does not exist
  private static sk.tuke.magsa.parserext.javacc.Parser parser;
E:\Thomass\Programming\Java\mags\src\sk\tuke\magsa\parserext\Parser.java:12: package sk.tuke.magsa.parserext.javacc does not exist
      parser = new sk.tuke.magsa.parserext.javacc.Parser(reader);
E:\Thomass\Programming\Java\mags\src\sk\tuke\magsa\parserext\Parser.java:14: package sk.tuke.magsa.parserext.javacc does not exist
      sk.tuke.magsa.parserext.javacc.Parser.ReInit(reader);
E:\Thomass\Programming\Java\mags\src\sk\tuke\magsa\parserext\Parser.java:18: package sk.tuke.magsa.parserext.javacc does not exist
      sk.tuke.magsa.metamodel.Model root = sk.tuke.magsa.parserext.javacc.Parser.parse();
E:\Thomass\Programming\Java\mags\src\sk\tuke\magsa\parserext\Parser.java:21: package sk.tuke.magsa.parserext.javacc does not exist
    } catch (sk.tuke.magsa.parserext.javacc.ParseException e) {
Note: E:\Thomass\Programming\Java\mags\src\sk\tuke\magsa\metamodel\Property.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
5 errors
BUILD FAILED (total time: 0 seconds)


There is no such bad temper that can not be fixed with some good wine.

hlsman

Raleon podla mna si importol zly Token preto ti to nesedi..
import tuke.pargen.annotation.Token;

Raleon

Quote from: hlsman on  10.05.2009, 22:47:51
Raleon podla mna si importol zly Token preto ti to nesedi..
import tuke.pargen.annotation.Token;
Sakra. Ano.  :embarassed:
Uz ten token berie...
Ale i tak hodi build tie iste chyby, a stale pise COLON namiesto :    (atd)

(aha, moze byt ze preto , lebo este constraints som nepoannotoval ?)


There is no such bad temper that can not be fixed with some good wine.

paly-sk

Quote from: Raleon on  10.05.2009, 22:52:16
Quote from: hlsman on  10.05.2009, 22:47:51
Raleon podla mna si importol zly Token preto ti to nesedi..
import tuke.pargen.annotation.Token;
Sakra. Ano.  :embarassed:
Uz ten token berie...
Ale i tak hodi build tie iste chyby, a stale pise COLON namiesto :    (atd)

(aha, moze byt ze preto , lebo este constraints som nepoannotoval ?)
COLON je v pohode, lebo tie lexikalne jednotky az potom nahradi, cize je to OK
skus to skompilovat s parametrom -Xlint:unchecked

hlsman

a este taka finta f, v tom nbproject/project.property ako sa pridavaju tie javac argumenty..
mne to nechcelo brat ten $basedir pretoze obsahoval medzeri a tak mi rozparsovalo jeden argument na viacero.. treba dat do uvodzoviek.

Raleon

Quote from: paly-sk on  10.05.2009, 23:01:15
Quote from: Raleon on  10.05.2009, 22:52:16
Quote from: hlsman on  10.05.2009, 22:47:51
Raleon podla mna si importol zly Token preto ti to nesedi..
import tuke.pargen.annotation.Token;
Sakra. Ano.  :embarassed:
Uz ten token berie...
Ale i tak hodi build tie iste chyby, a stale pise COLON namiesto :    (atd)

(aha, moze byt ze preto , lebo este constraints som nepoannotoval ?)
COLON je v pohode, lebo tie lexikalne jednotky az potom nahradi, cize je to OK
skus to skompilovat s parametrom -Xlint:unchecked
vyskusam...
Aha, po popisani vsetkych constraints uz chyba neni.. len taky cudny warning, ale vypluje aj nejake java subory..
Diky za pomoc.


There is no such bad temper that can not be fixed with some good wine.

Raleon

Model.el  zkade zozeniem ?
(ak treba pisat, tak ako :) )


There is no such bad temper that can not be fixed with some good wine.

Ing. nemtom

tu mam gramatiku, priamo z grammar.ebnf, este to je teple


Constraint ::= (Regex | StringOptions | Range | Length | Required)
Entity ::= (<ENTITY> <STRING_VALUE> (<LBR> (Property (Property)*) <RBR>))
Length ::= (<LENGTH> <INT_VALUE> <INT_VALUE>)
Model ::= (Entity (Entity)*)
Property ::= (<NAME> (<COLON> Type) ((Constraint ((<COMMA> Constraint))*))?)
Range ::= (<RANGE> <INT_VALUE> <INT_VALUE>)
Regex ::= (<REGEX> <STRING_VALUE>)
Required ::= <REQUIRED>
StringOptions ::= (<STROPTIONS> (<STRING_VALUE> (<STRING_VALUE>)*))
Type ::= (<INTEGER> | <REAL> | <STRING>)


a tu mam model.el, tiez este teple


entity Student {
meno : string
}


malo by to zhltnut nie? bo nekce :(
brix will be shat

Ing. nemtom

aha uz viiiiiim, hlsman mi pomohol aj ked o tom nevedel :D v Entity nema byt STRING_VALUE ale NAME
brix will be shat

Raleon

Quote from: Bc. nemtom on  11.05.2009, 00:09:30
...

entity Student {
meno : string
}


malo by to zhltnut nie? bo nekce :(

Thanx for inspiration...


There is no such bad temper that can not be fixed with some good wine.

Raleon



There is no such bad temper that can not be fixed with some good wine.